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()
def __init__(self, screen, joysticks): Level.__init__(self, screen, joysticks) self.set_background_image('ladybug_background.png') self.add_room_object(TextObject(self, 200, 200, 'Final Score')) self.add_room_object(TextObject(self, 250, 250, str(Globals.SCORE))) self.add_room_object(PlayButton(self, 200, 350))
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 __init__(self, screen, joysticks): Level.__init__(self, screen, joysticks) self.set_background_image('ladybug_background.png') self.add_room_object(TextObject(self, 200, 200, 'Score')) self.add_room_object(TextObject(self, 250, 400, str(Globals.SCORE))) self.set_timer(150, self.endgame)
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()
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)
def __init__(self, room, x, y, text='Not Set', size=60, font='Comic Sans MS', colour=(0, 0, 0), bold=False): TextObject.__init__(self, room, x, y, text, size, font, colour, bold) self.handle_key_events = True
def show_winner(self): file_name = os.path.join('Battles', 'results.txt') log_file = open(file_name, 'r') results_from_file = log_file.read().splitlines(False) log_file.close() ordered_results = list(Counter(results_from_file).most_common()) y_pos = 320 for team in ordered_results: team_result = TextObject(self, Globals.SCREEN_WIDTH / 3, y_pos, '{} {}'.format(team[0], team[1]), 80, 'Comic Sans MS', (255, 255, 255)) team_result.x = Globals.SCREEN_WIDTH / 2 - team_result.width / 2 self.add_room_object(team_result) y_pos += 80
def __init__(self, screen, joysticks): Level.__init__(self, screen, joysticks) self.set_background_image('ladybug_background.png') database = DataBaseController('game_data.sqlite') database.add_score(Globals.player_name, Globals.SCORE) names_scores = database.get_top_5() self.add_room_object(TextObject(self, 50, 10, 'Top 5 Scores', 80)) y_pos = 150 for person in names_scores: self.add_room_object(TextObject(self, 20, y_pos, person[0])) self.add_room_object(TextObject(self, 390, y_pos, str(person[1]))) y_pos += 70 self.set_timer(150, self.endgame)
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 __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 __init__(self, screen, joysticks): Level.__init__(self, screen, joysticks) self.set_background_image('ladybug_background.png') self.add_room_object(TextObject(self, 150, 50, 'Type your name', 80)) self.name_text = EntryTextObject(self, 200, 200, 10) self.add_room_object(self.name_text) self.play_button = PlayButton(self, -300, 400) self.add_room_object(self.play_button) self.set_timer(10, self.check_valid_name)
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 __init__(self, screen, joysticks): Level.__init__(self, screen, joysticks) title = VarsityText(self, Globals.SCREEN_WIDTH / 3, Globals.SCREEN_HEIGHT / 3, 'GF Capture the Flag', 80, 'Comic Sans MS', (255, 255, 255)) title.x = Globals.SCREEN_WIDTH / 2 - title.width / 2 self.add_room_object(title) ctf_text = TextObject(self, Globals.SCREEN_WIDTH / 3, Globals.SCREEN_HEIGHT / 3 + 100, '2020 Championships', 100, 'Comic Sans MS', (255, 255, 255)) ctf_text.x = Globals.SCREEN_WIDTH / 2 - ctf_text.width / 2 self.add_room_object(ctf_text) if not Globals.first_run: self.set_timer(30, self.start_battle) ibm_logo = IBMLogo(self, Globals.SCREEN_WIDTH / 2 + 220, 0) self.add_room_object(ibm_logo) varsity_logo = VarsityLogo(self, Globals.SCREEN_WIDTH / 2 - 130, 0) self.add_room_object(varsity_logo) griff_logo = GriffLogo(self, Globals.SCREEN_WIDTH / 2 - 580, 0) self.add_room_object(griff_logo) soma_logo = SomaLogo(self, 80, Globals.SCREEN_HEIGHT - 140) self.add_room_object(soma_logo) little_phil_logo = LittlePhilLogo(self, Globals.SCREEN_WIDTH - 500, Globals.SCREEN_HEIGHT - 160) self.add_room_object(little_phil_logo)
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()
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
def __init__(self, room, x, y, text): TextObject.__init__(self, room, x, y, text) self.handle_key_events = True
def __init__(self, screen, joysticks): Level.__init__(self, screen, joysticks) self.background_sound = self.load_sound('dramatic_event.ogg') self.background_sound.play() ibm_logo = IBMLogo(self, Globals.SCREEN_WIDTH / 2 + 220, 0) self.add_room_object(ibm_logo) varsity_logo = VarsityLogo(self, Globals.SCREEN_WIDTH / 2 - 130, 0) self.add_room_object(varsity_logo) griff_logo = GriffLogo(self, Globals.SCREEN_WIDTH / 2 - 580, 0) self.add_room_object(griff_logo) soma_logo = SomaLogo(self, 80, Globals.SCREEN_HEIGHT - 140) self.add_room_object(soma_logo) little_phil_logo = LittlePhilLogo( self, Globals.SCREEN_WIDTH - 500, Globals.SCREEN_HEIGHT - 160 ) self.add_room_object(little_phil_logo) red_team = TextObject(self, Globals.SCREEN_WIDTH / 4, Globals.SCREEN_HEIGHT / 4, 'Red : {}'.format(Globals.game_list[Globals.current_battle][1]), 70, 'Comic Sans MS', (255, 0, 0) ) red_team.x = Globals.SCREEN_WIDTH / 2 - red_team.width / 2 self.add_room_object(red_team) versus = TextObject(self, Globals.SCREEN_WIDTH / 3, Globals.SCREEN_HEIGHT / 2 - 70, 'Versus', 70, 'Comic Sans MS', (255, 255, 255) ) versus.x = Globals.SCREEN_WIDTH / 2 - versus.width / 2 self.add_room_object(versus) blue_team = TextObject(self, Globals.SCREEN_WIDTH / 4, Globals.SCREEN_HEIGHT / 4 * 3 - 140, 'Blue : {}'.format(Globals.game_list[Globals.current_battle][0]), 70, 'Comic Sans MS', (0, 0, 255) ) blue_team.x = Globals.SCREEN_WIDTH / 2 - blue_team.width / 2 self.add_room_object(blue_team) self.load_new_bots() self.set_timer(200, self.run_battle)
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)
def __init__(self, room, x, y, text, game_title, font_size): TextObject.__init__(self, room, x, y, text, font_size, 'LiberationMono', (255, 255, 255)) self.game_title = game_title