def check_events(): event = game.event.poll() if event.type == game.KEYUP: key_pressed = event.key if (key_pressed == K_ESCAPE): go_back() elif (key_pressed == K_SPACE or key_pressed == K_RETURN): #moving to the next "slide" global cur_text_time cur_text_time = -1.0 elif event.type == game.MOUSEMOTION: x, y = event.pos if (back_rect.collidepoint(x, y)): highlight_back(True) else: highlight_back(False) elif event.type == game.MOUSEBUTTONUP: x, y = event.pos if (back_rect.collidepoint(x, y)): go_back() elif (data.sound_image_rect.collidepoint(x, y)): data.mute_music(not data.music_muted) else: #moving to the next "slide" cur_text_time = -1.0 elif event.type == game.QUIT: data.terminate(0)
def check_events(): """ Elegxos event etsi wste na ginontai dektes energoies opws click, [Enter] klp ta opoia 9a proxwrhsoun sto epomeno keimeno xwris na xreiazetai o xrhsths na perimenei na teleiwsei o kanonikos xronos pou apaiteitai gia thn allagh mias diafaneias. """ event = game.event.poll() global cur_text_time if event.type == game.KEYUP: key_pressed = event.key if (key_pressed == K_ESCAPE): go_back() elif (key_pressed == K_SPACE or key_pressed == K_RETURN): #moving to the next "slide" cur_text_time = -1.0 elif event.type == game.MOUSEMOTION: x, y = event.pos if (back_rect.collidepoint(x, y)): highlight_back(True) else: highlight_back(False) elif event.type == game.MOUSEBUTTONUP: x, y = event.pos if (back_rect.collidepoint(x, y)): go_back() elif (data.sound_image_rect.collidepoint(x, y)): data.mute_music(not data.music_muted) else: #moving to the next "slide" cur_text_time = -1.0 elif event.type == game.QUIT: data.terminate(0)
def init_variables(): data.backgrounds.empty() data.barriers.empty() data.points.empty() data.floors.empty() data.finish_line.empty() data.LEVEL_2_EXIT = data.game_paused = False data.CURRENT_PAUSE_SELECTION = 0 global cat_hero data.score = 0 data.score_surface = data.score_font.render("Score:" + str(data.score)+"/900", 1, data.WHITE) cat_hero = object_animations.Cat_Hero(data.WINDOWWIDTH/100, data.WINDOWHEIGHT-100) global level_2_file try: level_2_file = open(path.join("resources", "levels", "level2.dat")) except IOError: print "The file", path.join("resources", "levels", "level2.dat"), "does not exist! The game will now exit!" data.terminate(1) else: #read the first WINDOWWIDTH/20 lines and blit them to the screen... for i in range(65): process_level_line(level_2_file.readline(), i*10) data.floors.add(object_animations.Floor(i*10, data.level2_floor_image)) data.backgrounds.add(object_animations.Background(0, data.level2_bg_image)) data.backgrounds.add(object_animations.Background(data.backgrounds.sprites()[0].width, data.level2_bg_image))
def check_events(): event = game.event.poll() if event.type == game.KEYUP: key_pressed = event.key if (key_pressed == K_ESCAPE): go_back() elif event.type == game.MOUSEMOTION: x, y = event.pos if (back_rect.collidepoint(x, y)): highlight_back(True) else: highlight_back(False) elif event.type == game.MOUSEBUTTONUP: global level_1_rect, level_2_rect, level_3_rect, level_4_rect x, y = event.pos if (level_1_rect.collidepoint(x, y)): load_level_1() elif (level_2_rect.collidepoint(x, y)): load_level_2() elif (level_3_rect.collidepoint(x, y)): load_level_3() elif (level_4_rect.collidepoint(x, y)): load_level_4() elif (back_rect.collidepoint(x, y)): go_back() elif (data.sound_image_rect.collidepoint(x, y)): data.mute_music(not data.music_muted) elif event.type == game.QUIT: data.terminate(0)
def launch_option(option_n): if (option_n == 0): return elif (option_n == 1): show_level_selection_screen() elif (option_n == 2): show_help_screen() elif (option_n == 3): show_credits_screen() elif (option_n == 4): data.terminate(0)
def check_events(): """ Elegxos twn event, pou einai o kersoras, ti koumpia pataei o xrhsths klp """ global CURRENT_MENU_SELECTION event = game.event.poll() if event.type == game.MOUSEMOTION: x, y = event.pos if (select_level_rect.collidepoint(x, y)): CURRENT_MENU_SELECTION = 1 elif (help_rect.collidepoint(x, y)): CURRENT_MENU_SELECTION = 2 elif (credits_rect.collidepoint(x, y)): CURRENT_MENU_SELECTION = 3 elif (quit_rect.collidepoint(x, y)): CURRENT_MENU_SELECTION = 4 highlight_option(CURRENT_MENU_SELECTION) elif event.type == game.MOUSEBUTTONUP: x, y = event.pos if (select_level_rect.collidepoint(x, y)): launch_option(1) elif (help_rect.collidepoint(x, y)): launch_option(2) elif (credits_rect.collidepoint(x, y)): launch_option(3) elif (quit_rect.collidepoint(x, y)): launch_option(4) elif (data.sound_image_rect.collidepoint(x, y)): data.mute_music(not data.music_muted) elif event.type == game.KEYUP: key_pressed = event.key if (key_pressed == K_RETURN or key_pressed == K_SPACE): launch_option(CURRENT_MENU_SELECTION) elif (key_pressed == K_ESCAPE): data.terminate(0) else: if (key_pressed == K_UP): CURRENT_MENU_SELECTION -= 1 elif (key_pressed == K_DOWN): CURRENT_MENU_SELECTION += 1 if (CURRENT_MENU_SELECTION > 4): CURRENT_MENU_SELECTION = 1 elif (CURRENT_MENU_SELECTION < 1): CURRENT_MENU_SELECTION = 4 highlight_option(CURRENT_MENU_SELECTION) elif event.type == game.QUIT: data.terminate(0)
def init_variables(): #arxikopoihsh metablhtwn #adeiasma twn sprite groups sthn periptwsh pou exoun antikeimena apo prohgoumena levels ta opoia exei #pai3ei o paikths. data.backgrounds.empty() data.barriers.empty() data.points.empty() data.floors.empty() data.finish_line.empty() data.LEVEL_1_EXIT = data.game_paused = False data.CURRENT_PAUSE_SELECTION = 0 global cat_hero data.score = 0 data.score_surface = data.score_font.render("Score:" + str(data.score)+ "/750", 1, data.WHITE) #O cat_hero einai ena sprite to opoio proswmoiwnei twn hrwa mas cat_hero = object_animations.Cat_Hero(data.WINDOWWIDTH/100, data.WINDOWHEIGHT-100) #anoigma tou arxeiou tou level gia diabasma! global level_1_file try: level_1_file = open(path.join("resources", "levels", "level1.dat")) except IOError: print "The file", path.join("resources", "levels", "level1.dat"), "does not exist! The game will now exit!" data.terminate(1) else: #Ka9e grammh einai 10 pixels kai ka9e keno ths ka9e grammhs 20 pixels, ara diabazontai oi prwtes #65 grammes gia na emfanistei h arxh ths pistas sthn o9onh. Epeita, to arxeio 9a diabazetai opote #xreiazetai seiriaka kai h pista 9a kataskeyazetai dynamika for i in range(65): process_level_line(level_1_file.readline(), i*10) data.floors.add(object_animations.Floor(i*10, data.level1_floor_image)) #Pros9esh twn arxikwn background sta sprite groups data.backgrounds.add(object_animations.Background(0, data.level1_bg_image)) data.backgrounds.add(object_animations.Background(data.backgrounds.sprites()[0].width, data.level1_bg_image))
def check_events(): event = game.event.poll() if event.type == game.KEYUP: key_pressed = event.key if (key_pressed == K_SPACE or key_pressed == K_RETURN or key_pressed == K_LCTRL): hero_jump() elif (key_pressed == K_ESCAPE): data.game_paused = True elif event.type == game.MOUSEBUTTONUP: x, y = event.pos if (data.sound_image_rect.collidepoint(x, y)): data.mute_music(not data.music_muted) else: hero_jump() elif event.type == game.QUIT: data.terminate(0) global cat_hero if (game.sprite.spritecollide(cat_hero, data.points, True)): add_score() data.points_sound.play() elif (game.sprite.spritecollide(cat_hero, data.barriers, False)): data.slam_sound.play() data.lose_sound.play() action_now = data.show_loser_options(1, cat_hero) if (action_now == 1): #restart to level start() else: data.LEVEL_1_EXIT = True menu_libs.level_selection.show() elif (game.sprite.spritecollide(cat_hero, data.finish_line, False)): #level complete! data.win_sound.play() data.level_now = 4 data.LEVEL_3_EXIT = True menu_libs.level_selection.show()