mirror of
https://github.com/stevenhowes/GoRetro.git
synced 2026-05-26 15:53:31 +01:00
Move all engine stuff to GoRetro. Still many interactions between game and engine code that there should not be.
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package GoRetro
|
||||
|
||||
/*
|
||||
* --------------------
|
||||
* damageReceiver
|
||||
* --------------------
|
||||
* During a collision a damageReciever handles damage from
|
||||
* a damageGiver
|
||||
*/
|
||||
|
||||
type damageReceiver struct {
|
||||
container *Element
|
||||
health float64
|
||||
}
|
||||
|
||||
func NewDamageReceiver(container *Element, health float64) *damageReceiver {
|
||||
return &damageReceiver{
|
||||
container: container,
|
||||
health: health,
|
||||
}
|
||||
}
|
||||
|
||||
func (dr *damageReceiver) onDraw() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dr *damageReceiver) onUpdate() error {
|
||||
// If we're out of health
|
||||
if dr.health <= 0 {
|
||||
// If we have an animator, run the destroy sequence
|
||||
if dr.container.checkComponentIsPresent(&animator{}) {
|
||||
ani := dr.container.getComponent(&animator{}).(*animator)
|
||||
|
||||
// If the sequence can't get set (doesn't exist) just remove us
|
||||
if !ani.setSequence("destroy") {
|
||||
dr.container.Active = false
|
||||
dr.container.Delete = true
|
||||
}
|
||||
}
|
||||
|
||||
// Stop any movers we have
|
||||
if dr.container.checkComponentIsPresent(&moverLinear{}) {
|
||||
lm := dr.container.getComponent(&moverLinear{}).(*moverLinear)
|
||||
lm.speed = 0
|
||||
}
|
||||
if dr.container.checkComponentIsPresent(&moverKeyboard{}) {
|
||||
km := dr.container.getComponent(&moverKeyboard{}).(*moverKeyboard)
|
||||
km.speed = 0
|
||||
}
|
||||
}
|
||||
|
||||
// If we've finished our destroy animation then we're not active and can be removed
|
||||
if dr.container.checkComponentIsPresent(&animator{}) {
|
||||
ani := dr.container.getComponent(&animator{}).(*animator)
|
||||
if ani.finished && ani.current == "destroy" {
|
||||
dr.container.Active = false
|
||||
dr.container.Delete = true
|
||||
}
|
||||
}
|
||||
/*if debugTick {
|
||||
fmt.Printf("health is %f\n", dr.health)
|
||||
}*/
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dr *damageReceiver) onCollision(other *Element) error {
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user