Bullet support

This commit is contained in:
2023-12-28 14:42:20 +01:00
parent b6776fa9f3
commit d336fa4d15
9 changed files with 196 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ import (
"gitlab.com/kbr4/9heroja/collision"
"gitlab.com/kbr4/9heroja/configuration"
"gitlab.com/kbr4/9heroja/resources"
"gitlab.com/kbr4/9heroja/weapons"
"image"
"image/color"
"log"
@@ -248,3 +249,17 @@ func (h *Hero) HandleCollisionEvent(other collision.Collidable) {
}
}
}
func (h *Hero) Fire(fire bool, offsetX float64, offsetY float64) (bullet *weapons.Handgun) {
if fire {
bullet = weapons.NewHandgun()
bullet.X = h.X + (resources.HeroTileSize / 2) - offsetX
bullet.Y = h.Y + (resources.HeroTileSize / 2) - offsetY
bullet.OffsetX = offsetX
bullet.OffsetY = offsetY
bullet.Fire(h.direction)
return bullet
} else {
return nil
}
}