Zombie and health bar

This commit is contained in:
2023-11-30 14:49:01 +01:00
parent 9ea4c3beb2
commit c5b8fc40cb
10 changed files with 188 additions and 10 deletions

21
main.go
View File

@@ -7,6 +7,7 @@ import (
"gitlab.com/kbr4/9heroja/hero"
"gitlab.com/kbr4/9heroja/input"
"gitlab.com/kbr4/9heroja/terrain"
"gitlab.com/kbr4/9heroja/zombie"
_ "image/png"
"log"
)
@@ -49,6 +50,7 @@ type Game struct {
hero *hero.Hero
terrain *terrain.Terrain
zombies []*zombie.Zombie
}
func (g *Game) Update() error {
@@ -67,6 +69,11 @@ func (g *Game) Update() error {
func (g *Game) Draw(screen *ebiten.Image) {
g.terrain.DrawTerrain(screen)
g.hero.DrawHero(screen)
for _, z := range g.zombies {
z.OffsetX = g.terrain.PositionX
z.OffsetY = g.terrain.PositionY
z.DrawZombie(screen)
}
}
func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
@@ -81,7 +88,21 @@ func init() {
GameInstance = &Game{}
GameInstance.control = &input.Keyboard{}
GameInstance.hero = hero.NewHero()
GameInstance.zombies = []*zombie.Zombie{zombie.NewZombie(), zombie.NewZombie(), zombie.NewZombie(), zombie.NewZombie(), zombie.NewZombie()}
// put zombies in random places on the screen but not too close to the hero or each other
for _, z := range GameInstance.zombies {
z.X = float64(configuration.Random(50, screenWidth-50))
z.Y = float64(configuration.Random(50, screenHeight-50))
for z.X > float64(screenWidth/2-64) && z.X < float64(screenWidth/2+64) && z.Y > float64(screenHeight/2-64) && z.Y < float64(screenHeight/2+64) {
z.X = float64(configuration.Random(0, screenWidth))
z.Y = float64(configuration.Random(0, screenHeight))
}
z.Walk()
}
GameInstance.terrain = terrain.NewTerrain()
GameInstance.hero.ChangeDirection(configuration.North)
GameInstance.terrain.ChangeDirection(configuration.North)
GameInstance.hero.Walk()