def _load_zone(self, zonepath): self.npcList = [] self.enemyList = [] areaFile = open(zonepath, 'r') for line in areaFile: lineparse = line.split(":") line0 = lineparse[0] line1 = lineparse[1][1:-1] if line0 == 'name': self.name = line1 elif line0 == 'description': self.description = line1 elif line0 == 'npc': if line1 != 'none': newNPC = character.NPC(line1.strip()) self.npcList.append(newNPC) else: self.npcList.append('none') elif line0 == 'enemy': if line1 != 'none': enemyNPC = character.Enemy(line1.strip()) self.enemyList.append(enemyNPC) else: self.enemyList.append('none') elif line0 in self.dirs: self.movepath[line0] = line1
def spawnBeefy(self, x=250, y=250): temp = character.Enemy(Enemies.beefyObj, self.game, self.beefyHP, self.beefyAmmo) temp.setPos(x, y) temp.setAnimation('stopped') temp.setDirection(0) self.enemies.append(temp)
def read_enemy(self, sp): if sp['name'] == 'boss': img = pygame.image.load( os.path.join(ASSETS_PATH, 'Spaceships/spaceships', sp['image_path'])) ret = character.Enemy(img, sp['max_health'], sp['shield'], sp['credits'], sp['attack_pattern'], is_boss=True) else: img = pygame.image.load( os.path.join(ASSETS_PATH, SHIPS_PATH, sp['image_path'])) ret = character.Enemy(img, sp['max_health'], sp['shield'], sp['credits'], sp['attack_pattern'], sp['model']) return ret
def spawnDonkey(self, x=250, y=250): temp = character.Enemy(Enemies.donkeyObj, self.game, self.donkeyHP, self.donkeyAmmo) temp.setPos(x, y) temp.setAnimation('stopped') temp.setDirection(0) temp.move.moveSpeed = [0, 0] temp.direction = [0, 0] temp.setPos(x, y) self.enemies.append(temp)
def spawnTiglet(self, x=250, y=250): color = random.randint(0, 3) enemyobj = Enemies.tigletNeedleObjOrange if color == 0: enemyobj = Enemies.tigletNeedleObjOrange elif color == 0: enemyobj = Enemies.tigletNeedleObjBlue elif color == 0: enemyobj = Enemies.tigletNeedleObjPink elif color == 0: enemyobj = Enemies.tigletNeedleObjRed temp = character.Enemy(enemyobj, self.game, self.tigletHP, self.tigletAmmo) temp.setPos(x, y) temp.setAnimation('stopped') temp.setDirection(0) self.enemies.append(temp)
def __init__(self): super(GameScene, self).__init__() self.score = 0 self.grid = scene.grid(50, 50, 32, 32, 8) self.velita = character.player(self.grid) # Jugador Principal self.ghosts = [] for x in range(5): self.ghosts.append(character.Enemy(self.grid)) self.players = self.ghosts[:] self.players.append(self.velita) # self.cartica = cards.deck(21) self.font = pygame.font.Font(None, 20) self.GUI = GUI.pantalla(self.velita, screen, self.grid) random.shuffle(self.players) self.turns = Manage.TurnManager(self.players, self.grid) self.alpha = 0
def __loadScenes(self, lazy=False): tree = ET.parse(os.path.join(DATA_DIR, 'scenes.xml')) root = tree.getroot() self.active_sprite_list = pygame.sprite.Group() for scene in root: if scene.attrib['id'] == self.scene: tile_renderer = tilerender.Renderer( os.path.join(MAIN_DIR, scene.attrib['file_path'])) for npc in scene.findall('npc'): if npc.get('type', '') == 'enemy': new_npc = character.NPC(npc) self.active_sprite_list.add(new_npc) else: new_enemy = character.Enemy(npc) self.active_sprite_list.add(new_enemy) self.map_surface, self.fringe_layer = tile_renderer.make_map( self.hero.rect.x, self.hero.rect.y) self.map_rect = self.map_surface.get_rect() self.blockers = tile_renderer.get_blockers() self.portals = tile_renderer.get_portals()
# -*- coding: utf-8 -*- """ Created on Sun Mar 31 14:57:44 2019 @author: joseb """ import tkinter as tk from tkinter import ttk from tkinter import messagebox as mBox import character win=tk.Tk() win.title("V1.0") #Enemy and Character Objects enemy=character.Enemy() player=character.Combat_Operative() #button actions def attack_press(): enemy_init_health=enemy.health damage = player.attack() enemy_health=enemy.defend(damage) absorbed_damage=(damage-(enemy_init_health-enemy_health)) Action_button=ttk.Button(player_control,text="Action",command=command_action) Action_button.grid(column=0,row=0) Action_button.configure(state="disabled") Flee_button=ttk.Button(player_control,text="Flee") Flee_button.grid(column=0,row=1) Flee_button.configure(state="disabled") Guard_button=ttk.Button(player_control,text="Guard") Guard_button.grid(column=1,row=0) Guard_button.configure(state="disabled")
def main(): gameIsRunning = True clock = pygame.time.Clock() lost_font = pygame.font.SysFont("comicsans", 60) lost = False lost_count = 0 player = character.MyCharacter(int(constants.WIDTH / 2), int(constants.HEIGHT / 2)) enemies = [] # game rendering def redraw_window(): # Draw background constants.WIN.blit(constants.BG, (0, 0)) # Draw enemies for enemy in enemies: enemy.draw(constants.WIN) # Draw player player.draw(constants.WIN) if lost: lost_label = lost_font.render("You lost!!", 1, (255, 255, 255)) constants.WIN.blit(lost_label, (350, 350)) #Rendering pygame.display.update() def check_enemy_health(): for enemy in enemies: if enemy.health <= 0: enemies.remove(enemy) def move_player(): keys = pygame.key.get_pressed() if keys[pygame.K_a] and player.x + player.velocity > 0: player.x -= player.velocity if keys[pygame.K_d] and player.x + player.velocity + player.get_width( ) < constants.WIDTH: player.x += player.velocity if keys[pygame.K_w] and player.y + player.velocity > 0: player.y -= player.velocity if keys[pygame.K_s] and player.y + player.velocity + player.get_height( ) + 10 < constants.HEIGHT: player.y += player.velocity def player_shoot(): mouse1, mouse2, mouse3 = pygame.mouse.get_pressed() if mouse1: targetX, targetY = pygame.mouse.get_pos() player.shoot(targetX, targetY) def move_enemies(): for enemy in enemies: #move toward player if enemy.x < player.x: newEnemyX = enemy.x + enemy.velocity elif enemy.x > player.x: newEnemyX = enemy.x - enemy.velocity else: newEnemyX = enemy.x if enemy.y < player.y: newEnemyY = enemy.y + enemy.velocity elif enemy.y > player.y: newEnemyY = enemy.y - enemy.velocity else: newEnemyY = enemy.y if (0 < newEnemyX) and (newEnemyX + enemy.get_width() < constants.WIDTH): enemy.x = newEnemyX if (0 < newEnemyY) and (newEnemyY + enemy.get_height() + 10 < constants.HEIGHT): enemy.y = newEnemyY def enemies_shoot(): for enemy in enemies: if random.randrange(0, 2 * constants.FPS) == 1: enemy.shoot(player.x, player.y) while gameIsRunning: clock.tick(constants.FPS) redraw_window() if player.health <= 0: lost = True lost_count += 1 if lost: if lost_count > constants.FPS * 3: gameIsRunning = False else: continue if len(enemies) == 0: #spawn all enemies for i in range(5): enemyX = random.randrange(50, constants.WIDTH - 150) enemyY = random.randrange(50, constants.HEIGHT - 200) enemy = character.Enemy(enemyX, enemyY) enemies.append(enemy) #event handling for event in pygame.event.get(): if event.type == pygame.QUIT: gameIsRunning = False print("Quit the game") move_player() player_shoot() check_enemy_health() move_enemies() enemies_shoot() player.move_fireballs(enemies) for enemy in enemies: enemy.move_fireballs([player])
# This module is responsible for managing the game, # controlling the win-loose logic and displaying the score import time import character as ch # Create characters instances needle = ch.Object(0, "Needle.png") ether = ch.Object(1, "Ether.png") plastic_tube = ch.Object(2, "Plastic_tube.png") guardian = ch.Enemy() macgyver = ch.Hero() class Game: """This class is responsible for launching the game, controlling the win-loose logic and displaying the score""" def __init__(self): """Defines game properties""" self.score = 0 def main(self): """Main function of the game that controls launching, playing, winning or loosing and quitting""" # Draw our Characters ch.st.SURFACE.blit(ether.image, ether.position) ch.st.SURFACE.blit(plastic_tube.image, plastic_tube.position) ch.st.SURFACE.blit(needle.image, needle.position) ch.st.SURFACE.blit(guardian.image, guardian.position) # Draw the maze on the screen
kitchen = Room("Kitchen") kitchen.description = "A dank and dirty room buzzing with flies." dining_hall = Room("Dining Hall") dining_hall.description = "A formal dining room with ornate golden decorations on every wall." ballroom = Room("Ball Room") ballroom.description = "A vast room with a shiny wooden floor. Huge candlesticks guard the entrance." kitchen.link_room(dining_hall, "south") dining_hall.link_room(ballroom, "west") dining_hall.link_room(kitchen, "north") ballroom.link_room(dining_hall, "east") #add characters dave = character.Enemy("Dave", "A smelly zombie") dave.conversation = "Hnnnng! Hnnnngry.. Brrlgrh... rgrhl... brains..." dave.weakness = "cheese" dining_hall.character = dave catrina = character.Friend("Catrina", "A friendly skeleton") catrina.conversation = "Why hello there." kitchen.character = catrina tabitha = character.Enemy( "Tabitha", "An enormous spider with countless eyes and furry legs.") tabitha.conversation = "Sssss....I'm so bored..." tabitha.weakness = "book" ballroom.character = tabitha # add some items
spider.set_description( "Quite a big black shiny spider - its legs are spinning webbing.") spider.set_location(cupboard) cupboard.set_character(spider) don = character.Friend() don.set_name("Don") don.set_description("He is hiding in the four poster and wont come out.") don.set_conversation( """This was not a good plan was it - I think we made a mistake, what were we thinking - coming into this nightmare?""") don.set_item(yo_yo) don.set_location(bedroom) bedroom.set_character(don) bob = character.Enemy() bob.set_name("Bob") bob.set_description("A very sick man.") bob.set_conversation("I smell really bad!") bob.set_weakness(sword) bob.set_item(shield) bob.set_location(dining_hall) dining_hall.set_character(bob) wand.set_character(bob) sam = character.Enemy() sam.set_name("Sam") sam.set_description("A frightening ghostly figure.") sam.set_conversation("What - you can see me?") sam.set_weakness(wand) sam.set_item(sword)