def on_draw(self): arcade.start_render() self.player_list.draw() self.bullet_list.draw() self.wall_list.draw() self.donut_list.draw() self.enemy_list.draw() self.enemy_bullet_list.draw() # Draw score and level text draw_text(f"Wave: {self.level + 1}", 10, 40, arcade.color.WHITE, 14) draw_text(f"Score: {self.score}", 10, 20, arcade.color.WHITE, 14)
def on_draw(self): arcade.start_render() draw_text( "Donut Run", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, arcade.color.BLACK, font_size=50, anchor_x="center", ) draw_text( "Click to start", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 75, arcade.color.GRAY, font_size=20, anchor_x="center", ) draw_text( "Use WASD/Arrow Keys to move, and use your mouse to aim!", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 100, arcade.color.GRAY, font_size=15, anchor_x="center", ) draw_text( f"TIP: {self.tip}", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 125, arcade.color.GRAY, font_size=15, anchor_x="center", )
def step(self, active_sprites, background, background_rect, main_menu_pict, img_dir, current_map, map1, map2, map3, health_bar, mobs, player_anim_up, player_anim_down, player_anim_left, player_anim_right, player_udar_up, player_udar_down, player_udar_left, player_udar_right, objects, player_sprite, skelet_anim_up, skelet_anim_down, skelet_anim_right, skelet_anim_left, player): self.clock.tick(self.FPS) for self.event in pygame.event.get(): if self.event.type == pygame.QUIT: # проверка для закрытия окна self.finished = True if self.playing_game: # Обновление keystate = pygame.key.get_pressed() if keystate[pygame.K_ESCAPE]: self.playing_game = False player_sprite.update(img_dir, current_map, map1, map2, map3, health_bar, mobs, player_anim_up, player_anim_down, player_anim_left, player_anim_right, player_udar_up, player_udar_down, player_udar_left, player_udar_right) objects.update(img_dir, current_map, map1, map2, map3, health_bar, mobs, player_anim_up, player_anim_down, player_anim_left, player_anim_right, player_udar_up, player_udar_down, player_udar_left, player_udar_right) mobs.update(player, active_sprites, img_dir, skelet_anim_up, skelet_anim_down, skelet_anim_right, skelet_anim_left, player_sprite) # Рендеринг self.screen.fill(BLACK) self.screen.blit(background, background_rect) active_sprites.draw(self.screen) draw_text() # Переворачиваем экран после отрисовки pygame.display.flip() else: self.in_main_menu(main_menu_pict)
def level_2_summary(): level_ended = True while level_ended == True: clock.tick(30) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # screen.blit(background, (0, 0)) screen.blit(background, (0, 0)) compliment_text = text.draw_text(screen, 'You\'re Almost There!', 100, 400, 150, constants.GREEN, "ariel") continue_text = text.draw_text(screen, 'Click [SPACE] to go to LEVEL 3', 60, 410, 400, constants.YELLOW, "ariel") pygame.display.flip() keystate = pygame.key.get_pressed() if keystate[pygame.K_SPACE]: # current_level.bg_ticks = pygame.time.get_ticks() level_ended = False
def on_draw(self): arcade.start_render() draw_text( "GAME OVER", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, arcade.color.BLACK, font_size=50, anchor_x="center", ) draw_text( f"You reached wave {self.level} and had a score of {self.score}!", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 75, arcade.color.GRAY, font_size=15, anchor_x="center", ) draw_text( "Click to restart", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 100, arcade.color.GRAY, font_size=15, anchor_x="center", )
def menu_start(): menu_ = True highscore_page = False load_data() while menu_ == True: clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False menu_sprites.update() screen.fill(constants.MENU_FILL) screen.blit(background, (0, 0)) menu_sprites.draw(screen) if highscore_page == True: screen.fill(constants.BLUE) text.draw_text(screen, "HIGHSCORES", 100, constants.WIDTH / 2, 20, constants.BLACK, "Haettenschweiler") text.draw_text(screen, "Press [ESCAPE] to return to MENU", 25, constants.WIDTH / 2 - 150, constants.HEIGHT - 40, constants.BLACK, "Haettenschweiler") text.draw_text(screen, "Press [SPACE] to START", 25, constants.WIDTH / 2 + 150, constants.HEIGHT - 40, constants.BLACK, "Haettenschweiler") for i in range(10): text.draw_text(screen, str(i + 1) + ". " + str(highscore_list[i]), 30, constants.WIDTH / 2, 150 + 40 * i, constants.BLACK, "Haettenschweiler") pygame.display.flip() keystate = pygame.key.get_pressed() if keystate[pygame.K_SPACE]: # current_level.bg_ticks = pygame.time.get_ticks() menu_ = False if keystate[pygame.K_h]: highscore_page = True if highscore_page == True: if keystate[pygame.K_ESCAPE]: highscore_page = False
def handle(clock): #print('Mode: Win') mf = hardware.last_rendered_frame sound_step = pygame.mixer.Sound('step.wav') colors = [ GR.COLORS_SPLASH_TEXT, GR.COLORS_SPLASH_TEXT + 1, GR.COLORS_SPLASH_TEXT + 2, GR.COLORS_SPLASH_TEXT + 3 ] sc = 0 og = GR.COLOR_PALETTE[GR.COLORS_MAZE_WALL] for i in range(8): GR.COLOR_PALETTE[GR.COLORS_MAZE_WALL] = GR.COLOR_PALETTE[colors[sc]] sc += 1 if sc >= len(colors): sc = 0 hardware.render_frame(mf) clock.tick(4) GR.COLOR_PALETTE[GR.COLORS_MAZE_WALL] = og pic = Frame() text.draw_text(pic, 0x1E, 0x1B, "We'll Getcha", [GR.COLORS_SPLASH_TEXT + 1]) text.draw_text(pic, 0x27, 0x28, "Next Time", [GR.COLORS_SPLASH_TEXT + 2]) acc = Frame() seg = 0 y = 0 animation = 0 while True: for _ in pygame.event.get(): pass if seg == 0: if y > 0: for x in range(128): acc.set_pixel(x, y - 2, pic.get_pixel(x, y - 2)) acc.set_pixel(x, y - 1, pic.get_pixel(x, y - 1)) nf = Frame(acc) sound_step.play(0) for i in range(32): nf.draw_image(0 + i * 8, y, GR.LITTLE_BUG[2][animation]) animation += 1 animation &= 1 y = y + 2 if y > 96: seg = 1 text.draw_text(pic, 0x5D, 0x28, "!", [GR.COLORS_SPLASH_TEXT + 3]) y = 0 hardware.render_frame(acc) clock.tick(1) hardware.render_frame(nf) clock.tick(10) elif seg == 1: if y > 0: for x in range(128): acc.set_pixel(x, y - 4, pic.get_pixel(x, y - 4)) acc.set_pixel(x, y - 3, pic.get_pixel(x, y - 3)) acc.set_pixel(x, y - 2, pic.get_pixel(x, y - 2)) acc.set_pixel(x, y - 1, pic.get_pixel(x, y - 1)) nf = Frame(acc) sound_step.play(0) nf.draw_image(92, y, GR.LITTLE_BUG[2][animation]) animation += 1 animation &= 1 y = y + 4 if y > 96: seg = 3 hardware.render_frame(nf) clock.tick(15) else: clock.tick(1) return "Mode: Game"
def handle(clock, event_handler): #print('Mode: Demo') # Make the bugs (not too close to center) bugs = [] for _ in range(16): while True: cx = random.randint(0, 19) cy = random.randint(0, 15) if (cx >= 6 and cx < 14) and (cy >= 6 and cy < 14): continue break bugs.append(Bug(cx * 4 + 25, cy * 4 + 17, random.randint(0, 3))) pic = Frame() # Draw the bugs mega = Maze(20, 16, 192) mode_game.draw_maze(mega._maze, pic) # Draw the big bugs bugimage = GR.BIG_BUG pic.draw_image(3, 32, bugimage['standing']) pic.draw_image(108, 32, bugimage['standing']) # The mouth mouth = Mouth(25 + 10 * 4, 17 + 8 * 4, random.randint(0, 3)) # Don't start on a dot pic.set_pixel(mouth.x, mouth.y, 0) hs = str(mode_game.HIGH_SCORE).rjust(4, '0') text.draw_text(pic, 19, 4, 'High Score ' + hs, GR.COLOR_SCORE) text.draw_text(pic, 26, 84, 'Play Giga-Bug', GR.COLOR_SCORE) transitions.wipe_in(pic) """ base_frame = Frame() base_frame.draw_image(10,15, GR.CHARS['A']) # The letter 'A' base_frame.draw_text(5,5, GR.CHARS,'Demonstration') base_frame.draw_image(20,25, GR.BIG_BUG['standing']) # Bug standing base_frame.draw_image(50,25, GR.BIG_BUG['dancing'][0]) # Bug dancing ... base_frame.draw_image(70,25, GR.BIG_BUG['dancing'][1]) # ... two animations direction = 1 # 0=UP, 1=RIGHT, 2=DOWN, 3=LEFT animation = 0 # 0 or 1 ... two animations while True: frame = Frame(base_frame) frame.draw_image(10,60, GR.MOUTH[direction][animation]) hardware.render_frame(frame) animation = (animation + 1) % 2 time.sleep(0.25) """ clock.tick(0.75) nf = MAG.draw_magnifier(pic, mouth.x - 8, mouth.y - 8, 17) MAG.draw_mouth_on_magnifier(nf, mouth) hardware.render_frame(nf) clock.tick(0.75) # Play this setup return play_game(clock, pic, mouth, bugs, event_handler)
def handle(clock, event_handler): #print('Mode: Splash') hardware.set_colors(GR.COLOR_PALETTE) pic = Frame() color_start1 = 0 color_start2 = 1 color_start3 = 2 colors = [ GR.COLORS_SPLASH_TEXT, GR.COLORS_SPLASH_TEXT + 1, GR.COLORS_SPLASH_TEXT + 2, GR.COLORS_SPLASH_TEXT + 3 ] text.draw_text(pic, 22, 14, 'Bob Bishop', GR.COLOR_CRUMB) text.draw_text(pic, 22, 34, 'Steve Bjork', GR.COLOR_CRUMB) text.draw_text(pic, 22, 44, 'Datasoft 1982', GR.COLOR_CRUMB) text.draw_text(pic, 22, 74, 'Chris Cantrell', colors[1]) text.draw_text(pic, 10, 4, 'DUNG BEETLES', colors, color_start1) text.draw_text(pic, 10, 24, 'Mega-Bug', colors, color_start2) text.draw_text(pic, 10, 64, 'Giga-Bug', colors, color_start3) transitions.wipe_out(pic) SONG_END = pygame.USEREVENT + 1 pygame.mixer.music.set_endevent(SONG_END) pygame.mixer.music.load('splash.wav') pygame.mixer.music.play() while True: for event in pygame.event.get(): if event.type == 25: return "Mode: Demo" if event_handler: ret = event_handler(event) if ret: pygame.mixer.music.stop() return ret nf = Frame(pic) text.draw_text(nf, 10, 4, 'DUNG BEETLES', colors, color_start1) text.draw_text(nf, 10, 24, 'Mega-Bug', colors, color_start2) text.draw_text(nf, 10, 64, 'Giga-Bug', colors, color_start3) color_start1 += 1 if color_start1 >= 4: color_start1 = 0 color_start2 += 1 if color_start2 >= 4: color_start2 = 0 color_start3 += 1 if color_start3 >= 4: color_start3 = 0 hardware.render_frame(nf) clock.tick(10)
def loser_loser(): pygame.mixer.music.load('sounds/chiptunes_ending.wav') pygame.mixer.music.set_volume(0.55) pygame.mixer.music.play(loops=-1) # You lost! Better luck next time s = pygame.Surface((constants.WIDTH, constants.HEIGHT)) random_sequence = [0, 1, 2, 3] choice = random.choice(random_sequence) highscore_page = False pause = True fade_bg = [] background = pygame.image.load( 'backgrounds/pygame_test_background.jpg').convert() arrow_image = pygame.transform.scale( pygame.image.load('sprites/arrow_image.png').convert_alpha(), (25, 25)) fade_num = 0 arrow = 0 while pause: clock.tick(15) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() fade_num += 1 if fade_num < 30: background.set_alpha(fade_num * 8) screen.blit(background, (0, 0)) elif highscore_page == True: keystate = pygame.key.get_pressed() if keystate[pygame.K_ESCAPE]: highscore_page = False screen.fill(constants.BLUE) text.draw_text(screen, "HIGHSCORES", 100, constants.WIDTH / 2, 20, constants.BLACK, "Haettenschweiler") text.draw_text(screen, "Press [ESCAPE] to return to GAME SUMMARY", 25, constants.WIDTH / 2, constants.HEIGHT - 40, constants.BLACK, "Haettenschweiler") for i in range(10): text.draw_text(screen, str(i + 1) + ". " + str(highscore_list[i]), 30, constants.WIDTH / 2, 150 + 40 * i, constants.BLACK, "Haettenschweiler") else: background.set_alpha(255) screen.blit(background, (0, 0)) keystate = pygame.key.get_pressed() if fade_num > 20 and total_score > highscore: text.draw_text( screen, 'Congratulations, you just beat your all time HIGHSCORE!', 80, 400, 50, constants.GREEN, "Haettenschweiler") if fade_num > 20 and total_score < highscore: if choice == 0: text.draw_text(screen, 'Better luck next time', 80, 400, 50, constants.GREEN, "Haettenschweiler") elif choice == 1: text.draw_text(screen, 'Hah! Is that all you got?', 60, 400, 50, constants.GREEN, "Haettenschweiler") elif choice == 2: text.draw_text(screen, 'Get your ass back training camp noobie', 60, 400, 50, constants.GREEN, "Haettenschweiler") elif choice == 3: text.draw_text(screen, "We don't accept losers here, beat it", 60, 400, 50, constants.GREEN, "Haettenschweiler") if fade_num > 60: text.draw_text(screen, 'Your SCORE: ' + str(total_score), 40, 400, 130, constants.YELLOW, "Haettenschweiler") if fade_num > 80: text.draw_text(screen, 'Current HIGHSCORE: ' + str(highscore), 40, 400, 200, constants.RED, "Haettenschweiler") if fade_num > 100: text.draw_text( screen, 'Fighters Destroyed: ' + str(summary.total_fighters_killed) + "/" + str(summary.total_fighters), 30, 400, 270, constants.WHITE, "Haettenschweiler") if fade_num > 110: text.draw_text( screen, 'Tanks Destroyed: ' + str(summary.total_tanks_killed) + "/" + str(summary.total_tanks), 30, 400, 320, constants.WHITE, "Haettenschweiler") if fade_num > 120: text.draw_text( screen, 'Helicopters Destroyed: ' + str(summary.total_helicopters_killed) + "/" + str(summary.total_helicopters), 30, 400, 370, constants.WHITE, "Haettenschweiler") if fade_num > 130: text.draw_text( screen, 'Time Elapsed: ' + str(round((summary.time / 1000), 2)), 30, 400, 420, constants.WHITE, "Haettenschweiler") if fade_num > 162: text.draw_text(screen, 'EXIT GAME', 40, 240, 540, constants.WHITE, "Haettenschweiler") text.draw_text(screen, 'HIGHSCORES', 40, 645, 540, constants.WHITE, "Haettenschweiler") if arrow == 0: screen.blit(arrow_image, (150, 550)) if arrow == 1: screen.blit(arrow_image, (550, 550)) if keystate[pygame.K_SPACE] and arrow == 0: pause = False if keystate[pygame.K_SPACE] and arrow == 1: highscore_page = True if keystate[pygame.K_LEFT]: arrow = 0 if keystate[pygame.K_RIGHT]: arrow = 1 pygame.display.update()
def winner_winner(): # You won! Good job gamer pygame.mixer.music.load('sounds/chiptunes_ending.wav') pygame.mixer.music.set_volume(0.55) pygame.mixer.music.play(loops=-1) s = pygame.Surface((constants.WIDTH, constants.HEIGHT)) highscore_page = False pause = True fade_bg = [] background = pygame.image.load( 'backgrounds/pygame_test_background.jpg').convert() arrow_image = pygame.transform.scale( pygame.image.load('sprites/arrow_image.png').convert_alpha(), (25, 25)) fade_num = 0 arrow = 0 while pause: clock.tick(15) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() fade_num += 1 if fade_num < 30: background.set_alpha(fade_num * 8) screen.blit(background, (0, 0)) elif highscore_page == True: keystate = pygame.key.get_pressed() if keystate[pygame.K_ESCAPE]: highscore_page = False screen.fill(constants.BLUE) text.draw_text(screen, "HIGHSCORES", 100, constants.WIDTH / 2, 20, constants.BLACK, "Haettenschweiler") text.draw_text(screen, "Press [ESCAPE] to return to GAME SUMMARY", 25, constants.WIDTH / 2, constants.HEIGHT - 40, constants.BLACK, "Haettenschweiler") for i in range(10): text.draw_text(screen, str(i + 1) + ". " + str(highscore_list[i]), 30, constants.WIDTH / 2, 150 + 40 * i, constants.BLACK, "Haettenschweiler") else: background.set_alpha(255) screen.blit(background, (0, 0)) keystate = pygame.key.get_pressed() if fade_num > 20 and total_score > highscore: text.draw_text( screen, 'Congratulations, you just beat your all time HIGHSCORE!', 40, 400, 50, constants.GREEN, "Haettenschweiler") if fade_num > 20 and total_score < highscore: text.draw_text(screen, 'Amazing run! Good job beating those bosses', 50, 400, 50, constants.GREEN, "Haettenschweiler") if fade_num > 60: text.draw_text(screen, 'Your SCORE: ' + str(total_score), 40, 400, 130, constants.YELLOW, "Haettenschweiler") if fade_num > 80: text.draw_text(screen, 'Current HIGHSCORE: ' + str(highscore), 40, 400, 200, constants.RED, "Haettenschweiler") if fade_num > 100: text.draw_text( screen, 'Fighters Destroyed: ' + str(summary.total_fighters_killed) + "/" + str(summary.total_fighters), 30, 400, 270, constants.WHITE, "Haettenschweiler") if fade_num > 110: text.draw_text( screen, 'Tanks Destroyed: ' + str(summary.total_tanks_killed) + "/" + str(summary.total_tanks), 30, 400, 320, constants.WHITE, "Haettenschweiler") if fade_num > 120: text.draw_text( screen, 'Helicopters Destroyed: ' + str(summary.total_helicopters_killed) + "/" + str(summary.total_helicopters), 30, 400, 370, constants.WHITE, "Haettenschweiler") if fade_num > 130: text.draw_text( screen, 'Time Elapsed: ' + str(round((summary.time / 1000), 2)), 30, 400, 420, constants.WHITE, "Haettenschweiler") if fade_num > 162: text.draw_text(screen, 'EXIT GAME', 40, 240, 540, constants.WHITE, "Haettenschweiler") text.draw_text(screen, 'HIGHSCORES', 40, 645, 540, constants.WHITE, "Haettenschweiler") # Here, I need to create return to menu and exit buttons. if arrow == 0: screen.blit(arrow_image, (150, 550)) if arrow == 1: screen.blit(arrow_image, (550, 550)) if keystate[pygame.K_SPACE] and arrow == 0: pause = False if keystate[pygame.K_SPACE] and arrow == 1: highscore_page = True if keystate[pygame.K_LEFT]: arrow = 0 if keystate[pygame.K_RIGHT]: arrow = 1 pygame.display.update()
dt = clock.tick(60) current_scene().update(dt) current_scene().draw() if state() == 3 and current_scene() == lunchscene: if not platformer.player: platformer.start() prog = (platformer.player.x + 45) / 280.0 if prog > 1.0 or pressed[K_d]: text.event_text() platformer.platformscene.update(dt) platformer.platformscene.draw() draw.draw_surf(platformer.platformscene.rendertarget, (10, 64)) if state() == 5 and current_scene() == bedscene: snake.update(dt, pressed) draw.draw_surf(snake.screen, (10, 64)) prog = snake.score.score / 20.0 if prog >= 1.0 or pressed[K_d]: text.event_text() if state() == 2 and current_scene() == essayscene: space.update(evs) draw.draw_surf(space.screen, (10, 64)) prog = space.score.score / 50.0 if prog >= 1.0 or pressed[K_d]: text.event_text() current_scene().set_progress(prog) draw.draw(textbox) text.draw_text(text.texts) draw.update()
if countdown == 0: ship.update() peluru_group.update() musuh_group.update() peluru_musuh_group.update() bom_group.update() peluru_laser_group.update() '''menggambar spirite group''' ship_group.draw(tampilan) peluru_group.draw(tampilan) musuh_group.draw(tampilan) peluru_musuh_group.draw(tampilan) bom_group.draw(tampilan) peluru_laser_group.draw(tampilan) text.draw_text() text.text_bos() '''Tombol atau keys ''' for event in pygame.event.get(): if event.type == pygame.QUIT: run = False if countdown > 0: text('WARNING!!', text40, putih, int(panjang / 2 - 110), int(lebar / 2 + 10)) count_timer = pygame.time.get_ticks() warning_fx.play() if count_timer - last_count > 1000: countdown -= 1 last_count = count_timer pygame.display.update()
def game_loop(): global BORDER_LOWER, BORDER_LEFT, BORDER_RIGHT global TICKS_PER_SECOND global SHOT_SPEED,SHIP_SPEED enemies = [] generate_enemy_wave(enemies) screen = pygame.display.get_surface() shoot_sound = sound.load_sound('psh.ogg') enemy_explosion_sound = sound.load_sound('uddh.ogg') position = [(SCREEN_SIZE[0]) / 2, BORDER_LOWER-10] ship_sprite = PlayerShip.PlayerShip(position) shot_sprite = Shot.Shot([0,0]) enemy_shot_sprite = Shot.Shot([0,0]) ship_sprite.size = ship_sprite.image.get_size() # shotX, shotY = shot_sprite.image.get_size() # enemy_shotX, enemy_shotY = shotX, shotY ship_sprite.coorX = ship_sprite.position[0] ship_sprite.coorY = ship_sprite.position[1] # shot_coorX = 0.0 # shot_coorY = 0.0 ship_sprite.coorX = (SCREEN_SIZE[0] - ship_sprite.size[0]) / 2 ship_sprite.coorY = BORDER_LOWER - ship_sprite.size[1] shot_exists = False enemy_shot_exists = False score = 0 clock = pygame.time.Clock() ticks = 0 done = False # Main game loop while not done: clock.tick(TICKS_PER_SECOND) ticks += 1 if (ticks % TICKS_PER_SECOND) == 0: fps = clock.get_fps() # print fps ##################################################################################### # read keyboard and move player ship events = pygame.event.get() keystate = pygame.key.get_pressed() if keystate[K_ESCAPE] == 1: done = True break if keystate[K_a] == 1: ship_sprite.move_left() if keystate[K_d] == 1: ship_sprite.move_right() if keystate[K_SPACE] == 1: if not shot_exists: shoot_sound.play() shot_exists = True shot_sprite.position[0], shot_sprite.position[1] = ship_sprite.position[0] + (ship_sprite.size[0] - shot_sprite.size[0]) / 2, ship_sprite.position[1] - shot_sprite.size[1] #generate shot near top middle of gun if keystate[K_e] == 1: if not enemy_shot_exists: #shoot_sound.play() enemy_shot_exists = True enemy_shot_sprite.position[0] = 400.0 #random.randint(BORDER_LEFT, BORDER_RIGHT) enemy_shot_sprite.position[1] = 400.0 #shot_coorX, shot_coorY = ship_sprite.coorX + (ship_sprite.size[0] - shotX) / 2, ship_sprite.coorY - shotY #generate shot near top middle of gun for event in events: if event.type == QUIT: done = True break ####################################################################################### # collision detection shot <-> enemies dying_enemies = [] # empty list that gets filled as enemies get shot for i in range(len(enemies)): if shot_exists: if collidesWith(shot_sprite,enemies[i]): # Collision! score += enemies[i].get_score() dying_enemies.append(i) shot_exists = False enemy_explosion_sound.play() # TODO: enemy explosion graphics explosion.create(enemies[i].position) #print "zerstort" # remove all enemies that were hit. delta = 0 for i in range(len(dying_enemies)): del enemies[dying_enemies[i + delta]] delta += 1 # each time we remove one, the index of all the others must be reduced. This assumes that the list of dying enemies is sorted # collision detection enemy_shot <-> PlayerShip #dying_enemies = [] # empty list that gets filled as enemies get shot if enemy_shot_exists: if collidesWith(enemy_shot_sprite,ship_sprite): # Collision! enemy_shot_exists = False enemy_explosion_sound.play() # TODO: ship explosion graphics # remove all enemies that were hit. # detect end of wave if len(enemies) == 0: generate_enemy_wave(enemies) ############################################################################################ if shot_exists: #move shot shot_sprite.position[1] -= SHOT_SPEED if shot_sprite.position[1] <= BORDER_UPPER: shot_exists = False if enemy_shot_exists: #move shot enemy_shot_sprite.position[1] += SHOT_SPEED if enemy_shot_sprite.position[1] >= BORDER_LOWER: enemy_shot_exists = False ############################################################################################ graphics.draw_background(screen) text.draw_text(screen, score) if shot_exists: # draw shot screen.blit (shot_sprite.image, (shot_sprite.position[0], shot_sprite.position[1])) if enemy_shot_exists: # draw shot screen.blit (shot_sprite.image, (enemy_shot_sprite.position[0], enemy_shot_sprite.position[1])) for i in range(len(enemies)): enemies[i].draw(screen) explosion.draw(screen) # draw player ship ship_sprite.draw(screen) # swap back and front buffers pygame.display.flip()
player.pre_world_draw() world.draw() player.draw() glDisable(GL_DEPTH_TEST) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0, options.get("dpy_width", int), options.get("dpy_height", int), 0, -1, 1) glColor3f(1.0, 1.0, 1.0) text.draw_text(str(round(clock.get_fps(), 2)), (255, 120, 120), (0, 0), (0, 0), 20, False, False) elif state == "menu": glDisable(GL_DEPTH_TEST) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0, options.get("dpy_width", int), options.get("dpy_height", int), 0, -1, 1) pygame.display.flip() key_press=[] key_release=[] mouse_press=[] mouse_release=[]