Fixed health bar positioning. Added fireball sfx.
This commit is contained in:
@@ -68,12 +68,11 @@ func (c *Canvas) Update() error {
|
||||
if !c.initialized {
|
||||
c.Initialize()
|
||||
} else {
|
||||
//update positions()
|
||||
//hero first
|
||||
c.UpdateHero()
|
||||
c.UpdateProjectiles()
|
||||
c.UpdateCharge()
|
||||
c.UpdateEnemies()
|
||||
c.SpawnEnemies()
|
||||
c.CleanupTargets()
|
||||
c.counter++
|
||||
}
|
||||
@@ -100,6 +99,7 @@ func (c *Canvas) Draw(drawimg *ebiten.Image) {
|
||||
c.Sprite.DrawImage(assets.ImageBank[assets.Weapon], op)
|
||||
}
|
||||
|
||||
//draw enemy shadows
|
||||
for _, es := range c.enemies {
|
||||
if es.GetEnemyState() < gamedata.EnemyStateExploding {
|
||||
|
||||
@@ -116,6 +116,7 @@ func (c *Canvas) Draw(drawimg *ebiten.Image) {
|
||||
}
|
||||
}
|
||||
|
||||
//draw enemies
|
||||
for _, e := range c.enemies {
|
||||
e.Draw()
|
||||
|
||||
@@ -127,13 +128,15 @@ func (c *Canvas) Draw(drawimg *ebiten.Image) {
|
||||
op.GeoM.Rotate(e.GetAngle())
|
||||
op.GeoM.Translate(e.GetPosition().X, e.GetPosition().Y)
|
||||
|
||||
//op := &ebiten.DrawImageOptions{}
|
||||
//op.GeoM.Translate(e.GetPosition().X-float64(e.GetSprite().Bounds().Dx())/2, e.GetPosition().Y-float64(e.GetSprite().Bounds().Dy())/2)
|
||||
c.Sprite.DrawImage(e.GetSprite(), op)
|
||||
|
||||
//do we need a health bar for this enemy?
|
||||
if e.Health() > 0 {
|
||||
x0 := e.GetPosition().X - float64(e.GetSprite().Bounds().Dx())
|
||||
|
||||
hbWidth := float64(e.MaxHealth())*2 + 4
|
||||
p1 := float64(e.GetSprite().Bounds().Dx())
|
||||
p0 := e.GetPosition().X - p1/2
|
||||
x0 := p0 - (hbWidth-p1)/2
|
||||
y0 := e.GetPosition().Y - 2/3.*float64(e.GetSprite().Bounds().Dy())
|
||||
vector.DrawFilledRect(c.Sprite, float32(x0), float32(y0), float32(e.MaxHealth())*2+4, 12, color.Black, true)
|
||||
vector.DrawFilledRect(c.Sprite, float32(x0+2), float32(y0+2), float32(e.Health())*2, 8, color.RGBA{R: 0xff, G: 0x00, B: 0x00, A: 0xff}, true)
|
||||
@@ -165,7 +168,6 @@ func (c *Canvas) Draw(drawimg *ebiten.Image) {
|
||||
text.Draw(c.Sprite, "PRESS START TO TRY AGAIN", fonts.SurviveFont.Arcade, 640/2-150, 480/2, color.White)
|
||||
}
|
||||
|
||||
//op := &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Reset()
|
||||
drawimg.DrawImage(c.Sprite, op)
|
||||
}
|
||||
@@ -293,16 +295,9 @@ func (c *Canvas) UpdateProjectiles() {
|
||||
c.collisionMask.DrawImage(e.GetSprite(), op)
|
||||
|
||||
if c.HasCollided(c.collisionMask, 640*480*4) {
|
||||
//fmt.Println("pixel collision")
|
||||
//delete(g.projectiles, k)
|
||||
projectilevalid = false
|
||||
//target.ToggleColor()
|
||||
e.SetHit()
|
||||
//target.SetOrigin(gamedata.Coordinates{X: rand.Float64() * 640, Y: rand.Float64() * 480})
|
||||
//target.Hit = true
|
||||
|
||||
/*player := audioContext.NewPlayerFromBytes(assets.TargetHit)
|
||||
player.Play()*/
|
||||
if c.eventmap[gamedata.GameEventTargetHit] != nil {
|
||||
c.eventmap[gamedata.GameEventTargetHit]()
|
||||
}
|
||||
@@ -381,13 +376,17 @@ func (c *Canvas) UpdateEnemies() {
|
||||
|
||||
e.Update()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (c *Canvas) SpawnEnemies() {
|
||||
if !c.gameover {
|
||||
|
||||
if !c.goblinspawned || c.goblindead {
|
||||
c.SpawnFlyEyes()
|
||||
}
|
||||
|
||||
if !c.goblinspawned { //&& c.counter > 1200 && !c.goblindead {
|
||||
if !c.goblinspawned && c.counter > 2400 && !c.goblindead {
|
||||
c.SpawnGoblin()
|
||||
}
|
||||
|
||||
@@ -508,5 +507,9 @@ func (c *Canvas) GoblinFireballEvent() {
|
||||
newfb.SetPosition(c.goblin.GetPosition())
|
||||
c.enemies = append(c.enemies, newfb)
|
||||
|
||||
if c.eventmap[gamedata.GameEventFireball] != nil {
|
||||
c.eventmap[gamedata.GameEventFireball]()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user