def check_button(self, mx, my, click): clicked = False self.surface.fill((34, 23, 36), (self.x, self.y, self.width, self.height)) if self.x + self.width > mx > self.x and self.y + self.height > my > self.y: self.surface.fill((104, 93, 106), (self.x, self.y, self.width, self.height)) if click[0] == 1: clicked = True text.show_text(self.text, self.x + 8, self.y + 5, 1, 9999, self.font, self.surface, 2) return clicked
def win_screen(): while True: display.fill((34, 23, 36)) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_ESCAPE: pygame.quit() sys.exit() text.show_text('You Win!', 150 - get_text_width('You Win!', 1) / 2, 90, 1, 9999, font, display) text.show_text(convert_time(total_time), 150 - get_text_width(convert_time(total_time), 1) / 2, 100, 1, 9999, font, display) screen.blit(pygame.transform.scale(display, (900, 600)), (-6, -6)) pygame.display.update() mainClock.tick(60)
def Restart_L(): # Not working dead = True text.show_text('click to restart', 150 - int(get_text_width('click to restart', 1) / 2), 97, 1, 9999, font, main_display) if click: dead = False temp = str(level) tile_map, entities, map_height, spawnpoint, total_cores, limits = load_level(temp) player = e.entity(spawnpoint[0] + 4, spawnpoint[1] - 17, 8, 15, 'player') player.set_offset([-3, -2]) level_time = 0 bullets = [] flashes = [] explosion_particles = [] particles = [] circle_effects = [] scroll_target = [player.get_center()[0], player.get_center()[1]] scroll = scroll_target.copy() true_scroll = scroll.copy() bar_height = 100 moved = False player_velocity = [0, 0]
# creates start button start_button = engine.Button(startx, starty, start_width, start_height, font, "start", display) if start_button.check_button(mx, my, click): sys.argv = ["text", name, level] exec(open("Aeroblaster.py").read()) display.fill((34, 23, 36), (startx, starty, start_width, start_height)) if startx + start_width > mx > startx and starty + start_height > my > starty: display.fill((104, 93, 106), (startx, starty, start_width, start_height)) if click[0] == 1: sys.argv = ["text", name, level] exec(open("Aeroblaster.py").read()) text.show_text('start', startx + 8, starty + 5, 1, 9999, font, display, 2) # creates end button end_button = engine.Button(endx, endy, end_width, end_height, font, "end", display) if end_button.check_button(mx, my, click): quit() # created controls button controls_button = engine.Button(contx, conty, cont_width, cont_height, font, "controls", display) if controls_button.check_button(mx, my, click): controls = True # creates name entry box display.fill((34, 23, 36), (namex, namey, name_width, name_height))
if explosion_particle[4][0] > 20: explosion_particle[4][0] -= dtf(dt) * game_speed * 0.5 color_offset = (explosion_particle[4][0] / explosion_particle[4][1]) * 30 * (1 + explosion_particle[3] / 8) pygame.draw.circle(main_display, (255 - color_offset * 1.1, 255 - color_offset * 1.2, 255 - color_offset), (explosion_particle[1][0] - scroll[0], explosion_particle[1][1] - scroll[1]), size) explosion_particle[4][0] += dtf(dt) * game_speed if explosion_particle[4][0] >= explosion_particle[4][1]: explosion_particles.pop(i) # Cursor ------------------------------------------------- # e.blit_center(main_display, cursor_img, (mx, my)) # UI ----------------------------------------------------- # if level == 1: text.show_text('Finish the level in less than 1 second!', 150 - int(get_text_width('Finish the level in less than 1 second!', 1) / 2), 35, 1, 9999, font, main_display) main_display.blit(core_img, (145, 47)) if level == 2: text.show_text('Drop to loop around. Error: not hidden level', 150 - int(get_text_width('Drop to loop around. Error: not hidden level', 1) / 2), 45, 1, 9999, font, main_display) if level == 3: text.show_text('shoot avoid ghcd?', 150 - int(get_text_width('shoot avoid ghcd?', 1) / 2), 45, 1, 9999, font, main_display) main_display.blit(turret_example_img, (107, 57)) main_display.blit(shot_example_img, (147, 57)) if dead: text.show_text('click to restart', 150 - int(get_text_width('click to restart', 1) / 2), 97, 1, 9999, font, main_display) if click:
# Cursor ------------------------------------------------- # e.blit_center(main_display, cursor_img, (mx, my)) # UI ----------------------------------------------------- # if level == 1: if not moved: controls_timer = (controls_timer + 1) % 50 if controls_timer <= 42: main_display.blit( controls_1, (player.x - scroll[0] - 17, player.y - scroll[1] - 22)) else: main_display.blit( controls_2, (player.x - scroll[0] - 17, player.y - scroll[1] - 22)) text.show_text('shoot', 150 - int(get_text_width('shoot', 1) / 2), 35, 1, 9999, font, main_display) main_display.blit(core_img, (145, 47)) if level == 2: text.show_text('drop to loop around', 150 - int(get_text_width('drop to loop around', 1) / 2), 45, 1, 9999, font, main_display) if level == 3: text.show_text('shoot avoid', 150 - int(get_text_width('shoot avoid', 1) / 2), 45, 1, 9999, font, main_display) main_display.blit(turret_example_img, (122, 57)) main_display.blit(shot_example_img, (163, 57)) if dead: text.show_text('click to restart', 150 - int(get_text_width('click to restart', 1) / 2), 97, 1, 9999, font, main_display)