1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-12 23:43:24 -05:00
OpenDiablo2/d2core/d2map/d2mapentity/animated_entity.go
dk c1a88c9cf7
Animation manager abstraction (#544)
* abstracted palettes, colors, and palette manager

* make asset manager use the palette manager interface

* added BGRA setter/getter, fixed lint errors

* abstraction for animation and animation manager
2020-07-05 13:01:44 -04:00

51 lines
1.2 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: createMapEntity(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) {
target.PushTranslation(
ae.offsetX+int((ae.subcellX-ae.subcellY)*16),
ae.offsetY+int(((ae.subcellX+ae.subcellY)*8)-5),
)
defer target.Pop()
ae.animation.Render(target)
}
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)
}
func (ae *AnimatedEntity) Advance(elapsed float64) {
ae.animation.Advance(elapsed)
}