148 lines
3.8 KiB
Go
148 lines
3.8 KiB
Go
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"image/color"
|
||
|
|
"loading/character"
|
||
|
|
"loading/objects"
|
||
|
|
"math"
|
||
|
|
|
||
|
|
"github.com/hajimehoshi/ebiten/v2"
|
||
|
|
"github.com/hajimehoshi/ebiten/v2/text"
|
||
|
|
"github.com/hajimehoshi/ebiten/v2/vector"
|
||
|
|
)
|
||
|
|
|
||
|
|
func DrawBobble(b objects.Bobble, image *ebiten.Image) {
|
||
|
|
|
||
|
|
if b.Radius < 0 {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
vector.DrawFilledCircle(image, b.Pose.X, b.Pose.Y, b.Radius+10, b.Bordercolor, true)
|
||
|
|
vector.DrawFilledCircle(image, b.Pose.X, b.Pose.Y, b.Radius, b.Color, true)
|
||
|
|
}
|
||
|
|
|
||
|
|
func DrawCharacter(c character.Character, image *ebiten.Image) {
|
||
|
|
|
||
|
|
if len(c.Shape) <= 0 {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
var path vector.Path
|
||
|
|
path.MoveTo(c.Pose.X, c.Pose.Y)
|
||
|
|
for _, p := range c.Shape {
|
||
|
|
|
||
|
|
//rotation time *dance*
|
||
|
|
newX := c.Pose.X + float32(math.Cos(float64(c.Angle)))*(p.X) - float32(math.Sin(float64(c.Angle)))*(p.Y)
|
||
|
|
newY := c.Pose.Y + float32(math.Sin(float64(c.Angle)))*(p.X) + float32(math.Cos(float64(c.Angle)))*(p.Y)
|
||
|
|
path.LineTo(newX, newY)
|
||
|
|
}
|
||
|
|
path.Close()
|
||
|
|
|
||
|
|
var vs []ebiten.Vertex
|
||
|
|
var is []uint16
|
||
|
|
|
||
|
|
vs, is = path.AppendVerticesAndIndicesForFilling(nil, nil)
|
||
|
|
|
||
|
|
for i := range vs {
|
||
|
|
vs[i].SrcX = 1
|
||
|
|
vs[i].SrcY = 1
|
||
|
|
vs[i].ColorR = float32(c.Color.R) / 0xFF
|
||
|
|
vs[i].ColorG = float32(c.Color.B) / 0xFF
|
||
|
|
vs[i].ColorB = float32(c.Color.G) / 0xFF
|
||
|
|
vs[i].ColorA = 1
|
||
|
|
}
|
||
|
|
|
||
|
|
op := &ebiten.DrawTrianglesOptions{}
|
||
|
|
|
||
|
|
//pose information
|
||
|
|
//angle := fmt.Sprintf("%.2f", c.Angle*180/math.Pi)
|
||
|
|
//delta := fmt.Sprintf("%.2f", c.DeltaAngle*180/math.Pi)
|
||
|
|
|
||
|
|
//text.Draw(image, angle, mplusTinyFont, int(c.Pose.X+20), int(c.Pose.Y), color.White)
|
||
|
|
//text.Draw(image, delta, mplusTinyFont, int(c.Pose.X+20), int(c.Pose.Y+15), color.White)
|
||
|
|
|
||
|
|
image.DrawTriangles(vs, is, whiteSubImage, op)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (g *Game) DrawLoading(image *ebiten.Image) {
|
||
|
|
|
||
|
|
//identifier
|
||
|
|
text.Draw(image, versionInfo, mplusTinyFont, 20, 60, color.White)
|
||
|
|
|
||
|
|
//radial
|
||
|
|
var xs []int
|
||
|
|
var ys []int
|
||
|
|
var tc []uint8
|
||
|
|
var scales []float32
|
||
|
|
|
||
|
|
fade_scale := 0xFF / numTiles
|
||
|
|
|
||
|
|
for i := 0; i < numTiles; i++ {
|
||
|
|
xs = append(xs, int(math.Cos(float64(g.counter)/(math.Pi*3)-float64(i)*math.Pi/3)*40+screenWidth/2-float64(tileWidth)/2))
|
||
|
|
ys = append(ys, int(math.Sin(float64(g.counter)/(math.Pi*3)-float64(i)*math.Pi/3)*40+screenHeight/2-float64(tileHeight)/2))
|
||
|
|
tc = append(tc, uint8(0xFF-fade_scale*i))
|
||
|
|
|
||
|
|
scales = append(scales, float32(math.Sin(float64(g.counter)/(math.Pi*12))/2+1))
|
||
|
|
}
|
||
|
|
|
||
|
|
for i := numTiles - 1; i >= 0; i-- {
|
||
|
|
drawTile(image, float32(xs[i]), float32(ys[i]), scales[i], color.RGBA{tc[i], tc[i], tc[i], 0xFF})
|
||
|
|
}
|
||
|
|
|
||
|
|
//Percentage >:]
|
||
|
|
//percent := (maxPercent - 1/math.Exp(float64(g.counter-1)-10/6)) / maxPercent
|
||
|
|
offset := float64(4.605)
|
||
|
|
exppart0 := float64(g.counter-1) / 10000
|
||
|
|
|
||
|
|
percent := maxPercent - 1/math.Exp(exppart0-offset)
|
||
|
|
if percent < 0 {
|
||
|
|
percent = 0
|
||
|
|
}
|
||
|
|
|
||
|
|
//100-1/e^(x/1000 - 4.6)
|
||
|
|
|
||
|
|
text.Draw(image, fmt.Sprintf("%.2f%%", percent), mplusTinyFont, screenWidth/2-70/2, screenHeight-80, color.RGBA{0xC0, 0xC0, 0xC0, 0xC0})
|
||
|
|
}
|
||
|
|
|
||
|
|
func drawTile(screen *ebiten.Image, x float32, y float32, scale float32, c color.RGBA) {
|
||
|
|
var scaleFactor float32 = 1
|
||
|
|
if scale > 0 {
|
||
|
|
scaleFactor = scale
|
||
|
|
}
|
||
|
|
drawTileToScale(screen, x, y, scaleFactor, c)
|
||
|
|
}
|
||
|
|
|
||
|
|
func drawTileToScale(screen *ebiten.Image, x float32, y float32, scale float32, c color.RGBA) {
|
||
|
|
|
||
|
|
var path vector.Path
|
||
|
|
|
||
|
|
//scale delta
|
||
|
|
xd := tileWidth * scale
|
||
|
|
yd := tileHeight * scale
|
||
|
|
|
||
|
|
//position at object origin shifted slightly for the half width/height adjustment
|
||
|
|
path.MoveTo(x-xd/2, y-yd/2)
|
||
|
|
path.LineTo(x+xd/2, y-yd/2)
|
||
|
|
path.LineTo(x+xd/2, y+yd/2)
|
||
|
|
path.LineTo(x-xd/2, y+yd/2)
|
||
|
|
path.LineTo(x-xd/2, y+yd/2)
|
||
|
|
path.Close()
|
||
|
|
|
||
|
|
var vs []ebiten.Vertex
|
||
|
|
var is []uint16
|
||
|
|
|
||
|
|
vs, is = path.AppendVerticesAndIndicesForFilling(nil, nil)
|
||
|
|
|
||
|
|
for i := range vs {
|
||
|
|
vs[i].SrcX = 1
|
||
|
|
vs[i].SrcY = 1
|
||
|
|
vs[i].ColorR = float32(c.R) / 0xFF
|
||
|
|
vs[i].ColorG = float32(c.B) / 0xFF
|
||
|
|
vs[i].ColorB = float32(c.G) / 0xFF
|
||
|
|
vs[i].ColorA = 1
|
||
|
|
}
|
||
|
|
|
||
|
|
op := &ebiten.DrawTrianglesOptions{}
|
||
|
|
screen.DrawTriangles(vs, is, whiteSubImage, op)
|
||
|
|
}
|