mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-30 07:06:18 -04:00
6104adc700
* Comments and newlines in engine.go * Comments and newlines in object.go * Comments and newlines in animated_entity.go * Comments and newlines in missile.go * Comments and newlines in npc.go * Comments and newlines in player.go * Removed object.go (incorrectly merged it in during rebase). * Comments and newlines in renderer.go. * Comments and newlines in map_entity.go. * Comments and newlines in walk_mesh.go. * Comments and newlines in viewport.go and tile_cache.go. * Comments and newlines in stamp.go and wilderness_tile_types.go. * Comments and newlines in everything else.
55 lines
1.3 KiB
Go
55 lines
1.3 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)
|
|
}
|
|
|
|
// 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)
|
|
}
|