Flip image each turn

This commit is contained in:
ekzyis 2024-09-23 06:25:23 +02:00
parent 72da5d3afd
commit 2c6018755f
1 changed files with 23 additions and 1 deletions

View File

@ -99,11 +99,19 @@ func (b *Board) Image() *image.RGBA {
piece = b.tiles[xi][yi] piece = b.tiles[xi][yi]
if piece != nil { if piece != nil {
draw.Draw(img, rect, piece.Image, p, draw.Over) pieceImg := piece.Image
if b.turn == Dark {
pieceImg = flipImage(pieceImg)
}
draw.Draw(img, rect, pieceImg, p, draw.Over)
} }
} }
} }
if b.turn == Dark {
return flipImage(img)
}
return img return img
} }
@ -649,3 +657,17 @@ func getTileColor(x, y int) Color {
return Dark return Dark
} }
} }
func flipImage(img image.Image) *image.RGBA {
bounds := img.Bounds()
flipped := image.NewRGBA(bounds)
// Flip the image vertically by reversing the Y coordinate
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
flipped.Set(x, bounds.Max.Y-y-1, img.At(x, y))
}
}
return flipped
}