2020-02-22 20:44:30 -05:00
|
|
|
package d2map
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-04-11 14:56:47 -04:00
|
|
|
"math"
|
|
|
|
|
2020-02-22 20:44:30 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Missile struct {
|
|
|
|
*AnimatedEntity
|
2020-02-23 03:23:18 -05:00
|
|
|
record *d2datadict.MissileRecord
|
2020-02-22 20:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func CreateMissile(x, y int, record *d2datadict.MissileRecord) (*Missile, error) {
|
|
|
|
animation, err := d2asset.LoadAnimation(
|
|
|
|
fmt.Sprintf("%s/%s.dcc", d2resource.MissileData, record.Animation.CelFileName),
|
|
|
|
d2resource.PaletteUnits,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-02-23 03:23:18 -05:00
|
|
|
if record.Animation.HasSubLoop {
|
|
|
|
animation.SetSubLoop(record.Animation.SubStartingFrame, record.Animation.SubEndingFrame)
|
|
|
|
}
|
|
|
|
|
|
|
|
animation.SetBlend(true)
|
|
|
|
//animation.SetPlaySpeed(float64(record.Animation.AnimationSpeed))
|
|
|
|
animation.SetPlayLoop(record.Animation.LoopAnimation)
|
2020-02-22 20:44:30 -05:00
|
|
|
animation.PlayForward()
|
|
|
|
entity := CreateAnimatedEntity(x, y, animation)
|
|
|
|
|
|
|
|
result := &Missile{
|
|
|
|
AnimatedEntity: entity,
|
|
|
|
record: record,
|
|
|
|
}
|
|
|
|
result.Speed = float64(record.Velocity)
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2020-02-23 03:23:18 -05:00
|
|
|
func (m *Missile) SetRadians(angle float64, done func()) {
|
|
|
|
r := float64(m.record.Range)
|
|
|
|
|
|
|
|
x := m.LocationX + (r * math.Cos(angle))
|
|
|
|
y := m.LocationY + (r * math.Sin(angle))
|
|
|
|
|
|
|
|
m.SetTarget(x, y, done)
|
|
|
|
}
|
|
|
|
|
2020-02-22 20:44:30 -05:00
|
|
|
func (m *Missile) Advance(tickTime float64) {
|
|
|
|
// TODO: collision detection
|
|
|
|
m.Step(tickTime)
|
|
|
|
m.AnimatedEntity.Advance(tickTime)
|
|
|
|
}
|