1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-06 18:27:20 -05:00
OpenDiablo2/d2core/d2map/missile.go
nicholas-eden bdfdeda67b
Add support for missiles (#308)
* WIP: Add support for missiles

Break AnimatedEntity into two parts to support single and composite animations.  Summon misssiles on right click.

* Break animated entity down further

Move npc only logic to npc struct, reduce duplication in map entities

* Change a bunch of int32s to int
2020-02-22 20:44:30 -05:00

40 lines
917 B
Go

package d2map
import (
"fmt"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
)
type Missile struct {
*AnimatedEntity
record *d2datadict.MissileRecord
}
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
}
animation.PlayForward()
entity := CreateAnimatedEntity(x, y, animation)
result := &Missile{
AnimatedEntity: entity,
record: record,
}
result.Speed = float64(record.Velocity)
return result, nil
}
func (m *Missile) Advance(tickTime float64) {
// TODO: collision detection
m.Step(tickTime)
m.AnimatedEntity.Advance(tickTime)
}