53 lines
874 B
Go
53 lines
874 B
Go
package world
|
|
|
|
import (
|
|
"pacman/engine/render"
|
|
"pacman/game/assets"
|
|
)
|
|
|
|
const (
|
|
MAZE_WIDTH = render.WIDTH / render.TileSize
|
|
MAZE_HEIGHT = render.HEIGHT / render.TileSize
|
|
)
|
|
|
|
type Maze [MAZE_WIDTH * MAZE_HEIGHT]assets.Tile
|
|
|
|
// Create a new maze and load data.
|
|
func NewMaze(data []byte) Maze {
|
|
m := Maze{}
|
|
m.Load(data)
|
|
return m
|
|
}
|
|
|
|
// Load data into maze.
|
|
func (m *Maze) Load(data []byte) {
|
|
n_bytes := m.readMaze(data)
|
|
|
|
for i := n_bytes; i < len(m); i++ {
|
|
m[i] = 0
|
|
}
|
|
}
|
|
|
|
// Read maze data.
|
|
func (m *Maze) readMaze(data []byte) int {
|
|
i := 0
|
|
for _, x := range data {
|
|
if x == '\n' {
|
|
continue
|
|
}
|
|
m[i] = assets.Tile(x)
|
|
i++
|
|
if i >= len(m) {
|
|
break
|
|
}
|
|
}
|
|
return i
|
|
}
|
|
|
|
func (m Maze) At(x, y uint8) assets.Tile {
|
|
return m[uint16(x)+(uint16(y)*MAZE_WIDTH)]
|
|
}
|
|
|
|
func (m *Maze) Set(x, y uint8, value assets.Tile) {
|
|
m[uint16(x)+(uint16(y)*MAZE_WIDTH)] = value
|
|
}
|