Exemplo n.º 1
0
    def init_image(self):
        sprite_sheet = SpriteSheet("data/item_objects.png")

        if self.x_vel < 0:
            self.image = sprite_sheet.get_image(coords.BRICK_PIECE_LEFT, c.IMG_MULTIPLIER, c.WHITE)
        else:
            self.image = sprite_sheet.get_image(coords.BRICK_PIECE_RIGHT, c.IMG_MULTIPLIER, c.WHITE)
Exemplo n.º 2
0
    def __init__(self, sound_manager, game_info):
        pygame.sprite.Sprite.__init__(self)

        self.sound_manager = sound_manager
        self.game_info = game_info

        self.state = c.STATE_STANDING
        self.power = c.POWER_SMALL
        self.direction = c.DIR_RIGHT
        self.world_shift = 0

        self.transition_state = None
        self.transition_timer = 0

        self.player_small_frames = {}
        self.player_frames = {}
        self.transition_frames = {}
        self.death_frame = None

        self.sprite_sheet = SpriteSheet("data/characters.gif")

        self.load_player_small_frames()
        self.load_player_adult_frames()

        self.image = self.get_player_frame(self.state, self.direction)
        self.rect = self.image.get_rect()

        self.rect.left = 100

        self.x_vel = 0
        self.y_vel = 0
Exemplo n.º 3
0
    def init_frames(self):
        sprite_sheet = SpriteSheet("data/tile_set.png")

        self.coin_box_frames.append(sprite_sheet.get_image(coords.COIN_BOX_1, c.IMG_MULTIPLIER, c.WHITE))
        self.coin_box_frames.append(sprite_sheet.get_image(coords.COIN_BOX_2, c.IMG_MULTIPLIER, c.WHITE))
        self.coin_box_frames.append(sprite_sheet.get_image(coords.COIN_BOX_3, c.IMG_MULTIPLIER, c.WHITE))

        self.empty_frame = sprite_sheet.get_image(coords.COIN_BOX_EMPTY, c.IMG_MULTIPLIER, c.WHITE)
Exemplo n.º 4
0
    def init_image(self):
        sprite_sheet = SpriteSheet("data/item_objects.png")

        if self.x_vel < 0:
            self.image = sprite_sheet.get_image(coords.BRICK_PIECE_LEFT,
                                                c.IMG_MULTIPLIER, c.WHITE)
        else:
            self.image = sprite_sheet.get_image(coords.BRICK_PIECE_RIGHT,
                                                c.IMG_MULTIPLIER, c.WHITE)
Exemplo n.º 5
0
    def init_score_dictionary(self):
        tile_set = SpriteSheet("data/item_objects.png")

        self.score_dict[0] = tile_set.get_image(coords.SCORE_WHITE_0, c.IMG_MULTIPLIER)
        self.score_dict[1] = tile_set.get_image(coords.SCORE_WHITE_1, c.IMG_MULTIPLIER)
        self.score_dict[2] = tile_set.get_image(coords.SCORE_WHITE_2, c.IMG_MULTIPLIER)
        self.score_dict[4] = tile_set.get_image(coords.SCORE_WHITE_4, c.IMG_MULTIPLIER)
        self.score_dict[5] = tile_set.get_image(coords.SCORE_WHITE_5, c.IMG_MULTIPLIER)
        self.score_dict[8] = tile_set.get_image(coords.SCORE_WHITE_8, c.IMG_MULTIPLIER)
Exemplo n.º 6
0
    def __init__(self, game_info):
        GameState.__init__(self, GameState.STATE_LOAD, GameState.STATE_GAME)

        self.game_info = game_info
        self.text_helper = TextHelper()

        self.load_screen_time = -1
        # Mario frame
        sprite_sheet = SpriteSheet("data/characters.gif")
        self.mario_frame = sprite_sheet.get_image(coords.MARIO_SMALL_STANDING_RIGHT, c.IMG_MULTIPLIER)
Exemplo n.º 7
0
    def init_frames(self):
        sprite_sheet = SpriteSheet("data/item_objects.png")

        self.coin_frames.append(sprite_sheet.get_image(coords.COIN_SPINNING_1, constants.IMG_MULTIPLIER))
        self.coin_frames.append(sprite_sheet.get_image(coords.COIN_SPINNING_2, constants.IMG_MULTIPLIER))
        self.coin_frames.append(sprite_sheet.get_image(coords.COIN_SPINNING_3, constants.IMG_MULTIPLIER))
        self.coin_frames.append(sprite_sheet.get_image(coords.COIN_SPINNING_4, constants.IMG_MULTIPLIER))

        for frame in self.coin_frames:
            frame.set_colorkey(constants.BLACK)
Exemplo n.º 8
0
    def __init__(self, game_info):
        GameState.__init__(self, GameState.STATE_LOAD, GameState.STATE_GAME)

        self.game_info = game_info
        self.text_helper = TextHelper()

        self.load_screen_time = -1
        # Mario frame
        sprite_sheet = SpriteSheet("data/characters.gif")
        self.mario_frame = sprite_sheet.get_image(
            coords.MARIO_SMALL_STANDING_RIGHT, c.IMG_MULTIPLIER)
Exemplo n.º 9
0
    def init_background(self):
        # Background
        background_ss = SpriteSheet("data/levels/level_1.png")
        self.background = background_ss.get_image(coords.LEVEL_1, constants.IMG_MULTIPLIER, constants.WHITE)

        # Title image
        title_screen_ss = SpriteSheet("data/title_screen.png")
        self.title = title_screen_ss.get_image(coords.MAIN_TITLE, constants.IMG_MULTIPLIER, constants.WHITE)

        self.title_rect = self.title.get_rect()
        self.title_rect.centerx = constants.SCREEN_WIDTH_MID
        self.title_rect.centery = 200
Exemplo n.º 10
0
    def __init__(self, x, y):
        Powerup.__init__(self, x, y)

        sprite_sheet = SpriteSheet("data/item_objects.png")

        self.x_vel = 2

        self.display_frame = sprite_sheet.get_image(coords.MUSHROOM_POWERUP, c.IMG_MULTIPLIER, c.BLACK)
        self.refresh_image(self.display_frame)

        self.time = 0

        self.y_cap = self.rect.y - self.rect.height
Exemplo n.º 11
0
    def __init__(self):
        GameState.__init__(self, GameState.STATE_MENU, GameState.STATE_LOAD)

        self.player_num = 1
        self.background = None
        self.title = None
        self.title_rect = None

        self.init_background()
        self.text_helper = TextHelper()

        item_objects_ss = SpriteSheet("data/item_objects.png")
        self.selector_frame = item_objects_ss.get_image(coords.TITLE_SELECTOR, constants.IMG_MULTIPLIER)
Exemplo n.º 12
0
    def __init__(self, game_info):
        self.game_info = game_info

        self.text_helper = TextHelper()
        self.coin_frame_idx = 0
        self.coin_time = 0

        # tile_set.png
        item_objects_ss = SpriteSheet("data/item_objects.png")

        self.coin_frames = []
        self.coin_frames.append(item_objects_ss.get_image(coords.TITLE_COIN_1, constants.IMG_MULTIPLIER))
        self.coin_frames.append(item_objects_ss.get_image(coords.TITLE_COIN_2, constants.IMG_MULTIPLIER))
        self.coin_frames.append(item_objects_ss.get_image(coords.TITLE_COIN_3, constants.IMG_MULTIPLIER))
Exemplo n.º 13
0
    def __init__(self):
        GameState.__init__(self, GameState.STATE_MENU, GameState.STATE_LOAD)

        self.player_num = 1
        self.background = None
        self.title = None
        self.title_rect = None

        self.init_background()
        self.text_helper = TextHelper()

        item_objects_ss = SpriteSheet("data/item_objects.png")
        self.selector_frame = item_objects_ss.get_image(
            coords.TITLE_SELECTOR, constants.IMG_MULTIPLIER)
Exemplo n.º 14
0
    def __init__(self, x, y):
        Powerup.__init__(self, x, y)

        sprite_sheet = SpriteSheet("data/item_objects.png")

        self.x_vel = 2

        self.display_frame = sprite_sheet.get_image(coords.MUSHROOM_POWERUP,
                                                    c.IMG_MULTIPLIER, c.BLACK)
        self.refresh_image(self.display_frame)

        self.time = 0

        self.y_cap = self.rect.y - self.rect.height
Exemplo n.º 15
0
class SpriteElement(Element):
    def __init__(self, pos, type, frames, frames_per_row, input):
        super().__init__(pos, input)
        self.sprite = SpriteSheet(res.textures[type])
        self.sprite.init(frames, frames_per_row)
        self.sprite.position = pos
        self.local_bounds = self.sprite.local_bounds

    def update(self, dt):
        if self.sprite.position != self.local_bounds.position:
            self.sprite.position = self.local_bounds.position

    def draw(self, target):
        target.draw(self.sprite)
Exemplo n.º 16
0
class SpriteElement(Element):
    def __init__(self, pos, type, input, frames, frames_per_row):
        super().__init__(pos, input)
        self.sprite = SpriteSheet(res.textures[type])
        self.sprite.init(frames, frames_per_row)
        self.sprite.position = pos
        self.local_bounds = self.sprite.local_bounds
        self.center = sf.Vector2(self.local_bounds.width/2, self.local_bounds.height/2)
        
    def update(self, dt):
        self.sprite.position = self.local_bounds.position
        
    def draw(self, target):
        target.draw(self.sprite)
Exemplo n.º 17
0
 def __init__(self, pos, type, input, frames, frames_per_row):
     super().__init__(pos, input)
     self.sprite = SpriteSheet(res.textures[type])
     self.sprite.init(frames, frames_per_row)
     self.sprite.position = pos
     self.local_bounds = self.sprite.local_bounds
     self.center = sf.Vector2(self.local_bounds.width/2, self.local_bounds.height/2)
Exemplo n.º 18
0
 def __init__(self, pos_x: int, pos_y: int, *groups):
     super().__init__(*groups)
     self.lifes = 3
     self.image = SpriteSheet('res/sprite/spritesheet.png').get_sprite(
         16, 38, 9, 10)
     self.image = pygame.transform.scale(self.image, (27, 30))
     self.rect = pygame.Rect(pos_x, pos_y, 27, 30)
Exemplo n.º 19
0
    def __load_spritesheet(self, object_name: str):
        ss_obj = self.__assets_file[object_name]
        ss_filepath = f'assets/{ss_obj["filepath"]}'

        ss_tile_size = ss_obj['tile_size']
        ss_render_tile_size = ss_obj['render_tile_size']

        return SpriteSheet(ss_filepath, ss_tile_size, ss_render_tile_size)
Exemplo n.º 20
0
    def __init__(self, *groups):
        super().__init__(*groups)
        sprite_sheet = SpriteSheet('res/sprite/spritesheet.png')
        self.sprites = {
            'HeroRun': [
                sprite_sheet.get_sprite(1, 9, 7, 7),
                sprite_sheet.get_sprite(11, 9, 7, 7),
                sprite_sheet.get_sprite(21, 9, 7, 7), (28, 28)
            ],
            'HeroGun': [
                sprite_sheet.get_sprite(32, 22, 11, 9),
                sprite_sheet.get_sprite(44, 22, 11, 9),
                sprite_sheet.get_sprite(56, 22, 11, 9), (44, 36)
            ]
        }

        self.image = sprite_sheet.get_sprite(0, 9, 9, 9)
        self.image = pygame.transform.scale(self.image, [28, 28])
        self.rect = pygame.Rect(32 * 8, 32 * 8, 28, 28)

        self.sprite_anim = 'HeroRun'
        self.animations = {'Gun': False, 'GunPerma': False}

        self.lado_x = [True, True]
        self.lado_y = [True, True]

        self.speed: int = 5
        self.velocity = 4
        self.sprite_count: int = 1

        self.rotation = None
Exemplo n.º 21
0
def basic_enemy(x, y, spritesheet: SpriteSheet, **kw):
    state = State(default_state="Walking", noraml_states={"Walking"})

    size = spritesheet.size

    rect = pygame.Rect((x, y), size)

    image_ref = spritesheet.process()
    return Enemy(state=state, image_ref=image_ref, rect=rect, **kw)
Exemplo n.º 22
0
def basic_player(game, spritesheet: SpriteSheet):
    state = State(noraml_states={"Idle", "Walking"},
                  unstopable_states={"Jumping", "Dead"})

    size = spritesheet.size

    rect = pygame.Rect((0, 0), size)

    image_ref = spritesheet.process()
    return Player(state=state, image_ref=image_ref, rect=rect)
Exemplo n.º 23
0
 def __init__(self):
     self.sprite = SpriteSheet(res.laser_light1)
     self.sprite.init(4, 4)
     self.sprite.origin = self.sprite.frame_dim/2
     self.explosion_sprite = SpriteSheet(res.explosion_missile1)
     self.explosion_sprite.init(9, 9, 0.05)
     self.explosion_sprite.origin = self.explosion_sprite.frame_dim/2
     self.damage = 1
     self.phase = 0 # 0 = Weapon to offscreen, 1 = offscreen to target, 2 = detonation
     self.target_room = None
     self.start_position = sf.Vector2(0, 0)
     self.to_offscreen_position = sf.Vector2(0, 0)
     self.from_offscreen_position = sf.Vector2(0, 0)
     self.target_position = sf.Vector2(0, 0)
     self.fire_time = 0
     self.hit_time = 0
     self.hit = True # Hit or miss?
     self.hit_shields = False # Hit shields or ship?
     self.active = False
     self.is_mine = False # Does this projectile belong to me? (Client only, used for lock_window stuff)
Exemplo n.º 24
0
    def __init__(self, x_pos: int, y_pos: int, mouse, *groups):
        super().__init__(*groups)

        spritesheet = SpriteSheet('res/sprite/spritesheet.png')
        self.sprites = [
            spritesheet.get_sprite(31, 12, 5, 5),
            spritesheet.get_sprite(37, 12, 5, 5),
            spritesheet.get_sprite(43, 12, 5, 5),
            spritesheet.get_sprite(49, 12, 5, 5),
            spritesheet.get_sprite(55, 12, 5, 5),
            spritesheet.get_sprite(61, 12, 5, 5)
        ]

        self.sprite_count: int = 0
        self.image = spritesheet.get_sprite(31, 12, 5, 5)
        self.image = pygame.transform.scale(self.image, (15, 15))
        self.mouse = mouse
        self.rect = pygame.Rect(x_pos, y_pos, 5, 5)

        self.pos_x = x_pos
        self.pos_y = y_pos

        self.ang = math.atan2(
            self.mouse[0] - self.rect.center[0],
            self.mouse[1] - self.rect.center[1]) - math.pi / 2
        self.ang_x = math.cos(self.ang) * 5
        self.ang_y = math.sin(self.ang) * 5
Exemplo n.º 25
0
    def __init__(self, id):
        self.id = id
        self.sprite = SpriteSheet(res.weapon)
        self.sprite.init(12, 12, 0.06)
        self.sprite.set_frame_loop(5, 5, False)

        self.slot = None  # WeaponSlot this weapon is in
        self.position = sf.Vector2(0, 0)

        self.firing = False  # Whether or not it's firing this turn
        self.powered = False  # Is the weapon powered or unpowered
        self.was_powered = False  # Was the weapon powered last turn? (Used for weapon slide out/in animation)
        self.target = None  # Target room

        self.charge = 0

        self.required_charge = 1
        self.required_power = 1  # Power consumption
        self.projectile_type = None
        self.num_shots = 2

        self.projectiles = [Projectile(), Projectile()]
Exemplo n.º 26
0
    def init_score_dictionary(self):
        tile_set = SpriteSheet("data/item_objects.png")

        self.score_dict[0] = tile_set.get_image(coords.SCORE_WHITE_0,
                                                c.IMG_MULTIPLIER)
        self.score_dict[1] = tile_set.get_image(coords.SCORE_WHITE_1,
                                                c.IMG_MULTIPLIER)
        self.score_dict[2] = tile_set.get_image(coords.SCORE_WHITE_2,
                                                c.IMG_MULTIPLIER)
        self.score_dict[4] = tile_set.get_image(coords.SCORE_WHITE_4,
                                                c.IMG_MULTIPLIER)
        self.score_dict[5] = tile_set.get_image(coords.SCORE_WHITE_5,
                                                c.IMG_MULTIPLIER)
        self.score_dict[8] = tile_set.get_image(coords.SCORE_WHITE_8,
                                                c.IMG_MULTIPLIER)
Exemplo n.º 27
0
class Projectile:
    def __init__(self):
        self.sprite = SpriteSheet(res.laser_light1)
        self.sprite.init(4, 4)
        self.sprite.origin = self.sprite.frame_dim/2
        self.explosion_sprite = SpriteSheet(res.explosion_missile1)
        self.explosion_sprite.init(9, 9, 0.05)
        self.explosion_sprite.origin = self.explosion_sprite.frame_dim/2
        self.damage = 1
        self.phase = 0 # 0 = Weapon to offscreen, 1 = offscreen to target, 2 = detonation
        self.target_room = None
        self.start_position = sf.Vector2(0, 0)
        self.to_offscreen_position = sf.Vector2(0, 0)
        self.from_offscreen_position = sf.Vector2(0, 0)
        self.target_position = sf.Vector2(0, 0)
        self.fire_time = 0
        self.hit_time = 0
        self.hit = True # Hit or miss?
        self.hit_shields = False # Hit shields or ship?
        self.active = False
        self.is_mine = False # Does this projectile belong to me? (Client only, used for lock_window stuff)

    def apply_simulation_time(self, time):
        if self.phase == 0:
            start_position = self.start_position
            end_position = self.to_offscreen_position
            interp = (time - self.fire_time)/(1.0) # Half a second to offscreen
            if time > self.fire_time+1.0:
                self.phase = 1
        elif self.phase == 1:
            start_position = self.from_offscreen_position
            end_position = self.target_position
            interp = (time - (self.hit_time-0.7))/(0.7) # Third of a second from offscreen to target
            #if time > self.hit_time:
            #    self.phase = 2
            
        self.sprite.rotation = math.degrees(math.atan2(end_position.y-start_position.y, end_position.x-start_position.x))
        self.sprite.position = start_position + (end_position-start_position)*interp

    def detonate(self):
        if self.hit_shields:
            self.target_room.ship.shield_system.shields -= self.damage
        else:
            self.target_room.ship.hull_points -= self.damage
            if self.target_room.system:
                self.target_room.system.deal_damage(self.damage)
        self.active = False
        self.phase = 2
        self.explosion_sprite.set_frame_loop(0, 8, False)
        self.explosion_sprite.position = self.sprite.position
Exemplo n.º 28
0
 def __init__(self, pos_x: int, pos_y: int, *groups):
     super().__init__(*groups)
     self.type: str = 'Gun'
     self.perma_item: str = 'GunPerma'
     spritesheet = SpriteSheet('res/sprite/spritesheet.png')
     self.sprites = [
         spritesheet.get_sprite(0, 0, 11, 7),
         spritesheet.get_sprite(12, 0, 11, 7),
         spritesheet.get_sprite(24, 0, 11, 7),
         spritesheet.get_sprite(36, 0, 11, 7)
     ]
     self.sprite_count: int = 0
     self.image = spritesheet.get_sprite(0, 0, 11, 7)
     self.image = pygame.transform.scale(self.image, [22, 14])
     self.rect = pygame.Rect(pos_x, pos_y, 35, 28)
Exemplo n.º 29
0
    def init_background(self):
        # Background
        background_ss = SpriteSheet("data/levels/level_1.png")
        self.background = background_ss.get_image(coords.LEVEL_1,
                                                  constants.IMG_MULTIPLIER,
                                                  constants.WHITE)

        # Title image
        title_screen_ss = SpriteSheet("data/title_screen.png")
        self.title = title_screen_ss.get_image(coords.MAIN_TITLE,
                                               constants.IMG_MULTIPLIER,
                                               constants.WHITE)

        self.title_rect = self.title.get_rect()
        self.title_rect.centerx = constants.SCREEN_WIDTH_MID
        self.title_rect.centery = 200
Exemplo n.º 30
0
class Weapon:
    def __init__(self, id):
        self.id = id
        self.sprite = SpriteSheet(res.weapon)
        self.sprite.init(12, 12, 0.06)
        self.sprite.set_frame_loop(5, 5, False)

        self.slot = None  # WeaponSlot this weapon is in
        self.position = sf.Vector2(0, 0)

        self.firing = False  # Whether or not it's firing this turn
        self.powered = False  # Is the weapon powered or unpowered
        self.was_powered = False  # Was the weapon powered last turn? (Used for weapon slide out/in animation)
        self.target = None  # Target room

        self.charge = 0

        self.required_charge = 1
        self.required_power = 1  # Power consumption
        self.projectile_type = None
        self.num_shots = 2

        self.projectiles = [Projectile(), Projectile()]

    def apply_simulation_time(self, time):
        if time <= 0.3:  # weapon slide in/out animation
            if self.powered and not self.was_powered:
                self.position = self.slot.position + self.slot.powered_offset * (
                    time / 0.3)
            if not self.powered and self.was_powered:
                self.position = self.slot.position + self.slot.powered_offset - self.slot.powered_offset * (
                    time / 0.3)

        if self.firing:
            for projectile in self.projectiles:
                if time >= projectile.fire_time:
                    if time <= projectile.hit_time:
                        if not projectile.active:
                            self.sprite.set_frame_loop(5, 11, False)
                        projectile.active = True
                    else:
                        if projectile.hit and projectile.active:
                            projectile.detonate()

    def tuplify(self):
        return (self.id, )
Exemplo n.º 31
0
    def init_frames(self):
        sprite_sheet = SpriteSheet("data/item_objects.png")

        self.coin_frames.append(
            sprite_sheet.get_image(coords.COIN_SPINNING_1,
                                   constants.IMG_MULTIPLIER))
        self.coin_frames.append(
            sprite_sheet.get_image(coords.COIN_SPINNING_2,
                                   constants.IMG_MULTIPLIER))
        self.coin_frames.append(
            sprite_sheet.get_image(coords.COIN_SPINNING_3,
                                   constants.IMG_MULTIPLIER))
        self.coin_frames.append(
            sprite_sheet.get_image(coords.COIN_SPINNING_4,
                                   constants.IMG_MULTIPLIER))

        for frame in self.coin_frames:
            frame.set_colorkey(constants.BLACK)
Exemplo n.º 32
0
    def init_frames(self):
        sprite_sheet = SpriteSheet("data/characters.gif")

        self.goomba_frames.append(sprite_sheet.get_image(coords.GOOMBA_LEFT, c.IMG_MULTIPLIER, c.BLUE))
        self.goomba_frames.append(sprite_sheet.get_image(coords.GOOMBA_RIGHT, c.IMG_MULTIPLIER, c.BLUE))
        self.dead_frame = sprite_sheet.get_image(coords.GOOMBA_DEAD, c.IMG_MULTIPLIER, c.BLUE)
Exemplo n.º 33
0
 def __init__(self, pos, type, frames, frames_per_row, input):
     super().__init__(pos, input)
     self.sprite = SpriteSheet(res.textures[type])
     self.sprite.init(frames, frames_per_row)
     self.sprite.position = pos
     self.local_bounds = self.sprite.local_bounds
Exemplo n.º 34
0
 def init_frames(self):
     sprite_sheet = SpriteSheet("data/tile_set.png")
     self.display_frame = sprite_sheet.get_image(coords.BRICK, c.IMG_MULTIPLIER, c.WHITE)
Exemplo n.º 35
0
class Player(pygame.sprite.Sprite):
    def __init__(self, sound_manager, game_info):
        pygame.sprite.Sprite.__init__(self)

        self.sound_manager = sound_manager
        self.game_info = game_info

        self.state = c.STATE_STANDING
        self.power = c.POWER_SMALL
        self.direction = c.DIR_RIGHT
        self.world_shift = 0

        self.transition_state = None
        self.transition_timer = 0

        self.player_small_frames = {}
        self.player_frames = {}
        self.transition_frames = {}
        self.death_frame = None

        self.sprite_sheet = SpriteSheet("data/characters.gif")

        self.load_player_small_frames()
        self.load_player_adult_frames()

        self.image = self.get_player_frame(self.state, self.direction)
        self.rect = self.image.get_rect()

        self.rect.left = 100

        self.x_vel = 0
        self.y_vel = 0

    def load_player_small_frames(self):
        dir_keys = [c.DIR_LEFT, c.DIR_RIGHT]
        self.player_small_frames[c.STATE_STANDING] = dict((key, []) for key in dir_keys)
        self.player_small_frames[c.STATE_WALKING] = dict((key, []) for key in dir_keys)
        self.player_small_frames[c.STATE_JUMPING] = dict((key, []) for key in dir_keys)
        self.transition_frames = dict((key, []) for key in dir_keys)

        # Standing frames
        small_standing_left = self.sprite_sheet.get_image(coords.MARIO_SMALL_STANDING_LEFT, c.IMG_MULTIPLIER)
        small_standing_right = self.sprite_sheet.get_image(coords.MARIO_SMALL_STANDING_RIGHT, c.IMG_MULTIPLIER)
        self.player_small_frames[c.STATE_STANDING][c.DIR_LEFT].append(small_standing_left)
        self.player_small_frames[c.STATE_STANDING][c.DIR_RIGHT].append(small_standing_right)

        # Jumping frames
        small_jumping_left = self.sprite_sheet.get_image(coords.MARIO_SMALL_JUMPING_LEFT, c.IMG_MULTIPLIER)
        small_jumping_right = self.sprite_sheet.get_image(coords.MARIO_SMALL_JUMPING_RIGHT, c.IMG_MULTIPLIER)
        self.player_small_frames[c.STATE_JUMPING][c.DIR_LEFT].append(small_jumping_left)
        self.player_small_frames[c.STATE_JUMPING][c.DIR_RIGHT].append(small_jumping_right)

        # Transition frames
        self.transition_frames[c.DIR_LEFT] = self.sprite_sheet.get_image(coords.MARIO_TRANSITION_MID_LEFT, c.IMG_MULTIPLIER)
        self.transition_frames[c.DIR_RIGHT] = self.sprite_sheet.get_image(coords.MARIO_TRANSITION_MID_RIGHT, c.IMG_MULTIPLIER)

        # Death frame
        self.death_frame = self.sprite_sheet.get_image(coords.MARIO_DEAD, c.IMG_MULTIPLIER)

        # Walking frames
        right_1 = self.sprite_sheet.get_image(coords.MARIO_SMALL_WALKING_RIGHT_1, c.IMG_MULTIPLIER)
        right_2 = self.sprite_sheet.get_image(coords.MARIO_SMALL_WALKING_RIGHT_2, c.IMG_MULTIPLIER)
        right_3 = self.sprite_sheet.get_image(coords.MARIO_SMALL_WALKING_RIGHT_3, c.IMG_MULTIPLIER)

        self.player_small_frames[c.STATE_WALKING][c.DIR_RIGHT].append(right_1)
        self.player_small_frames[c.STATE_WALKING][c.DIR_RIGHT].append(right_2)
        self.player_small_frames[c.STATE_WALKING][c.DIR_RIGHT].append(right_3)

        left_1 = self.sprite_sheet.get_image(coords.MARIO_SMALL_WALKING_LEFT_1, c.IMG_MULTIPLIER)
        left_2 = self.sprite_sheet.get_image(coords.MARIO_SMALL_WALKING_LEFT_2, c.IMG_MULTIPLIER)
        left_3 = self.sprite_sheet.get_image(coords.MARIO_SMALL_WALKING_LEFT_3, c.IMG_MULTIPLIER)

        self.player_small_frames[c.STATE_WALKING][c.DIR_LEFT].append(left_1)
        self.player_small_frames[c.STATE_WALKING][c.DIR_LEFT].append(left_2)
        self.player_small_frames[c.STATE_WALKING][c.DIR_LEFT].append(left_3)

    def load_player_adult_frames(self):
        dir_keys = [c.DIR_LEFT, c.DIR_RIGHT]
        self.player_frames[c.STATE_STANDING] = dict((key, []) for key in dir_keys)
        self.player_frames[c.STATE_WALKING] = dict((key, []) for key in dir_keys)
        self.player_frames[c.STATE_JUMPING] = dict((key, []) for key in dir_keys)
        self.player_frames[c.STATE_CROUCHING] = dict((key, []) for key in dir_keys)

        # Standing frames
        big_standing_left = self.sprite_sheet.get_image(coords.MARIO_BIG_STANDING_LEFT, c.IMG_MULTIPLIER)
        big_standing_right = self.sprite_sheet.get_image(coords.MARIO_BIG_STANDING_RIGHT, c.IMG_MULTIPLIER)
        self.player_frames[c.STATE_STANDING][c.DIR_LEFT].append(big_standing_left)
        self.player_frames[c.STATE_STANDING][c.DIR_RIGHT].append(big_standing_right)

        # Jumping frames
        big_jumping_left = self.sprite_sheet.get_image(coords.MARIO_BIG_JUMPING_LEFT, c.IMG_MULTIPLIER)
        big_jumping_right = self.sprite_sheet.get_image(coords.MARIO_BIG_JUMPING_RIGHT, c.IMG_MULTIPLIER)
        self.player_frames[c.STATE_JUMPING][c.DIR_LEFT].append(big_jumping_left)
        self.player_frames[c.STATE_JUMPING][c.DIR_RIGHT].append(big_jumping_right)

        # Crouching frames
        big_crouching_left = self.sprite_sheet.get_image(coords.MARIO_BIG_CROUCHING_LEFT, c.IMG_MULTIPLIER)
        big_crouching_right = self.sprite_sheet.get_image(coords.MARIO_BIG_CROUCHING_RIGHT, c.IMG_MULTIPLIER)
        self.player_frames[c.STATE_CROUCHING][c.DIR_LEFT].append(big_crouching_left)
        self.player_frames[c.STATE_CROUCHING][c.DIR_RIGHT].append(big_crouching_right)

        # Walking frames
        right_1 = self.sprite_sheet.get_image(coords.MARIO_BIG_WALKING_RIGHT_1, c.IMG_MULTIPLIER)
        right_2 = self.sprite_sheet.get_image(coords.MARIO_BIG_WALKING_RIGHT_2, c.IMG_MULTIPLIER)
        right_3 = self.sprite_sheet.get_image(coords.MARIO_BIG_WALKING_RIGHT_3, c.IMG_MULTIPLIER)

        self.player_frames[c.STATE_WALKING][c.DIR_RIGHT].append(right_1)
        self.player_frames[c.STATE_WALKING][c.DIR_RIGHT].append(right_2)
        self.player_frames[c.STATE_WALKING][c.DIR_RIGHT].append(right_3)

        left_1 = self.sprite_sheet.get_image(coords.MARIO_BIG_WALKING_LEFT_1, c.IMG_MULTIPLIER)
        left_2 = self.sprite_sheet.get_image(coords.MARIO_BIG_WALKING_LEFT_2, c.IMG_MULTIPLIER)
        left_3 = self.sprite_sheet.get_image(coords.MARIO_BIG_WALKING_LEFT_3, c.IMG_MULTIPLIER)

        self.player_frames[c.STATE_WALKING][c.DIR_LEFT].append(left_1)
        self.player_frames[c.STATE_WALKING][c.DIR_LEFT].append(left_2)
        self.player_frames[c.STATE_WALKING][c.DIR_LEFT].append(left_3)

    def get_player_frame(self, state, direction, position=0):
        if self.power == c.POWER_SMALL:
            frame_idx = position % len(self.player_small_frames[state][direction])
            return self.player_small_frames[state][direction][frame_idx]
        else:
            frame_idx = position % len(self.player_frames[state][direction])
            return self.player_frames[state][direction][frame_idx]

    def shift(self, shift):
        self.world_shift += shift

    def refresh_rect(self):
        bottom = self.rect.bottom
        left = self.rect.left
        self.rect = self.image.get_rect()
        self.rect.bottom = bottom
        self.rect.x = left

    def update(self, level, current_time):
        if self.transition_state:
            if self.transition_state == c.TRANSITION_SMALL_TO_BIG:
                self.small_to_big(current_time)
            elif self.transition_state == c.TRANSITION_BIG_TO_SMALL:
                self.big_to_small(current_time)
            elif self.transition_state == c.TRANSITION_DEATH_SEQUENCE:
                self.death_sequence(current_time)
                self.calc_gravity()
                self.rect.y += self.y_vel

            self.refresh_rect()
            return

        self.calc_gravity()

        self.rect.x += self.x_vel

        # TODO group all these collision groups together

        ground_collisions_x = pygame.sprite.spritecollide(self, level.ground_group, False)
        for platform in ground_collisions_x:
            if self.x_vel > 0:
                self.rect.right = platform.rect.left
            elif self.x_vel < 0:
                self.rect.left = platform.rect.right

        coin_box_collisions_x = pygame.sprite.spritecollide(self, level.coin_box_group, False)
        for coin_box in coin_box_collisions_x:
            if self.x_vel > 0:
                self.rect.right = coin_box.rect.left
            elif self.x_vel < 0:
                self.rect.left = coin_box.rect.right

        brick_box_collisions_x = pygame.sprite.spritecollide(self, level.brick_box_group, False)
        for brick_box in brick_box_collisions_x:
            if self.x_vel > 0:
                self.rect.right = brick_box.rect.left
            elif self.x_vel < 0:
                self.rect.left = brick_box.rect.right

        self.rect.y += self.y_vel
        ground_collisions_y = pygame.sprite.spritecollideany(self, level.ground_group)
        if ground_collisions_y:
            self.rect.bottom = ground_collisions_y.rect.top
            self.y_vel = 0

        coin_box_collisions_y = pygame.sprite.spritecollideany(self, level.coin_box_group)
        if coin_box_collisions_y:
            if self.y_vel < 0:
                self.rect.top = coin_box_collisions_y.rect.bottom
                points, coins = coin_box_collisions_y.activate()
                self.game_info.points += points
                self.game_info.coins += coins
            else:
                self.rect.bottom = coin_box_collisions_y.rect.top

            self.y_vel = 0

        brick_box_collisions_y = pygame.sprite.spritecollideany(self, level.brick_box_group)
        if brick_box_collisions_y:
            if self.y_vel < 0:
                self.rect.top = brick_box_collisions_y.rect.bottom
                if self.power == c.POWER_SMALL:
                    brick_box_collisions_y.activate()
                else:
                    brick_box_collisions_y.kill()
                    box_rect = brick_box_collisions_y.rect

                    self.sound_manager.play_sound(c.SOUND_BRICK_SMASH)

                    brick_piece_nw = BrickPiece(box_rect.left + 5, box_rect.top + 5, -2, -5)
                    brick_piece_sw = BrickPiece(box_rect.left + 5, box_rect.bottom - 20, -2, -3)
                    brick_piece_ne = BrickPiece(box_rect.right - 5, box_rect.top + 5, 2, -5)
                    brick_piece_se = BrickPiece(box_rect.right - 5, box_rect.bottom - 20, 2, -3)

                    level.brick_piece_group.add(brick_piece_nw)
                    level.brick_piece_group.add(brick_piece_sw)
                    level.brick_piece_group.add(brick_piece_ne)
                    level.brick_piece_group.add(brick_piece_se)
                brick_box_collisions_y.update(current_time)
            else:
                self.rect.bottom = brick_box_collisions_y.rect.top
            self.y_vel = 0

        if self.state == c.STATE_CROUCHING:
            self.image = self.get_player_frame(self.state, self.direction)
            self.refresh_rect()
        elif self.y_vel != 0:
            self.image = self.get_player_frame(c.STATE_JUMPING, self.direction)
        elif self.x_vel == 0:
            self.image = self.get_player_frame(c.STATE_STANDING, self.direction)
            self.refresh_rect()
        else:
            self.image = self.get_player_frame(c.STATE_WALKING, self.direction, (self.rect.x + self.world_shift) // 30)

    def start_death_sequence(self):
        self.sound_manager.play_music(c.MUSIC_DEATH)
        self.state = c.STATE_TRANSITION
        self.transition_state = c.TRANSITION_DEATH_SEQUENCE
        self.y_vel = -15

    def calc_gravity(self):
        if self.y_vel == 0:
            self.y_vel = 1
        else:
            self.y_vel += .45

    def death_sequence(self, current_time):
        time_delta = current_time - self.transition_timer

        self.image = self.death_frame

        if self.transition_timer == 0:
            self.transition_timer = current_time
        elif time_delta > 3000:
            self.state = c.STATE_DEAD
        else:
            self.transition_timer += 1

    def small_to_big(self, current_time):
        time_delta = current_time - self.transition_timer

        if self.transition_timer == 0:
            self.transition_timer = current_time
            self.image = self.transition_frames[self.direction]
        elif 100 <= time_delta < 200:
            self.image = self.get_player_frame(c.STATE_STANDING, self.direction)
        elif 200 <= time_delta < 300:
            self.image = self.transition_frames[self.direction]
        elif 300 <= time_delta < 400:
            self.image = self.get_player_frame(c.STATE_STANDING, self.direction)
        elif 400 <= time_delta < 500:
            self.image = self.transition_frames[self.direction]
        elif 500 <= time_delta < 600:
            self.image = self.get_player_frame(c.STATE_STANDING, self.direction)
        elif 600 <= time_delta:
            self.power = c.POWER_LARGE
            self.state = c.STATE_STANDING
            self.transition_state = None
            self.image = self.get_player_frame(c.STATE_STANDING, self.direction)

        self.transition_timer += 1

    def big_to_small(self, current_time):
        time_delta = current_time - self.transition_timer

        if self.transition_timer == 0:
            self.transition_timer = current_time
            self.image = self.transition_frames[self.direction]
        elif 100 <= time_delta < 200:
            self.image = self.get_player_frame(c.STATE_STANDING, self.direction)
        elif 200 <= time_delta < 300:
            self.image = self.transition_frames[self.direction]
        elif 300 <= time_delta < 400:
            self.image = self.get_player_frame(c.STATE_STANDING, self.direction)
        elif 400 <= time_delta < 500:
            self.image = self.transition_frames[self.direction]
        elif 500 <= time_delta < 600:
            self.image = self.get_player_frame(c.STATE_STANDING, self.direction)
        elif 600 <= time_delta:
            self.power = c.POWER_SMALL
            self.state = c.STATE_STANDING
            self.transition_state = None
            self.image = self.get_player_frame(c.STATE_STANDING, self.direction)

        self.transition_timer += 1

    def powerup(self, powerup):
        if self.state == c.STATE_TRANSITION:
            return

        self.state = c.STATE_TRANSITION
        self.transition_state = None

        if powerup == c.POWERUP_MUSHROOM:
            self.transition_state = c.TRANSITION_SMALL_TO_BIG

        self.sound_manager.play_sound(c.SOUND_POWERUP)

        self.transition_timer = 0

    def transition(self, target_power):
        if self.state == c.STATE_TRANSITION:
            return

        self.sound_manager.play_sound(c.SOUND_POWERUP)
        self.state = c.STATE_TRANSITION
        self.transition_state = None

        if self.power == c.POWER_SMALL and target_power == c.POWER_LARGE:
            self.transition_state = c.TRANSITION_SMALL_TO_BIG
        elif self.power == c.POWER_LARGE and target_power == c.POWER_SMALL:
            self.transition_state = c.TRANSITION_BIG_TO_SMALL

        self.transition_timer = 0

    def go_right(self):
        self.x_vel = 5
        self.direction = c.DIR_RIGHT
        self.state = c.STATE_WALKING

    def go_left(self):
        self.x_vel = -5
        self.direction = c.DIR_LEFT
        self.state = c.STATE_WALKING

    def jump(self):
        if self.y_vel == 0:
            self.y_vel += -13
            self.sound_manager.play_sound(c.SOUND_SMALL_JUMP)
            self.state = c.STATE_JUMPING

    def crouch(self):
        if self.power != c.POWER_SMALL and self.y_vel == 0 and self.x_vel == 0:
            self.state = c.STATE_CROUCHING

    def stop(self):
        self.x_vel = 0
        self.state = c.STATE_STANDING
Exemplo n.º 36
0
 def __init__(self):
     image = SpriteSheet('res/sprite/spritesheet.png')
     self.tiles = {'Block': image.get_sprite(78, 0, 18, 18),
                   'Floor': image.get_sprite(77, 66, 18, 18)}
Exemplo n.º 37
0
    def init_frames(self):
        sprite_sheet = SpriteSheet("data/characters.gif")

        self.koopa_frames.append(sprite_sheet.get_image(coords.KOOPA_GREEN_LEFT_1, c.IMG_MULTIPLIER, c.BLUE))
        self.koopa_frames.append(sprite_sheet.get_image(coords.KOOPA_GREEN_LEFT_2, c.IMG_MULTIPLIER, c.BLUE))
Exemplo n.º 38
0
 def __init__(self, tile_id: int, x: int, y: int, spritesheet: SpriteSheet):
     pygame.sprite.Sprite.__init__(self)
     self.image = spritesheet.get_sprite_by_id(tile_id)
     self.rect = self.image.get_rect()
     self.rect.x, self.rect.y = x, y
Exemplo n.º 39
0
 def init_frames(self):
     sprite_sheet = SpriteSheet("data/tile_set.png")
     self.display_frame = sprite_sheet.get_image(coords.BRICK,
                                                 c.IMG_MULTIPLIER, c.WHITE)
Exemplo n.º 40
0
 def __init__(self):
     self.tiles = WorldMapSprite()
     map = SpriteSheet('res/sprite/spritesheet.png').get_sprite(105, 9, 47, 47)
     self.map_array_block_wall= pygame.PixelArray(map).extract((255,255,255))
     self.map_array_items = pygame.PixelArray(map).extract((255, 0, 0))
     self.map_array_enemys = pygame.PixelArray(map).extract((0, 255, 0))
Exemplo n.º 41
0
    def init_frames(self):
        sprite_sheet = SpriteSheet("data/characters.gif")

        self.shell_frame = sprite_sheet.get_image(coords.SHELL_GREEN, c.IMG_MULTIPLIER, c.BLUE)