Example #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.__lifeCounter.dec():
                            player.clearInterval(self.__spawnTimeoutId)
                            self.__spawnTimeoutId = None
                            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
            self.__stop()
Example #2
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.__lifeCounter.dec():
                            player.clearInterval(self.__spawnTimeoutId)
                            self.__spawnTimeoutId = None
                            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
            self.__stop()
Example #3
0
 def onDrag(self, transform):
     frameDuration = player.getFrameDuration()
     if frameDuration > 0:
         self.__transVel += 0.1*transform.trans/frameDuration
     if transform.pivot != avg.Point2D(0,0):
         self.__curPivot = transform.pivot
     if transform.rot > math.pi:
         transform.rot -= 2*math.pi
     if frameDuration > 0:
         self.__angVel += 0.1*transform.rot/frameDuration
Example #4
0
 def onDrag(self, transform):
     frameDuration = player.getFrameDuration()
     if frameDuration > 0:
         self.__transVel += 0.1*transform.trans/frameDuration
     if transform.pivot != avg.Point2D(0,0):
         self.__curPivot = transform.pivot
     if transform.rot > math.pi:
         transform.rot -= 2*math.pi
     if frameDuration > 0:
         self.__angVel += 0.1*transform.rot/frameDuration
Example #5
0
    def __onInertiaFrame(self):
        transNorm = self.__transVel.getNorm()
        if transNorm - self.__friction > 0:
            direction = self.__transVel.getNormalized()
            self.__transVel = direction * (transNorm-self.__friction)
            curTrans = self.__transVel * player.getFrameDuration()
        else:
            curTrans = avg.Point2D(0, 0)

        if self.__angVel != 0:
            angSign = self.__angVel/math.fabs(self.__angVel)
            self.__angVel -= angSign * self.__friction / 200
            newAngSign = self.__angVel/math.fabs(self.__angVel)
            if newAngSign != angSign:
                self.__angVel = 0
        curAng = self.__angVel * player.getFrameDuration()
        self.__curPivot += curTrans

        if transNorm - self.__friction > 0 or self.__angVel != 0:
            if self.__moveHandler:
                self.__moveHandler(Transform(curTrans,  curAng, 1, self.__curPivot))
        else:
            self.__stop()
Example #6
0
    def __onInertiaFrame(self):
        transNorm = self.__transVel.getNorm()
        if transNorm - self.__friction > 0:
            direction = self.__transVel.getNormalized()
            self.__transVel = direction * (transNorm-self.__friction)
            curTrans = self.__transVel * player.getFrameDuration()
        else:
            curTrans = avg.Point2D(0, 0)

        if self.__angVel != 0:
            angSign = self.__angVel/math.fabs(self.__angVel)
            self.__angVel -= angSign * self.__friction / 200
            newAngSign = self.__angVel/math.fabs(self.__angVel)
            if newAngSign != angSign:
                self.__angVel = 0
        curAng = self.__angVel * player.getFrameDuration()
        self.__curPivot += curTrans

        if transNorm - self.__friction > 0 or self.__angVel != 0:
            if self.__moveHandler:
                self.__moveHandler(Transform(curTrans,  curAng, 1, self.__curPivot))
        else:
            self.__stop()
Example #7
0
    def __onFrame(self):
        delta = player.getFrameDuration()

        oldCurFrame = self.__curFrameNum
        self.__curFrameNum += (delta * self.__fps) / 1000.
        if int(oldCurFrame) != int(self.__curFrameNum):
            if self.__curFrameNum > len(self._info) - 1:
                if self.__loop:
                    self.__curFrameNum = 0
                else:
                    self.__curFrameNum = len(self._info) - 1
                    self.pause()
                self.notifySubscribers(self.END_OF_ANIMATION, [])
            self._selectSprite(self.__curFrameNum)
Example #8
0
    def __onFrame(self):
        delta = player.getFrameDuration()

        oldCurFrame = self.__curFrameNum
        self.__curFrameNum += (delta * self.__fps) / 1000.
        if int(oldCurFrame) != int (self.__curFrameNum):
            if self.__curFrameNum > len(self._info)-1:
                if self.__loop:
                    self.__curFrameNum = 0
                else:
                    self.__curFrameNum = len(self._info)-1
                    self.pause()
                self.notifySubscribers(self.END_OF_ANIMATION, [])
            self._selectSprite(self.__curFrameNum)
Example #9
0
 def checkTime():
     self.assertEqual(player.getFrameTime(), 50)
     self.assertEqual(player.getFrameDuration(), 50)
     self.assertEqual(player.getEffectiveFramerate(), 20)
Example #10
0
 def checkTime():
     self.assertEqual(player.getFrameTime(), 50)
     self.assertEqual(player.getFrameDuration(), 50)
     self.assertEqual(player.getEffectiveFramerate(), 20)
 def onFrame(self):
     if self.__shouldMove:
         speed = float(self.argvoptions.speed)
         self.__runningBlock.pos += (speed * player.getFrameDuration(), 0)
         if self.__runningBlock.pos.x > self.size.x:
             self.__runningBlock.pos = (0, 100)
Example #12
0
 def onFrame(self):
     if self.__shouldMove:
         speed = float(self.argvoptions.speed)
         self.__runningBlock.pos += (speed * player.getFrameDuration(), 0)
         if self.__runningBlock.pos.x > self.size.x:
             self.__runningBlock.pos = (0, 100)
Example #13
0
 def onFrame(self):
     self._text.text = '%06d' % player.getFrameTime()
     self._rect.angle += player.getFrameDuration() * 0.001