1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-16 04:25:23 +00:00
OpenDiablo2/d2core/d2map/d2mapentity/animated_entity.go

52 lines
1.2 KiB
Go
Raw Normal View History

2020-06-21 22:40:37 +00:00
package d2mapentity
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
)
// AnimatedEntity represents an animation that can be projected onto the map.
type AnimatedEntity struct {
mapEntity
direction int
action int
repetitions int
animation *d2asset.Animation
}
2019-11-07 03:12:15 +00:00
// CreateAnimatedEntity creates an instance of AnimatedEntity
func CreateAnimatedEntity(x, y int, animation *d2asset.Animation) *AnimatedEntity {
entity := &AnimatedEntity{
mapEntity: createMapEntity(x, y),
animation: animation,
2019-11-15 03:20:01 +00:00
}
entity.mapEntity.directioner = entity.rotate
return entity
}
2019-11-07 03:12:15 +00:00
// 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)
}
2019-11-17 21:06:02 +00:00
2020-06-24 14:13:11 +00:00
func (ae *AnimatedEntity) GetDirection() int {
return ae.direction
2019-11-17 21:06:02 +00:00
}
// 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)
}