Flip image each turn
This commit is contained in:
		
							parent
							
								
									72da5d3afd
								
							
						
					
					
						commit
						2c6018755f
					
				@ -99,11 +99,19 @@ func (b *Board) Image() *image.RGBA {
 | 
			
		||||
 | 
			
		||||
			piece = b.tiles[xi][yi]
 | 
			
		||||
			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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -649,3 +657,17 @@ func getTileColor(x, y int) Color {
 | 
			
		||||
		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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user