示例#1
0
    def step(self, bot):
        '''
        Called after one frame of this action has completed.
        '''
        if self.actions is None:
            self.actions = [actionKind() for actionKind in self.actionKinds]

        self.simulator.popPosition(bot.player.pos)

        while self.actions:
            done, changes, faceRight = self.actions[0].prepNextStep(bot.player)

            if not done:
                break
            self.actions.pop(0)
        else:
            self.checkFinalNodeKey(bot.player, stepped=True)
            return True

        bot.applyStateChanges(changes)

        if faceRight and not bot.player.isFacingRight():
            bot.sendRequest(AimPlayerAtMsg(pi / 2, 1.0, bot.world.lastTickId))
        elif (not faceRight) and bot.player.isFacingRight():
            bot.sendRequest(AimPlayerAtMsg(-pi / 2, 1.0, bot.world.lastTickId))

        self.stepsTaken += 1

        return False
示例#2
0
    def _fireShotAtPointNow(self, pos, error=0.15):
        if self.agent.stopped or self.player.dead:
            return
        thrust = 1.0
        x1, y1 = self.player.pos
        x2, y2 = pos
        angle = atan2(x2 - x1, -(y2 - y1))
        angle += error * (2 * random.random() - 1)
        self.sendRequest(AimPlayerAtMsg(angle, thrust, self.world.lastTickId))
        self.sendRequest(ShootMsg(self.world.lastTickId))

        if self._angleRequestedThisTick is not None:
            angle, thrust = self._angleRequestedThisTick
            self.sendRequest(
                AimPlayerAtMsg(angle, thrust, self.world.lastTickId))
示例#3
0
    def updatePlayerViewAngle(self):
        '''Updates the viewing angle of the player based on the mouse pointer
        being at the position pos. This gets its own method because it needs
        to happen as the result of a mouse motion and of the viewManager
        scrolling the screen.'''
        dx, dy = self.mousePos
        pos = (self.playerSprite.rect.center[0] + dx,
               self.playerSprite.rect.center[1] + dy)

        if self.playerSprite.rect.collidepoint(pos):
            return

        # Angle is measured clockwise from vertical.
        theta = atan2(dx, -dy)
        dist = (dx**2 + dy**2)**0.5

        # Calculate a thrust value based on distance.
        if dist < self.NO_GHOST_THRUST_MOUSE_RADIUS:
            thrust = 0.0
        elif dist > self.FULL_GHOST_THRUST_MOUSE_RADIUS:
            thrust = 1.0
        else:
            span = (self.FULL_GHOST_THRUST_MOUSE_RADIUS -
                    self.NO_GHOST_THRUST_MOUSE_RADIUS)
            thrust = (dist - self.NO_GHOST_THRUST_MOUSE_RADIUS) / span

        self.gameInterface.sendRequest(
            AimPlayerAtMsg(theta, thrust, tickId=self.getTickId()))
示例#4
0
    def _doAim(self):
        playerPos = self.bot.player.pos
        dx = self.pos[0] - playerPos[0]
        dy = self.pos[1] - playerPos[1]
        theta = atan2(dx, -dy)

        self.bot.sendRequest(
            AimPlayerAtMsg(theta, 1.0, self.bot.world.lastTickId))
示例#5
0
 def fireShotAtPoint(self, pos, error=0.15):
     thrust = 1.0
     x1, y1 = self.player.pos
     x2, y2 = pos
     angle = atan2(x2 - x1, -(y2 - y1))
     angle += error * (2 * random.random() - 1)
     self.sendRequest(AimPlayerAtMsg(angle, thrust, self.world.lastTickId))
     self.sendRequest(ShootMsg(self.world.lastTickId))
    def processEvent(self, event):
        '''Event processing works in the following way:
        1. If there is a prompt on screen, the prompt will either use the
        event, or pass it on.
        2. If passed on, the event will be sent back to the main class, for it
        to process whether player movement uses this event. If it doesn't use
        the event, it will pass it back.
        3. If so, the hotkey manager will see if the event means anything to
        it.  If not, that's the end, the event is ignored.
        '''

        # Handle events specific to in-game.
        di = self.gameInterface.detailsInterface
        if self.player:
            if event.type == pygame.KEYDOWN:
                self.processKeyEvent(event.key, True)
            elif event.type == pygame.KEYUP:
                self.processKeyEvent(event.key, False)
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 1:
                    if self.player.dead:
                        if di.trajectoryOverlay.isActive():
                            angle = di.trajectoryOverlay \
                                .getTrajectory().getAngle()
                            di.doAction(ACTION_RESPAWN)
                            self.gameInterface.sendRequest(
                                AimPlayerAtMsg(angle,
                                               1.0,
                                               tickId=self.getTickId()))
                            self._fireShot()
                        else:
                            di.doAction(ACTION_RESPAWN)
                    elif self.player.machineGunner:
                        self.player.machineGunner.firing = True
                    elif di.trajectoryOverlay.isActive():
                        trajectory = di.trajectoryOverlay.getTrajectory()
                        if isinstance(trajectory, PredictedRicochetTrajectory):
                            self._fireShot()
                        else:
                            di.doAction(ACTION_USE_UPGRADE)
                    else:
                        # Fire a shot.
                        self._fireShot()
                else:
                    self.processKeyEvent(mouseButton(event.button), True)
            elif event.type == pygame.MOUSEBUTTONUP:
                if event.button == 1:
                    if self.player.machineGunner:
                        self.player.machineGunner.firing = False
                else:
                    self.processKeyEvent(mouseButton(event.button), False)

            else:
                return event
示例#7
0
    def _reAim(self):
        now = self.bot.world.getMonotonicTime()
        dist = distance(self.bot.player.pos, self.zone.defn.pos)

        if dist < 100:
            if self.bot.player.ghostThrust:
                self.bot.sendRequest(
                    AimPlayerAtMsg(0, 0, self.bot.world.lastTickId))
        elif dist < 300 or self.nextCheckTime < now:
            playerPos = self.bot.player.pos
            zonePos = self.zone.defn.pos
            dx = zonePos[0] - playerPos[0]
            dy = zonePos[1] - playerPos[1]
            theta = atan2(dx, -dy)
            thrust = min(1, distance(playerPos, zonePos) / 300.)

            self.bot.sendRequest(
                AimPlayerAtMsg(theta, thrust, self.bot.world.lastTickId))

            now = self.bot.world.getMonotonicTime()
            self.nextCheckTime = now + 0.5
示例#8
0
 def maybeSendAimMsg(self, tickId):
     '''
     Tell the server where the local player is facing.
     '''
     player = self.localState.player
     if player:
         lastAngle, lastThrust = self.lastPlayerAimSent
         if (lastAngle != player.angleFacing
                 or lastThrust != player.ghostThrust):
             reactor.callLater(
                 0, self.game.agentRequest, self,
                 AimPlayerAtMsg(player.angleFacing, player.ghostThrust,
                                tickId))
             self.lastPlayerAimSent = (player.angleFacing,
                                       player.ghostThrust)
    def updatePlayerViewAngle(self):
        '''Updates the viewing angle of the player based on the mouse pointer
        being at the position pos. This gets its own method because it needs
        to happen as the result of a mouse motion and of the viewManager
        scrolling the screen.'''
        if self.world.uiOptions.showPauseMessage:
            return

        if self.player and self.player.dead and \
                self.gameInterface.detailsInterface.trajectoryOverlay.enabled:

            # Move ghost towards the orb
            pos0 = self.player.pos
            zone = self.player.getZone()
            if zone is None:
                theta = 0
                dist = 0
            else:
                pos1 = zone.defn.pos
                theta = atan2(pos1[0] - pos0[0], -(pos1[1] - pos0[1]))
                dist = distance(pos0, pos1) * MAP_TO_SCREEN_SCALE
        else:
            dx, dy = self.mousePos
            pos = (self.playerSprite.rect.center[0] + dx,
                   self.playerSprite.rect.center[1] + dy)

            if self.playerSprite.rect.collidepoint(pos):
                return

            # Angle is measured clockwise from vertical.
            theta = atan2(dx, -dy)
            dist = (dx**2 + dy**2)**0.5

        # Calculate a thrust value based on distance.
        if dist < self.NO_GHOST_THRUST_MOUSE_RADIUS:
            thrust = 0.0
        elif dist > self.FULL_GHOST_THRUST_MOUSE_RADIUS:
            thrust = 1.0
        else:
            span = (self.FULL_GHOST_THRUST_MOUSE_RADIUS -
                    self.NO_GHOST_THRUST_MOUSE_RADIUS)
            thrust = (dist - self.NO_GHOST_THRUST_MOUSE_RADIUS) / span
            thrust **= 2

        self.gameInterface.sendRequest(
            AimPlayerAtMsg(theta, thrust, tickId=self.getTickId()))
示例#10
0
    def applyInputState(self, inputState):
        directions = [
            (LEFT_STATE, inputState.left),
            (RIGHT_STATE, inputState.right),
            (JUMP_STATE, inputState.jump),
            (DOWN_STATE, inputState.drop),
        ]
        for key, value in directions:
            if self.player.getState(key) != value:
                self.sendRequest(
                    UpdatePlayerStateMsg(value,
                                         stateKey=key,
                                         tickId=self.world.lastTickId))

        self.sendRequest(
            AimPlayerAtMsg(inputState.angle,
                           inputState.thrust,
                           tickId=self.world.lastTickId))
        self._angleRequestedThisTick = (inputState.angle, inputState.thrust)
        self.sendRequest(
            GrapplingHookMsg(inputState.hook, tickId=self.world.lastTickId))
示例#11
0
 def _playerDied(self, killer, deathType):
     self.currentRoute = None
     self.sendRequest(AimPlayerAtMsg(0, 0, self.world.lastTickId))
     self.currentOrder.playerDied()