1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-08 03:07:18 -05:00
OpenDiablo2/d2core/d2map/d2mapentity/animated_entity.go

57 lines
1.4 KiB
Go
Raw Normal View History

2020-06-21 18:40:37 -04:00
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
}
2019-11-06 22:12:15 -05:00
// CreateAnimatedEntity creates an instance of AnimatedEntity
func CreateAnimatedEntity(x, y int, animation d2interface.Animation) *AnimatedEntity {
entity := &AnimatedEntity{
mapEntity: createMapEntity(x, y),
animation: animation,
2019-11-14 22:20:01 -05:00
}
entity.mapEntity.directioner = entity.rotate
return entity
}
2019-11-06 22:12:15 -05:00
// 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)),
)
defer target.Pop()
ae.animation.Render(target)
}
2019-11-17 16:06:02 -05:00
// GetDirection returns the current facing direction of this entity.
2020-06-24 10:13:11 -04:00
func (ae *AnimatedEntity) GetDirection() int {
return ae.direction
2019-11-17 16:06:02 -05:00
}
// 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)
}