Zombie and health bar
This commit is contained in:
21
main.go
21
main.go
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user