Skip to content

Instantly share code, notes, and snippets.

@plutov
Created February 22, 2024 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plutov/be16a70d6f517e0fe5e81089ca1edad8 to your computer and use it in GitHub Desktop.
Save plutov/be16a70d6f517e0fe5e81089ca1edad8 to your computer and use it in GitHub Desktop.
// ...
var (
backgroundColor = color.RGBA{50, 100, 50, 50}
snakeColor = color.RGBA{200, 50, 150, 150}
foodColor = color.RGBA{200, 200, 50, 150}
)
type Game struct {
input *Input
board *Board
}
func NewGame() *Game {
return &Game{
input: NewInput(),
board: NewBoard(boardRows, boardCols),
}
}
func (g *Game) Update() error {
return g.board.Update(g.input)
}
func (g *Game) Draw(screen *ebiten.Image) {
screen.Fill(backgroundColor)
if g.board.gameOver {
ebitenutil.DebugPrint(screen, fmt.Sprintf("Game Over. Score: %d", g.board.points))
} else {
width := ScreenHeight / boardRows
for _, p := range g.board.snake.body {
ebitenutil.DrawRect(screen, float64(p.y*width), float64(p.x*width), float64(width), float64(width), snakeColor)
}
if g.board.food != nil {
ebitenutil.DrawRect(screen, float64(g.board.food.y*width), float64(g.board.food.x*width), float64(width), float64(width), foodColor)
}
ebitenutil.DebugPrint(screen, fmt.Sprintf("Score: %d", g.board.points))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment