Example #1
0
    def __init__(self, screen):
        Level.__init__(self, screen)
        if Globals.winner == 'Red':
            winner = Globals.red_player
            colour = (255, 0, 0)
        elif Globals.winner == 'Blue':
            winner = Globals.blue_player
            colour = (0, 0, 255)
        else:
            winner = 'Draw'
            colour = (255, 255, 255)

        winner_text = TextObject(self, Globals.SCREEN_WIDTH / 3,
                                 Globals.SCREEN_HEIGHT / 3 * 2, winner, 80)
        winner_text.colour = colour
        winner_text.update_text()
        winner_text.x = Globals.SCREEN_WIDTH / 2 - winner_text.width / 2
        self.add_room_object(winner_text)

        battle_text = TextObject(self, Globals.SCREEN_WIDTH / 3,
                                 Globals.SCREEN_HEIGHT / 3, 'Battle Winner',
                                 80)
        battle_text.colour = colour
        battle_text.update_text()
        battle_text.x = Globals.SCREEN_WIDTH / 2 - battle_text.width / 2
        self.add_room_object(battle_text)

        Globals.background_music.stop()

        break_sound = self.load_sound('rock_breaking.ogg')
        self.applause = self.load_sound('applause.wav')
        break_sound.play()
        self.set_timer(60, self.applaud)

        self.set_timer(240, self.end_game)
Example #2
0
class L_Easy(Level):

    def __init__(self, screen, joysticks):
        Level.__init__(self, screen, joysticks)

        # - Set Background image - #
        self.set_background_image("background.jpg")

        # - Set up maze, objects 32x32 25x17 - #
        room_objects = [
            'bbbbbbbbbbbbbbbbbbbbbbbbb',
            'bp______________________b',
            'b___bbbbb___bbbbbbbb__bbb',
            'b___b___bb__bb_____b___bb',
            'b___b____b__b___b___b___b',
            'b___bb___b__b___bbb__b__b',
            'b____b___b__b______b____b',
            'b____b___b__bbbb__b_____b',
            'bbbbbbbbbb_____b__b_____b',
            'b________________bbbbbbdb',
            'b____bbbb_______b_______b',
            'bbbbb_______b_b__b__bb__b',
            'b_____bbbb__b_b__b__bb__b',
            'b________b__b_b_____bb__b',
            'bbbbbb___b__b_bb____bbbbb',
            'bg_____b_________b_____gb',
            'bbbbbbbbbbbbbbbbbbbbbbbbb'
        ]

        for i, row in enumerate(room_objects):
            for j, obj in enumerate(row):
                if obj == 'b':
                    self.add_room_object(Block(self, j*32, i*32))
                elif obj == 'd':
                    self.add_room_object(BlockDoor(self, j * 32, i * 32))
                elif obj == 'p':
                    self.add_room_object(Player(self, j*32, i*32))
                elif obj == 'g':
                    self.add_room_object(Goal(self, j*32, i*32))
                elif obj == 'm':
                    self.add_room_object(Monster(self, j*32, i*32))

        # - Add Banner for game info (lives) 800x56 - #
        self.add_room_object(Banner(self, 0, 544))

        # - Add Text - #
        self.score_text = TextObject(self, 20, 560, 'Lives: %i' % Globals.LIVES)
        self.score_text.depth = 1000
        self.score_text.colour = (255, 255, 255)
        self.score_text.update_text()
        self.add_room_object(self.score_text)

    def update_score(self, value):
        Globals.LIVES += value
        if Globals.LIVES == 0:
            self.running = False
            self.quitting = True
        self.score_text.text = 'Lives: %i' % Globals.LIVES
        self.score_text.update_text()
Example #3
0
class L_Hard(Level):
    def __init__(self, screen, joysticks):
        Level.__init__(self, screen, joysticks)

        # - Set Background image - #
        self.set_background_image("background.jpg")

        # - Home location for the player - #
        self.home_x = 11 * 32
        self.home_y = 7 * 32

        # - Set up maze, objects 32x32 25x17 - #
        room_objects = [
            'bbbbbbbbbbbbbbbbbbbbbbbbb', 'b___________m___________b',
            'b___bbbbb_d_bbbbbbbb__bdb', 'b___b___bb_bbb_____b___bb',
            'b___b____b__b___b___b___b', 'b___bb___b__b___bbb__b__b',
            'b____b___bp_b______b___mb', 'b____b___b__bbbb__b_____b',
            'b____bbbbb_m___b__b_____b', 'b____m________b__bbbbbbbb',
            'b____bbbb____b__b_______b', 'bbbbb_______b_b__b__bb__b',
            'b_____bbbbb_b_b__b__bb__b', 'b_________b___b_____bb__b',
            'bbbbbbbbbbbbbdbb__bbbb__b', 'b______g_______b_bb_____b',
            'bbbbbbbbbbbbbbbbbbbbbbbbb'
        ]

        for i, row in enumerate(room_objects):
            for j, obj in enumerate(row):
                if obj == 'b':
                    self.add_room_object(Block(self, j * 32, i * 32))
                elif obj == 'd':
                    self.add_room_object(BlockDoor(self, j * 32, i * 32))
                elif obj == 'p':
                    self.add_room_object(Player(self, j * 32, i * 32))
                elif obj == 'g':
                    self.add_room_object(Goal(self, j * 32, i * 32))
                elif obj == 'm':
                    self.add_room_object(Monster(self, j * 32, i * 32))

        # - Add Banner for game info (lives) 800x56 - #
        self.add_room_object(Banner(self, 0, 544))

        # - Add Text - #
        self.score_text = TextObject(self, 20, 560,
                                     'Lives: %i' % Globals.LIVES)
        self.score_text.depth = 1000
        self.score_text.colour = (255, 255, 255)
        self.score_text.update_text()
        self.add_room_object(self.score_text)

    def update_score(self, value):
        Globals.LIVES += value
        if Globals.LIVES == 0:
            self.running = False
            self.quitting = True
        self.score_text.text = 'Lives: %i' % Globals.LIVES
        self.score_text.update_text()
Example #4
0
class Level1(Level):
    def __init__(self, screen, joysticks):
        Level.__init__(self, screen, joysticks)

        # - Set Background image - #
        self.set_background_image('ocean.png')
        self.set_background_scroll(4)

        self.add_room_object(Plane(self, 468, Globals.SCREEN_HEIGHT - 60))

        self.add_room_object(
            Island1(self, random.randint(65, Globals.SCREEN_WIDTH - 130),
                    -100))
        self.add_room_object(
            Island2(self, random.randint(65, Globals.SCREEN_WIDTH - 130),
                    -300))
        self.add_room_object(
            Island3(self, random.randint(65, Globals.SCREEN_WIDTH - 130),
                    -500))

        # - Add Banner for game info (lives) 800x56 - #
        self.add_room_object(Banner(self, 0, 544))

        # - Add Text - #
        self.score_text = TextObject(self, 20, 560,
                                     'Lives: %i' % Globals.LIVES)
        self.score_text.depth = 200
        # self.score_text.font = 'Arial'
        self.score_text.colour = (255, 255, 255)
        self.score_text.update_text()
        self.add_room_object(self.score_text)

        # Load Sounds
        self.fire_bullet_sound = self.load_sound("fire_bullet.wav")
        self.explosion_sound = self.load_sound("explosion.wav")

        # - Add first Enemy plane after 5 Seconds - #
        self.set_timer(150, self.add_enemy)

    def update_score(self, value):
        Globals.LIVES += value
        if Globals.LIVES == 0:
            self.running = False
            self.quitting = True
        self.score_text.text = 'Lives: %i' % Globals.LIVES
        self.score_text.update_text()

    def add_enemy(self):
        self.add_room_object(
            Enemy(self, random.randint(0, Globals.SCREEN_WIDTH), -100))
        # - Add new enemy every 2 seconds until max of 10 - #
        Globals.total_count += 1
        if Globals.total_count < 10:
            self.set_timer(60, self.add_enemy)
Example #5
0
class Arena(Level):
    def __init__(self, screen):
        Level.__init__(self, screen)

        self.set_background_image("background.png")

        Globals.red_bots.append(Red1(self, Globals.SCREEN_WIDTH - 250, Globals.SCREEN_HEIGHT / 4))
        Globals.blue_bots.append(Blue1(self, 108, Globals.SCREEN_HEIGHT / 3))
        Globals.red_bots.append(Red2(self, Globals.SCREEN_WIDTH - 250, Globals.SCREEN_HEIGHT / 4 * 2))
        Globals.blue_bots.append(Blue2(self, 108, Globals.SCREEN_HEIGHT / 3 * 2))
        Globals.red_bots.append(Red3(self, Globals.SCREEN_WIDTH - 250, Globals.SCREEN_HEIGHT / 4 * 3))
        Globals.blue_bots.append(Blue3(self, 228, Globals.SCREEN_HEIGHT / 4))
        Globals.red_bots.append(Red4(self, Globals.SCREEN_WIDTH - 140, Globals.SCREEN_HEIGHT / 3))
        Globals.blue_bots.append(Blue4(self, 228, Globals.SCREEN_HEIGHT / 4 * 2))
        Globals.red_bots.append(Red5(self, Globals.SCREEN_WIDTH - 140, Globals.SCREEN_HEIGHT / 3 * 2))
        Globals.blue_bots.append(Blue5(self, 228, Globals.SCREEN_HEIGHT / 4 * 3))

        for i in range(len(Globals.red_bots)):
            self.add_room_object(Globals.red_bots[i])

        for i in range(len(Globals.blue_bots)):
            self.add_room_object(Globals.blue_bots[i])
            Globals.blue_bots[i].rotate(180)

        Globals.red_flag = RedFlag(self, 200, Globals.SCREEN_HEIGHT / 2 - 26)
        Globals.blue_flag = BlueFlag(self, Globals.SCREEN_WIDTH - 232, Globals.SCREEN_HEIGHT / 2 - 26)

        self.add_room_object(Globals.red_flag)
        self.add_room_object(Globals.blue_flag)

        self.red_danger_zone = DangerZone(self, 0, -150)
        self.blue_danger_zone = DangerZone(self, 0, -150)

        self.can_update_red_danger = True
        self.can_update_blue_danger = True

        self.add_room_object(self.red_danger_zone)
        self.add_room_object(self.blue_danger_zone)

        self.danger_siren = self.load_sound('danger_siren.ogg')

        Globals.background_music = self.load_sound('battle-music.ogg')
        Globals.background_music.play(-1)

        self.counter = 3600
        self.seconds = 120
        text_minutes = int(self.seconds / 60)
        text_seconds = self.seconds % 60
        self.counter_text = TextObject(self, Globals.SCREEN_WIDTH/2 - 50, 10, "{}:{:02d}".format(text_minutes, text_seconds))
        self.add_room_object(self.counter_text)
        self.counter_text.x = Globals.SCREEN_WIDTH / 2 - self.counter_text.width/2

        self.blue_score_text = TextObject(self, Globals.SCREEN_WIDTH / 2 - 50, 10, str(Globals.blue_enemy_side_time), 30)
        self.add_room_object(self.blue_score_text)
        self.blue_score_text.x = Globals.SCREEN_WIDTH / 3 - self.counter_text.width / 2

        self.red_score_text = TextObject(self, Globals.SCREEN_WIDTH / 2 - 50, 10, str(Globals.red_enemy_side_time), 30)
        self.add_room_object(self.red_score_text)
        self.red_score_text.x = Globals.SCREEN_WIDTH / 3 * 2 - self.counter_text.width / 2

        self.set_timer(3600, self.timed_out)
        self.update_screen_text()

    def tick(self):
        self.counter -= 1

        if self.can_update_blue_danger:
            for bot in Globals.blue_bots:
                if bot.point_to_point_distance(bot.x, bot.y, Globals.blue_flag.x, Globals.blue_flag.y) < 50:
                    self.can_update_blue_danger = False
                    self.danger_siren.play()
                    self.set_timer(20, self.end_blue_danger)
                    break
        else:
            self.blue_danger_zone.x = Globals.blue_flag.x - 60
            self.blue_danger_zone.y = Globals.blue_flag.y - 60

        if self.can_update_red_danger:
            for bot in Globals.red_bots:
                if bot.point_to_point_distance(bot.x, bot.y, Globals.red_flag.x, Globals.red_flag.y) < 50:
                    self.can_update_red_danger = False
                    self.danger_siren.play()
                    self.set_timer(20, self.end_red_danger)
                    break
        else:
            self.red_danger_zone.x = Globals.red_flag.x - 60
            self.red_danger_zone.y = Globals.red_flag.y - 60

    def end_blue_danger(self):
        self.blue_danger_zone.y = -150
        self.can_update_blue_danger = True

    def end_red_danger(self):
        self.red_danger_zone.y = -150
        self.can_update_red_danger = True

    def update_screen_text(self):
        self.seconds -= 1
        text_minutes = int(self.seconds / 60)
        text_seconds = self.seconds % 60
        self.counter_text.text = "{}:{:02d}".format(text_minutes, text_seconds)
        self.counter_text.update_text()
        self.counter_text.x = Globals.SCREEN_WIDTH / 2 - self.counter_text.width / 2

        self.blue_score_text.text = str(Globals.blue_enemy_side_time)
        self.blue_score_text.update_text()

        self.red_score_text.text = str(Globals.red_enemy_side_time)
        self.red_score_text.update_text()

        if self.counter > 0:
            self.set_timer(30, self.update_screen_text)

    def timed_out(self):
        if Globals.red_enemy_side_time > Globals.blue_enemy_side_time:
            Globals.winner = 'Red'
        elif Globals.blue_enemy_side_time > Globals.red_enemy_side_time:
            Globals.winner = 'Blue'
        else:
            Globals.winner = 'Draw'
        self.running = False
Example #6
0
class Platform(Level):
    def __init__(self, screen, joysticks):
        Level.__init__(self, screen, joysticks)

        # - Set Background image - #
        self.set_background_image("wood_background.jpg")

        # - Preload images from disk - #
        img_grnd_flat = self.load_image('Grass_Tile_Flat.png')
        img_grnd_left = self.load_image('Grass_Tile_Corner_Edge_l.png')
        img_grnd_right = self.load_image('Grass_Tile_Corner_Edge_r.png')
        img_grnd_under = self.load_image('Grass_Tile_lower.png')

        # - Set up maze, objects 32x32 25x17 - #
        room_objects = [
            'lmmmmmmmmmmmmmmmmmmmmmmmr', 'ug_________________M____u',
            'u_______________________u', 'umrG ___________________u',
            'u_______________________u', 'u_lmmr_lmmmmmr______lr__u',
            'u_____________lmmmr_____u', 'u______________________lu',
            'u__________M____________u', 'u__________________Glmmmu',
            'u_____M________lr_______u', 'u_________lmmr___lr_____u',
            'u_______________________u', 'ummmr__lr_______________u',
            'u________lmmmr__________u', 'up______________________u',
            'ummmmmmmmmmmmmmmmmmmmmmmu'
        ]

        for i, row in enumerate(room_objects):
            for j, obj in enumerate(row):
                if obj == 'm':
                    self.add_room_object(
                        Block(self, j * 32, i * 32, img_grnd_flat))
                elif obj == 'l':
                    self.add_room_object(
                        Block(self, j * 32, i * 32, img_grnd_left))
                elif obj == 'r':
                    self.add_room_object(
                        Block(self, j * 32, i * 32, img_grnd_right))
                elif obj == 'u':
                    self.add_room_object(
                        Block(self, j * 32, i * 32, img_grnd_under))
                elif obj == 'p':
                    self.add_room_object(Player(self, j * 32, i * 32))
                elif obj == 'g':
                    self.add_room_object(Goal(self, j * 32, i * 32))
                elif obj == 'G':
                    self.add_room_object(Monster2(self, j * 32, i * 32))
                elif obj == 'M':
                    self.add_room_object(Monster(self, j * 32, i * 32))

        # - Add Banner for game info (lives) 800x56 - #
        self.add_room_object(Banner(self, 0, 544))

        # - Add Text - #
        self.score_text = TextObject(self, 20, 560,
                                     'Lives: %i' % Globals.LIVES)
        self.score_text.depth = 1000
        self.score_text.colour = (255, 255, 255)
        self.score_text.update_text()
        self.add_room_object(self.score_text)

    def update_lives(self, value):
        Globals.LIVES += value
        if Globals.LIVES == 0:
            self.running = False
            self.quitting = True
        self.score_text.text = 'Lives: %i' % Globals.LIVES
        self.score_text.update_text()