コード例 #1
0
    def collide_punchers(self):
        if not self.invuln_frames:
            center_col = grid.col_at(self.center_x)
            center_row = grid.row_at(self.center_y)

            if self.level.has_tile(grid.PunchZone, center_col, center_row):
                self._activate_punch_zone(center_col, center_row)
                return

            # Only do special upwards puncher checks if player isn't moving up
            if self.y_vel >= 0:

                # Upwards punchers can also punch based on left and right of the
                # entity rather than just the player's center.  Otherwise, you'll
                # sometimes see the player stand for a moment on the very edge of an
                # upwards puncher
                left_col = grid.col_at(self.x + 2)
                if self.level.has_tile(grid.PunchZone, left_col, center_row):
                    tile = self.level.get_tile(grid.PunchZone, left_col,
                                               center_row)
                    if tile.direction == const.UP:
                        self._activate_punch_zone(left_col, center_row)
                        return

                right_col = grid.col_at(self.x + self._width - 3)
                if self.level.has_tile(grid.PunchZone, right_col, center_row):
                    tile = self.level.get_tile(grid.PunchZone, right_col,
                                               center_row)
                    if tile.direction == const.UP:
                        self._activate_punch_zone(right_col, center_row)

        elif self.invuln_frames:
            self.invuln_frames -= 1
コード例 #2
0
    def _collide_stage(self):
        """checks collision with stage and updates movement accordingly

        if screen_edge is True, then the edge of the screen acts as a wall."""

        for step in range(1, self.CHECK_STEPS + 1):
            diff_x = self._next_x() - self._x
            diff_y = self._next_y() - self._y

            if diff_x < 0:
                dir_x = const.LEFT
            elif diff_x > 0:
                dir_x = const.RIGHT
            else:
                dir_x = 0

            if diff_y < 0:
                dir_y = const.UP
            elif diff_y > 0:
                dir_y = const.DOWN
            else:
                dir_y = 0

            left_x = self._x
            right_x = left_x + self._width - 1
            top_y = int(self._y + (diff_y * (step / self.CHECK_STEPS)))
            bottom_y = top_y + self._height - 1

            if dir_y == const.UP:
                if self.level.collide_horiz(left_x, right_x, top_y,
                                            self.collide_deathlock):
                    self._snap_y(grid.row_at(top_y), const.BOTTOM)
            elif dir_y == const.DOWN:
                if self.level.collide_horiz(left_x, right_x, bottom_y,
                                            self.collide_deathlock):
                    self._snap_y(grid.row_at(bottom_y), const.TOP)

            left_x = int(self._x + (diff_x * (step / 4)))
            right_x = left_x + self._width - 1
            top_y = self._y
            bottom_y = top_y + self._height - 1

            if dir_x == const.LEFT:
                if self.level.collide_vert(left_x, top_y, bottom_y,
                                           self.collide_deathlock):
                    self._snap_x(grid.col_at(left_x), const.RIGHT)

            elif dir_x == const.RIGHT:
                if self.level.collide_vert(right_x, top_y, bottom_y,
                                           self.collide_deathlock):
                    self._snap_x(grid.col_at(right_x), const.LEFT)
コード例 #3
0
    def _collide_checkpoints(self):
        col = grid.col_at(self.center_x)
        row = grid.row_at(self.center_y)
        if self.level.has_tile(grid.CheckpointRay, col, row):
            ray = self.level.get_tile(grid.CheckpointRay, col, row)

            if not (ray.checkpoint is self.checkpoint):
                self._deactivate_checkpoint()
                ray.checkpoint.active = True
                self.checkpoint = ray.checkpoint
                self.CHECKPOINT_CHANGE_SOUNDS.play_random()
コード例 #4
0
 def touching_goal(self):
     col = grid.col_at(self.center_x)
     row = grid.row_at(self.center_y)
     return self.level.has_tile(grid.PlayerGoalZone, col, row)
コード例 #5
0
ファイル: editor.py プロジェクト: winterbeak/deathlock-jam
def mouse_col():
    return grid.col_at(events.mouse.position[0])