def __init__(self, key, keyboard): print('key init: ',key) self.pressed = EventHook() self.released = EventHook() self._key = key keyboard.keyPressed += self._keyPressed keyboard.keyReleased += self._keyReleased
class Keyboard: def __init__(self): print('Keyboard init') self.keyPressed = EventHook() self.keyReleased = EventHook() def AKeyHasBeenPressed(self,key): self.keyPressed.fire(key) def AKeyHasBeenReleased(self, key): self.keyReleased.fire(key)
class KeyEvent: def __init__(self, key, keyboard): print('key init: ',key) self.pressed = EventHook() self.released = EventHook() self._key = key keyboard.keyPressed += self._keyPressed keyboard.keyReleased += self._keyReleased def _keyPressed(self,key): if(key == self._key): self.pressed.fire() def _keyReleased(self,key): if(key == self._key): self.released.fire()
class Avatar(Character): energy = 0 boosts = [] # Events AVATAR_MOVE = None def __init__(self): super().__init__() self.AVATAR_MOVE = EventHook() print("Avatar init") def moveTo(self, x, y): super().moveTo(x,y); self.AVATAR_MOVE.fire(self) def attack(self, monster): if monster == None: return if self.activeWeapon == None: self.setActiveWeapon(None, True) damage = self.getActiveWeapon().getDamage() print("Attacked for " + str(damage) + " damage!") def acquire(self): print("Acquiring an item")
def __init__(self): print('Keyboard init') self.keyPressed = EventHook() self.keyReleased = EventHook()
def __init__(self): super().__init__() self.AVATAR_MOVE = EventHook() print("Avatar init")