From 0e3097a125bbe95db7f12b659defd80219dc06ec Mon Sep 17 00:00:00 2001 From: Zed Date: Fri, 17 Oct 2025 00:55:12 -0400 Subject: [PATCH] Now there's healing potions distributed and you can pick them up to heal. --- 05_Bigger/combat.go | 6 +++++- 05_Bigger/data.go | 8 +++++--- 05_Bigger/game.go | 42 +++++++++++++++++++++++++++++++++++++++--- 05_Bigger/map.go | 4 ++-- 05_Bigger/maze.go | 11 ----------- 05_Bigger/ui.go | 4 ++++ 6 files changed, 55 insertions(+), 20 deletions(-) diff --git a/05_Bigger/combat.go b/05_Bigger/combat.go index 1d326c5..dc4b1e4 100644 --- a/05_Bigger/combat.go +++ b/05_Bigger/combat.go @@ -19,7 +19,7 @@ func (game *Game) EnemyDeath() { } } -func (game *Game) ApplyDamage(attacker *Enemy, defender *Enemy) { +func (game *Game) ApplyDamage(attacker *Thing, defender *Thing) { damage := rand.Int() % attacker.Damage defender.HP -= damage if damage == 0 { @@ -33,9 +33,13 @@ func (game *Game) ApplyDamage(attacker *Enemy, defender *Enemy) { func (game *Game) Attack(target Position) { enemy, hit_enemy := game.Enemies[target] + loot, hit_loot := game.Loot[target] if hit_enemy { game.ApplyDamage(&game.Player, enemy) game.ApplyDamage(enemy, &game.Player) + } else if hit_loot { + game.Player.HP += loot.Healing + delete(game.Loot, target) } } diff --git a/05_Bigger/data.go b/05_Bigger/data.go index 928bca9..065883d 100644 --- a/05_Bigger/data.go +++ b/05_Bigger/data.go @@ -22,19 +22,21 @@ type Position struct { Y int } -type Enemy struct { +type Thing struct { HP int Pos Position Damage int + Healing int } type Game struct { Screen tcell.Screen Level Map Paths Paths - Player Enemy + Player Thing Status string Width int Height int - Enemies map[Position]*Enemy + Enemies map[Position]*Thing + Loot map[Position]*Thing } diff --git a/05_Bigger/game.go b/05_Bigger/game.go index df700ac..e519cc5 100644 --- a/05_Bigger/game.go +++ b/05_Bigger/game.go @@ -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) +} diff --git a/05_Bigger/map.go b/05_Bigger/map.go index a98a02f..39a4ca6 100644 --- a/05_Bigger/map.go +++ b/05_Bigger/map.go @@ -34,13 +34,13 @@ func (game *Game) Inbounds(pos Position, offset int) bool { func (game *Game) Occupied(pos Position) bool { _, is_enemy := game.Enemies[pos] + _, is_loot := game.Loot[pos] is_player := pos == game.Player.Pos // Inbounds comes first to prevent accessing level with bad x,y return !game.Inbounds(pos, 1) || game.Level[pos.Y][pos.X] == WALL || - is_enemy || - is_player + is_enemy || is_loot || is_player } func (game *Game) FillMap(target Map, setting rune) { diff --git a/05_Bigger/maze.go b/05_Bigger/maze.go index 9ed6a59..b750017 100644 --- a/05_Bigger/maze.go +++ b/05_Bigger/maze.go @@ -105,14 +105,3 @@ func (game *Game) AddRooms(dead_ends []Position) []Position { return dead_ends } - -func (game *Game) WorldGenerator() { - game.NewMap() - dead_ends := game.NewMaze() - game.NewMap() - - room_pos := game.AddRooms(dead_ends) - dead_ends = game.NewMaze() - - game.PlaceEnemies(room_pos) -} diff --git a/05_Bigger/ui.go b/05_Bigger/ui.go index 2b12957..ac952c9 100644 --- a/05_Bigger/ui.go +++ b/05_Bigger/ui.go @@ -77,6 +77,10 @@ func (game *Game) Render() { game.DrawEntity('G', pos, tcell.ColorRed) } + for pos, _ := range game.Loot { + game.DrawEntity('!', pos, tcell.ColorGreen) + } + game.DrawStatus() game.Screen.Show() }