Automatic shooting

This commit is contained in:
2024-01-04 05:57:21 +01:00
parent d336fa4d15
commit 156e3ed43c
5 changed files with 51 additions and 35 deletions

View File

@@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"gitlab.com/kbr4/9heroja/collision"
"gitlab.com/kbr4/9heroja/configuration"
"gitlab.com/kbr4/9heroja/resources"
@@ -25,6 +24,8 @@ type Handgun struct {
IsFlying bool
X float64
Y float64
OffsetXAtStart float64
OffsetYAtStart float64
OffsetX float64
OffsetY float64
IsDisintegrated bool
@@ -41,16 +42,13 @@ func (h *Handgun) DrawHandgunBullet(screen *ebiten.Image) {
}
if !h.IsDisintegrated && h.IsFlying {
ebitenutil.DebugPrint(screen, fmt.Sprintf("\n\n\n\n\n\n\ndx: %f y:%f isint: %t, flying: %t", h.X, h.Y, h.IsDisintegrated, h.IsFlying))
op := &ebiten.DrawImageOptions{}
op.GeoM.Reset()
op.GeoM.Translate(h.X+h.OffsetX, h.Y+h.OffsetY)
op.GeoM.Translate(h.X+h.OffsetX-h.OffsetXAtStart, h.Y+h.OffsetY-h.OffsetYAtStart)
op.GeoM.Scale(1, 1)
screen.DrawImage(
handgunBulletImage,
op,
)
op.ColorScale.Scale(1, 1, 1, 1)
// draw circle
screen.DrawImage(handgunBulletImage, op)
}
}
@@ -92,10 +90,10 @@ func (h *Handgun) CollisionShape() collision.Polygon {
if !h.IsDisintegrated {
return collision.Polygon{
Points: []collision.Point{
{X: h.X + h.OffsetX, Y: h.Y + h.OffsetY},
{X: h.X + h.OffsetX + 4, Y: h.Y + h.OffsetY},
{X: h.X + h.OffsetX + 4, Y: h.Y + h.OffsetY + 4},
{X: h.X + h.OffsetX, Y: h.Y + h.OffsetY + 4},
{X: h.X + h.OffsetX - 3 - h.OffsetXAtStart, Y: h.Y + h.OffsetY - 3 - h.OffsetYAtStart},
{X: h.X + h.OffsetX + 7 - h.OffsetXAtStart, Y: h.Y + h.OffsetY - 3 - h.OffsetYAtStart},
{X: h.X + h.OffsetX + 7 - h.OffsetXAtStart, Y: h.Y + h.OffsetY + 7 - h.OffsetYAtStart},
{X: h.X + h.OffsetX - 3 - h.OffsetXAtStart, Y: h.Y + h.OffsetY + 7 - h.OffsetYAtStart},
},
}
} else {
@@ -119,16 +117,16 @@ func (h *Handgun) HandleCollisionEvent(other collision.Collidable) {
}
func (h *Handgun) Move() {
if slices.Contains([]configuration.Direction{configuration.North, configuration.NorthEast, configuration.NorthWest}, h.direction) {
h.Y -= 1
h.Y -= 6
}
if slices.Contains([]configuration.Direction{configuration.South, configuration.SouthEast, configuration.SouthWest}, h.direction) {
h.Y += 1
h.Y += 6
}
if slices.Contains([]configuration.Direction{configuration.East, configuration.NorthEast, configuration.SouthEast}, h.direction) {
h.X += 1
h.X += 6
}
if slices.Contains([]configuration.Direction{configuration.West, configuration.NorthWest, configuration.SouthWest}, h.direction) {
h.X -= 1
h.X -= 6
}
}