Created
February 22, 2024 10:07
-
-
Save plutov/be16a70d6f517e0fe5e81089ca1edad8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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