mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-10 06:16:27 -05:00
6104adc700
* Comments and newlines in engine.go * Comments and newlines in object.go * Comments and newlines in animated_entity.go * Comments and newlines in missile.go * Comments and newlines in npc.go * Comments and newlines in player.go * Removed object.go (incorrectly merged it in during rebase). * Comments and newlines in renderer.go. * Comments and newlines in map_entity.go. * Comments and newlines in walk_mesh.go. * Comments and newlines in viewport.go and tile_cache.go. * Comments and newlines in stamp.go and wilderness_tile_types.go. * Comments and newlines in everything else.
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
package d2mapentity
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
|
)
|
|
|
|
// Missile is a simple animated entity representing a projectile,
|
|
// such as a spell or arrow.
|
|
type Missile struct {
|
|
*AnimatedEntity
|
|
record *d2datadict.MissileRecord
|
|
}
|
|
|
|
// CreateMissile creates a new Missile and initializes it's animation.
|
|
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
|
|
}
|
|
|
|
if record.Animation.HasSubLoop {
|
|
animation.SetSubLoop(record.Animation.SubStartingFrame, record.Animation.SubEndingFrame)
|
|
}
|
|
|
|
animation.SetEffect(d2enum.DrawEffectModulate)
|
|
//animation.SetPlaySpeed(float64(record.Animation.AnimationSpeed))
|
|
animation.SetPlayLoop(record.Animation.LoopAnimation)
|
|
animation.PlayForward()
|
|
entity := CreateAnimatedEntity(x, y, animation)
|
|
|
|
result := &Missile{
|
|
AnimatedEntity: entity,
|
|
record: record,
|
|
}
|
|
result.Speed = float64(record.Velocity)
|
|
|
|
return result, nil
|
|
}
|
|
|
|
// SetRadians adjusts the entity target based on it's range, rotating it's
|
|
// current destination by the value of angle in radians.
|
|
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)
|
|
}
|
|
|
|
// Advance is called once per frame and processes a
|
|
// single game tick.
|
|
func (m *Missile) Advance(tickTime float64) {
|
|
// TODO: collision detection
|
|
m.Step(tickTime)
|
|
m.AnimatedEntity.Advance(tickTime)
|
|
}
|