2020-06-21 18:40:37 -04:00
|
|
|
package d2mapentity
|
2020-02-22 20:44:30 -05:00
|
|
|
|
|
|
|
import (
|
2020-04-11 14:56:47 -04:00
|
|
|
"math"
|
|
|
|
|
2020-07-31 17:55:11 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
|
2020-09-20 17:52:01 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2records"
|
2020-02-22 20:44:30 -05:00
|
|
|
)
|
|
|
|
|
2020-07-09 16:11:01 -04:00
|
|
|
// Missile is a simple animated entity representing a projectile,
|
|
|
|
// such as a spell or arrow.
|
2020-02-22 20:44:30 -05:00
|
|
|
type Missile struct {
|
|
|
|
*AnimatedEntity
|
2020-09-20 17:52:01 -04:00
|
|
|
record *d2records.MissileRecord
|
2020-02-22 20:44:30 -05:00
|
|
|
}
|
|
|
|
|
2020-08-05 21:27:45 -04:00
|
|
|
// ID returns the missile uuid
|
|
|
|
func (m *Missile) ID() string {
|
|
|
|
return m.AnimatedEntity.uuid
|
|
|
|
}
|
|
|
|
|
2020-07-23 12:56:50 -04:00
|
|
|
// GetPosition returns the position of the missile
|
2020-07-21 08:51:09 -04:00
|
|
|
func (m *Missile) GetPosition() d2vector.Position {
|
|
|
|
return m.AnimatedEntity.Position
|
|
|
|
}
|
|
|
|
|
2020-07-23 12:56:50 -04:00
|
|
|
// GetVelocity returns the velocity vector of the missile
|
2020-07-21 08:51:09 -04:00
|
|
|
func (m *Missile) GetVelocity() d2vector.Vector {
|
|
|
|
return m.AnimatedEntity.velocity
|
|
|
|
}
|
|
|
|
|
2020-07-09 16:11:01 -04:00
|
|
|
// SetRadians adjusts the entity target based on it's range, rotating it's
|
|
|
|
// current destination by the value of angle in radians.
|
2020-02-23 03:23:18 -05:00
|
|
|
func (m *Missile) SetRadians(angle float64, done func()) {
|
|
|
|
r := float64(m.record.Range)
|
|
|
|
|
2020-07-13 09:06:50 -04:00
|
|
|
x := m.Position.X() + (r * math.Cos(angle))
|
|
|
|
y := m.Position.Y() + (r * math.Sin(angle))
|
2020-02-23 03:23:18 -05:00
|
|
|
|
2020-07-18 18:07:13 -04:00
|
|
|
m.setTarget(d2vector.NewPosition(x, y), done)
|
2020-02-23 03:23:18 -05:00
|
|
|
}
|
|
|
|
|
2020-07-09 16:11:01 -04:00
|
|
|
// Advance is called once per frame and processes a
|
|
|
|
// single game tick.
|
2020-02-22 20:44:30 -05:00
|
|
|
func (m *Missile) Advance(tickTime float64) {
|
|
|
|
// TODO: collision detection
|
|
|
|
m.Step(tickTime)
|
|
|
|
m.AnimatedEntity.Advance(tickTime)
|
|
|
|
}
|