Example #1
0
 def __init__(self):
     self.resource_manager = engine.ResourceManager()
     engine.GameObject.__init__(self,
                                layer=0,
                                handle_collisions=True,
                                solid=True,
                                object_type="enemy")
Example #2
0
    def __init__(self, text, screen_size, coordinate_size, justify="center"):
        self.scale = (screen_size[0]/coordinate_size[0], screen_size[1]/(coordinate_size[1]+16))
        self.width = 144*self.scale[0]
        self.height = 40*self.scale[1]
        # pygame.Surface.__init__(self, screen_size)
        engine.CoordinateSurface.__init__(self, pygame.Rect((0, 0), (self.width, self.height)), (144, 40))
        self.fill((0, 0, 0, 255))
        self.resource_manager = engine.ResourceManager()
        self.resource_manager.add_font('game_text', FONT_DIR + 'zeldadxt.ttf', int(self.scale[1]*12))
        self.text = str(text)
        self.text_speed = 5
        self.frame_counter = 0
        self.next_letter = False
        self.justify = justify
        self.lines = []
        self.current_line = 0
        self.current_letter = 0
        self.waiting = False
        self.scrolling = False
        self.scroll_frame = 0
        self.finished = False
        self.rendered_letters = []
        self.line_starts = []
        self.letter_spacing = 8 * self.scale[0]

        line = ""
        for char in self.text:
            if char != '\\':
                line += char
            else:
                self.lines.append(line)
                line = ""
        self.lines.append(line)
        if self.justify == "center":
            for line in self.lines:
                letters = len(line)
                line_start = self.width/2 - (letters/2)*self.letter_spacing
                self.line_starts.append(line_start)
        elif self.justify == "left":
            for i in xrange (0, len(self.lines)):
                self.line_starts.append(8*self.scale[0])
Example #3
0
 def __init__(self, object_type):
     self.resource_manager = engine.ResourceManager()
     self.effect_sheet = engine.Spritesheet(SPRITE_DIR + "Effects.png")
     engine.GameObject.__init__(self, layer=100, object_type=object_type)
     self.animation_speed = 15
Example #4
0
 def __init__(self):
     self.resource_manager = engine.ResourceManager()
     self.tile_sheet = engine.Spritesheet(SPRITE_DIR + "OverworldSheet.png")
Example #5
0
    def __init__(self, facing, mode="slash"):
        self.resource_manager = engine.ResourceManager()
        link_sheet = engine.Spritesheet(SPRITE_DIR + "Link.png")

        # Load animations
        self.resource_manager.add_spritesheet_strip_offsets('link_sword_right', link_sheet, (192, 128), 4, 4, (16, 16), 0, 0, (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets('link_sword_up', link_sheet, (128, 128), 4, 4, (16, 16), 0, 0, (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets('link_sword_down', link_sheet, (64, 128), 4, 4, (16, 16), 0, 0, (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets('link_sword_left', link_sheet, (0, 128), 4, 4, (16, 16), 0, 0, (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets('link_sword_spin_clockwise', link_sheet, (0, 144), 8, 8, (16, 16), 0, 0, (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets('link_sword_spin_counter', link_sheet, (0, 160), 8, 8, (16, 16), 0, 0, (64, 64, 192))
        self.directions = ['link_sword_right', 'link_sword_up', 'link_sword_left', 'link_sword_down']

        engine.GameObject.__init__(self, image=self.resource_manager.get_images(self.directions[facing]), layer=25,
                                   persistent=True)

        self.add_animation('link_sword_up', self.resource_manager.get_images('link_sword_up'))
        self.add_animation('link_sword_down', self.resource_manager.get_images('link_sword_down'))
        self.add_animation('link_sword_right', self.resource_manager.get_images('link_sword_right'))
        self.add_animation('link_sword_left', self.resource_manager.get_images('link_sword_left'))
        self.add_animation('link_sword_spin_clockwise', self.resource_manager.get_images('link_sword_spin_clockwise'))
        self.add_animation('link_sword_spin_counter', self.resource_manager.get_images('link_sword_spin_counter'))

        self.set_animation(self.directions[facing], 0)

        self.animation_speed = 30

        self.facing = facing
        self.handle_collisions = True
        frame_col = {'up': ((3, 10), (1, 6)),
                     'ur': ((0, 6), (10, 10)),
                     'right': ((0, 11), (6, 1)),
                     'dr': ((0, 0), (10, 10)),
                     'down': ((11, 0), (1, 6)),
                     'dl': ((6, 0), (10, 10)),
                     'left': ((10, 11), (6, 1)),
                     'ul': ((6, 6), (10, 10)),
                     'right_upper': ((0, 3), (6, 1))}
        hit_boxes = {'up': ((2, 4), (6, 12)),
                     'ur': ((0, 0), (16, 16)),
                     'right': ((0, 8), (12, 6)),
                     'dr': ((0, 0), (16, 16)),
                     'down': ((2, 0), (6, 12)),
                     'dl': ((0, 0), (16, 16)),
                     'left': ((4, 8), (12, 6)),
                     'ul': ((0, 0), (16, 16)),
                     'right_upper': ((0, 2), (12, 6))}
        self.collision_rects = {'link_sword_up': [Rect(frame_col['right_upper']), Rect(frame_col['ur']), Rect(frame_col['up'])],
                                'link_sword_down': [Rect(frame_col['left']), Rect(frame_col['dl']), Rect(frame_col['down'])],
                                'link_sword_right': [Rect(frame_col['up']), Rect(frame_col['ur']), Rect(frame_col['right'])],
                                'link_sword_left': [Rect(frame_col['up']), Rect(frame_col['ul']), Rect(frame_col['left'])],
                                'link_sword_spin_clockwise': [Rect(frame_col['dr']), Rect(frame_col['down']),
                                                              Rect(frame_col['dl']), Rect(frame_col['left']),
                                                              Rect(frame_col['ul']), Rect(frame_col['up']),
                                                              Rect(frame_col['ur']), Rect(frame_col['right'])],
                                'link_sword_spin_counter': [Rect(frame_col['dl']), Rect(frame_col['down']),
                                                            Rect(frame_col['dr']), Rect(frame_col['right']),
                                                            Rect(frame_col['ur']), Rect(frame_col['up']),
                                                            Rect(frame_col['ul']), Rect(frame_col['left'])]}
        self.hitbox_rects = {'link_sword_up': [Rect(hit_boxes['right_upper']), Rect(hit_boxes['ur']), Rect(hit_boxes['up'])],
                             'link_sword_down': [Rect(hit_boxes['left']), Rect(hit_boxes['dl']), Rect(hit_boxes['down'])],
                             'link_sword_right': [Rect(hit_boxes['up']), Rect(hit_boxes['ur']), Rect(hit_boxes['right'])],
                             'link_sword_left': [Rect(hit_boxes['up']), Rect(hit_boxes['ul']), Rect(hit_boxes['left'])],
                             'link_sword_spin_clockwise': [Rect(hit_boxes['dr']), Rect(hit_boxes['down']),
                                                           Rect(hit_boxes['dl']), Rect(hit_boxes['left']),
                                                           Rect(hit_boxes['ul']), Rect(hit_boxes['up']),
                                                           Rect(hit_boxes['ur']), Rect(hit_boxes['right'])],
                             'link_sword_spin_counter': [Rect(hit_boxes['dl']), Rect(hit_boxes['down']),
                                                         Rect(hit_boxes['dr']), Rect(hit_boxes['right']),
                                                         Rect(hit_boxes['ur']), Rect(hit_boxes['up']),
                                                         Rect(hit_boxes['ul']), Rect(hit_boxes['left'])]}
        self.call_special_update = True
Example #6
0
    def __init__(self, layer=50):
        self.resource_manager = engine.ResourceManager()
        link_sheet = engine.Spritesheet(SPRITE_DIR + "Link.png")
        overworld_sheet = engine.Spritesheet(SPRITE_DIR + "OverworldSheet.png")
        self.resource_manager.add_spritesheet_strip_offsets(
            'overworld_tiles', overworld_sheet, (1, 1), 600, 24, (16, 16), 1,
            1)

        # Load animations
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_walk_down', link_sheet, (32, 0), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_walk_up', link_sheet, (64, 0), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_walk_left', link_sheet, (0, 0), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_walk_right', link_sheet, (96, 0), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_push_down', link_sheet, (32, 16), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_push_up', link_sheet, (64, 16), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_push_left', link_sheet, (0, 16), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_push_right', link_sheet, (96, 16), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_shield_walk_down', link_sheet, (32, 32), 2, 2, (16, 16), 0,
            0, (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_shield_walk_up', link_sheet, (64, 32), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_shield_walk_left', link_sheet, (0, 32), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))  # These two might be messed up
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_shield_walk_right', link_sheet, (96, 32), 2, 2, (16, 16), 0,
            0, (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_use_shield_down', link_sheet, (32, 48), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))  # Needs to be fixed
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_use_shield_up', link_sheet, (64, 48), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_use_shield_left', link_sheet, (0, 48), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))  # Take a look at black spot
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_use_shield_right', link_sheet, (96, 48), 2, 2, (16, 16), 0,
            0, (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_hop_down', link_sheet, (0, 64), 3, 3, (16, 16), 0, 0,
            (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_fall', link_sheet, (0, 96), 3, 3, (16, 16), 0, 0,
            (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_sword_down', link_sheet, (32, 112), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_sword_up', link_sheet, (64, 112), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_sword_left', link_sheet, (0, 112), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))
        self.resource_manager.add_spritesheet_strip_offsets(
            'link_sword_right', link_sheet, (96, 112), 2, 2, (16, 16), 0, 0,
            (64, 64, 192))
        engine.GameObject.__init__(
            self,
            self.resource_manager.get_images('link_walk_down'),
            layer,
            collision_rect=pygame.Rect((3, 4), (10, 11)),
            handle_collisions=True,
            object_type="player",
            persistent=True)

        # Add animations to Link
        self.add_animation('link_walk_up',
                           self.resource_manager.get_images('link_walk_up'))
        self.add_animation('link_walk_down',
                           self.resource_manager.get_images('link_walk_down'))
        self.add_animation('link_walk_right',
                           self.resource_manager.get_images('link_walk_right'))
        self.add_animation('link_walk_left',
                           self.resource_manager.get_images('link_walk_left'))
        self.add_animation('link_push_up',
                           self.resource_manager.get_images('link_push_up'))
        self.add_animation('link_push_down',
                           self.resource_manager.get_images('link_push_down'))
        self.add_animation('link_push_left',
                           self.resource_manager.get_images('link_push_left'))
        self.add_animation('link_push_right',
                           self.resource_manager.get_images('link_push_right'))
        self.add_animation(
            'link_shield_walk_up',
            self.resource_manager.get_images('link_shield_walk_up'))
        self.add_animation(
            'link_shield_walk_down',
            self.resource_manager.get_images('link_shield_walk_down'))
        self.add_animation(
            'link_shield_walk_right',
            self.resource_manager.get_images('link_shield_walk_right'))
        self.add_animation(
            'link_shield_walk_left',
            self.resource_manager.get_images('link_shield_walk_left'))
        self.add_animation(
            'link_use_shield_up',
            self.resource_manager.get_images('link_use_shield_up'))
        self.add_animation(
            'link_use_shield_down',
            self.resource_manager.get_images('link_use_shield_down'))
        self.add_animation(
            'link_use_shield_left',
            self.resource_manager.get_images('link_use_shield_left'))
        self.add_animation(
            'link_use_shield_right',
            self.resource_manager.get_images('link_use_shield_right'))
        self.add_animation('link_hop_down',
                           self.resource_manager.get_images('link_hop_down'))
        self.add_animation('link_fall',
                           self.resource_manager.get_images('link_fall'))
        self.add_animation('link_sword_up',
                           self.resource_manager.get_images('link_sword_up'))
        self.add_animation('link_sword_down',
                           self.resource_manager.get_images('link_sword_down'))
        self.add_animation(
            'link_sword_right',
            self.resource_manager.get_images('link_sword_right'))
        self.add_animation('link_sword_left',
                           self.resource_manager.get_images('link_sword_left'))

        # Group animations
        self.link_walk = [
            "link_walk_right", "link_walk_up", "link_walk_left",
            "link_walk_down"
        ]
        self.link_push = [
            "link_push_right", "link_push_up", "link_push_left",
            "link_push_down"
        ]
        self.link_shield_walk = [
            "link_shield_walk_right", "link_shield_walk_up",
            "link_shield_walk_left", "link_shield_walk_down"
        ]
        self.link_use_shield = [
            "link_use_shield_right", "link_use_shield_up",
            "link_use_shield_left", "link_use_shield_down"
        ]
        self.link_sword = [
            "link_sword_right", "link_sword_up", "link_sword_left",
            "link_sword_down"
        ]

        # Add sounds to Link
        self.resource_manager.add_sound('link_hop',
                                        SOUND_DIR + 'LA_Link_Jump.wav')
        self.resource_manager.add_sound('link_land',
                                        SOUND_DIR + 'LA_Link_Land.wav')
        self.resource_manager.add_sound('link_shield',
                                        SOUND_DIR + 'LA_Shield.wav')
        self.resource_manager.add_sound('link_fall',
                                        SOUND_DIR + 'LA_Link_Fall.wav')
        self.resource_manager.add_sound('link_sword_1',
                                        SOUND_DIR + 'LA_Sword_Slash1.wav')
        self.resource_manager.add_sound('link_sword_2',
                                        SOUND_DIR + 'LA_Sword_Slash2.wav')
        self.resource_manager.add_sound('link_sword_3',
                                        SOUND_DIR + 'LA_Sword_Slash3.wav')
        self.resource_manager.add_sound('link_sword_4',
                                        SOUND_DIR + 'LA_Sword_Slash4.wav')
        self.resource_manager.add_sound('link_sword_charge',
                                        SOUND_DIR + 'LA_Sword_Charge.wav')
        self.resource_manager.add_sound('link_sword_spin',
                                        SOUND_DIR + 'LA_Sword_Spin.wav')
        self.resource_manager.add_sound('link_sword_tap',
                                        SOUND_DIR + 'LA_Sword_Tap.wav')
        self.resource_manager.add_sound('grass_cut',
                                        SOUND_DIR + 'LA_Bush_Cut.wav')

        self.sword_slashes = [
            'link_sword_1', 'link_sword_2', 'link_sword_3', 'link_sword_4'
        ]

        # Configure Link's properties
        self.speed = 1.25  # 1.25
        self.movement = {
            0: (self.speed, 0),
            1: (0, -self.speed),
            2: (-self.speed, 0),
            3: (0, self.speed)
        }
        self.direction = 3
        self.facing = 3
        self.big_grass = ["big_grass", "big_forest_grass"]
        self.short_grass = ["short_grass", "short_forest_grass"]
        self.effect_short_grass = [
            "effect_short_grass", "effect_short_forest_grass"
        ]
        self.in_grass = False
        self.shield = False
        self.left = None
        self.right = None
        self.controllable = True
        self.no_clip = False
        self.direction_held = False
        self.body_rect = self.rect
        self.interaction_rect = None  # self.collision_rect.copy()
        self.standard_animation_speed = 15
        self.solid = True

        # Link's States
        # self.walk = WalkingState()
        # self.collide = CollidingState()
        # self.shield = ShieldState()
        self._state = WalkingState(self)
        self.state = "WalkingState"