Exemplo n.º 1
0
    def main_map(self, screen, player, assets):
        escape_call = Escape()
        sector_map = IconTree(self.images)
        sector_map.update()
        player_loc = sector_map.root
        alive = True
        win = None
        while alive and win is None:
            screen.blit(self.bg, (0, 0))
            screen.blit(self.legend, (580, 20))
            screen.blit(self.up, self.up_rect)
            screen.blit(self.down, self.down_rect)

            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
                    break

                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        escape_call.escape_menu(screen)
                        break
                elif event.type == MOUSEBUTTONDOWN:
                    position = pygame.mouse.get_pos()
                    if self.up_rect.collidepoint(
                            position) or self.down_rect.collidepoint(position):
                        sector_map.scroll(screen, player_loc, self.bg,
                                          self.legend, self.up, self.down,
                                          self.up_rect, self.down_rect)
                    for sp in sector_map.sprites():
                        if sp.is_child(player_loc) and sp.collide(position):
                            player_loc = sp
                            if sp.type == 'minion':
                                alive = battle(screen, player, assets,
                                               escape_call)
                            elif sp.type == 'boss':
                                win = battle(screen,
                                             player,
                                             assets,
                                             escape_call,
                                             boss=True)
                            elif sp.type == 'unknown':
                                alive = events(screen, player, assets,
                                               escape_call)
                            elif sp.type == 'repair':
                                repair(screen, player, assets, escape_call)
                            elif sp.type == 'shop':
                                shop(screen, player, assets, escape_call)
                if alive:
                    sector_map.draw(screen, player_loc)
                    pygame.display.update()
            if player.current_health <= 0:
                break
        if not win or player.current_health <= 0:
            game_over(screen)
        if (win):
            game_win(screen)
Exemplo n.º 2
0
def repair(screen, player, assets, escape_call):
    pygame.font.init()
    bg = pygame.transform.scale(
        pygame.image.load(
            os.path.join(ASSETS_PATH, 'Background', 'nebula', 'nebula07.png')),
        (SCREEN_WIDTH, SCREEN_HEIGHT))
    large = pygame.font.Font(None, 64)
    repair_msg = large.render("Your ship has repaired 30%", False,
                              BRIGHT_WHITE)
    repair_msg2 = large.render("hull integrity.", False, BRIGHT_WHITE)
    rep1_rect = repair_msg.get_rect(midbottom=(SCREEN_WIDTH / 2,
                                               SCREEN_HEIGHT / 2))
    rep2_rect = repair_msg2.get_rect(midtop=rep1_rect.midbottom)
    small = pygame.font.Font(None, 22)
    cont_no = small.render("Continue", False, RED)
    cont_go = small.render("Continue", False, GREEN)
    rect = cont_no.get_rect(center=(SCREEN_WIDTH / 2, SCREEN_HEIGHT * (2 / 3)))
    player_rect = player.image.get_rect(center=(SCREEN_WIDTH / 2,
                                                SCREEN_HEIGHT / 6))
    player.move(player_rect.x, player_rect.y)
    player.current_health += int(player.max_health * 0.30)
    if player.current_health > player.max_health:
        player.current_health = player.max_health
    screen.blit(bg, (0, 0))
    player.draw(screen)
    screen.blit(repair_msg, rep1_rect)
    screen.blit(repair_msg2, rep2_rect)
    screen.blit(cont_no, rect)
    pygame.display.update()
    pygame.time.wait(1000)
    escape_call = Escape()

    while True:
        pygame.time.Clock().tick(40)
        pos = pygame.mouse.get_pos()
        if rect.collidepoint(pos):
            screen.blit(cont_go, rect)
        else:
            screen.blit(cont_no, rect)
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    escape_call.escape_menu(screen)
                    break

            elif event.type == MOUSEBUTTONDOWN:
                if rect.collidepoint(pos):
                    return
        pygame.display.update()
Exemplo n.º 3
0
 def instructions_menu(self, screen):
     escape_call = Escape()
     ret = True
     while ret:
         pygame.time.Clock().tick(40)
         screen.blit(self.bg, (0, 0))
         for event in pygame.event.get():
             if event.type == QUIT:
                 pygame.quit()
                 sys.exit()
                 break
         pygame.display.update()
         ret = self.buttons(screen)
    def __init__(self, audiofiles_dir):
        self.explode = Explode(audiofiles_dir=audiofiles_dir)
        self.escape = Escape()
        ######
        sorted_items, self.wating_times = explode_and_escape_time()

        print(sorted_items)

        func_dict = {
            'describe_explosion_start': self.explode.on,
            'describe_explosion_end': self.explode.off,
            'launch_balls_start': self.escape.on,
            'launch_balls_end': self.escape.off
        }

        sortfunc = SortFunctions(sorted_items, func_dict)
        self.func = sortfunc.func
Exemplo n.º 5
0
class Map(object):

    scenes = {
        'last_day_on_earth': LastDayOnEarth(),
        'death': Death(),
        'exploring': Exploring(),
        'escape': Escape(),
        'deactivation': Deactivation()
    }

    def __init__(self, start_scene):
        self.start_scene = start_scene

    def next_scene(self, scene_name):
        return Map.scenes.get(scene_name)

    def opening_scene(self):
        return self.next_scene(self.start_scene)
Exemplo n.º 6
0
 def run(self):
     self.game = Escape()
     self.game.start()
Exemplo n.º 7
0
class Game(object):

    def run(self):
        self.game = Escape()
        self.game.start()
Exemplo n.º 8
0
        # update the display every iteration of this loop
        pygame.display.update()
    player.credits += loot
    salvage(screen, board, player, assets)
    player.drain_shields()
    return True


if __name__ == "__main__":
    # Run battle.py directly to test battle functionality
    pygame.init()
    pygame.display.init()
    screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
    # declare the size of the map
    assets = GameAssets()
    escape_call = Escape()
    player = Player()
    player.move(0, SCREEN_HEIGHT / 3)
    basics = assets.all_cards['basic']
    for _ in range(4):
        player.all_cards.append(basics[0].copy())
        player.all_cards.append(basics[1].copy())
    for _ in range(2):
        player.all_cards.append(assets.all_cards['fighter'][0].copy())
    ret = True
    while ret:
        ret = battle(screen, player, assets, escape_call)
    game_over(screen)
    pygame.display.quit()
Exemplo n.º 9
0
from subprocess import run as run_block, Popen, PIPE, CalledProcessError
from sys import executable
from escape import Escape

escape = Escape('"')
executable = '"' + executable + '"'


def bs(value: bytes):
    """bytes to string converter"""
    return str(value)[2:-1]


def run(*args) -> bytes:
    command = ' '.join(args)
    try:
        r = run_block(command, shell=True, stdout=PIPE, check=True)
    except CalledProcessError as e:
        raise OSError(f'{command} failed\n'
                      f'{e.stderr}, Exit Code: {e.returncode}\n')
    if r.stderr:
        raise OSError(f'{command} failed\n'
                      f'{r.stderr}, Exit Code: {r.returncode}\n')
    return r.stdout


def run_async(*args) -> Popen:
    """https://stackoverflow.com/questions/16071866/non-blocking-subprocess-call
    p = run_async("command")
    while p.poll() is None:
        ...