Now there's healing potions distributed and you can pick them up to heal.

master
Zed A. Shaw 1 month ago
parent 0ea41bf059
commit 0e3097a125
  1. 6
      05_Bigger/combat.go
  2. 8
      05_Bigger/data.go
  3. 42
      05_Bigger/game.go
  4. 4
      05_Bigger/map.go
  5. 11
      05_Bigger/maze.go
  6. 4
      05_Bigger/ui.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)
}
}

@ -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
}

@ -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)
}

@ -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) {

@ -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)
}

@ -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()
}

Loading…
Cancel
Save