Added weapon system. Animated laser.
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"mover/elements"
|
||||
"mover/fonts"
|
||||
"mover/gamedata"
|
||||
"mover/weapons"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/text"
|
||||
@@ -43,6 +44,7 @@ type Canvas struct {
|
||||
gameover bool
|
||||
|
||||
lasercoords []gamedata.Coordinates
|
||||
holster *weapons.Holster
|
||||
}
|
||||
|
||||
func NewCanvas(a gamedata.Area) *Canvas {
|
||||
@@ -63,6 +65,7 @@ func NewCanvas(a gamedata.Area) *Canvas {
|
||||
score: 0,
|
||||
runtime: 0.,
|
||||
counter: 0,
|
||||
holster: weapons.NewHolster(),
|
||||
}
|
||||
c.laserMask.Clear()
|
||||
c.eventmap = make(map[gamedata.GameEvent]func())
|
||||
@@ -79,8 +82,8 @@ func (c *Canvas) Update() error {
|
||||
c.Initialize()
|
||||
} else {
|
||||
c.UpdateHero()
|
||||
c.UpdateWeapons()
|
||||
c.UpdateProjectiles()
|
||||
c.UpdateLaser()
|
||||
c.UpdateCharge()
|
||||
c.UpdateEnemies()
|
||||
c.SpawnEnemies()
|
||||
@@ -227,7 +230,6 @@ func (c *Canvas) UpdateHero() {
|
||||
if !c.gameover {
|
||||
c.UpdateHeroPosition()
|
||||
c.ComputeHeroCollisions()
|
||||
c.AddProjectiles()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,31 +277,26 @@ func (c *Canvas) ComputeHeroCollisions() {
|
||||
func (c *Canvas) AddProjectiles() {
|
||||
|
||||
//add new projectiles
|
||||
/*
|
||||
if c.lastInputs.Shot && c.counter%14 == 0 {
|
||||
|
||||
loc := gamedata.Coordinates{
|
||||
X: c.hero.Pos.X,
|
||||
Y: c.hero.Pos.Y,
|
||||
}
|
||||
angle := c.lastInputs.ShotAngle
|
||||
velocity := 5.
|
||||
|
||||
c.projectiles = append(c.projectiles, elements.NewProjectile(loc, angle, velocity))
|
||||
|
||||
if c.hero.Upgrade {
|
||||
c.projectiles = append(c.projectiles, elements.NewProjectile(loc, angle+math.Pi, velocity))
|
||||
}
|
||||
|
||||
if c.eventmap[gamedata.GameEventNewShot] != nil {
|
||||
c.eventmap[gamedata.GameEventNewShot]()
|
||||
}
|
||||
if c.lastInputs.Shot && c.counter%14 == 0 {
|
||||
|
||||
loc := gamedata.Coordinates{
|
||||
X: c.hero.Pos.X,
|
||||
Y: c.hero.Pos.Y,
|
||||
}
|
||||
*/
|
||||
if c.lastInputs.Shot {
|
||||
c.laser.SetPosition(c.hero.Pos)
|
||||
c.laser.SetAngle(c.lastInputs.ShotAngle)
|
||||
angle := c.lastInputs.ShotAngle
|
||||
velocity := 5.
|
||||
|
||||
c.projectiles = append(c.projectiles, elements.NewProjectile(loc, angle, velocity))
|
||||
|
||||
if c.hero.Upgrade {
|
||||
c.projectiles = append(c.projectiles, elements.NewProjectile(loc, angle+math.Pi, velocity))
|
||||
}
|
||||
|
||||
if c.eventmap[gamedata.GameEventNewShot] != nil {
|
||||
c.eventmap[gamedata.GameEventNewShot]()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -362,7 +359,11 @@ func (c *Canvas) UpdateProjectiles() {
|
||||
}
|
||||
|
||||
func (c *Canvas) UpdateLaser() {
|
||||
|
||||
c.laser.Update()
|
||||
if c.lastInputs.Shot {
|
||||
c.laser.SetPosition(c.hero.Pos)
|
||||
c.laser.SetAngle(c.lastInputs.ShotAngle)
|
||||
}
|
||||
c.laser.SetFiring(c.lastInputs.Shot)
|
||||
if c.lastInputs.Shot {
|
||||
c.laserMask.Clear()
|
||||
@@ -826,11 +827,11 @@ func (c *Canvas) LaserAttempt4() {
|
||||
if math.Abs(math.Mod(a, math.Pi)) == math.Pi/2 { // Check for vertical beam
|
||||
d = math.Abs(x1 - x0)
|
||||
c.lasercoords[3] = gamedata.Coordinates{X: x0, Y: y1} // Align on x-axis
|
||||
fmt.Printf("vertical beam\n")
|
||||
//fmt.Printf("vertical beam\n")
|
||||
} else if math.Tan(a) == 0 { // Check for horizontal beam
|
||||
d = math.Abs(y1 - y0)
|
||||
c.lasercoords[3] = gamedata.Coordinates{X: x1, Y: y0} // Align on y-axis
|
||||
fmt.Printf("horizontal beam\n")
|
||||
//fmt.Printf("horizontal beam\n")
|
||||
} else { // General case
|
||||
m0 := math.Tan(a)
|
||||
m1 := -1 / m0
|
||||
@@ -838,9 +839,9 @@ func (c *Canvas) LaserAttempt4() {
|
||||
yi := xi*m0 - x0*m0 + y0
|
||||
c.lasercoords[3] = gamedata.Coordinates{X: xi, Y: yi}
|
||||
d = math.Sqrt(math.Pow(x1-xi, 2) + math.Pow(y1-yi, 2))
|
||||
fmt.Printf("%f \n", d)
|
||||
//fmt.Printf("%f \n", d)
|
||||
}
|
||||
fmt.Printf("%f \n", a)
|
||||
//fmt.Printf("%f \n", a)
|
||||
|
||||
if d <= 50 && e.GetEnemyState() <= gamedata.EnemyStateHit {
|
||||
|
||||
@@ -857,7 +858,7 @@ func (c *Canvas) LaserAttempt4() {
|
||||
if c.eventmap[gamedata.GameEventTargetHit] != nil {
|
||||
c.eventmap[gamedata.GameEventTargetHit]()
|
||||
}
|
||||
fmt.Println("laser'd")
|
||||
//fmt.Println("laser'd")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -884,3 +885,23 @@ func (c *Canvas) CleanSplashes() {
|
||||
|
||||
c.splashes = c.splashes[:i]
|
||||
}
|
||||
|
||||
func (c *Canvas) UpdateWeapons() {
|
||||
if !c.gameover {
|
||||
//check for weapon inputs
|
||||
if c.lastInputs.CycleWeapon {
|
||||
c.holster.CycleWeapon()
|
||||
}
|
||||
|
||||
//now let's update some shit based on the weapon
|
||||
switch c.holster.GetActiveWeapon().GetWeaponType() {
|
||||
case gamedata.WeaponTypeGun:
|
||||
c.AddProjectiles()
|
||||
case gamedata.WeaponTypeLaser:
|
||||
c.UpdateLaser()
|
||||
}
|
||||
} else {
|
||||
c.laser.SetFiring(false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user