def __init__(self, ): super().__init__() gameoverImg = pygame.display.get_surface().copy() goBGimgGrp = objects.ImageGroup([gameoverImg], screen.screen) gameoverBG = objects.GameObject(goBGimgGrp, self, 0, (0, 0)) gameoverObj = objects.GameObject(objects.gmovImgGrp, self, 1, (-10, -10)) gameRestarter = objects.GameRestarter(self)
def fireball(source, spell_range, d_key): dx, dy = objects.direction_dict[d_key] icon = source.inventory.spell.icons[d_key] ball = objects.Projectile(dx, dy, 0, spell_range, aoe=True) explosion = objects.SpellEffect(name='explosion', spell_range=2, render_frames=10, damage=10, icons={ 'n': 0xE388, 's': 0xE388, 'e': 0xE388, 'w': 0xE388, 'se': 0xE388, 'sw': 0xE388, 'ne': 0xE388, 'nw': 0xE388, 'hit': 0xE388 }, charges=0, aoe_function=fireball_explode) fireball = objects.GameObject('fireball', source.x + dx, source.y + dy, icon, projectile=ball, spell=explosion, update_func=objects.update_ammo) return fireball
def __init__(self, ): super().__init__() resultBGObj = objects.GameObject(objects.resultBGImgGrp, self, 0, [-10, -10]) clearObj = objects.ClearObj(self) comet = objects.Comet(self) clearObj.cmt = comet comet.clrobj = clearObj
def __init__(self, ): super().__init__() self.havePause = True background = objects.GameObject(objects.bgImgGrp, self, 0, (-106, 0)) hero = objects.Hero(self) hpgauge = objects.HPGauge(hero, objects.HPImgGrp, self) enemySpawner = objects.EnemySpawner(self, hero)
def add_player(self, game, player_name): player_id = game.game_id + str(len(game.players)) player_fighter = objects.Fighter(hp=30, defense=2, power=5, recharge=20, death_function=Player.death) p_inv = objects.Inventory() p_avatar = objects.GameObject(name=player_name, x=1, y=1, icon=0xE000, inventory=p_inv, fighter=player_fighter, current_map=None, player_flag=True, update_func=objects.update_player) player_cam = objects.Camera(0, 0, 37, 22) player = Player(id=player_id, name=player_name, camera=player_cam, avatar=p_avatar, fov_algo='BASIC', light_walls=True, sight_radius=4) return player
def __init__(self, ): super().__init__() titleBG = objects.GameObject(objects.titleBGImgGrp, self, 0, [-10, -10]) titleUI = objects.TitleUI(self)
def place_objects(self, room): num_monsters = random.randint(0, self.max_room_monsters) monster_counter = 0 for i in range(num_monsters): x = random.randint(room.x, room.x2) y = random.randint(room.y, room.y2) if not self.is_blocked_at(x, y): if random.randint(0, 100) < 80: ai_component = game_ai.BasicMonster(20) monster_fighter = objects.Fighter( hp=10, defense=0, power=3, recharge=20, death_function=ai_component.monster_death) monster = objects.GameObject( 'orc', x, y, 0xE101, blocks=True, fighter=monster_fighter, ai=ai_component, update_func=objects.update_monster) else: ai_component = game_ai.BasicMonster(30) monster_fighter = objects.Fighter( hp=16, defense=1, power=4, recharge=30, death_function=ai_component.monster_death) monster = objects.GameObject( 'troll', x, y, 0xE100, blocks=True, fighter=monster_fighter, ai=ai_component, update_func=objects.update_monster) monster.current_map = self self.objects.append(monster) num_items = random.randint(0, self.max_room_items) for i in range(num_items): x = random.randint(room.x + 1, room.x2 - 1) y = random.randint(room.y + 1, room.y2 - 1) if not self.is_blocked_at(x, y): item_component = objects.Item(use_function=effects.cast_heal) item = objects.GameObject('healing potion', x, y, 0xE201, item=item_component, active=False) self.objects.append(item) item.current_map = self item.send_to_back()
def make_map(self, player): num_rooms = 0 for r in range(self.max_rooms): w = random.randint(self.min_room_size, self.max_room_size) h = random.randint(self.min_room_size, self.max_room_size) x = random.randint(0, self.width - w - 1) y = random.randint(0, self.height - h - 1) new_room = Room(x, y, w, h) failed = False for other_room in self.rooms: if new_room.intersect(other_room): failed = True break if not failed: new_room.get_walls() self.draw_room(new_room) (new_x, new_y) = new_room.center() if num_rooms == 0: player.x = new_x player.y = new_y else: (prev_x, prev_y) = self.rooms[num_rooms - 1].center() if random.randint(0, 1): self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) #for wall in new_room.walls: #for x, y in wall: #self.tiles[x][y] = 2 self.rooms.append(new_room) self.place_objects(new_room) num_rooms += 1 # debug light casting torch_room = random.choice(self.rooms) torch_x = random.randint(torch_room.x + 1, torch_room.x2 - 1) torch_y = random.randint(torch_room.y + 1, torch_room.y2 - 1) print(torch_x, torch_y) torchlight = objects.LightSource(radius=2, color=colors.lighter_yellow) torch = objects.GameObject('torch', torch_x, torch_y, 0xE200, light_source=torchlight, active=False) torch.current_map = self torch.light_source.cast_light() self.objects.append(torch) sword_item = objects.Item() sword_wpn = objects.Weapon(2, effects.sword_attack) sword = objects.GameObject('sword', player.x + 1, player.y + 1, 0xE251, item=sword_item, weapon=sword_wpn, active=False) sword.current_map = self self.objects.append(sword) bow_item = objects.Item() bow_wpn = objects.Weapon(2, effects.bow_attack, ranged=True, radius=5, ammo_icons={ 'n': 0xE350, 's': 0xE351, 'w': 0xE352, 'e': 0xE353, 'ne': 0xE354, 'nw': 0xE355, 'se': 0xE356, 'sw': 0xE357 }, ammo_name='arrow') bow = objects.GameObject('bow', player.x - 1, player.y - 1, 0xE252, item=bow_item, weapon=bow_wpn, active=False) bow.current_map = self self.objects.append(bow) spear_item = objects.Item() spear_wpn = objects.Weapon(power=2, attack_function=effects.spear_attack, special=effects.push_back) spear = objects.GameObject('spear', player.x, player.y - 1, 0xE253, item=spear_item, weapon=spear_wpn, active=False) spear.current_map = self self.objects.append(spear) axe_item = objects.Item() axe_wpn = objects.Weapon(power=2, attack_function=effects.axe_attack) axe = objects.GameObject('axe', player.x - 1, player.y + 1, 0xE250, item=axe_item, weapon=axe_wpn, active=False) axe.current_map = self self.objects.append(axe) lb_item = objects.Item() lb_spell = objects.SpellEffect(name='Lightning', spell_range=5, damage=15, render_frames=3, icons={ 'n': 0xE370, 's': 0xE370, 'w': 0XE371, 'e': 0xE371, 'ne': 0xE372, 'sw': 0xE372, 'nw': 0xE373, 'se': 0xE373, 'hit': 0xE374 }, charges=5, aoe_function=effects.lightning_bolt) lb_book = objects.GameObject('Book of Lightning Bolt', player.x + 1, player.y, 0xE360, item=lb_item, spell=lb_spell, active=False, update_func=objects.update_spell) lb_book.current_map = self self.objects.append(lb_book) fb_item = objects.Item() fb_spell = objects.SpellEffect(name='Fireball', spell_range=10, damage=10, render_frames=3, icons={ 'n': 0xE380, 's': 0xE381, 'w': 0xE382, 'e': 0xE383, 'ne': 0xE384, 'nw': 0xE385, 'se': 0xE386, 'sw': 0xE387, 'hit': 0xE388 }, charges=5, aoe_function=effects.fireball) fb_book = objects.GameObject('Book of Fireball', player.x - 1, player.y, 0xE361, item=fb_item, spell=fb_spell, active=False, update_func=objects.update_spell) fb_book.current_map = self self.objects.append(fb_book) self.assign_object_ids()