예제 #1
0
    def update_level_state(self):
        new_x, new_y = level_state.get_coordinates(self.rect.x, self.rect.y)
        self.replacement = level_state.update_observation(
            self.prev_x, self.prev_y, new_x, new_y, self.id, self.replacement)
        self.prev_x = new_x
        self.prev_y = new_y

        if len(self._Sprite__g) == 0:
            # print(self.id, "killed. New coordinates: (", new_x, new_y, ")")
            level_state.delete_observation(new_x, new_y, self.replacement)
예제 #2
0
    def change_to_piece(self, group):
        arg_list = [
            (self.rect.x, self.rect.y - (self.rect.height / 2), -2, -12),
            (self.rect.right, self.rect.y - (self.rect.height / 2), 2, -12),
            (self.rect.x, self.rect.y, -2, -6),
            (self.rect.right, self.rect.y, 2, -6)
        ]

        for arg in arg_list:
            group.add(BrickPiece(*arg))
        x, y = level_state.get_coordinates(self.rect.x, self.rect.y)
        level_state.delete_observation(x, y)
        self.kill()
예제 #3
0
 def __init__(self, x, y, sheet, image_rect_list, scale, id=None):
     stuff.Stuff.__init__(self, x, y, sheet, image_rect_list, scale)
     self.rect.centerx = x
     self.state = c.REVEAL
     self.y_vel = -1
     self.x_vel = 0
     self.direction = c.RIGHT
     self.box_height = y
     self.gravity = 1
     self.max_y_vel = 8
     self.animate_timer = 0
     self.id = id
     if self.id == c.FIREBALL_ID:
         self.replacement = c.AIR_ID
     else:
         self.replacement = c.SOLID_ID
     self.prev_x, self.prev_y = level_state.get_coordinates(
         self.rect.x, self.rect.y)
예제 #4
0
    def setup_enemy(self,
                    x,
                    y,
                    direction,
                    name,
                    sheet,
                    frame_rect_list,
                    in_range,
                    range_start,
                    range_end,
                    is_vertical=False,
                    id=None,
                    q=None,
                    level=None):
        self.textsurface = None if q is None else level.q_font.render(
            q, True, (255, 255, 255))
        self.frames = []
        self.frame_index = 0
        self.animate_timer = 0
        self.gravity = 1.5
        self.state = c.WALK

        self.name = name
        self.direction = direction
        self.load_frames(sheet, frame_rect_list)
        self.image = self.frames[self.frame_index]
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.bottom = y
        self.in_range = in_range
        self.range_start = range_start
        self.range_end = range_end
        self.isVertical = is_vertical
        self.set_velocity()
        self.death_timer = 0
        self.id = id
        self.replacement = c.AIR_ID
        self.prev_x, self.prev_y = level_state.get_coordinates(
            self.rect.x, self.rect.y)

        if self.textsurface is not None and c.PRINT_Q_VALUES:
            self.image.blit(self.textsurface, (3, 15))
예제 #5
0
    def bumped(self):
        self.rect.y += self.y_vel
        self.y_vel += self.gravity

        if self.rect.y > self.rest_height + 5:
            self.rect.y = self.rest_height
            self.state = c.OPENED
            if self.type == c.TYPE_MUSHROOM:
                self.group.add(powerup.Mushroom(self.rect.centerx,
                                                self.rect.y))
            elif self.type == c.TYPE_FIREFLOWER:
                self.group.add(
                    powerup.FireFlower(self.rect.centerx, self.rect.y))
            elif self.type == c.TYPE_LIFEMUSHROOM:
                self.group.add(
                    powerup.LifeMushroom(self.rect.centerx, self.rect.y))
            x, y = level_state.get_coordinates(self.rect.x, self.rect.y)
            level_state.update_observation(x, y, x, y, c.SOLID_ID, c.SOLID_ID)
        self.frame_index = 4
        self.image = self.frames[self.frame_index]
예제 #6
0
    def update(self, game_info, player_x, level):
        if np.abs(player_x - self.rect.x) <= c.UPDATE_RADIUS:
            self.current_time = game_info[c.CURRENT_TIME]
            self.handle_state()
            self.animation()
            self.update_position(level)

            new_x, new_y = level_state.get_coordinates(self.rect.x,
                                                       self.rect.y)
            self.replacement = level_state.update_observation(
                self.prev_x, self.prev_y, new_x, new_y, self.id,
                self.replacement)
            self.prev_x = new_x
            self.prev_y = new_y

        if len(self._Sprite__g) == 0:
            # print(self.id, "killed. New coordinates: (", new_x, new_y, ")")
            level_state.delete_observation(self.prev_x, self.prev_y)
            # level_state.print_2d(level_state.state)

        if self.textsurface is not None and c.PRINT_Q_VALUES:
            self.image.blit(self.textsurface, (3, 15))
예제 #7
0
 def update(self):
     if self.state == c.BUMPED:
         self.bumped()
     elif self.state == c.OPENED:
         x, y = level_state.get_coordinates(self.rect.x, self.rect.y)
         level_state.update_observation(x, y, x, y, c.SOLID_ID, c.SOLID_ID)
예제 #8
0
 def update_level_state(self):
     if len(self._Sprite__g) == 0:
         x, y = level_state.get_coordinates(self.rect.x, self.rect.y)
         level_state.delete_observation(x, y)