Bug fix: rects

This commit is contained in:
Hajime Hoshi 2013-11-29 23:18:44 +09:00
parent 89c33eac85
commit 7c91b03678

View File

@ -47,13 +47,29 @@ func (game *Rects) InitTextures(tf graphics.TextureFactory) {
} }
} }
func min(a, b int) int {
if a < b {
return a
}
return b
}
func abs(a int) int {
if a < 0 {
return -a
}
return a
}
func (game *Rects) Update(context ebiten.GameContext) { func (game *Rects) Update(context ebiten.GameContext) {
game.rectBounds.X = rand.Intn(context.ScreenWidth()) x1 := rand.Intn(context.ScreenWidth())
game.rectBounds.Y = rand.Intn(context.ScreenHeight()) x2 := rand.Intn(context.ScreenWidth())
game.rectBounds.Width = y1 := rand.Intn(context.ScreenHeight())
rand.Intn(context.ScreenWidth()-game.rectBounds.X) + 1 y2 := rand.Intn(context.ScreenHeight())
game.rectBounds.Height = game.rectBounds.X = min(x1, x2)
rand.Intn(context.ScreenHeight()-game.rectBounds.Y) + 1 game.rectBounds.Y = min(y1, y2)
game.rectBounds.Width = abs(x1 - x2)
game.rectBounds.Height = abs(y1 - y2)
game.rectColor.R = uint8(rand.Intn(math.MaxUint8)) game.rectColor.R = uint8(rand.Intn(math.MaxUint8))
game.rectColor.G = uint8(rand.Intn(math.MaxUint8)) game.rectColor.G = uint8(rand.Intn(math.MaxUint8))