def check_player_events(): global game_timer, burst_fire cont = cls.Controler() movement = 5 left_margin = 0 + 10 right_margin = glob.WINDOW_SIZE[0] - 70 pressed = pygame.key.get_pressed() if pressed[cont.Left] and player.position_x > left_margin: player.position_x -= movement if pressed[cont.Right] and player.position_x < right_margin: player.position_x += movement # IZMENJENO burst fire je najmanje vreme izmedju dve rakete burst_fire += 1 if pressed[cont.Fire] and (glob.ENEMIES_IS_READY or destroyer.is_ready): # Metak se ispaljuje u svakom 20-tom ciklusu # Promenio na 2 da bi se brze prelazila igrica tokom testiranja if burst_fire > 2: # Zvuk pri ispaljivanju metaka rocket_sound = mixer.Sound('sounds/laser.wav') rocket_sound.play() rocket = cls.Rocket() rocket.rect.x = player.position_x + 26 # razlika u velicina slika rocket.rect.y = player.position_y glob.all_sprites_list.add(rocket) glob.rockets_list.add(rocket) burst_fire = 0
def choose_players(): global NUM_IMG_PLAYER1, NUM_IMG_PLAYER2 cont = cls.Controler() left1 = pygame.image.load('images/left.png') right1 = pygame.image.load('images/right.png') left2 = pygame.image.load('images/left.png') right2 = pygame.image.load('images/right.png') play_img = pygame.image.load('images/play.png') back_img = pygame.image.load('images/back.png') play = True size = len(PLAYER_1_IMG_256px) while True: gui.screen.blit(glob.game_background, (0, 0)) gui.screen.blit(left1, (236, 318)) gui.screen.blit(left2, (660, 318)) gui.screen.blit(right1, (576, 318)) gui.screen.blit(right2, (1000, 318)) if play: gui.screen.blit(play_img, (500, 480)) else: gui.screen.blit(back_img, (500, 480)) gui.screen.blit(PLAYER_1_IMG_256px[NUM_IMG_PLAYER1], (310, 222)) gui.screen.blit(PLAYER_2_IMG_256px[NUM_IMG_PLAYER2], (734, 222)) events = pygame.event.get() for e in events: if e.type == pygame.QUIT: exit() if e.type == pygame.KEYDOWN: if e.key == pygame.K_ESCAPE: exit() if e.type == pygame.MOUSEBUTTONDOWN: if left1.get_rect(topleft=(236, 318)).collidepoint( pygame.mouse.get_pos()): NUM_IMG_PLAYER1 = (NUM_IMG_PLAYER1 - 1 + size) % size elif left2.get_rect(topleft=(660, 318)).collidepoint( pygame.mouse.get_pos()): NUM_IMG_PLAYER2 = (NUM_IMG_PLAYER2 - 1 + size) % size elif right1.get_rect(topleft=(576, 318)).collidepoint( pygame.mouse.get_pos()): NUM_IMG_PLAYER1 = (NUM_IMG_PLAYER1 + 1 + size) % size elif right2.get_rect(topleft=(1000, 318)).collidepoint( pygame.mouse.get_pos()): NUM_IMG_PLAYER2 = (NUM_IMG_PLAYER2 + 1 + size) % size if e.type == pygame.KEYDOWN: if e.key == cont.Left1: NUM_IMG_PLAYER1 = (NUM_IMG_PLAYER1 - 1 + size) % size elif e.key == cont.Right1: NUM_IMG_PLAYER1 = (NUM_IMG_PLAYER1 + 1 + size) % size elif e.key == cont.Left2: NUM_IMG_PLAYER2 = (NUM_IMG_PLAYER2 - 1 + size) % size elif e.key == cont.Right2: NUM_IMG_PLAYER2 = (NUM_IMG_PLAYER2 + 1 + size) % size elif e.key == pygame.K_DOWN: play = False elif e.key == pygame.K_UP: play = True elif pygame.K_RETURN: if play is not True: print('menu') glob.return_to_main_menu() return else: return pygame.display.update()
def check_player_events(burst_fire1, burst_fire2, game_taimer): global player1, player2 # Ako je igra gotova ne mogu se izvrsavati komande if end_game: return burst_fire1, burst_fire2 cont = cls.Controler() movement = 4 left_margin = 0 + 10 right_margin = glob.WINDOW_SIZE[1] - 120 pressed = pygame.key.get_pressed() if pressed[cont.Left1] and player1.position_y > left_margin: player1.position_y -= movement if pressed[cont.Right1] and player1.position_y < right_margin: player1.position_y += movement burst_fire1 += 1 if pressed[cont.Fire1] and game_taimer > 100: # Metak se ispaljuje u svakom 50-tom ciklusu if burst_fire1 > 40: # Zvuk pri ispaljivanju metaka rocket_sound = mixer.Sound('sounds/laser.wav') rocket_sound.play() rocket = cls.leftRocket() rocket.rect.x = player1.position_x + 20 rocket.rect.y = player1.position_y + 30 glob.all_sprites_list.add(rocket) glob.left_rockets_list.add(rocket) burst_fire1 = 0 if pressed[cont.Left2] and player2.position_y > left_margin: player2.position_y -= movement if pressed[cont.Right2] and player2.position_y < right_margin: player2.position_y += movement burst_fire2 += 1 if pressed[cont.Fire2] and game_taimer > 100: if burst_fire2 > 40: rocket_sound = mixer.Sound('sounds/laser.wav') rocket_sound.play() rocket = cls.rightRocket() rocket.rect.x = player2.position_x rocket.rect.y = player2.position_y + 26 glob.all_sprites_list.add(rocket) glob.right_rockets_list.add(rocket) burst_fire2 = 0 return burst_fire1, burst_fire2