Move tile drawing into game renderer
This commit is contained in:
parent
8a33bb68aa
commit
b61b01a4aa
2 changed files with 10 additions and 10 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package renderer
|
||||
|
||||
import (
|
||||
"pacman/engine/render"
|
||||
"pacman/game/world"
|
||||
)
|
||||
|
||||
|
|
@ -9,7 +8,7 @@ import (
|
|||
func DrawMaze(maze *world.Maze, x, y uint8) {
|
||||
for tile_x := range uint8(world.MAZE_WIDTH) {
|
||||
for tile_y := range uint8(world.MAZE_HEIGHT) {
|
||||
render.DrawTile(x+tile_x, y+tile_y, maze.At(tile_x, tile_y))
|
||||
DrawTile(x+tile_x, y+tile_y, maze.At(tile_x, tile_y))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
47
game/renderer/tile.go
Normal file
47
game/renderer/tile.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package renderer
|
||||
|
||||
import (
|
||||
"pacman/engine/render"
|
||||
"pacman/game/assets"
|
||||
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
// DrawTile draws a single tile at the specified tile coordinates (x, y).
|
||||
//
|
||||
// The coordinates are in tile space, not pixels. The top-left tile is (0, 0),
|
||||
// and the bottom-right is (27, 35) given the fixed resolution and tile size.
|
||||
//
|
||||
// The appearance of the tile is determined by the provided assets.Tile value.
|
||||
func DrawTile(x, y uint8, tile assets.Tile) {
|
||||
px := int32(x) * render.TileSize
|
||||
py := int32(y) * render.TileSize
|
||||
|
||||
// For now, just draw simple circles and rectangles.
|
||||
switch tile {
|
||||
case assets.TILE_PACMAN:
|
||||
drawPacman(px, py)
|
||||
case assets.TILE_BLINKY:
|
||||
drawGhost(px, py, rl.Red)
|
||||
case assets.TILE_PINKY:
|
||||
drawGhost(px, py, rl.Pink)
|
||||
case assets.TILE_INKY:
|
||||
drawGhost(px, py, rl.Blue)
|
||||
case assets.TILE_CLYDE:
|
||||
drawGhost(px, py, rl.Orange)
|
||||
case assets.TILE_PELLET:
|
||||
rl.DrawCircle(px+(render.TileSize/2), py+(render.TileSize/2), 1, rl.Beige)
|
||||
case assets.TILE_POWER_PELLET:
|
||||
rl.DrawCircle(px+(render.TileSize/2), py+(render.TileSize/2), 2, rl.Beige)
|
||||
case assets.TILE_WALL:
|
||||
rl.DrawRectangle(px, py, render.TileSize, render.TileSize, rl.DarkBlue)
|
||||
}
|
||||
}
|
||||
|
||||
func drawGhost(x, y int32, col rl.Color) {
|
||||
rl.DrawCircle(x+(render.TileSize/2), y+(render.TileSize/2), 3, col)
|
||||
}
|
||||
|
||||
func drawPacman(x, y int32) {
|
||||
rl.DrawCircle(x+(render.TileSize/2), y+(render.TileSize/2), 3, rl.Yellow)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue