2020-02-01 18:55:56 -05:00
|
|
|
package d2map
|
2019-11-06 18:25:19 -05:00
|
|
|
|
|
|
|
import (
|
2020-02-01 18:55:56 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
2020-02-01 20:39:28 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
2019-11-06 18:25:19 -05:00
|
|
|
)
|
|
|
|
|
2020-02-22 20:44:30 -05:00
|
|
|
// AnimatedEntity represents an animation that can be projected onto the map.
|
2019-11-06 18:25:19 -05:00
|
|
|
type AnimatedEntity struct {
|
2020-02-22 20:44:30 -05:00
|
|
|
mapEntity
|
|
|
|
direction int
|
|
|
|
action int
|
|
|
|
repetitions int
|
2019-12-24 01:48:45 -05:00
|
|
|
|
2020-02-22 20:44:30 -05:00
|
|
|
animation *d2asset.Animation
|
2019-11-06 18:25:19 -05:00
|
|
|
}
|
|
|
|
|
2019-11-06 22:12:15 -05:00
|
|
|
// CreateAnimatedEntity creates an instance of AnimatedEntity
|
2020-02-22 20:44:30 -05:00
|
|
|
func CreateAnimatedEntity(x, y int, animation *d2asset.Animation) *AnimatedEntity {
|
|
|
|
entity := &AnimatedEntity{
|
|
|
|
mapEntity: createMapEntity(x, y),
|
|
|
|
animation: animation,
|
2019-11-14 22:20:01 -05:00
|
|
|
}
|
2020-02-22 20:44:30 -05:00
|
|
|
entity.mapEntity.directioner = entity.rotate
|
|
|
|
return entity
|
2019-11-06 18:25:19 -05:00
|
|
|
}
|
|
|
|
|
2019-11-06 22:12:15 -05:00
|
|
|
// Render draws this animated entity onto the target
|
2020-02-22 20:44:30 -05:00
|
|
|
func (ae *AnimatedEntity) Render(target d2render.Surface) {
|
2019-12-28 16:46:08 -05:00
|
|
|
target.PushTranslation(
|
2020-02-22 20:44:30 -05:00
|
|
|
ae.offsetX+int((ae.subcellX-ae.subcellY)*16),
|
|
|
|
ae.offsetY+int(((ae.subcellX+ae.subcellY)*8)-5),
|
2019-12-24 01:48:45 -05:00
|
|
|
)
|
2019-12-28 16:46:08 -05:00
|
|
|
defer target.Pop()
|
2020-02-22 20:44:30 -05:00
|
|
|
ae.animation.Render(target)
|
2019-11-06 18:25:19 -05:00
|
|
|
}
|
2019-11-17 16:06:02 -05:00
|
|
|
|
2020-02-22 20:44:30 -05:00
|
|
|
func (ae AnimatedEntity) GetDirection() int {
|
|
|
|
return ae.direction
|
2019-11-17 16:06:02 -05:00
|
|
|
}
|
2019-12-02 16:55:48 -05:00
|
|
|
|
2020-02-22 20:44:30 -05:00
|
|
|
// rotate sets direction and changes animation
|
|
|
|
func (ae *AnimatedEntity) rotate(angle float64) {
|
2020-02-22 22:33:58 -05:00
|
|
|
ae.direction = angleToDirection(angle)
|
2020-02-02 12:46:19 -05:00
|
|
|
|
2020-02-22 22:33:58 -05:00
|
|
|
ae.animation.SetDirection(ae.direction)
|
2019-12-13 00:33:11 -05:00
|
|
|
}
|
|
|
|
|
2020-02-22 20:44:30 -05:00
|
|
|
func (ae *AnimatedEntity) Advance(elapsed float64) {
|
|
|
|
ae.animation.Advance(elapsed)
|
2019-12-13 00:33:11 -05:00
|
|
|
}
|