def __onFrame(self): dt = player.getFrameDuration() * 0.001 self.__scrollingBg.update(dt) bullets = self.__player.getActiveBullets() enemiesActive = False for e in self.__enemies: if e.active: enemiesActive = True if e.alive: for b in bullets: if self.__bulletCollisionDetector.detect(e.pos, b.pos): self.__scoreCounter.inc() e.destroy() b.destroy() break if e.alive: # no bullet hit if self.__player.alive and \ self.__playerCollisionDetector.detect(e.pos, self.__player.pos): e.destroy() if self.__liveCounter.dec(): self.__stop() self.__player.destroy() if e.alive: # no player collision e.update(dt) if self.__player.alive: self.__player.update(dt, self.__keyStates) elif not self.__player.updateBullets(dt) and not enemiesActive: # player dead, all bullets and enemies left the screen, all destroy videos played player.unsubscribe(player.ON_FRAME, self.__frameHandlerId) self.__frameHandlerId = None
def __abort(self): if self.__frameHandlerID: player.unsubscribe(player.ON_FRAME, self.__frameHandlerID) self.__frameHandlerID = None if self.__inertiaHandler: self.__inertiaHandler.abort() self.__inertiaHandler = None
def _disconnectContacts(self): for contact in self._contacts: contact.unsubscribe(avg.Contact.CURSOR_MOTION, self.__onMotion) contact.unsubscribe(avg.Contact.CURSOR_UP, self.__onUp) self._contacts = set() if self.__frameHandlerID: player.unsubscribe(player.ON_FRAME, self.__frameHandlerID) self.__frameHandlerID = None
def __stopIdleDemo(self): self.__gameDiv.unsubscribe(self.__demoDownHandlerID) player.unsubscribe(player.ON_FRAME, self.__onIdleFrame) avg.fadeIn(self.__gameDiv, 200) self.__ctrlDiv.sensitive = True for p in self.__idlePlayers: p.setDead() self.__restartIdleTimer()
def __onUp(self, event): nodeGone = self._handleNodeGone() if event.contact and not (nodeGone): self.__dirty = True self._contacts.remove(event.contact) if len(self._contacts) == 0: player.unsubscribe(player.ON_FRAME, self.__frameHandlerID) self.__frameHandlerID = None self._handleUp(event)
def __onUp(self, event): nodeGone = self._handleNodeGone() if event.contact and not(nodeGone): self.__dirty = True self._contacts.remove(event.contact) if len(self._contacts) == 0: player.unsubscribe(player.ON_FRAME, self.__frameHandlerID) self.__frameHandlerID = None self._handleUp(event)
def __stop(self, forceClearWins=False): def restart(): for p in self.__activePlayers: p.setDead(False) avg.fadeIn(self.__winsDiv, 200) self.__winsDiv.sensitive = True self.__activateIdleTimer() if forceClearWins: self.__clearButton.activate() else: self.__preStart() player.unsubscribe(player.ON_FRAME, self.__onGameFrame) self.__shield.deactivate() self.__blocker.deactivate() player.setTimeout(2000, restart)
def _handleUp(self, event): numContacts = len(self._contacts) if numContacts == 0: contact = event.contact transform = Transform(self.__filteredRelContactPos(contact) - self.__lastPosns[0]) player.unsubscribe(player.ON_FRAME, self.__frameHandlerID) self.__frameHandlerID = None if self.__friction != -1: self.__inertiaHandler.onDrag(transform) self.__inertiaHandler.onUp() else: self._setEnd(event) self.notifySubscribers(Recognizer.UP, [transform]) elif numContacts == 1: self.__newPhase() else: self.__newPhase() if self.__isFiltered(): del self.__filters[event.contact]
def onFrame(): player.clearInterval(self.longTimeoutId) self.longTimeoutId = None player.setTimeout(0, onTimeOut) player.unsubscribe(player.ON_FRAME, self.onFrameID)
def __enterIdle(self): player.unsubscribe(player.ON_FRAME, self.__frameHandlerID)
def __stop(self): player.unsubscribe(player.ON_FRAME, self.__frameHandlerId) self.__frameHandlerId = None
def stop(self): player.unsubscribe(player.ON_FRAME, self.__onFrame)
def onUp(self): player.unsubscribe(player.ON_FRAME, self.__frameHandlerID) self.__frameHandlerID = player.subscribe(player.ON_FRAME, self.__onInertiaFrame) self.__onInertiaFrame()
def __stop(self): player.unsubscribe(player.ON_FRAME, self.__frameHandlerID) self.__stopHandler() self.__stopHandler = None self.__moveHandler = None
def __onUp(self, event): self.__rawContactCircle.opacity = 0 self.__filteredContactCircle.opacity = 0 self.__contact = None self.__filters = None player.unsubscribe(self.__onFrame)
def __onDelete(self): if self.__frameHandlerID: player.unsubscribe(self.__frameHandlerID) self.__frameHandlerID = None
def pause(self): if self.__playing: self.__playing = False player.unsubscribe(self.__frameHandlerID) self.__frameHandlerID = None
def abort(self): player.unsubscribe(player.ON_FRAME, self.__frameHandlerID) self.__stopHandler = None self.__moveHandler = None