如何运行
核心源码如下
package main
import (
"github.com/hajimehoshi/ebiten"
"image/color"
"math"
)
type Game struct {
circles []Circle
}
func (g *Game) Update(screen *ebiten.Image) error {
for i := range g.circles {
g.circles[i].x += g.circles[i].speed * math.Cos(g.circles[i].direction)
g.circles[i].y += g.circles[i].speed * math.Sin(g.circles[i].direction)
if g.circles[i].x <= 0 || g.circles[i].y <= 0 || g.circles[i].x >= screenWidth || g.circles[i].y >= screenHeight {
g.circles[i].direction += math.Pi
}
}
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
for _, circle := range g.circles {
drawCircle(screen, circle.x, circle.y, circleRadius, color.White)
}
}
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
return screenWidth, screenHeight
}