mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-03 23:26:41 -05:00
921d44a70c
* Initial test and benchmark for mapEntity.Step(). * Removed `&& !m.hasPath()` from mapEntity.atTarget * Direction is now updated when the path node changes mid-step and target is updated when path is set. * Test improvements. * Deleted old benchmark function and tidying. * d2math.Abs added. * Abs benchmark and optimisation. * Negate and Distance benchmark. * Length and SetLength benchmark. * Lerp and Dot benchmark. * Cross and Normalize benchmark. * Angle and SignedAngle benchmark. * Trivial change to Vector.Abs()
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package d2mapentity
|
|
|
|
import (
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
|
)
|
|
|
|
// AnimatedEntity represents an animation that can be projected onto the map.
|
|
type AnimatedEntity struct {
|
|
mapEntity
|
|
direction int
|
|
action int
|
|
repetitions int
|
|
|
|
animation d2interface.Animation
|
|
}
|
|
|
|
// CreateAnimatedEntity creates an instance of AnimatedEntity
|
|
func CreateAnimatedEntity(x, y int, animation d2interface.Animation) *AnimatedEntity {
|
|
entity := &AnimatedEntity{
|
|
mapEntity: newMapEntity(x, y),
|
|
animation: animation,
|
|
}
|
|
entity.mapEntity.directioner = entity.rotate
|
|
|
|
return entity
|
|
}
|
|
|
|
// Render draws this animated entity onto the target
|
|
func (ae *AnimatedEntity) Render(target d2interface.Surface) {
|
|
renderOffset := ae.Position.RenderOffset()
|
|
target.PushTranslation(
|
|
int((renderOffset.X()-renderOffset.Y())*16),
|
|
int(((renderOffset.X()+renderOffset.Y())*8)-5),
|
|
)
|
|
|
|
defer target.Pop()
|
|
ae.animation.Render(target)
|
|
}
|
|
|
|
// GetDirection returns the current facing direction of this entity.
|
|
func (ae *AnimatedEntity) GetDirection() int {
|
|
return ae.direction
|
|
}
|
|
|
|
// rotate sets direction and changes animation
|
|
func (ae *AnimatedEntity) rotate(direction int) {
|
|
ae.direction = direction
|
|
|
|
ae.animation.SetDirection(ae.direction)
|
|
}
|
|
|
|
// Advance is called once per frame and processes a
|
|
// single game tick.
|
|
func (ae *AnimatedEntity) Advance(elapsed float64) {
|
|
ae.animation.Advance(elapsed)
|
|
}
|