Exemple #1
0
    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
Exemple #2
0
 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
Exemple #3
0
 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
Exemple #4
0
    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
Exemple #5
0
 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
Exemple #6
0
 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()
Exemple #7
0
 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
Exemple #8
0
 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)
Exemple #9
0
 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)
Exemple #10
0
    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)
Exemple #11
0
 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]
Exemple #12
0
 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]
Exemple #13
0
 def onFrame():
     player.clearInterval(self.longTimeoutId)
     self.longTimeoutId = None
     player.setTimeout(0, onTimeOut)
     player.unsubscribe(player.ON_FRAME, self.onFrameID)
Exemple #14
0
 def __enterIdle(self):
     player.unsubscribe(player.ON_FRAME, self.__frameHandlerID)
Exemple #15
0
 def __stop(self):
     player.unsubscribe(player.ON_FRAME, self.__frameHandlerId)
     self.__frameHandlerId = None
Exemple #16
0
 def stop(self):
     player.unsubscribe(player.ON_FRAME, self.__onFrame)
Exemple #17
0
 def __stop(self):
     player.unsubscribe(player.ON_FRAME, self.__frameHandlerId)
     self.__frameHandlerId = None
Exemple #18
0
 def onFrame():
         player.clearInterval(self.longTimeoutId)
         self.longTimeoutId = None
         player.setTimeout(0, onTimeOut)
         player.unsubscribe(player.ON_FRAME, self.onFrameID)
Exemple #19
0
 def onUp(self):
     player.unsubscribe(player.ON_FRAME, self.__frameHandlerID)
     self.__frameHandlerID = player.subscribe(player.ON_FRAME, self.__onInertiaFrame)
     self.__onInertiaFrame()
Exemple #20
0
 def __stop(self):
     player.unsubscribe(player.ON_FRAME, self.__frameHandlerID)
     self.__stopHandler()
     self.__stopHandler = None
     self.__moveHandler = None
Exemple #21
0
 def __onUp(self, event):
     self.__rawContactCircle.opacity = 0
     self.__filteredContactCircle.opacity = 0
     self.__contact = None
     self.__filters = None
     player.unsubscribe(self.__onFrame)
Exemple #22
0
 def __onDelete(self):
     if self.__frameHandlerID:
         player.unsubscribe(self.__frameHandlerID)
         self.__frameHandlerID = None
Exemple #23
0
 def onUp(self):
     player.unsubscribe(player.ON_FRAME, self.__frameHandlerID)
     self.__frameHandlerID = player.subscribe(player.ON_FRAME, self.__onInertiaFrame)
     self.__onInertiaFrame()
Exemple #24
0
 def __onDelete(self):
     if self.__frameHandlerID:
         player.unsubscribe(self.__frameHandlerID)
         self.__frameHandlerID = None
Exemple #25
0
 def pause(self):
     if self.__playing:
         self.__playing = False
         player.unsubscribe(self.__frameHandlerID)
         self.__frameHandlerID = None
Exemple #26
0
 def abort(self):
     player.unsubscribe(player.ON_FRAME, self.__frameHandlerID)
     self.__stopHandler = None
     self.__moveHandler = None
Exemple #27
0
 def __enterIdle(self):
     player.unsubscribe(player.ON_FRAME, self.__frameHandlerID)
 def __onUp(self, event):
     self.__rawContactCircle.opacity = 0
     self.__filteredContactCircle.opacity = 0
     self.__contact = None
     self.__filters = None
     player.unsubscribe(self.__onFrame)
Exemple #29
0
 def pause(self):
     if self.__playing:
         self.__playing = False
         player.unsubscribe(self.__frameHandlerID)
         self.__frameHandlerID = None