|
|
|
|
@ -14,10 +14,11 @@ func NewGame(width int, height int) (*Game) { |
|
|
|
|
|
|
|
|
|
game.Width = width |
|
|
|
|
game.Height = height |
|
|
|
|
game.Enemies = make(map[Position]*Enemy) |
|
|
|
|
game.Enemies = make(map[Position]*Thing) |
|
|
|
|
game.Loot = make(map[Position]*Thing) |
|
|
|
|
game.Level = make(Map, height, height) |
|
|
|
|
game.Paths = make(Paths, height, height) |
|
|
|
|
game.Player = Enemy{20, Position{1,1}, 4} |
|
|
|
|
game.Player = Thing{20, Position{1,1}, 4, 0} |
|
|
|
|
|
|
|
|
|
return &game |
|
|
|
|
} |
|
|
|
|
@ -33,7 +34,21 @@ func (game *Game) Exit() { |
|
|
|
|
func (game *Game) PlaceEnemies(places []Position) { |
|
|
|
|
for _, pos := range places { |
|
|
|
|
if rand.Int() % 2 == 0 { |
|
|
|
|
game.Enemies[pos] = &Enemy{10, pos, 4} |
|
|
|
|
enemy := new(Thing) |
|
|
|
|
enemy.HP = 10 |
|
|
|
|
enemy.Pos = pos |
|
|
|
|
enemy.Damage = 4 |
|
|
|
|
game.Enemies[pos] = enemy |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (game *Game) PlaceLoot(places []Position) { |
|
|
|
|
for _, pos := range places { |
|
|
|
|
if !game.Occupied(pos) { |
|
|
|
|
loot := new(Thing) |
|
|
|
|
loot.Healing = 10 |
|
|
|
|
game.Loot[pos] = loot |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -48,3 +63,24 @@ func (game *Game) Restart() { |
|
|
|
|
game.NewMap() |
|
|
|
|
game.Render() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (game *Game) WorldGenerator() { |
|
|
|
|
// clear the map to all '#'
|
|
|
|
|
game.NewMap() |
|
|
|
|
|
|
|
|
|
// first generate a maze to get dead ends
|
|
|
|
|
dead_ends := game.NewMaze() |
|
|
|
|
|
|
|
|
|
// this clears the previous map
|
|
|
|
|
game.NewMap() |
|
|
|
|
|
|
|
|
|
// then use the dead_ends to create rooms
|
|
|
|
|
room_pos := game.AddRooms(dead_ends) |
|
|
|
|
|
|
|
|
|
// re-run the maze gen, and it'll work around the rooms
|
|
|
|
|
dead_ends = game.NewMaze() |
|
|
|
|
|
|
|
|
|
// finally place enemies inside the rooms
|
|
|
|
|
game.PlaceEnemies(room_pos) |
|
|
|
|
game.PlaceLoot(room_pos) |
|
|
|
|
} |
|
|
|
|
|