Esempio n. 1
0
    def initialize(self):
        pygame.init()
        self.screen = pygame.display.set_mode(window_size)
        self.screen_width = self.screen.get_rect().width
        self.screen_height = self.screen.get_rect().height
        preload()
        self.map = Map(self, 'media/map.txt', images['tiles'], self.screen)
        temp_width = 150
        temp_height = 150
        self.minimap = MiniMap(
            self.engine, self, self.map,
            Rect([
                self.screen.get_rect().width - temp_width, 0, temp_width,
                temp_height
            ]))
        #self.clock = pygame.time.Clock()
        pygame.time.set_timer(USEREVENT, 1000)
        self.font = pygame.font.Font('media/freesansbold.ttf', 40)
        self.timer = pygame.time.Clock()

        self.engine.screen_width = self.screen.get_rect().width
        self.engine.screen_height = self.screen.get_rect().height
        self.engine.world_width = self.map.world_width
        self.engine.world_height = self.map.world_height
        self.engine.tile_width = self.map.tile_width
        self.engine.tile_height = self.map.tile_height

        for l in self.engine._lifes:
            l.sprite = get_sprite(l.sprite_name)(l)
Esempio n. 2
0
    def new(self):
        self.dragging_camera = False
        self.all_sprites = pg.sprite.LayeredUpdates()
        self.items = pg.sprite.Group()
        self.imps = pg.sprite.Group()
        self.woods = pg.sprite.Group()
        self.map = Map(self)
        self.map.generate(200, 200)
        self.map.light(vec(10, 10), 20, 1)
        self.camera = Camera(self)
        self.game_speed = 200

        self.pause = False
        self.mode = None
        self.dragging = 0  # 0: False, 1: add, -1:remove

        pg.mixer.music.load(path.join(self.snd_dir, 'ObservingTheStar.ogg'))

        Imp(self, vec(10, 10))
        self.camera.focus(vec(10 * config.TILESIZE, 10 * config.TILESIZE))

        self.resource = {
            'woods': 0,
            'iron': 0,
        }
Esempio n. 3
0
 def update(self, dt):
     # print("update", dt)
     if self.current_key != "" and self.can_walk_again:
         self.can_walk_again = False
         Clock.schedule_once(self.update_can_walk_again, 0.3)
         # print(self.current_key)
         self.next_move = self.move(self.current_key)
         # print(self.tile, self.next_move)
         possible = [x + y for x, y in zip(self.tile, self.next_move)]
         self.tile = possible
         print(self.tile)
     
     # collisions:
     for widget in self.parent.children:
         if widget is self:
             continue
         if self.tile == widget.tile:
             # print(widget)
             if isinstance(widget, Grass):
                 print("grass")
             if isinstance(widget, Door):
                 print("door", self.parent.map.filename, widget.map)
                 self.parent.clean_widgets()
                 self.parent.map = Map(widget.map, GAME.get("tilesize"))
                 self.parent.new()
     
     # camera:
     self.parent.camera.update(self.parent.player)
     for sprite in self.parent.children:
         self.parent.camera.apply(sprite)
Esempio n. 4
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     print("Town")
     self.player = Player()
     self.add_widget(self.player)
     self.map = Map(GAME.get("first_map"), GAME.get("tilesize"))
     self.new()
Esempio n. 5
0
    def __init__(self, resources: Resources) -> None:
        self.camera = Vector2d(0, 0)
        self.stopwatch = Stopwatch(resources)

        # Objective 4: Create a Player
        self.player = Player(resources)

        # Objective 5: Create a Map
        self.map = Map(resources)
Esempio n. 6
0
    def make_map(self):
        tileset_path = os.path.join(self.game.map_folder, 'RPGpack_sheet.png')
        tileset = TileSet(tileset_path, tilesize=32)
        grass_tile_ids = [41, 42, 43, 44, 81, 82, 83, 84]
        grass_tiles = [tileset[id] for id in grass_tile_ids]

        wall_tile_ids = [267, 268, 269, 270]
        wall_tiles = [tileset[id] for id in wall_tile_ids]

        W = 10
        H = 10
        map_data = generate_maze(H, W)
        map_data = convert_to_thick_walls(map_data)

        H = len(map_data)
        W = len(map_data[0])

        self.map = Map(W, H)
        self.game.map = self.map

        empty_cells = []
        wall_cells = []
        map_img = pg.Surface((self.map.width, self.map.height))
        for r in range(H):
            for c in range(W):
                if map_data[r][c] == 0:
                    tile = random.choice(grass_tiles)
                    empty_cells.append((r, c))
                else:
                    tile = random.choice(wall_tiles)
                    wall_cells.append((r, c))

                map_img.blit(tile, (c * TILESIZE, r * TILESIZE))

        self.player_init_pos = random.choice(empty_cells)
        self.goal_pos = random.choice(empty_cells)

        self.game.map_img = map_img
        self.game.map_rect = map_img.get_rect()
        self.wall_cells = wall_cells
Esempio n. 7
0
    def load_data(self):
        """
        Loads the necessary assets for the game. 
        :return: None
        """
        # Game map
        self.map = Map(path.join(self.game_folder, 'map3.txt'))

        self.pause_screen_effect = pg.Surface(self.screen.get_size()).convert()
        self.pause_screen_effect.fill((0, 0, 0, 225))

        # Fog of war
        self.fog = pg.Surface(self.screen.get_size()).convert()
        self.fog.fill(NIGHT_COLOR)

        # Light on the player
        self.light_mask = pg.image.load(path.join(self.img_folder, LIGHT_MASK)).convert_alpha()
        self.light_mask = pg.transform.smoothscale(self.light_mask, (LIGHT_RADIUS, LIGHT_RADIUS))
        self.light_rect = self.light_mask.get_rect()

        # HUD Elements
        self.mag_img = pg.transform.smoothscale(pg.image.load(path.join(self.img_folder, CLIP_IMG)),
                                                (40, 40)).convert_alpha()
        # Crosshairs
        self.crosshairs = [
            pg.transform.smoothscale(pg.image.load(path.join(self.crosshair_folder, crosshair)),
                                     (32, 32)).convert_alpha()
            for crosshair in CROSSHAIRS]
        # todo - have a menu decide the player's crosshair
        self.crosshair = choice(self.crosshairs)

        # Item pickups
        self.pickup_items = {}
        for item in ITEM_IMAGES:
            self.pickup_items[item] = []
            self.pickup_items[item] = pg.image.load(path.join(self.item_folder, ITEM_IMAGES[item])).convert_alpha()

        # Fonts
        self.hud_font = path.join(self.img_folder, 'Fonts\Impacted2.0.ttf')

        # Sound loading
        self.music_tracks = {"main menu": MAIN_MENU_MUSIC, 'Game over': GAME_OVER_MUSIC, 'background music': BG_MUSIC}
        pg.mixer.music.load(path.join(self.music_folder, self.music_tracks['background music']))
        pg.mixer.music.set_volume(.5)

        self.swing_noises = {}
        for weapon in PLAYER_SWING_NOISES:
            noise = pg.mixer.Sound(path.join(self.snd_folder, PLAYER_SWING_NOISES[weapon]))
            noise.set_volume(.25)
            self.swing_noises[weapon] = noise

        self.player_hit_sounds = []
        for snd in PLAYER_HIT_SOUNDS:
            self.player_hit_sounds.append(pg.mixer.Sound(path.join(self.snd_folder, snd)))

        self.weapon_sounds = {}
        for weapon in WEAPONS['sound']:
            self.weapon_sounds[weapon] = {}
            sound_list = {}
            for snd in WEAPONS['sound'][weapon]:
                noise = pg.mixer.Sound(path.join(self.snd_folder, WEAPONS['sound'][weapon][snd]))
                noise.set_volume(.9)
                sound_list[snd] = noise
            self.weapon_sounds[weapon] = sound_list

        self.zombie_moan_sounds = []
        for snd in ZOMBIE_MOAN_SOUNDS:
            noise = pg.mixer.Sound(path.join(self.snd_folder, snd))
            noise.set_volume(.25)
            self.zombie_moan_sounds.append(noise)

        self.zombie_hit_sounds = {}
        for type in ENEMY_HIT_SOUNDS:
            self.zombie_hit_sounds[type] = []
            for snd in ENEMY_HIT_SOUNDS[type]:
                snd = pg.mixer.Sound(path.join(self.snd_folder, snd))
                snd.set_volume(.75)
                self.zombie_hit_sounds[type].append(snd)

        self.player_foot_steps = {}
        for terrain in PLAYER_FOOTSTEPS:
            self.player_foot_steps[terrain] = []
            for snd in PLAYER_FOOTSTEPS[terrain]:
                snd = pg.mixer.Sound(path.join(self.snd_folder, snd))
                snd.set_volume(.5)
                self.player_foot_steps[terrain].append(snd)

        # Bullets
        self.bullet_images = {}
        self.bullet_images['lg'] = pg.transform.smoothscale(pg.image.load(path.join(self.img_folder, RIFLE_BULLET_IMG)),
                                                            (10, 3)).convert_alpha()
        self.bullet_images['med'] = pg.transform.smoothscale(
            pg.image.load(path.join(self.img_folder, HANDGUN_BULLET_IMG)), (5, 3)).convert_alpha()
        self.bullet_images['sm'] = pg.transform.smoothscale(pg.image.load(
            path.join(self.img_folder, SHOTGUN_BULLET_IMG)).convert_alpha(), (7, 7))

        # Effects
        self.gun_flashes = [pg.image.load(path.join(self.img_folder, flash)).convert_alpha() for flash in
                            MUZZLE_FLASHES]

        # Load enemy animations
        self.enemy_imgs = [pg.transform.smoothscale(pg.image.load(path.join(self.game_folder, name)),
                                                    (96, 96)).convert_alpha() for name in
                           ENEMY_IMGS]
        # Load player animations
        self.default_player_weapon = 'knife'
        self.default_player_action = 'idle'
        self.player_animations = {'handgun': {}, 'knife': {}, 'rifle': {}, 'shotgun': {}}

        # Create all hand gun animations
        self.player_animations['handgun']['idle'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha()
                                                     for name in HANDGUN_ANIMATIONS['idle']]
        self.player_animations['handgun']['melee'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha()
                                                      for name in HANDGUN_ANIMATIONS['melee']]
        self.player_animations['handgun']['move'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha()
                                                     for name in HANDGUN_ANIMATIONS['move']]
        self.player_animations['handgun']['reload'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha()
                                                       for name in HANDGUN_ANIMATIONS['reload']]
        self.player_animations['handgun']['shoot'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha()
                                                      for name in HANDGUN_ANIMATIONS['shoot']]

        # Create all knife animations
        self.player_animations['knife']['idle'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha() for
                                                   name in KNIFE_ANIMATIONS['idle']]
        self.player_animations['knife']['melee'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha() for
                                                    name in KNIFE_ANIMATIONS['melee']]
        self.player_animations['knife']['move'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha() for
                                                   name in KNIFE_ANIMATIONS['move']]

        # Create all rifle animations
        self.player_animations['rifle']['idle'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha() for
                                                   name in RIFLE_ANIMATIONS['idle']]
        self.player_animations['rifle']['melee'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha() for
                                                    name in RIFLE_ANIMATIONS['melee']]
        self.player_animations['rifle']['move'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha() for
                                                   name in RIFLE_ANIMATIONS['move']]
        self.player_animations['rifle']['reload'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha()
                                                     for name in RIFLE_ANIMATIONS['reload']]
        self.player_animations['rifle']['shoot'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha() for
                                                    name in RIFLE_ANIMATIONS['shoot']]

        # Create all shotgun animations
        self.player_animations['shotgun']['idle'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha()
                                                     for name in SHOTGUN_ANIMATIONS['idle']]
        self.player_animations['shotgun']['melee'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha()
                                                      for name in SHOTGUN_ANIMATIONS['melee']]
        self.player_animations['shotgun']['move'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha()
                                                     for name in SHOTGUN_ANIMATIONS['move']]
        self.player_animations['shotgun']['reload'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha()
                                                       for name in SHOTGUN_ANIMATIONS['reload']]
        self.player_animations['shotgun']['shoot'] = [pg.image.load(path.join(self.game_folder, name)).convert_alpha()
                                                      for name in SHOTGUN_ANIMATIONS['shoot']]