Skip to content

Instantly share code, notes, and snippets.

@orleonedev
Created April 13, 2022 07:05
Show Gist options
  • Save orleonedev/961384f8e346a07822b0669f23468adf to your computer and use it in GitHub Desktop.
Save orleonedev/961384f8e346a07822b0669f23468adf to your computer and use it in GitHub Desktop.
WillPower HealthComponent Version 0.0.1(3)
class WPHealthComponent: GKComponent {
var healthStateMachine: GKStateMachine
var game: WPGame
var char: WPEntity
var maxHearts: Int
var heartCounter: Int {
//......
}
init(withGame: WPGame, characterEnt: WPEntity, maxHearts: Int){
self.game = withGame
self.char = characterEnt
self.maxHearts = maxHearts
self.heartCounter = maxHearts
let defend = WPDefendState(withGame: game, entity: char)
let hit = WPHitState(withGame: game, entity: char)
let defeated = WPDefeatedState(withGame: game, entity: char)
let invulnerable = WPInvulnerableState(withGame: game, entity: char)
healthStateMachine = GKStateMachine(states: [defend,hit,defeated,invulnerable])
super.init()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func update(deltaTime seconds: TimeInterval) {
healthStateMachine.update(deltaTime: seconds)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment