Пример #1
0
def handle_events(frame_time):

    global game_play, game_over, game_clear
    events = get_events()
    for event in events:
        if event.type == SDL_KEYDOWN:
            state = finn.get_state_from_key(event.key)
            if state is not None:
                finn.change_state(state)

        elif event.type == SDL_KEYUP:
            if event.key == finn.get_key_from_state():
                finn.frame_stop = True

        elif event.type == SDL_MOUSEBUTTONDOWN:
            if game_play:
                if collision.point_in_rect(event.x, game_framework.height - event.y, \
                                        game_framework.width - pause_image.w // 2 - 10, game_framework.height - pause_image.h // 2 - 10,
                                        pause_image.w, pause_image.h):
                    game_framework.push_state(pause_state)
                    return;
                elif collision.point_in_rect(event.x, game_framework.height - event.y, \
                                        back_image.w // 2 + 10, game_framework.height - back_image.h // 2 - 10,
                                        back_image.w, back_image.h):
                    game_framework.change_state(title_state)
                    return;


            if game_over:
                if collision.point_in_rect(event.x, game_framework.height - event.y, \
                                        game_framework.width // 2 - back_image.w , game_framework.height // 5 + back_image.h  // 2,
                                        back_image.w, back_image.h):
                    game_framework.change_state(title_state)
                    return;
                elif collision.point_in_rect(event.x, game_framework.height - event.y, \
                                        game_framework.width // 2 + retry_image.w, game_framework.height // 5 + retry_image.h // 2,
                                        retry_image.w, retry_image.h):
                    game_framework.change_state(game_state_level_03)
                    return;

            elif game_clear:
                if collision.point_in_rect(event.x, game_framework.height - event.y, \
                                        game_framework.width // 2 - back_image.w, game_framework.height // 5 + back_image.h // 2,
                                        back_image.w, back_image.h):
                    game_framework.change_state(title_state)
                    return;
                '''elif collision.point_in_rect(event.x, game_framework.height - event.y, \
Пример #2
0
def handle_events(frame_time):
    events = get_events()
    for event in events:
        if event.type == SDL_MOUSEBUTTONDOWN:
            if collision.point_in_rect(event.x, game_framework.height - event.y, \
                                    game_framework.width - pause_image.w // 2 - 10, game_framework.height - pause_image.h // 2 - 10,
                                    pause_image.w, pause_image.h):
                game_framework.pop_state()
                break
Пример #3
0
 def get_hexagon_point_from_point(self, x, y):
     
     _y = (y - self.mapoffsety) // (self.tileheight // 2)
     
     for _x in range(self.width):
         hx = self.mapoffsetx + _x * self.tilewidth + ( (_y+1) % 2 ) * (self.tilewidth // 2)
         hy = self.mapoffsety + _y * (self.tileheight // 2)
         if collision.point_in_rect(x,y,hx,hy,self.tilewidth,self.tileheight):
             return (hx, hy)
     
     return (-1, -1)
Пример #4
0
def handle_events(frame_time):
    events = get_events()
    for event in events:
        if (event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
            game_framework.quit()

        elif event.type == SDL_MOUSEBUTTONDOWN:
            if collision.point_in_rect(event.x, game_framework.height - event.y, \
                                    game_framework.width // 2, game_framework.height * 0.3,
                                    game_start_image.w, game_start_image.h):
                game_framework.change_state(game_state_level_01)
      
            elif collision.point_in_rect(event.x, game_framework.height - event.y, \
                                    game_framework.width // 2, game_framework.height * 0.3 - game_start_image.h,
                                    tutorial_image.w, tutorial_image.h):
                game_framework.change_state(tutorial_state)

            elif collision.point_in_rect(event.x, game_framework.height - event.y, \
                                    game_framework.width - exit_image.w // 2 - 10, game_framework.height - exit_image.h // 2 - 10,
                                         exit_image.w, exit_image.h):
                game_framework.quit()