コード例 #1
0
ファイル: gameover_state.py プロジェクト: qndls42/2DGP_New
def handle_events():
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            del title_state.bgm
            del store_state.bgm
            game_framework.quit()
        else:
            if event.type == SDL_KEYDOWN:
                if event.key == SDLK_LEFT:
                    if store_state.sel_x > 380:
                        store_state.sel_x -= 150
                    pass
                elif event.key == SDLK_RIGHT:
                    if store_state.sel_x <= 380:
                        store_state.sel_x += 150
                    pass
                elif event.key == SDLK_SPACE:
                    if store_state.sel_x == 380:
                        del title_state.bgm
                        game_framework.change_state(title_state)
                        pass
                    elif store_state.sel_x == 530:
                        del store_state.bgm
                        game_framework.change_state(store_state)
                        pass
    pass
コード例 #2
0
ファイル: MainState.py プロジェクト: thdbs/bine
def handle_events():
    global running
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN:
            InputManager.KeyDown(event.key)
            if event.key == SDLK_ESCAPE:
                game_framework.quit()
            #나중에 없애기
            if event.key == SDLK_m:
                m1 = TurtleMonster(797 + 500+ random.randint(10, 500), 935, 55, 80, Hero)
                MonsterList.append(m1)
        elif event.type == SDL_KEYUP:
            InputManager.KeyUp(event.key)
        elif event.type == SDL_MOUSEMOTION:
            InputManager.mouseX, InputManager.mouseY = event.x, 720 - event.y
        elif event.type == SDL_MOUSEBUTTONDOWN:
            if event.button == SDL_BUTTON_LEFT:
                InputManager.LButton = True
            elif event.button == SDL_BUTTON_RIGHT:
                InputManager.RButton = True
        elif event.type == SDL_MOUSEBUTTONUP:
            if event.button == SDL_BUTTON_LEFT:
                InputManager.LButton = False
            elif event.button == SDL_BUTTON_RIGHT:
                InputManager.RButton = False
コード例 #3
0
ファイル: game_main.py プロジェクト: WindowsHyun/2DGraphics
def handle_events():
    global Game_Running, Rabbit_Frame, Rabbit_Direction, GAME_Scenes
    global Game_Map, Game_MapCheck, GameMap_Col, GameMap_Row, GameCreated_Line, Rabbit_Y, Rabbit_X, Rabbit_UpDownDirection, RabbitJump_LimitCount, Rabbit_Jet
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT or event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
            # 종료버튼을 누르거나 or 키보드의 ESC 키를 누를경우 종료를 한다.
            """
            GameUpdate_Menu("Game_Select")
            Rabbit_Y ,Rabbit_X, Rabbit_UpDownDirection, RabbitJump_LimitCount = 100, 100, "Up", 0
            Game_Map, Game_MapCheck, GameCreated_Line = GameMap_Reset(GameMap_Col, GameMap_Row, Game_Map, Game_MapCheck)
            game_framework.change_state(game_select)
            """
            Rabbit_Y = 0
            Game_Over()
            print("Game_Over")
        if event.type == SDL_MOUSEBUTTONDOWN:
            x, y = event.x, Canvas_Height - event.y
            #GAME_Scenes = GameMenu_Click(GAME_Scenes, x, y)
            print(x, "-", y)
            ##################################################
            # 종료할경우 Game_Running를 죽인다.
            if GAME_Scenes == False:
                game_framework.quit()
            ##################################################
        if event.type == SDL_KEYDOWN and event.key == SDLK_LEFT:
            Rabbit_Direction = "Left"
        if event.type == SDL_KEYDOWN and event.key == SDLK_RIGHT:
            Rabbit_Direction = "Right"
        if event.type == SDL_KEYDOWN and event.key == SDLK_SPACE:
            #Rabbit_Jet = True
            pass
    pass
コード例 #4
0
ファイル: main_state.py プロジェクト: SooYoung4458/2DGP
def handle_events(frame_time):
    global mario
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
            game_framework.push_state(title_state)

        elif event.type == SDL_KEYDOWN:
            if event.key == SDLK_UP :
                if mario.y == 90 :
                    mario.state = 'JUMP'
                    mario.jump_sound.play()
                if mario.y != 90 :
                    mario.state = 'JUMP2'
                    mario.jump_sound.play()

            elif event.key == SDLK_DOWN:
                if mario.state == 'RUN' :
                    mario.state = 'SLIDE'

        elif event.type == SDL_KEYUP:
            if event.key == SDLK_DOWN:
                if mario.state == 'SLIDE' :
                    mario.state = 'RUN'
コード例 #5
0
ファイル: title_state.py プロジェクト: JeongMinSik/2dgame
def handle_events(frame_time):
    global name_x, select_menu, ishelp
    events=get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif(event.type == SDL_MOUSEMOTION):
            class_cursor.Cursor.x,class_cursor.Cursor.y=event.x,600-event.y
        elif event.type == SDL_MOUSEBUTTONDOWN and event.button ==SDL_BUTTON_LEFT:
            ishelp = False
            if select_menu == True:
                click_type = check_click(event.x,600-event.y)
                if click_type == NEW_GAME or click_type == LOAD_GAME:
                    game_framework.push_state(main_state,click_type)
                if click_type == HELP:
                    ishelp = True
        else:
            if(event.type) == (SDL_KEYDOWN):
                ishelp=False
            if(event.type, event.key) == (SDL_KEYDOWN,SDLK_ESCAPE):
                game_framework.quit()
            elif(event.type, event.key) == (SDL_KEYDOWN,SDLK_SPACE):
                if name_x != 365:
                    name_x =365
                else:
                    select_menu = True
コード例 #6
0
def handle_events():
    global isMouseClicked, isButtonClicked, MouseList, maincharacter, stargoal, is_goal, frame, main_state
    events = get_events()

    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
            is_goal = False
        elif event.type == SDL_MOUSEMOTION:
            if isMouseClicked:
                MouseList.append([event.x, 600 - event.y, random.randint(0, 3)])
        elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
            game_framework.change_state(title_state)
        elif (event.type, event.button) == (SDL_MOUSEBUTTONDOWN, SDL_BUTTON_LEFT):
            isMouseClicked = True
            mx = event.x
            my = 600 - event.y
            if (10 < mx < 90) and (515 < my < 585):
                startbutton.image = load_image("resource/start_button2.png")
                startbutton.draw()
                isButtonClicked = True
            if (710 < mx < 785) and (515 < my < 585):
                isButtonClicked = False
                MouseList = []
                enter()

        elif (event.type, event.button) == (SDL_MOUSEBUTTONUP, SDL_BUTTON_LEFT):
            isMouseClicked = False
コード例 #7
0
ファイル: main_state.py プロジェクト: yksgmksy/2DGP
def handle_events(frame_time):
    # fill here
    global hero, slime, bullets, slimes, interface, rand
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        else:
            if (event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
                game_framework.quit()
            else:
                hero.handle_events(event)
            if event.type == SDL_MOUSEBUTTONDOWN:
                if hero.weaponstate == 2:
                    if hero.x > event.x:
                        bullets.append(Bullet(hero.x, hero.y, event.x, event.y, 0))
                    else:
                        bullets.append(Bullet(hero.x, hero.y, event.x, event.y, 1))
            if (event.type, event.key) == (SDL_KEYDOWN, SDLK_p):
                rand = random.randint(0, 3)
                if rand == 0:
                    slimes.append(Slime_red())
                elif rand == 1:
                    slimes.append(Slime_blue())
                elif rand == 2:
                    slimes.append(Slime_pink())
                elif rand == 3:
                    slimes.append(Slime_yellow())
コード例 #8
0
ファイル: main.py プロジェクト: WindowsHyun/2DGraphics
def handle_events():
    global Game_Running, Rabbit_Frame, Rabbit_Direction, GAME_Scenes
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT or event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
            # 종료버튼을 누르거나 or 키보드의 ESC 키를 누를경우 종료를 한다.
            game_framework.quit()
        if event.type == SDL_MOUSEBUTTONDOWN:
            x, y = event.x, Canvas_Height - event.y
            GAME_Scenes = GameMenu_Click(GAME_Scenes, x, y)
            ##################################################
            # 종료할경우 Game_Running를 죽인다.
            if GAME_Scenes == "False":
                game_framework.quit()
            if GAME_Scenes == "GameSelect":
                GameUpdate_Menu("Game_Select")
                game_framework.change_state(game_select)
            if GAME_Scenes == "Game_Score":
                GameUpdate_Menu("Game_Score")
                game_framework.change_state(game_score)
            if GAME_Scenes == "Game_Help":
                GameUpdate_Menu("Game_Help")
                game_framework.change_state(game_help)
            ##################################################
            pass
    pass
コード例 #9
0
def handle_events(frame_time):
    global main_pause

    events = get_events()
    stage.handle_event(events)
    wing.handle_event(events)
    boots.handle_event(events)
    fire_wall.handle_event(events)
    for fireBall in fireBalls:
        fireBall.handle_event(events)
    for jem in jems:
        jem.handle_event(events)

    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN:
            if event.key == SDLK_ESCAPE:
                game_framework.change_state(title_state)
            elif event.key == SDLK_h:
                game_framework.push_state(hold_state)
            elif event.key == SDLK_x and time_gauge.saved_percent > 0:  # 타임 리프 시작
                Change_time_back(True)
            else:
                sonic.handle_event(event)

        elif event.type == SDL_KEYUP:
            if event.key == SDLK_x:  # 타임 리프 중지
                Change_time_back(False)
コード例 #10
0
def handle_events():
    events = get_events()
    global select
    global selectsound, selectmovesound
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        else:
            if(event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
                game_framework.quit()
            elif(event.type, event.key) == (SDL_KEYDOWN, SDLK_SPACE):
                selectsound.play()
                delay(0.7)
                if select == 0:
                    game_framework.change_state(player1_main_state)
                elif select == 1:
                    game_framework.change_state(player2_main_state)
            if(event.type, event.key) == (SDL_KEYDOWN, SDLK_LEFT):
                if(select == 1):
                    select = 0
                    selectmovesound.play()
            elif(event.type, event.key) == (SDL_KEYDOWN, SDLK_RIGHT):
                if(select == 0) :
                    select = 1
                    selectmovesound.play()
コード例 #11
0
def handle_events(frame_time):
    global testing
    global arrow
    global score
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        if event.type == SDL_KEYDOWN:
            if event.key == SDLK_ESCAPE:
                game_framework.quit()
            if event.key == SDLK_1 and arrow[0].launch == False and arrow[0].timeck == False:
                arrow[0].launch, ballistas[0].launch, arrow[0].timeck = True, True, True
                arrow[0].x, arrow[0].y = 110, 280
            if event.key == SDLK_2 and arrow[1].launch == False and arrow[1].timeck == False:
                arrow[1].launch, ballistas[1].launch, arrow[1].timeck = True, True, True
                arrow[1].x, arrow[1].y = 210, 230
            if event.key == SDLK_3 and arrow[2].launch == False and arrow[2].timeck == False:
                arrow[2].launch, ballistas[2].launch, arrow[2].timeck = True, True, True
                arrow[2].x, arrow[2].y = 310, 180
            if event.key == SDLK_4 and arrow[3].launch == False and arrow[3].timeck == False:
                arrow[3].launch, ballistas[3].launch, arrow[3].timeck = True, True, True
                arrow[3].x, arrow[3].y = 410, 130
            if event.key == SDLK_u:
                score.score += 1000
            if event.key == SDLK_b:
                score.score -= 1000
コード例 #12
0
ファイル: PlanetGame.py プロジェクト: ParkGwangGyu/2D-Game
def handle_events():
    global arrive_planet,attack,select, x, y, start,attackplanet,selectplanet,check
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
            game_framework.quit()
        elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_s):
            start = 1
        elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_SPACE):
            game_framework.push_state(PlanetGame2)
        elif event.type == SDL_MOUSEBUTTONDOWN:
            if event.button == SDL_BUTTON_LEFT:
                x, y = event.x , 700-event.y
                for planet in allplanet:
                    if planet.x - 50 < x < planet.x + 50 and planet.y - 50 < y < planet.y + 50:
                        x = planet.x
                        y = planet.y
                        # if planet.planet_image == 1:
                        if attack == False:
                            attack=True
                            print("Attak!")
                        elif attack == True:
                            attack = False
                        else:
                            if select == False:
                                select == True
                                print("select!")
                            elif select == True:
                                select == False
                        selectplanet = planet
                        planet.check = 1
                        select = True
                        arrive_planet = planet.name
コード例 #13
0
def handle_events(frame_time):
    global testing
    global arrows
    global score, weather
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        if event.type == SDL_KEYDOWN:
            if event.key == SDLK_ESCAPE:
                game_framework.quit()
            if event.key == SDLK_1 and ballistas[0].state == ballistas[0].READY:
                arrows.append(weapon.Arrow(110, 280))
                ballistas[0].state = ballistas[0].LAUNCH
            if event.key == SDLK_2 and ballistas[1].state == ballistas[1].READY:
                arrows.append(weapon.Arrow(210, 230))
                ballistas[1].state = ballistas[1].LAUNCH
            if event.key == SDLK_3 and ballistas[2].state == ballistas[2].READY:
                arrows.append(weapon.Arrow(310, 180))
                ballistas[2].state = ballistas[2].LAUNCH
            if event.key == SDLK_4 and ballistas[3].state == ballistas[3].READY:
                arrows.append(weapon.Arrow(410, 130))
                ballistas[3].state = ballistas[3].LAUNCH
            if event.key == SDLK_5:
                weather = background.Snow()
            if event.key == SDLK_6:
                weather = background.Rain()
            if event.key == SDLK_u:
                Life.life -= 20
            if event.key == SDLK_b:
                score.score -= 1000
コード例 #14
0
ファイル: main_state.py プロジェクト: ricky626/Python
def handle_events():
    events = get_events()
    for event in events:
        if (event.type == SDL_QUIT) or (event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE):
            game_framework.quit()

        hero.handle_events(event)
コード例 #15
0
def handle_events():
    global running      #함수가 작동 중인지 여부 확인.

    global Sliding      # 슬라이딩 중 다른 조작 못 하게.
    global Jumping      # 점프 중 다른 조작 못 하게.

    global braveCookie
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT :     #나가기 버튼을 누르면 함수 종료.
            game_framework.quit()
        elif event.type == SDL_KEYDOWN: #키 다운 상태일 때.
            if event.key == SDLK_ESCAPE:
                game_framework.change_state(title_state)
            elif event.key == SDLK_UP :
                if braveCookie.Jumping == 0:
                    braveCookie.Jump()
                    braveCookie.PlusJumping()
                elif braveCookie.Jumping == 1:
                    braveCookie.ReDifine_Frame()
                    braveCookie.Jump_Double()
            elif event.key == SDLK_DOWN and braveCookie.Jumping == 0:
                braveCookie.Slide()
                Sliding += 1
        if event.type == SDL_KEYUP :    #키를 떼면!
            if Sliding != 0 :
                braveCookie.Running()
                Sliding = 0
コード例 #16
0
ファイル: Shop.py プロジェクト: kjk3510/2D_GameProgramming
def handle_events():
    events = get_events()
    global x, y, PlayerName, ui, buy_weapon, shop_button
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()

        elif event.type == SDL_MOUSEMOTION:
            x, y = event.x, 800 - event.y

        elif event.type == SDL_MOUSEBUTTONDOWN:
            x, y = event.x, 800 - event.y

            if x > 40 and x < 190 and y > 350 and y < 530 :
                buy_weapon = ItemBuy('weapon', buy_weapon)
                shop_button.play(1)
            if x > 225 and x < 375 and y > 590 and y < 765 :
                UI.AddArmor(None)
                shop_button.play(1)
            if x > 400 and x < 556 and y > 350 and y < 530 :
                UI.AddBomb(None)
                shop_button.play(1)

        else:
            if (event.type, event.key) == (SDL_KEYDOWN, SDLK_SPACE):
                game_framework.change_state(mainGame)
コード例 #17
0
ファイル: main_state.py プロジェクト: heosungjin/2DGP
def handle_events():
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
            game_framework.change_state(title_state)
コード例 #18
0
def handle_events(frame_time):
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif (event.type, event.button) == (SDL_MOUSEBUTTONDOWN, SDL_BUTTON_LEFT):
            global btn
            btn.click()

        elif event.type == SDL_MOUSEMOTION:
            x, y = event.x, event.y
            # 399-menubtn.w/2,599-menutitle.h-menubtn.h + 48*3
            print(x, y)
            if x > 399-menubtn.w/2 and x < 399-menubtn.w/2 + 160 and y > menutitle.h + 48*0 and y < menutitle.h + 48*0+48:
                MenuBtn.MOUSEON = 0
                print(MenuBtn.MOUSEON)
            elif x > 399-menubtn.w/2 and x < 399-menubtn.w/2 + 160 and y > menutitle.h + 48*1 and y < menutitle.h + 48*1+48:
                MenuBtn.MOUSEON = 1
                print(MenuBtn.MOUSEON)
            elif x > 399-menubtn.w/2 and x < 399-menubtn.w/2 + 160 and y > menutitle.h + 48*2 and y < menutitle.h + 48*2+48:
                MenuBtn.MOUSEON = 2
                print(MenuBtn.MOUSEON)
            elif x > 399-menubtn.w/2 and x < 399-menubtn.w/2 + 160 and y > menutitle.h + 48*3 and y < menutitle.h + 48*3+48:
                MenuBtn.MOUSEON = 3
                print(MenuBtn.MOUSEON)
            else:
                MenuBtn.MOUSEON = 4
        else:
            if(event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
                game_framework.quit()
            elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_SPACE):
                game_framework.change_state(worldmap)
コード例 #19
0
def handle_events():
    events = get_events()
    global x, y, PlayerName, ui, ui_button
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()

        elif event.type == SDL_MOUSEMOTION:
            x, y = event.x, 800 - event.y

        elif event.type == SDL_MOUSEBUTTONDOWN:
            x, y = event.x, 800 - event.y
            if x > 73 and x < 263 and y > 296 and y < 488:
                ui = UI("Sunny")
                UI.Type = 0
                UI.Init(None)
                print("Suny!!!!!!!!!!!!!!!!")
                ui_button.play(1)
                #game_framework.push_state(mainGame)
                game_framework.change_state(Shop)
            if x > 336 and x < 525 and y > 296 and y < 488:
                ui = UI("Raby")
                UI.Type = 1
                UI.Init(None)
                print("Raby!!!!!!!!!!!!!!")
                ui_button.play(1)
                #game_framework.push_state(mainGame)
                game_framework.change_state(Shop)
                #game_framework.change_state(main_raby)

        else:
            if (event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
                game_framework.quit()
コード例 #20
0
ファイル: MainState.py プロジェクト: thdbs/bine
def handle_events():
    global running
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN:
            InputManager.KeyDown(event.key)
            if event.key == SDLK_ESCAPE:
                game_framework.quit()
        elif event.type == SDL_KEYUP:
            InputManager.KeyUp(event.key)
        elif event.type == SDL_MOUSEMOTION:
            InputManager.mouseX, InputManager.mouseY = event.x, 720 - event.y
            InputManager.mPos.x, InputManager.mPos.y = event.x + Camera.x, 720 - event.y + Camera.y
        elif event.type == SDL_MOUSEBUTTONDOWN:
            if event.button == SDL_BUTTON_LEFT:
                InputManager.LButton = True
            elif event.button == SDL_BUTTON_RIGHT:
                InputManager.RButton = True
        elif event.type == SDL_MOUSEBUTTONUP:
            if event.button == SDL_BUTTON_LEFT:
                InputManager.LButton = False
            elif event.button == SDL_BUTTON_RIGHT:
                InputManager.RButton = False
コード例 #21
0
def handle_events():
    global time, go_shop, go_shop_click, bgm, sum_score
    global x, y
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()

        elif event.type == SDL_MOUSEMOTION:
            x, y = event.x, 800 - event.y

        elif event.type == SDL_MOUSEBUTTONDOWN:
            x, y = event.x, 800 - event.y
            if x > 485 and x < 735 and y > 195 and y < 255:
                go_shop.play()
                bgm.stop()
                game_framework.change_state(main_state)

            if x > 470 and x < 540 and y > 264 and y < 320:
                go_shop.play()
                game_framework.push_state(shop)

        else:
            if(event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
                game_framework.quit()

            elif event.type == SDL_KEYDOWN and event.key == SDLK_2:
                sum_score += 100
コード例 #22
0
ファイル: clear.py プロジェクト: ParkGwangGyu/2D-Game
def handle_events():
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
            game_framework.quit()
コード例 #23
0
ファイル: main_state.py プロジェクト: ricky626/Python
def handle_events():
    events = get_events()

    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        hero.handle_events(event)
コード例 #24
0
ファイル: first_stage.py プロジェクト: khs300kr/2DGP
def handle_events(frame_time):
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        else:
            if (event.type,event.key) == (SDL_KEYDOWN,SDLK_ESCAPE):
                game_framework.quit()
            elif (event.type,event.key) == (SDL_KEYDOWN,SDLK_UP):
                if floor.portal_flag == True:
                    temp.character_life = character.life
                    temp.character_skill = character.skill
                    game_framework.change_state(Semiboss_state)
                else:
                    pass
            else:
                character.handle_event(event)
                if character.b_attack == True:
                    shooting()
                if character.skill > 0 :
                    if character.b_skill == True:
                        if skillcol == False:
                            skilling()
                            character.skilldown()
                background.handle_event(event)
                floor.handle_event(event)
コード例 #25
0
def handle_events():
    global player, background, x, y

    events = get_events()

    if background.frame >= 8:
        #print(background.frame)
        converter.player_hpsize = player.hpsize
        converter.player_score = player.score
        game_framework.change_state(main_state3)

    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()

        elif event.type == SDL_MOUSEBUTTONDOWN:
            if player.mouse_x > 354 and player.mouse_x < 446 and player.mouse_y > 259 and player.mouse_y < 291:
                result_ok_sound.play()
                game_framework.change_state(lobby)



        else:
            if event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
                player.bgm.stop()
                game_framework.change_state(title_state)

            elif event.type == SDL_KEYDOWN and event.key == SDLK_2:
                converter.player_hpsize = player.hpsize
                converter.player_score = player.score
                game_framework.change_state(main_state3)

            else:
                player.handle_events(event)
コード例 #26
0
ファイル: game_main.py プロジェクト: rlatldms/2DGP
def handle_events():
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()

        if (event.type, event.button) == (SDL_MOUSEBUTTONDOWN, SDL_BUTTON_LEFT):
            object.click = True
            object.sound_click.play()
            if object.drop_coin[object.stage - 1][object.monsters_count - 1] == True:
                if (object.coinX - 18 < event.x and event.x < object.coinX + 15) and (465 < event.y and event.y < 495):
                    object.sound_eatCoin.play()
                    object.eat_coin += 100
                    object.drop_coin[object.stage - 1][object.monsters_count - 1] = False

        elif (event.type, event.button) == (SDL_MOUSEBUTTONUP, SDL_BUTTON_LEFT):
            object.click = False

        elif event.type == SDL_KEYDOWN:
            if event.key == SDLK_a and object.eat_coin >= object.skill_upgrade:
                object.sound_upgrage.play()
                object.my_damage += 5
                object.eat_coin -= object.skill_upgrade
                object.skill_upgrade += 100 * object.stage
            if event.key == SDLK_q:
                object.my_damage += 100
コード例 #27
0
ファイル: main_state.py プロジェクト: yunjongmin/2DProject
def handle_events(frame_time):
    global collisionRectShow

    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
            game_framework.change_state(title_state)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_z:
            if player.get_player() == player_class.PLAYER_A :
                player_missile.showMissile(player.x, player.y)
            elif player.get_player() == player_class.PLAYER_S :
                player_protect_missile.showMissile(player.x, player.y)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_x:
            if player.get_player() == player_class.PLAYER_A :
                if player_special_missile_s.get_view() == False:
                    player_special_missile.showSpecial(player.x, player.y)
            elif player.get_player() == player_class.PLAYER_S :
                if player_special_missile.get_view() == False:
                    player_special_missile_s.showSpecial(player.x, player.y)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_r:
            if collisionRectShow == True:
                collisionRectShow = False
            else:
                collisionRectShow = True
        else:
            player.handle_event(event)
コード例 #28
0
ファイル: main_state.py プロジェクト: JungMin-Cho/2DGP
def handle_events():

    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
            game_framework.change_state(title_state)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_SPACE:
            #LEFT_RUN, RIGHT_RUN, LEFT_STAND, RIGHT_STAND = 0, 1, 2, 3
            if boy.state == 0:
                boy.state = 1
            elif boy.state == 1:
                boy.state = 0
            elif boy.state == 2:
                boy.state = 0
                boy.run_frames = 0
                #boy.stand_frames = 0
            elif boy.state == 3:
                boy.state = 1
                boy.run_frames = 0
        elif event.type == SDL_KEYDOWN and event.key == SDLK_h:
            global test
            if test == 0:
                test = 1
            else:
                test = 0
コード例 #29
0
ファイル: title_state.py プロジェクト: ricky626/Python
def handle_events():
    events = get_events()
    for event in events:
        if (event.type == SDL_QUIT) or (event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE):
            game_framework.quit()

        elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_SPACE):
            game_framework.change_state(main_state)
コード例 #30
0
ファイル: rank.py プロジェクト: SongHyoungJong/2D
def handle_events(frame_time):
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        else:
            if (event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
                game_framework.change_state(title_state)
コード例 #31
0
ファイル: menu_state.py プロジェクト: lth915/LeeTaeHoon-2DGP
def handle_events(frame_time):
    global mx, my, Btn, Selected

    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
            game_framework.quit()
        elif event.type == SDL_MOUSEMOTION:
            mx, my = event.x, 799 - event.y
            if (mx > 600 - Btn.width / 2) & (mx < 600 + Btn.width / 2) & (
                    my > 400 - Btn.height / 2) & (my < 400 + Btn.height / 2):
                Selected.y = 400
            elif (mx > 600 - Btn.width / 2) & (mx < 600 + Btn.width / 2) & (
                    my > 300 - Btn.height / 2) & (my < 300 + Btn.height / 2):
                Selected.y = 300
            elif (mx > 600 - Btn.width / 2) & (mx < 600 + Btn.width / 2) & (
                    my > 200 - Btn.height / 2) & (my < 200 + Btn.height / 2):
                Selected.y = 200
            elif (mx > 600 - Btn.width / 2) & (mx < 600 + Btn.width / 2) & (
                    my > 100 - Btn.height / 2) & (my < 100 + Btn.height / 2):
                Selected.y = 100
            else:
                Selected.y = -100
        elif event.type == SDL_MOUSEBUTTONDOWN:
            click.play()
            if Selected.y == 400:
                BG.music_off()
                game_framework.push_state(main_state)
            if Selected.y == 300:
                BG.music_off()
                game_framework.push_state(help_state)
            if Selected.y == 200:
                BG.music_off()
                game_framework.push_state(option_state)
            if Selected.y == 100:
                BG.music_off()
                game_framework.quit()
    pass
コード例 #32
0
def handle_events():
    global button
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
            game_framework.quit()
        elif event.type == SDL_MOUSEMOTION:
            mouse_x, mouse_y = event.x, 900 - event.y - 1

            if 800 - 200 <= mouse_x <= 800 + 200 and 300 - 50 <= mouse_y <= 300 + 50:
                button = START
            elif 800 - 200 <= mouse_x <= 800 + 200 and 180 - 50 <= mouse_y <= 180 + 50:
                button = EXIT
            else:
                button = NONE
        elif event.type == SDL_MOUSEBUTTONDOWN:
            if button == START:
                game_framework.change_state(main_state)
            elif button == EXIT:
                game_framework.quit()
コード例 #33
0
def handle_events():
    global mouse_x
    global mouse_y
    global mouse_down
    global start_on
    global maptool_on
    global exit_on
    global click_bgm

    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        else:
            if (event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
                game_framework.quit()
            if event.type == SDL_MOUSEMOTION:
                mouse_x, mouse_y = event.x, window_height - 1 - event.y
                button_col()
            if (event.type, event.button) == (SDL_MOUSEBUTTONDOWN, SDL_BUTTON_LEFT):
                mouse_down = True
                if start_on:
                    start_on = False
                    mouse_down = False
                    mapstage_state.mouse_x, mapstage_state.mouse_y = mouse_x, mouse_y
                    click_bgm.play()
                    game_framework.change_state(mapstage_state)
                if maptool_on:
                    maptool_on = False
                    mouse_down = False
                    maptool.mouse_x, maptool.mouse_y = mouse_x, mouse_y
                    click_bgm.play()
                    game_framework.change_state(maptool)
                if exit_on:
                    exit_on = False
                    mouse_down = False
                    game_framework.quit()
            if (event.type, event.button) == (SDL_MOUSEBUTTONUP, SDL_BUTTON_LEFT):
                mouse_down = False
コード例 #34
0
def handle_events():
    global frame

    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        else:
            if (event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
                game_framework.quit()
            elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_RETURN):
                if frame == 0:
                    title_state.choiceMusic()
                    game_framework.change_state(main_game)
                else:
                    game_framework.quit()
            elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_UP):
                title_state.selectMusic()
                frame = 0
            elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_DOWN):
                title_state.selectMusic()
                frame = 1
コード例 #35
0
def handle_events():
    global serving
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif ((event.type, event.key) == (SDL_KEYDOWN, SDLK_SPACE)):
            main_state.boy = None
            main_state.floor = None
            main_state.burner = None
            main_state.refrig = None
            main_state.sink = None
            main_state.cabinet = None
            main_state.kitchen_floor = None
            main_state.frame = None
            main_state.table = None
            main_state.font = None
            main_state.customer = None
            main_state.messeage = None
            main_state.Money = 100
            main_state.Left_time = 300
            main_state.life = 3
            main_state.x = 0

            main_state.food_1_stack = 0
            main_state.food_2_stack = 0
            main_state.food_3_stack = 0
            main_state.food_4_stack = 0
            main_state.food_5_stack = 0
            main_state.food_6_stack = 0

            main_state.Table_1 = 0
            main_state.Table_2 = 0
            main_state.Table_3 = 0
            main_state.Table_4 = 0
            main_state.Table_5 = 0
            main_state.Table_6 = 0

            main_state.Table_1_order = 0
            main_state.Table_2_order = 0
            main_state.Table_3_order = 0
            main_state.Table_4_order = 0
            main_state.Table_5_order = 0
            main_state.Table_6_order = 0

            main_state.Table_1_orderd_Q = 0
            main_state.Table_1_orderd_W = 0
            main_state.Table_1_orderd_E = 0
            main_state.Table_1_orderd_R = 0
            main_state.Table_1_orderd_T = 0
            main_state.Table_1_orderd_Y = 0

            main_state.Table_2_orderd_Q = 0
            main_state.Table_2_orderd_W = 0
            main_state.Table_2_orderd_E = 0
            main_state.Table_2_orderd_R = 0
            main_state.Table_2_orderd_T = 0
            main_state.Table_2_orderd_Y = 0

            main_state.Table_3_orderd_Q = 0
            main_state.Table_3_orderd_W = 0
            main_state.Table_3_orderd_E = 0
            main_state.Table_3_orderd_R = 0
            main_state.Table_3_orderd_T = 0
            main_state.Table_3_orderd_Y = 0

            main_state.Table_4_orderd_Q = 0
            main_state.Table_4_orderd_W = 0
            main_state.Table_4_orderd_E = 0
            main_state.Table_4_orderd_R = 0
            main_state.Table_4_orderd_T = 0
            main_state.Table_4_orderd_Y = 0

            main_state.Table_5_orderd_Q = 0
            main_state.Table_5_orderd_W = 0
            main_state.Table_5_orderd_E = 0
            main_state.Table_5_orderd_R = 0
            main_state.Table_5_orderd_T = 0
            main_state.Table_5_orderd_Y = 0

            main_state.Table_6_orderd_Q = 0
            main_state.Table_6_orderd_W = 0
            main_state.Table_6_orderd_E = 0
            main_state.Table_6_orderd_R = 0
            main_state.Table_6_orderd_T = 0
            main_state.Table_6_orderd_Y = 0

            main_state.Table_1_timer = 0
            main_state.Table_2_timer = 0
            main_state.Table_3_timer = 0
            main_state.Table_4_timer = 0
            main_state.Table_5_timer = 0
            main_state.Table_6_timer = 0

            main_state.time_literal = 0
            main_state.time_literal_2 = 0
            main_state.time_literal_3 = 0

            main_state.food_literal_1 = 0.0
            main_state.food_literal_2 = 0.0
            main_state.food_literal_3 = 0.0
            main_state.food_literal_4 = 0.0
            main_state.food_literal_5 = 0.0
            main_state.food_literal_6 = 0.0

            main_state.customer_literal_1 = 0
            main_state.customer_literal_2 = 0
            main_state.customer_literal_3 = 0
            main_state.customer_literal_4 = 0
            main_state.customer_literal_5 = 0
            main_state.customer_literal_6 = 0

            main_state.a = 0
            main_state.b = 0
            main_state.c = 0
            main_state.d = 0
            main_state.e = 0
            main_state.f = 0

            main_state.food_timer = 0.0
            main_state.customer_timer = 0.0
            main_state.messeage_timer = 0.0
            main_state.customer_frame = 0
            main_state.frame_time = 0.0
            main_state.order = 0

            cooking_state.cook_stack_1 = 0
            cooking_state.cook_stack_2 = 0
            cooking_state.cook_stack_3 = 0
            cooking_state.cook_stack_4 = 0
            cooking_state.cook_stack_5 = 0
            cooking_state.cook_stack_6 = 0
            cooking_state.cook_type = 0
            cooking_state.is_cooking_fail = 0

            game_framework.push_state(start_state)
コード例 #36
0
ファイル: stage2_play_state.py プロジェクト: EomDongyeon/2DGP
def handle_events(frame_time):
    global player, bg, stairs, up_key
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN:
            if event.key == SDLK_ESCAPE:
                game_framework.quit()
            if event.key == SDLK_q:
                if (Timer.time_state == Timer.TIME_ACTIVATION):
                    Timer.total_gauge += 10
                Character.player_score += 1
                if (Character.player_score < 100):
                    current_time = get_time()
                    frame_time = get_frame_time(frame_time)
                    player.jump(frame_time, stairs)
                    if (Character.moveStop == False):
                        if (Character.player_score >= 5):
                            bg.bg_moveY()
                            for stair in stairs:
                                stair.moveY()
                            player.moveY(stairs)
            if event.key == SDLK_w:  #방향전환
                Character.player_score += 1
                if (Timer.time_state == Timer.TIME_ACTIVATION):
                    Timer.total_gauge += 10
                if (Character.player_score < 100):
                    player.change_dir(stairs)
                    current_time = get_time()
                    frame_time = get_frame_time(frame_time)
                    player.jump(frame_time, stairs)
                    if (Character.moveStop == False):
                        if (Character.player_score >= 5):
                            bg.bg_moveY()
                            for stair in stairs:
                                stair.moveY()
                            player.moveY(stairs)
            if event.key == SDLK_F1:
                f = open('data/player_info_data.txt', 'r')
                info_data = json.load(f)
                f.close()
                info_data[-1]['item_life'] = False
                f = open('data/player_info_data.txt', 'w')
                json.dump(info_data, f)
                f.close()

            if event.key == SDLK_F2:
                f = open('data/player_info_data.txt', 'r')
                info_data = json.load(f)
                f.close()
                if (info_data[-1]['item_stop'] == True):
                    Timer.time_state = Timer.TIME_STOP
                    info_data[-1]['item_stop'] = False
                f = open('data/player_info_data.txt', 'w')
                json.dump(info_data, f)
                f.close()
        if event.key == SDLK_F5:
            Character.invincibility_mode = True

        elif event.type == SDL_KEYUP:
            if event.key == SDLK_q:
                Character.jump_key = True
            if event.key == SDLK_w:
                Character.jump_key = True
コード例 #37
0
def handle_events(frame_time):
    global mouse_x, mouse_y, enemy_team, enemy_count, target_enemy_index, isMouseDown, now_stage, stage_play_time, bomb_sound
    events = get_events()
    for event in events:
        if (event.type == SDL_QUIT):
            game_framework.quit()
        elif (event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE):
            game_framework.quit()
        elif (event.type == SDL_KEYDOWN
              and event.key == SDLK_1):  # 스테이지 넘어가는 치트키
            #game_framework.change_state(clear_state)
            stage_play_time = 9999999
        elif (event.type == SDL_KEYDOWN
              and event.key == SDLK_2):  # 스테이지 실패 치트키
            game_framework.change_state(lose_state)
        elif (event.type == SDL_KEYDOWN
              and event.key == SDLK_3):  # 현재 적들 몰살 치트키
            for enemy in enemy_team:
                if (enemy.x > 0):
                    enemy.state = 'dying'
                    bomb_sound.play()
        elif (event.type == SDL_MOUSEMOTION):
            mouse_x = event.x
            mouse_y = 599 - event.y
            # print(mouse_x, mouse_y)
            if (isMouseDown and target_enemy_index != -1):
                enemy_team[target_enemy_index].x = mouse_x
                enemy_team[target_enemy_index].y = mouse_y
        elif (event.type == SDL_MOUSEBUTTONDOWN):
            isMouseDown = True
            mouse_x = event.x
            mouse_y = 599 - event.y
            target_enemy_index = -1
            if (now_stage < JSON_DATA['stage_difficult_change_level_1']):
                for i in range(enemy_count * 1):
                    if (enemy_team[i].state == 'running'
                            or enemy_team[i].state == 'attacking'):
                        if (enemy_team[i].x - enemy_team[i].running_width / 2
                                <= mouse_x and mouse_x <=
                                enemy_team[i].x + enemy_team[i].running_width /
                                2  # running_width 와 attacking_width 는 같음
                                and enemy_team[i].y -
                                enemy_team[i].running_height / 2 <= mouse_y
                                and mouse_y <= enemy_team[i].y +
                                enemy_team[i].running_height / 2):
                            target_enemy_index = i
                            enemy_team[i].state = 'dragging'
                            enemy_team[i].falling_speed = 0
                            break
            elif (now_stage < JSON_DATA['stage_difficult_change_level_2']):
                for i in range(enemy_count * 2):
                    if (enemy_team[i].state == 'running'
                            or enemy_team[i].state == 'attacking'):
                        if (enemy_team[i].x - enemy_team[i].running_width / 2
                                <= mouse_x and mouse_x <=
                                enemy_team[i].x + enemy_team[i].running_width /
                                2  # running_width 와 attacking_width 는 같음
                                and enemy_team[i].y -
                                enemy_team[i].running_height / 2 <= mouse_y
                                and mouse_y <= enemy_team[i].y +
                                enemy_team[i].running_height / 2):
                            target_enemy_index = i
                            enemy_team[i].state = 'dragging'
                            enemy_team[i].falling_speed = 0
                            break
            else:
                for i in range(enemy_count * 3):
                    if (enemy_team[i].state == 'running'
                            or enemy_team[i].state == 'attacking'):
                        if (enemy_team[i].x - enemy_team[i].running_width / 2
                                <= mouse_x and mouse_x <=
                                enemy_team[i].x + enemy_team[i].running_width /
                                2  # running_width 와 attacking_width 는 같음
                                and enemy_team[i].y -
                                enemy_team[i].running_height / 2 <= mouse_y
                                and mouse_y <= enemy_team[i].y +
                                enemy_team[i].running_height / 2):
                            target_enemy_index = i
                            enemy_team[i].state = 'dragging'
                            enemy_team[i].falling_speed = 0
                            break
        if (event.type == SDL_MOUSEBUTTONUP
                or (isMouseDown == True and mouse_x == 0 or mouse_x == 799
                    or mouse_y == 0 or mouse_y == 599)):
            isMouseDown = False
            if (target_enemy_index != -1):
                enemy_team[target_enemy_index].state = 'falling'
                mouse_y = 599 - event.y
                enemy_team[target_enemy_index].falling_started_y = mouse_y
            target_enemy_index = -1
コード例 #38
0
def update():
    global time
    time += 1
    if time == 300:
        game_framework.quit()
    pass
コード例 #39
0
def handle_events(frame_time):
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN:
            if event.key == SDLK_ESCAPE:
                game_framework.quit()

            elif event.key == SDLK_LEFT:
                player1.key_down = True
                player1.left_move = 1
                player1.right_move = 0
                player1.up_move =0
                player1.down_move =0
                if event.key == SDLK_RIGHT:
                    player1.left_move = 0
                    player1.right_move = 1
                    player1.up_move =0
                    player1.down_move =0

            elif event.key == SDLK_RIGHT:
                player1.key_down = True
                player1.right_move = 1
                player1.left_move = 0
                player1.up_move =0
                player1.down_move =0
                if event.key == SDLK_LEFT:
                    player1.left_move = 1
                    player1.right_move = 0
                    
            
            elif event.key == SDLK_UP:
                player1.key_down = True
                player1.up_move = 1
                player1.down_move = 0
                player1.right_move = 0
                player1.left_move = 0
                
            elif event.key == SDLK_DOWN:
                player1.key_down = True
                player1.down_move = 1
                player1.up_move = 0
                player1.right_move = 0
                player1.left_move = 0 

            elif event.key == SDLK_SPACE:
                player1.missile_shoot()
            
            elif event.key == SDLK_z:
                player1.special_missile_shoot()

        elif event.type == SDL_KEYUP:
            player1.frame = 5
            if event.key == SDLK_LEFT:
                player1.key_down = False
            elif event.key == SDLK_RIGHT:
                player1.key_down = False
            elif event.key == SDLK_UP:
                player1.key_down = False
            elif event.key == SDLK_DOWN:
                player1.key_down == False
コード例 #40
0
def handle_events():
    global x, note_Ss, note_Ds, note_Fs, note_SPACEs, note_Js, note_Ks, note_Ls, machine
    global score_1

    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
            game_framework.change_state(title_state_easy)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_SPACE:
            x = 203
            effect_1.draw()
            update_canvas()
            delay(0.01)
            for note_SPACE in note_SPACEs:
                if collide(machine, note_SPACE):
                    effect_2.draw()
                    #note_1.remove()
                    score_1 += 100
                    print(score_1)
                    update_canvas()
                    delay(0.01)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_s:
            x = 37
            effect_1.draw()
            update_canvas()
            delay(0.01)
            for note_S in note_Ss:
                if collide(machine, note_S):
                    effect_2.draw()
                    #note_1.remove()
                    score_1 += 100
                    print(score_1)
                    update_canvas()
                    delay(0.01)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_d:
            x = 87
            effect_1.draw()
            update_canvas()
            delay(0.01)
            for note_D in note_Ds:
                if collide(machine, note_D):
                    effect_2.draw()
                    #note_1.remove()
                    score_1 += 100
                    print(score_1)
                    update_canvas()
                    delay(0.01)

        elif event.type == SDL_KEYDOWN and event.key == SDLK_f:
            x = 140
            effect_1.draw()
            update_canvas()
            delay(0.01)
            for note_F in note_Fs:
                if collide(machine, note_F):
                    effect_2.draw()
                    #note_1.remove()
                    score_1 += 100
                    print(score_1)
                    update_canvas()
                    delay(0.01)

        elif event.type == SDL_KEYDOWN and event.key == SDLK_j:
            x = 266
            effect_1.draw()
            update_canvas()
            delay(0.01)
            for note_J in note_Js:
                if collide(machine, note_J):
                    effect_2.draw()
                    #note_1.remove()
                    score_1 += 100
                    print(score_1)
                    update_canvas()
                    delay(0.01)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_k:
            x = 320
            effect_1.draw()
            update_canvas()
            delay(0.01)
            for note_K in note_Ks:
                if collide(machine, note_K):
                    effect_2.draw()
                    #note_1.remove()
                    score_1 += 100
                    print(score_1)
                    update_canvas()
                    delay(0.01)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_l:
            x = 370
            effect_1.draw()
            update_canvas()
            delay(0.01)
            for note_L in note_Ls:
                if collide(machine, note_L):
                    effect_2.draw()
                    #note_1.remove()
                    score_1 += 100
                    print(score_1)
                    update_canvas()
                    delay(0.01)
コード例 #41
0
def handle_events():
    global H, stop, up_key_on, down_key_on, left_key_on, right_key_on, rev_state
    global skill_inv, selection
    global play_sound
    eve = get_events()
    for e in eve:
        if e.type is SDL_QUIT:
            print('quit')
            game_framework.quit()
        if e.key == SDLK_j:
            if H[-1].state is hero.hero.h_stand or H[
                    -1].state is hero.hero.h_move:
                return
            if H[-1].state is hero.hero.h_jump_ready:
                return
            H[-1].attack_type = random.randint(0, 1)
            H[-1].state = hero.hero.h_attack[H[-1].attack_type]
            H[-1].frame = 0
            H[-1].attack_num = (H[-1].attack_num + 1) % 10
            if e.type == SDL_KEYDOWN:
                hero.hero.sound_attack.play(1)
        if (e.type, e.key) == (SDL_KEYDOWN, SDLK_w):
            up_key_on = True
            down_key_on = False
            if H[-1].jump is True:
                return
            H[-1].change_state(hero.hero.h_jump_ready)
        if (e.type, e.key) == (SDL_KEYDOWN, SDLK_s):
            down_key_on = True
            up_key_on = False
        if (e.type, e.key) == (SDL_KEYDOWN, SDLK_a):
            H[-1].go_L = True
            if H[-1].state is hero.hero.h_stand:
                H[-1].change_state(hero.hero.h_move)
            left_key_on = True
            right_key_on = False
        if (e.type, e.key) == (SDL_KEYDOWN, SDLK_d):
            H[-1].go_R = True
            if H[-1].state is hero.hero.h_stand:
                H[-1].change_state(hero.hero.h_move)
            right_key_on = True
            left_key_on = False
        if (e.type, e.key) == (SDL_KEYUP, SDLK_w):
            up_key_on = False
            if H[-1].jump is True or H[-1].state != hero.hero.h_jump_ready:
                return
            H[-1].change_state(hero.hero.h_jump)
        if (e.type, e.key) == (SDL_KEYUP, SDLK_s):
            down_key_on = False
        if (e.type, e.key) == (SDL_KEYUP, SDLK_a):
            H[-1].go_L = False
            if (H[-1].go_L, H[-1].go_R) == (False, False):
                if H[-1].state is hero.hero.h_move:
                    H[-1].state = hero.hero.h_stand
                    H[-1].frame = 0
            left_key_on = False
        if (e.type, e.key) == (SDL_KEYUP, SDLK_d):
            H[-1].go_R = False
            if (H[-1].go_L, H[-1].go_R) == (False, False):
                if H[-1].state is hero.hero.h_move:
                    H[-1].state = hero.hero.h_stand
                    H[-1].frame = 0
            right_key_on = False
        if (e.type, e.key) == (SDL_KEYDOWN, SDLK_k):
            H += [hero.hero(H[-1].x, H[-1].y, H[-1].state, H[-1].hp, H[-1].jump, H[-1].ascend, H[-1].attack_effect, \
                  H[-1].attack_type, H[-1].attack_frame, H[-1].go_L, H[-1].go_R, H[-1].look, H[-1].extra_hit_size_x, H[-1].extra_hit_size_y,\
                    H[-1].ate_depress, H[-1].maxheight, H[-1].extra_hit_time, H[-1].change_pics)]
            for he in H:
                if he is not H[-1]: he.overwhelming = True
            H[-2].del_time = time.time()
            H[-1].dash_dist = 30
            H[-1].dashing = True
            H[-1].dash_dir = 0
            H[-1].ascend = False
            if up_key_on is True:
                H[-1].dash_dir |= 1
            if down_key_on is True:
                H[-1].dash_dir |= 10
            if left_key_on is True:
                H[-1].dash_dir |= 100
            if right_key_on is True:
                H[-1].dash_dir |= 1000
        if (e.type, e.key) == (SDL_KEYDOWN, SDLK_q):
            tmp = selection
            next = max((selection - 1), 0)
            if tmp == next: selection = 2
            else: selection = next
        if (e.type, e.key) == (SDL_KEYDOWN, SDLK_e):
            tmp = selection
            next = min((selection + 1), 2)
            if tmp == next: selection = 0
            else: selection = next
        if (e.type, e.key) == (SDL_KEYDOWN, SDLK_p):
            if stop is True:
                stop = False
            else:
                stop = True
        if (e.type, e.key) == (SDL_KEYDOWN, SDLK_l):
            skill_inv[selection].handle_events()
コード例 #42
0
def handle_events():
    global is_key_pressed
    global is_attack_key_pressing
    global bullet_dir
    global isaac, background, monster_count

    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN:
            if event.key == SDLK_ESCAPE:
                game_framework.push_state(pause_state)
            elif event.key == SDLK_1:
                game_framework.change_state(main_state_2)
            elif event.key == SDLK_0:
                monster_count = 0
                for gusher in gushers:
                    game_world.remove_object(gusher)
                    gushers.remove(gusher)
            elif event.key == SDLK_d:
                isaac.body_is_move = True
                isaac.velocity_x += isaac.velocity
                isaac.body_bottom = 0
                is_key_pressed += 1
            elif event.key == SDLK_a:
                isaac.body_is_move = True
                isaac.velocity_x -= isaac.velocity
                isaac.body_bottom = 180
                is_key_pressed += 1
            elif event.key == SDLK_w:
                isaac.body_is_move = True
                isaac.velocity_y += isaac.velocity
                isaac.body_bottom = 90
                is_key_pressed += 1
            elif event.key == SDLK_s:
                isaac.body_is_move = True
                isaac.velocity_y -= isaac.velocity
                isaac.body_bottom = 90
                is_key_pressed += 1
            elif event.key == SDLK_RIGHT:
                isaac.left = 160
                is_attack_key_pressing += 1
                bullet_dir = 0
            elif event.key == SDLK_LEFT:
                isaac.left = 480
                is_attack_key_pressing += 1
                bullet_dir = 1
            elif event.key == SDLK_UP:
                isaac.left = 320
                is_attack_key_pressing += 1
                bullet_dir = 2
            elif event.key == SDLK_DOWN:
                isaac.left = 0
                is_attack_key_pressing += 1
                bullet_dir = 3
        elif event.type == SDL_KEYUP:
            if event.key == SDLK_d:
                is_key_pressed -= 1
                if is_key_pressed == 0:
                    isaac.body_is_move = False
                    isaac.body_frame = 0
                isaac.velocity_x -= isaac.velocity
            elif event.key == SDLK_a:
                is_key_pressed -= 1
                if is_key_pressed == 0:
                    isaac.body_is_move = False
                    isaac.body_frame = 0
                isaac.velocity_x += isaac.velocity
            elif event.key == SDLK_w:
                is_key_pressed -= 1
                if is_key_pressed == 0:
                    isaac.body_is_move = False
                    isaac.body_frame = 0
                isaac.velocity_y -= isaac.velocity
            elif event.key == SDLK_s:
                is_key_pressed -= 1
                if is_key_pressed == 0:
                    isaac.body_is_move = False
                    isaac.body_frame = 0
                isaac.velocity_y += isaac.velocity
            elif event.key == SDLK_RIGHT:
                is_attack_key_pressing -= 1
            elif event.key == SDLK_LEFT:
                is_attack_key_pressing -= 1
            elif event.key == SDLK_UP:
                is_attack_key_pressing -= 1
            elif event.key == SDLK_DOWN:
                is_attack_key_pressing -= 1

    pass
コード例 #43
0
def handle_events():
    global map,customMap,rekeys,mapMaker,CW,CH,customMap,rekeys,toggle,toggleInKey,stageNum,isStructure,strMaker,\
        customStructure,strkeys

    events = get_events()
    for key in events:
        if key.type == SDL_QUIT: gf.quit()
        elif (key.type, key.key) == (SDL_KEYDOWN, SDLK_ESCAPE): gf.pop_state()
        elif (key.type) == (SDL_KEYDOWN):
            if key.key == SDLK_1:
                if isStructure:
                    strMaker.left = 0
                else:
                    mapMaker.mapType = 0
            elif key.key == SDLK_2:
                if isStructure:
                    strMaker.left = strMaker.w
                else:
                    mapMaker.mapType = 1
            elif key.key == SDLK_3:
                if isStructure:
                    strMaker.left = strMaker.w * 2
                else:
                    mapMaker.mapType = 2
            elif key.key == SDLK_4:
                if isStructure:
                    strMaker.left = strMaker.w * 3
                else:
                    mapMaker.mapType = 3
            elif key.key == SDLK_5:
                if isStructure:
                    strMaker.left = strMaker.w * 4
                else:
                    mapMaker.mapType = 4
            elif key.key == SDLK_6:
                if isStructure:
                    strMaker.left = strMaker.w * 5
                else:
                    mapMaker.mapType = 5
            elif key.key == SDLK_7:
                if isStructure:
                    strMaker.left = strMaker.w * 6
                else:
                    mapMaker.mapType = 6
            elif key.key == SDLK_8:
                if isStructure:
                    strMaker.left = strMaker.w * 7
                else:
                    mapMaker.mapType = 7
            elif key.key == SDLK_9:
                if isStructure:
                    strMaker.left = strMaker.w * 8
                else:
                    mapMaker.mapType = 8
            elif key.key == SDLK_0:
                if isStructure:
                    isStructure = False
                    print("structureMaker is", isStructure)
                else:
                    isStructure = True
                    print("structureMaker is", isStructure)
            if isStructure:
                if key.key == SDLK_t:
                    strMaker.bottom += strMaker.h
                    if strMaker.bottom > 1500:
                        strMaker.bottom -= strMaker.h
                elif key.key == SDLK_g:
                    strMaker.bottom -= strMaker.h
                    if strMaker.bottom < 0:
                        strMaker.bottom += strMaker.h
                elif key.key == SDLK_f:
                    strMaker.left -= strMaker.w
                    if strMaker.left < 0:
                        strMaker.left += strMaker.w
                elif key.key == SDLK_h:
                    strMaker.left += strMaker.w
                    if strMaker.left > 1500:
                        strMaker.left -= strMaker.w

            if key.key == SDLK_RIGHT:
                if isStructure:
                    strMaker.x += strMaker.w
                    if strMaker.x >= CW:
                        strMaker.x -= strMaker.w
                else:
                    mapMaker.x += mapMaker.w
                if mapMaker.x >= CW:
                    mapMaker.x -= mapMaker.w

            elif key.key == SDLK_LEFT:
                if isStructure:
                    strMaker.x -= strMaker.w
                    if strMaker.x <= 0:
                        strMaker.x += strMaker.w
                else:
                    mapMaker.x -= mapMaker.w
                if mapMaker.x <= 0:
                    mapMaker.x += mapMaker.w

            elif key.key == SDLK_UP:
                if isStructure:
                    strMaker.y += strMaker.h
                    if strMaker.y >= CH + strMaker.h:
                        strMaker.y -= strMaker.h
                else:
                    mapMaker.y += mapMaker.h
                if mapMaker.y >= CH + mapMaker.h:
                    mapMaker.y -= mapMaker.h

            elif key.key == SDLK_DOWN:
                if isStructure:
                    strMaker.y -= strMaker.h
                    if strMaker.y <= 0:
                        strMaker.y += strMaker.h
                else:
                    mapMaker.y -= mapMaker.h
                if mapMaker.y <= 0:
                    mapMaker.y += mapMaker.h

            if key.key == SDLK_c:
                if isStructure:
                    strkeys = []
                else:
                    rekeys = []

            if key.key == SDLK_q:
                if toggle:
                    toggleInKey = 1
                else:
                    toggleInKey = 0

                if isStructure:
                    psl, psb, psx, psy = strMaker.left, strMaker.bottom, strMaker.x, strMaker.y
                    if strkeys == []:
                        strkeys.append((psl, psb, psx, psy))
                    else:
                        troble = False
                        for m in strkeys:
                            l, b, x, y = m
                            if psx == x and psy == y:
                                troble = True
                                if psl == l and psb == b:
                                    print(
                                        "structure you press key q, perfect same!!"
                                    )
                                    break
                                elif psl != l or psb != b:
                                    print(
                                        "structure wow different thing,changing"
                                    )
                                    strkeys.append((psl, psb, psx, psy))
                                    strkeys.remove(m)
                                    break
                        if troble == False:
                            strkeys.append((psl, psb, psx, psy))
                else:
                    px, py, pn = mapMaker.x, mapMaker.y, mapMaker.mapType
                    if rekeys == []:
                        rekeys.append((px, py, pn))
                    else:
                        troble = False
                        for m in rekeys:
                            x, y, n = m
                            if px == x and py == y:
                                troble = True
                                if pn == n:
                                    print("is same! Number!")
                                    break
                                elif pn != n:
                                    print("is change!!! map!")
                                    rekeys.append((px, py, pn))
                                    rekeys.remove(m)
                                    break
                        if troble == False:
                            rekeys.append((px, py, pn))
            elif key.key == SDLK_w:
                if isStructure:
                    for m in strkeys:
                        _, _, x, y = m
                        if strMaker.x == x and strMaker.y == y:
                            rekeys.remove(m)
                            break
                else:
                    for m in rekeys:
                        x, y, _ = m
                        if mapMaker.x == x and mapMaker.y == y:
                            rekeys.remove(m)
                            break

                if toggle:
                    toggleInKey = 2

            elif key.key == SDLK_e:
                if toggle:
                    toggleInKey = 0
                    toggle = False
                elif toggle == False:
                    toggle = True
                print("toggle is ", toggle, "toggle in key is ", toggleInKey)
            elif key.key == SDLK_r:
                if isStructure:
                    if strkeys == []:
                        print("structure None!!!")
                    else:
                        customStructure.append(strkeys)
                        print(
                            json.dumps(customStructure,
                                       ensure_ascii=False,
                                       indent=""))
                        with open("stageInStructure.json",
                                  'a',
                                  encoding="utf-8") as make_f:
                            json.dump(customStructure, make_f)
                            print("structure save done!!")
                else:
                    if rekeys == []:
                        print("map None!!")
                    else:
                        customMap.append(rekeys)
                        stageNum += 1
                        print(
                            json.dumps(customMap,
                                       ensure_ascii=False,
                                       indent="\t"))
                        with open("stageInMap.json", 'a',
                                  encoding="utf-8") as make_file:
                            json.dump(customMap, make_file)
                        print("map save done!!")
コード例 #44
0
def handle_events(frame_time):
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        else:
            if (event.type, event.key) == (SDL_KEYDOWN, SDLK_ESCAPE):
                game_framework.change_state(title_state)
            elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_LSHIFT):
                for pokemon in pokemons:
                    if pokemon.selection == True:
                        Meele_Attack(pokemon)

            elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_SPACE):
                for pokemon in pokemons:
                    if pokemon.selection == True:
                        if pokemon.fix == False:
                            pokemon.fix = True
                            fix_time.init_time = SDL_GetTicks()
                            Fix_Attack(pokemon)
                        else:
                            pokemon.fix = False

            elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_1):  #water
                for pokemon in pokemons:
                    if pokemon.selection == True:
                        if skill_1() == True:
                            WideDamage(pokemon)

            elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_2):
                for pokemon in pokemons:
                    if pokemon.selection == True:
                        if skill_2() == True:
                            Flame(pokemon)

            elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_3):
                for pokemon in pokemons:
                    if pokemon.selection == True:
                        # if pokemon.type == 0:
                        if skill_3() == True:
                            Stem_Chain(pokemon)

            elif (event.type, event.key) == (SDL_KEYDOWN,
                                             SDLK_n):  # go to next stage
                game_framework.change_state(stage2)

            elif event.type == SDL_MOUSEBUTTONDOWN and event.button == SDL_BUTTON_LEFT:
                for pokemon in pokemons:
                    if point_collide(pokemon, event.x, 600 - event.y):
                        pokemon.selection = True
                    else:
                        pokemon.selection = False
                for resource in resources:
                    if point_collide(resource, event.x, 600 - event.y):
                        resources.remove(resource)
                        for inven in invens:
                            inven.get_resource(resource.type)

            else:
                for pokemon in pokemons:
                    if pokemon.selection == True:
                        pokemon.handle_event(event)
                if pokeball.hp <= 0:
                    game_framework.change_state(gameover_state)
                if victory_time.passed_time() > 50000:
                    game_framework.change_state(victory_state)
コード例 #45
0
ファイル: game_over.py プロジェクト: lhr1/2DGP
def update():
    if not running:
        game_framework.quit()  #quit은 exit를 호출한다. 앞 상태의 resume을 수행한다.

    GameOverImg.update()
コード例 #46
0
ファイル: main_state.py プロジェクト: sdkdk10/2D_TeamProject
def handle_events():
    global mouseX
    global mouseY
    global Tboy
    global selectedIndex

    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
            game_framework.change_state(title_state)
        elif event.type == SDL_KEYDOWN:
            if event.key == SDLK_0:
                Tboy = 0
            elif event.key == SDLK_1:
                Tboy = 1
                selectedIndex = 1
            elif event.key == SDLK_2:
                Tboy = 2
                selectedIndex = 2
            elif event.key == SDLK_3:
                Tboy = 3
                selectedIndex = 3
            elif event.key == SDLK_4:
                Tboy = 4
                selectedIndex = 4

            elif event.key == SDLK_5:
                Tboy = 5
                selectedIndex = 5

            elif event.key == SDLK_6:
                Tboy = 6
                selectedIndex = 6

            elif event.key == SDLK_7:
                Tboy = 7
                selectedIndex = 7

            elif event.key == SDLK_8:
                Tboy = 8
                selectedIndex = 8

            elif event.key == SDLK_9:
                Tboy = 9
                selectedIndex = 9

            elif event.key == SDLK_a:
                Tboy = 10
                selectedIndex = 10

            elif event.key == SDLK_UP:
                Tboy += 1
                if Tboy >= 5:
                    Tboy = 4
                    selectedIndex = 4
                selectedIndex += 1
            elif event.key == SDLK_DOWN:
                Tboy -= 1
                if Tboy <= 0:
                    Tboy = 1
                    selectedIndex = 1
                selectedIndex -= 1
        elif event.type == SDL_KEYDOWN or event.type == SDL_KEYUP:
            team[Tboy].handle_event(event)
        elif event.type == SDL_MOUSEMOTION:
            mouseX = event.x
            mouseY = 600 - event.y
コード例 #47
0
ファイル: interface_state.py プロジェクト: DeukYu/CookieRun
def handle_events():
    global x, y, Click, CharChoice, PetChoice
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
            game_framework.quit()
        if event.type == SDL_MOUSEMOTION:
            x, y = event.x, 500 - event.y - 1
            if Click == 0: #Lobby
                if 600 - 75 <= x <= 600 + 75 and 40 - 25 <= y <= 40 + 25:
                    imageStartButton.motion = 1
                    button_sound.button_on()
                else:
                    imageStartButton.motion = 0
                if 625 - 55 <= x <= 625 + 55 and 200 - 25 <= y <= 200 + 25:
                    imagePetButton.motion = 1
                    button_sound.button_on()
                else:
                    imagePetButton.motion = 0
                if 615 - 60 <= x <= 615 + 60 and 120 - 25 <= y <= 120 + 25:
                    imageCookieButton.motion = 1
                    button_sound.button_on()
                else:
                    imageCookieButton.motion = 0
            elif Click == 1: # Pet
                if 600 - 25 <= x <= 600 - 5 and 350 - 25 <= y <= 350 - 5:
                    imagePetSelection.Exit = 1
                    imagePetSelection.ExitMotion = 1
                    button_sound.button_on()
                elif 150 + 10 <= y <= 150 + 33:
                    if 200 + 15 <= x <= 200 + 90:
                        PetChoice = 0
                        imagePetSelection.Exit = 1
                        imageSelectButton.motion = 1
                    elif 200 + 113 <= x <= 200 + 188:
                        PetChoice = 1
                        imagePetSelection.Exit = 1
                        imageSelectButton.motion = 2
                    elif 200 + 211 <= x <= 200 + 286:
                        PetChoice = 2
                        imagePetSelection.Exit = 1
                        imageSelectButton.motion = 3
                    elif 200 + 310 <= x <= 200 + 385:
                        PetChoice = 3
                        imagePetSelection.Exit = 1
                        imageSelectButton.motion = 4
                    button_sound.button_on()
                else:
                    imagePetSelection.Exit = 0
                    imagePetSelection.ExitMotion = 0
                    imageSelectButton.motion = 0
            elif Click == 2: # Cookie
                if 600 - 25 <= x <= 600 - 5 and 350 - 25 <= y <= 350 - 5:
                    imageCookieSelection.Exit = 1
                    imageCookieSelection.ExitMotion = 1
                    button_sound.button_on()
                elif 150 + 10 <= y <= 150 + 33:
                    if 200 + 15 <= x <= 200 + 90:
                        CharChoice = 0
                        imageCookieSelection.Exit = 1
                        imageSelectButton.motion = 1
                    elif 200 + 113 <= x <= 200 + 188:
                        CharChoice = 1
                        imageCookieSelection.Exit = 1
                        imageSelectButton.motion = 2
                    elif 200 + 211 <= x <= 200 + 286:
                        CharChoice = 2
                        imageSelectButton.motion = 3
                        imageCookieSelection.Exit = 1
                    elif 200 + 310 <= x <= 200 + 385:
                        CharChoice = 3
                        imageCookieSelection.Exit = 1
                        imageSelectButton.motion = 4
                    button_sound.button_on()
                else:
                    imageCookieSelection.Exit = 0
                    imageCookieSelection.ExitMotion = 0
                    imageSelectButton.motion = 0
        if event.type == SDL_MOUSEBUTTONDOWN and event.button == SDL_BUTTON_LEFT:
            if Click == 0:
                if imagePetButton.motion == 1:
                    Click = 1
                elif imageCookieButton.motion == 1:
                    Click = 2
                elif imageStartButton.motion == 1:
                    game_framework.change_state(main_state)
            elif Click == 1:
                if imagePetSelection.Exit == 1:
                    Click = 0
                    imagePetSelection.Exit = 0
                    imageSelectButton.motion = 0
            elif Click == 2:
                if imageCookieSelection.Exit == 1:
                    Click = 0
                    imageCookieSelection.Exit = 0
                    imageSelectButton.motion = 0
コード例 #48
0
def handle_events():
    eve = get_events()
    for e in eve:
        if e.type == SDL_KEYDOWN:
            if e.key == SDLK_ESCAPE:
                game_framework.quit()
コード例 #49
0
ファイル: main_state.py プロジェクト: nkj4444/2D-GP
def handle_events():
    global running
    global x
    global y
    global move, attack
    global move6_1, move8_1, move4_1, move2_1, move7_1, move9_1, move1_1, move3_1, move6_2, move8_2, move4_2, move2_2, move7_2, move9_2, move1_2, move3_2
    global rect1
    global cursor_x, cursor_y, mouse_cursor_change, move_point_x, move_point_y, move_point_pop, attack_point_x, attack_point_y, attack_point_pop
    global player_move1_trigger, player_attack_trigger, player_rest_trigger, end

    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
            running = False
        elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
            running = False
        elif event.type == SDL_KEYDOWN and event.key == SDLK_SPACE and turn == 1:
            turn_change()
        elif event.type == SDL_KEYDOWN and event.key == SDLK_RIGHT and turn == 1:
            turn_change()

        elif event.type == SDL_MOUSEBUTTONDOWN and turn == 1:

            if end == True:
                running = False
            elif event.x > 300 and event.x < 600 and event.y > 900 and event.y < 1000:
                move = True
                attack = False
                cursor_x = 300
                cursor_y = 300
                mouse_cursor_change = True
            elif event.x > 0 and event.x < 300 and event.y > 800 and event.y < 900:
                attack = True
                move = False
                cursor_x = 300
                cursor_y = 300
                mouse_cursor_change = True
            elif event.x > 0 and event.x < 300 and event.y > 900 and event.y < 1000:
                player_attack_trigger, player_move1_trigger = False, False
                move, attack = False, False
                mouse_cursor_change = False
                attack_point_pop = False
                move_point_pop = False
                player_rest_trigger = True

            elif event.x > 300 and event.x < 600 and event.y > 800 and event.y < 900:
                turn_change()
            elif event.y < 300 or event.y > 700 and move == True:
                print('overrange!')
                move = False
                attack = False
            elif event.y < 300 or event.y > 700 and attack == True:
                print('overrange!')
                attack = False
                move = False

        elif event.type == SDL_MOUSEBUTTONUP and turn == 1 and move == True:

            if event.x > maprect[P_x + 1][P_y].x and event.x < maprect[
                    P_x + 2][P_y].x and event.y > maprect[P_x][
                        P_y].y and event.y < maprect[P_x][P_y - 1].y:
                move6_1 = True
                player_move1_trigger = True
                move8_1, move4_1, move2_1, move7_1, move9_1, move1_1, move3_1 = False, False, False, False, False, False, False
                mouse_cursor_change = False
                attack_point_pop = False
                move_point_x = maprect[P_x + 1][P_y].x + 50
                move_point_y = 1000 - maprect[P_x][P_y - 1].y + 50
                move_point_pop = True
            elif event.x > maprect[P_x][P_y].x and event.x < maprect[
                    P_x + 1][P_y].x and event.y > maprect[P_x][
                        P_y + 1].y and event.y < maprect[P_x][P_y].y:
                move8_1 = True
                attack_point_pop = False
                player_move1_trigger = True
                move6_1, move4_1, move2_1, move7_1, move9_1, move1_1, move3_1 = False, False, False, False, False, False, False
                mouse_cursor_change = False
                move_point_x = maprect[P_x][P_y].x + 50
                move_point_y = 1000 - maprect[P_x][P_y].y + 50
                move_point_pop = True
            elif P_y < 2 and event.x > maprect[P_x][
                    P_y].x and event.x < maprect[
                        P_x + 1][P_y].x and event.y > maprect[P_x][
                            P_y - 1].y and maprect[P_x + 1][P_y].x + 100:
                move2_1 = True
                attack_point_pop = False
                player_move1_trigger = True
                move6_1, move8_1, move4_1, move7_1, move9_1, move1_1, move3_1 = False, False, False, False, False, False, False
                mouse_cursor_change = False
                move_point_x = maprect[P_x][P_y].x + 50
                move_point_y = 1000 - maprect[P_x][P_y - 1].y - 50
                move_point_pop = True
            elif P_y >= 2 and event.x > maprect[P_x][
                    P_y].x and event.x < maprect[
                        P_x + 1][P_y].x and event.y > maprect[P_x][
                            P_y - 1].y and event.y < maprect[P_x][P_y - 2].y:
                move2_1 = True
                attack_point_pop = False
                player_move1_trigger = True
                move6_1, move8_1, move4_1, move7_1, move9_1, move1_1, move3_1 = False, False, False, False, False, False, False
                mouse_cursor_change = False
                move_point_x = maprect[P_x][P_y].x + 50
                move_point_y = 1000 - maprect[P_x][P_y - 1].y - 50
                move_point_pop = True
            elif P_x < 2 and event.x > maprect[0][P_y].x and event.x < maprect[
                    1][P_y].x and event.y > maprect[P_x][
                        P_y].y and event.y < maprect[P_x][P_y - 1].y:
                move4_1 = True
                attack_point_pop = False
                player_move1_trigger = True
                move6_1, move8_1, move2_1, move7_1, move9_1, move1_1, move3_1 = False, False, False, False, False, False, False
                mouse_cursor_change = False
                move_point_x = maprect[P_x - 1][P_y].x + 50
                move_point_y = 1000 - maprect[P_x][P_y].y - 50
                move_point_pop = True
            elif P_x >= 2 and event.x > maprect[
                    P_x - 1][P_y].x and event.x < maprect[P_x][
                        P_y].x and event.y > maprect[P_x][
                            P_y].y and event.y < maprect[P_x][P_y - 1].y:
                move4_1 = True
                attack_point_pop = False
                player_move1_trigger = True
                move6_1, move8_1, move2_1, move7_1, move9_1, move1_1, move3_1 = False, False, False, False, False, False, False
                mouse_cursor_change = False
                move_point_x = maprect[P_x - 1][P_y].x + 50
                move_point_y = 1000 - maprect[P_x][P_y].y - 50
                move_point_pop = True
            elif event.x > maprect[P_x + 1][P_y].x and event.x < maprect[
                    P_x + 2][P_y].x and event.y > maprect[P_x][
                        P_y + 1].y and event.y < maprect[P_x][P_y].y:
                move9_1 = True
                attack_point_pop = False
                player_move1_trigger = True
                move6_1, move8_1, move4_1, move2_1, move7_1, move1_1, move3_1 = False, False, False, False, False, False, False
                mouse_cursor_change = False
                move_point_x = maprect[P_x + 1][P_y].x + 50
                move_point_y = 1000 - maprect[P_x][P_y + 1].y - 50
                move_point_pop = True
            elif event.x > maprect[P_x + 1][P_y].x and event.x < maprect[
                    P_x + 2][P_y].x and event.y > maprect[P_x][
                        P_y - 1].y and event.y < maprect[P_x][P_y - 2].y:
                move3_1 = True
                attack_point_pop = False
                player_move1_trigger = True
                move6_1, move8_1, move4_1, move2_1, move7_1, move9_1, move1_1 = False, False, False, False, False, False, False
                mouse_cursor_change = False
                move_point_x = maprect[P_x + 1][P_y].x + 50
                move_point_y = 1000 - maprect[P_x][P_y - 1].y - 50
                move_point_pop = True
            elif P_x < 2 and event.x > maprect[0][P_y].x and event.x < maprect[
                    1][P_y].x and event.y > maprect[P_x][
                        P_y + 1].y and event.y < maprect[P_x][P_y].y:
                move7_1 = True
                attack_point_pop = False
                player_move1_trigger = True
                move6_1, move8_1, move4_1, move2_1, move9_1, move1_1, move3_1 = False, False, False, False, False, False, False
                mouse_cursor_change = False
                move_point_x = maprect[P_x - 1][P_y].x + 50
                move_point_y = 1000 - maprect[P_x][P_y + 1].y - 50
                move_point_pop = True

            elif P_x >= 2 and event.x > maprect[
                    P_x - 1][P_y].x and event.x < maprect[P_x][
                        P_y].x and event.y > maprect[P_x][
                            P_y + 1].y and event.y < maprect[P_x][P_y].y:
                move7_1 = True
                attack_point_pop = False
                player_move1_trigger = True
                move6_1, move8_1, move4_1, move2_1, move9_1, move1_1, move3_1 = False, False, False, False, False, False, False
                mouse_cursor_change = False
                move_point_x = maprect[P_x - 1][P_y].x + 50
                move_point_y = 1000 - maprect[P_x][P_y + 1].y - 50
                move_point_pop = True
            elif P_x < 2 and event.x > maprect[0][P_y].x and event.x < maprect[
                    1][P_y].x and event.y > maprect[P_x][
                        P_y - 1].y and event.y < maprect[P_x][P_y - 2].y:
                move1_1 = True
                attack_point_pop = False
                player_move1_trigger = True
                move6_1, move8_1, move4_1, move2_1, move7_1, move9_1, move3_1 = False, False, False, False, False, False, False
                mouse_cursor_change = False
                move_point_x = maprect[P_x - 1][P_y].x + 50
                move_point_y = 1000 - maprect[P_x][P_y - 1].y - 50
                move_point_pop = True

            elif P_x >= 2 and event.x > maprect[
                    P_x - 1][P_y].x and event.x < maprect[P_x][
                        P_y].x and event.y > maprect[P_x][
                            P_y - 1].y and event.y < maprect[P_x][P_y - 2].y:
                move1_1 = True
                attack_point_pop = False
                player_move1_trigger = True
                move6_1, move8_1, move4_1, move2_1, move7_1, move9_1, move3_1 = False, False, False, False, False, False, False
                mouse_cursor_change = False
                move_point_x = maprect[P_x - 1][P_y].x + 50
                move_point_y = 1000 - maprect[P_x][P_y - 1].y - 50
                move_point_pop = True

        elif event.type == SDL_MOUSEBUTTONUP and turn == 1 and attack == True and event.y < 700 and event.y > 300:

            if event.x > maprect[P_x + 1][P_y].x and event.x < maprect[
                    P_x + 2][P_y].x and event.y > maprect[P_x][
                        P_y].y and event.y < maprect[P_x][P_y - 1].y:
                # move6_1
                move_point_pop = False
                mouse_cursor_change = False
                player_attack_trigger = True

                attack_point_x = maprect[P_x + 1][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y - 1].y + 50
                attack_point_pop = True
            elif event.x > maprect[P_x + 2][P_y].x and event.x < maprect[
                    P_x + 3][P_y].x and event.y > maprect[
                        P_x + 1][P_y].y and event.y < maprect[P_x + 1][P_y -
                                                                       1].y:
                # move6_2
                move_point_pop = False
                mouse_cursor_change = False
                player_attack_trigger = True

                attack_point_x = maprect[P_x + 2][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x + 1][P_y - 1].y + 50
                attack_point_pop = True
            elif event.x > maprect[P_x][P_y].x and event.x < maprect[
                    P_x + 1][P_y].x and event.y > maprect[P_x][
                        P_y + 1].y and event.y < maprect[P_x][P_y].y:
                # move8_1
                move_point_pop = False
                mouse_cursor_change = False
                player_attack_trigger = True

                attack_point_x = maprect[P_x][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y].y + 50
                attack_point_pop = True
            elif event.x > maprect[P_x][P_y + 1].x and event.x < maprect[
                    P_x + 1][P_y + 1].x and event.y > maprect[P_x][
                        P_y + 2].y and event.y < maprect[P_x][P_y + 1].y:
                # move8_2
                move_point_pop = False
                mouse_cursor_change = False
                player_attack_trigger = True

                attack_point_x = maprect[P_x][P_y + 1].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y + 1].y + 50
                attack_point_pop = True
            elif P_y < 2 and event.x > maprect[P_x][
                    P_y].x and event.x < maprect[
                        P_x + 1][P_y].x and event.y > maprect[P_x][
                            P_y - 1].y and maprect[P_x + 1][P_y].x + 100:
                # move2_1
                move_point_pop = False
                player_attack_trigger = True
                mouse_cursor_change = False
                attack_point_x = maprect[P_x][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y - 1].y - 50
                attack_point_pop = True
            elif P_y < 2 and event.x > maprect[P_x][
                    P_y - 1].x and event.x < maprect[P_x + 1][
                        P_y - 1].x and event.y > maprect[P_x][
                            P_y - 2].y and maprect[P_x + 1][P_y - 1].x + 100:
                # move2_2
                move_point_pop = False
                player_attack_trigger = True
                mouse_cursor_change = False
                attack_point_x = maprect[P_x][P_y - 1].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y - 2].y - 50
                attack_point_pop = True
            elif P_y >= 2 and event.x > maprect[P_x][
                    P_y].x and event.x < maprect[
                        P_x + 1][P_y].x and event.y > maprect[P_x][
                            P_y - 1].y and event.y < maprect[P_x][P_y - 2].y:
                # move2_1
                move_point_pop = False
                player_attack_trigger = True
                mouse_cursor_change = False
                attack_point_x = maprect[P_x][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y - 1].y - 50
                attack_point_pop = True
            elif P_y >= 2 and event.x > maprect[P_x][
                    P_y - 1].x and event.x < maprect[P_x + 1][
                        P_y - 1].x and event.y > maprect[P_x][
                            P_y - 2].y and event.y < maprect[P_x][P_y - 3].y:
                # move2_2
                move_point_pop = False
                player_attack_trigger = True
                mouse_cursor_change = False
                attack_point_x = maprect[P_x][P_y - 1].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y - 2].y - 50
                attack_point_pop = True
            elif P_x < 2 and event.x > maprect[0][P_y].x and event.x < maprect[
                    1][P_y].x and event.y > maprect[P_x][
                        P_y].y and event.y < maprect[P_x][P_y - 1].y:
                # move4_1
                move_point_pop = False
                player_attack_trigger = True
                mouse_cursor_change = False
                attack_point_x = maprect[P_x - 1][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y].y - 50
                attack_point_pop = True
            elif P_x < 2 and event.x > maprect[0][P_y].x and event.x < maprect[
                    1][P_y].x and event.y > maprect[
                        P_x - 1][P_y].y and event.y < maprect[P_x - 1][P_y -
                                                                       1].y:
                # move4_2
                move_point_pop = False
                player_attack_trigger = True
                mouse_cursor_change = False
                attack_point_x = maprect[P_x - 2][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x - 1][P_y].y - 50
                attack_point_pop = True
            elif P_x >= 2 and event.x > maprect[
                    P_x - 1][P_y].x and event.x < maprect[P_x][
                        P_y].x and event.y > maprect[P_x][
                            P_y].y and event.y < maprect[P_x][P_y - 1].y:
                # move4_1
                move_point_pop = False
                mouse_cursor_change = False
                player_attack_trigger = True
                attack_point_x = maprect[P_x - 1][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y].y - 50
                attack_point_pop = True
            elif P_x >= 2 and event.x > maprect[
                    P_x - 2][P_y].x and event.x < maprect[
                        P_x - 1][P_y].x and event.y > maprect[P_x - 1][
                            P_y].y and event.y < maprect[P_x - 1][P_y - 1].y:
                # move4_2
                move_point_pop = False
                mouse_cursor_change = False
                player_attack_trigger = True
                attack_point_x = maprect[P_x - 2][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x - 1][P_y].y - 50
                attack_point_pop = True
            elif event.x > maprect[P_x + 1][P_y].x and event.x < maprect[
                    P_x + 2][P_y].x and event.y > maprect[P_x][
                        P_y + 1].y and event.y < maprect[P_x][P_y].y:
                # move9_1
                player_attack_trigger = True
                move_point_pop = False
                mouse_cursor_change = False
                attack_point_x = maprect[P_x + 1][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y + 1].y - 50
                attack_point_pop = True
            elif event.x > maprect[P_x + 2][P_y + 1].x and event.x < maprect[
                    P_x + 3][P_y + 1].x and event.y > maprect[P_x + 1][
                        P_y + 2].y and event.y < maprect[P_x + 1][P_y + 1].y:
                # move9_2
                player_attack_trigger = True
                move_point_pop = False
                mouse_cursor_change = False
                attack_point_x = maprect[P_x + 2][P_y + 1].x + 50
                attack_point_y = 1000 - maprect[P_x + 1][P_y + 2].y - 50
                attack_point_pop = True
            elif event.x > maprect[P_x + 1][P_y + 1].x and event.x < maprect[
                    P_x + 2][P_y + 1].x and event.y > maprect[P_x][
                        P_y + 2].y and event.y < maprect[P_x][P_y + 1].y:
                # move9_1+y1
                player_attack_trigger = True
                move_point_pop = False
                mouse_cursor_change = False
                attack_point_x = maprect[P_x + 1][P_y + 1].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y + 2].y - 50
                attack_point_pop = True
            elif event.x > maprect[P_x + 2][P_y].x and event.x < maprect[
                    P_x + 3][P_y].x and event.y > maprect[P_x + 1][
                        P_y + 1].y and event.y < maprect[P_x + 1][P_y].y:
                # move9_1+x1
                player_attack_trigger = True
                move_point_pop = False
                mouse_cursor_change = False
                attack_point_x = maprect[P_x + 2][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x + 1][P_y + 1].y - 50
                attack_point_pop = True

            elif event.x > maprect[P_x + 1][P_y].x and event.x < maprect[
                    P_x + 2][P_y].x and event.y > maprect[P_x][
                        P_y - 1].y and event.y < maprect[P_x][P_y - 2].y:
                # move3_1
                player_attack_trigger = True
                move_point_pop = False
                mouse_cursor_change = False
                attack_point_x = maprect[P_x + 1][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y - 1].y - 50
                attack_point_pop = True
            elif event.x > maprect[P_x + 2][P_y - 1].x and event.x < maprect[
                    P_x + 3][P_y - 1].x and event.y > maprect[P_x + 1][
                        P_y - 2].y and event.y < maprect[P_x + 1][P_y - 3].y:
                # move3_2
                player_attack_trigger = True
                move_point_pop = False
                mouse_cursor_change = False
                attack_point_x = maprect[P_x + 2][P_y - 1].x + 50
                attack_point_y = 1000 - maprect[P_x + 1][P_y - 2].y - 50
                attack_point_pop = True
            elif event.x > maprect[P_x + 2][P_y].x and event.x < maprect[
                    P_x + 3][P_y].x and event.y > maprect[P_x + 1][
                        P_y - 1].y and event.y < maprect[P_x + 1][P_y - 2].y:
                # move3_1+x1
                player_attack_trigger = True
                move_point_pop = False
                mouse_cursor_change = False
                attack_point_x = maprect[P_x + 2][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x + 1][P_y - 1].y - 50
                attack_point_pop = True
            elif event.x > maprect[P_x + 1][P_y - 1].x and event.x < maprect[
                    P_x + 2][P_y - 1].x and event.y > maprect[P_x][
                        P_y - 2].y and event.y < maprect[P_x][P_y - 3].y:
                # move3_1-y1
                player_attack_trigger = True
                move_point_pop = False
                mouse_cursor_change = False
                attack_point_x = maprect[P_x + 1][P_y - 1].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y - 2].y - 50
                attack_point_pop = True
            elif P_x < 2 and event.x > maprect[0][P_y].x and event.x < maprect[
                    1][P_y].x and event.y > maprect[P_x][
                        P_y + 1].y and event.y < maprect[P_x][P_y].y:
                #  move7_1
                player_attack_trigger = True
                move_point_pop = False
                mouse_cursor_change = False
                attack_point_x = maprect[P_x - 1][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y + 1].y - 50
                attack_point_pop = True
            elif P_x < 2 and event.x > maprect[0][
                    P_y + 1].x and event.x < maprect[1][
                        P_y + 1].x and event.y > maprect[P_x - 1][
                            P_y + 2].y and event.y < maprect[P_x - 1][P_y +
                                                                      1].y:
                #  move7_2
                player_attack_trigger = True
                move_point_pop = False
                mouse_cursor_change = False
                attack_point_x = maprect[P_x - 2][P_y + 1].x + 50
                attack_point_y = 1000 - maprect[P_x - 1][P_y + 2].y - 50
                attack_point_pop = True

            elif P_x >= 2 and event.x > maprect[
                    P_x - 1][P_y].x and event.x < maprect[P_x][
                        P_y].x and event.y > maprect[P_x][
                            P_y + 1].y and event.y < maprect[P_x][P_y].y:
                # move7_1
                move_point_pop = False
                player_attack_trigger = True
                mouse_cursor_change = False
                attack_point_x = maprect[P_x - 1][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y + 1].y - 50
                attack_point_pop = True
            elif P_x >= 2 and event.x > maprect[
                    P_x - 2][P_y].x and event.x < maprect[
                        P_x - 1][P_y].x and event.y > maprect[P_x - 1][
                            P_y + 1].y and event.y < maprect[P_x - 1][P_y].y:
                # move7_1-x1
                move_point_pop = False
                player_attack_trigger = True
                mouse_cursor_change = False
                attack_point_x = maprect[P_x - 2][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x - 1][P_y + 1].y - 50
                attack_point_pop = True
            elif P_x >= 2 and event.x > maprect[P_x - 1][
                    P_y + 1].x and event.x < maprect[P_x][
                        P_y + 1].x and event.y > maprect[P_x][
                            P_y + 2].y and event.y < maprect[P_x][P_y + 1].y:
                # move7_1+y1
                move_point_pop = False
                player_attack_trigger = True
                mouse_cursor_change = False
                attack_point_x = maprect[P_x - 1][P_y + 1].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y + 2].y - 50
                attack_point_pop = True
            elif P_x >= 2 and event.x > maprect[P_x - 2][
                    P_y + 1].x and event.x < maprect[P_x - 1][
                        P_y + 1].x and event.y > maprect[P_x - 1][
                            P_y + 2].y and event.y < maprect[P_x - 1][P_y +
                                                                      1].y:
                # move7_2
                move_point_pop = False
                player_attack_trigger = True
                mouse_cursor_change = False
                attack_point_x = maprect[P_x - 2][P_y + 1].x + 50
                attack_point_y = 1000 - maprect[P_x - 1][P_y + 2].y - 50
                attack_point_pop = True
            elif P_x < 2 and event.x > maprect[0][P_y].x and event.x < maprect[
                    1][P_y].x and event.y > maprect[P_x][
                        P_y - 1].y and event.y < maprect[P_x][P_y - 2].y:
                # move7_1
                move_point_pop = False
                player_attack_trigger = True
                mouse_cursor_change = False
                attack_point_x = maprect[P_x - 1][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y - 1].y - 50
                attack_point_pop = True
            elif P_x < 2 and event.x > maprect[0][
                    P_y + 1].x and event.x < maprect[1][
                        P_y + 1].x and event.y > maprect[P_x - 1][
                            P_y].y and event.y < maprect[P_x - 1][P_y - 1].y:
                # move7_2
                move_point_pop = False
                player_attack_trigger = True
                mouse_cursor_change = False
                attack_point_x = maprect[P_x - 2][P_y + 1].x + 50
                attack_point_y = 1000 - maprect[P_x - 1][P_y].y - 50
                attack_point_pop = True

            elif P_x >= 2 and event.x > maprect[
                    P_x - 1][P_y].x and event.x < maprect[P_x][
                        P_y].x and event.y > maprect[P_x][
                            P_y - 1].y and event.y < maprect[P_x][P_y - 2].y:
                # move1_1
                player_attack_trigger = True
                move_point_pop = False
                mouse_cursor_change = False
                attack_point_x = maprect[P_x - 1][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y - 1].y - 50
                attack_point_pop = True
            elif P_x >= 2 and event.x > maprect[P_x - 2][
                    P_y - 1].x and event.x < maprect[P_x - 1][
                        P_y - 1].x and event.y > maprect[P_x - 1][
                            P_y - 2].y and event.y < maprect[P_x - 1][P_y -
                                                                      3].y:
                # move1_2
                player_attack_trigger = True
                move_point_pop = False
                mouse_cursor_change = False
                attack_point_x = maprect[P_x - 2][P_y - 1].x + 50
                attack_point_y = 1000 - maprect[P_x - 1][P_y - 2].y - 50
                attack_point_pop = True
            elif P_x >= 2 and event.x > maprect[
                    P_x - 2][P_y].x and event.x < maprect[
                        P_x - 1][P_y].x and event.y > maprect[P_x - 1][
                            P_y - 1].y and event.y < maprect[P_x - 1][P_y -
                                                                      2].y:
                # move1_1-x1
                player_attack_trigger = True
                move_point_pop = False
                mouse_cursor_change = False
                attack_point_x = maprect[P_x - 2][P_y].x + 50
                attack_point_y = 1000 - maprect[P_x - 1][P_y - 1].y - 50
                attack_point_pop = True
            elif P_x >= 2 and event.x > maprect[P_x - 1][
                    P_y - 1].x and event.x < maprect[P_x][
                        P_y - 1].x and event.y > maprect[P_x][
                            P_y - 2].y and event.y < maprect[P_x][P_y - 3].y:
                # move1_1-y1
                player_attack_trigger = True
                move_point_pop = False
                mouse_cursor_change = False
                attack_point_x = maprect[P_x - 1][P_y - 1].x + 50
                attack_point_y = 1000 - maprect[P_x][P_y - 2].y - 50
                attack_point_pop = True

        elif event.type == SDL_MOUSEMOTION:
            if move == True or attack == True:
                if event.y < 700 and event.y > 300:
                    cursor_x = event.x
                    cursor_y = 1000 - event.y
コード例 #50
0
def update():
    if not running:
        game_framework.quit()
コード例 #51
0
def handle_events():
    global mouse_x
    global mouse_y
    global elf_upgrade
    global elf_d, elf_s
    global save
    global move_ui
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
            game_framework.quit()

        ############################################################################ 키보드 q또는 w 업글용
        elif event.type == SDL_KEYDOWN and event.key == SDLK_q and save != None:
            if save.upgrade == 0 and ui.money >= 120:
                save.upgrade = 1
                ui.money -= 120
            elif save.upgrade == 1 and ui.money >= 160:
                save.upgrade = 2
                ui.money -= 160
            save = None

        elif event.type == SDL_KEYDOWN and event.key == SDLK_w and save != None:
            if save.upgrade == 1 and ui.money >= 180 and str(save).find("magic") == -1:
                save.upgrade = 3
                ui.money -= 180
            save = None

        ############################################################################# 마우스 움직임
        elif event.type == SDL_MOUSEMOTION:
            mouse_x, mouse_y = event.x, 720 - event.y

            if mouse_x >= 1280 - 128 and mouse_x <= 1280 and mouse_y >= 720 - 128 and mouse_y <= 720:
                ui.move_ui = 1
            elif mouse_x >= 1280 - 128 and mouse_x <= 1280 and mouse_y >= 720 - 128 * 2 and mouse_y <= 720 - 128:
                ui.move_ui = 2
            elif mouse_x >= 1280 - 128 and mouse_x <= 1280 and mouse_y >= 720 - 128 * 3 and mouse_y <= 720 - 128 * 2:
                ui.move_ui = 3
            elif mouse_x >= 1280 - 128 and mouse_x <= 1280 and mouse_y >= 0 and mouse_y <= 128 and elf_upgrade == 0:
                ui.move_ui = 4
            elif mouse_x >= 1280 - 128 and mouse_x <= 1280 and mouse_y >= 0 and mouse_y <= 128 and elf_upgrade == 1:
                ui.move_ui = 5
            else:
                ui.move_ui = 0

        ############################################################################# 마우스 좌클릭
        elif event.type == SDL_MOUSEBUTTONDOWN:
            save = None

            ui.left_click = 1
            if mouse_x >= 1280 - 128 and mouse_x <= 1280 and mouse_y >= 720 - 128 and mouse_y <= 720 and ui.money >= 70:
                ui.cho_tower = 1
            elif mouse_x >= 1280 - 128 and mouse_x <= 1280 and mouse_y >= 720 - 128 * 2 and mouse_y <= 720 - 128 and ui.money >= 80:
                ui.cho_tower = 2
            elif mouse_x >= 1280 - 128 and mouse_x <= 1280 and mouse_y >= 720 - 128 * 3 and mouse_y <= 720 - 128 * 2 and ui.money >= 100:
                ui.cho_tower = 3
            elif mouse_x >= 1280 - 128 and mouse_x <= 1280 and mouse_y >= 0 and mouse_y <= 128 and elf_upgrade == 0 and ui.money >= 200:
                ui.money -= 100
                elf_upgrade = 1
                elf_s = 0.15
            elif mouse_x >= 1280 - 128 and mouse_x <= 1280 and mouse_y >= 0 and mouse_y <= 128 and elf_upgrade == 1 and ui.money >= 400:
                ui.money -= 250
                elf_upgrade = 2
                elf_d = 80
            else:
                ui.cho_tower = 0

            if tile.in_tower[int((mouse_x - elf_move_window_x - 64) / 128) + (int((720-(mouse_y - elf_move_window_y) + 64) / 128) * 20)] == 1:
                ui.cho_build_tower = 1
                ui.cho_build_x = int((mouse_x - elf_move_window_x - 64) / 128) * 128 + 128
                ui.cho_build_y = int((mouse_y - elf_move_window_y + 128) / 128) * 128 - 64
            elif tile.in_tower[int((mouse_x - elf_move_window_x - 64) / 128) + (int((720-(mouse_y - elf_move_window_y) + 64) / 128) * 20)] == 2:
                ui.cho_build_tower = 2
                ui.cho_build_x = int((mouse_x - elf_move_window_x - 64) / 128) * 128 + 128
                ui.cho_build_y = int((mouse_y - elf_move_window_y + 128) / 128) * 128 - 64
            elif tile.in_tower[int((mouse_x - elf_move_window_x - 64) / 128) + (int((720-(mouse_y - elf_move_window_y) + 64) / 128) * 20)] == 3:
                ui.cho_build_tower = 3
                ui.cho_build_x = int((mouse_x - elf_move_window_x - 64) / 128) * 128 + 128
                ui.cho_build_y = int((mouse_y - elf_move_window_y + 128) / 128) * 128 - 64
            else:
                ui.cho_build_tower = 0


            for game_object in game_world.all_objects():
                if str(game_object).find("arrow_tower") != -1 or str(game_object).find("magic_tower") != -1 or str(game_object).find("buff_tower") != -1:
                    if mouse_x >= game_object.x + elf_move_window_x - 64 and mouse_x <= game_object.x + elf_move_window_x + 64 and mouse_y >= game_object.y + elf_move_window_y - 64 and mouse_y <= game_object.y + elf_move_window_y + 64:
                        save = game_object

        ############################################################################# 마우스 좌클릭 땜
        elif event.type == SDL_MOUSEBUTTONUP:
            if tile.in_tower[int((mouse_x - elf_move_window_x - 64) / 128) + (int((720-(mouse_y - elf_move_window_y) + 64) / 128) * 20)] == 0 and game_framework.text3[int((mouse_x - elf_move_window_x - 64) / 128) + (int((720-(mouse_y - elf_move_window_y) + 64) / 128) * 20)] == '1':
                tile.in_tower[int((mouse_x - elf_move_window_x - 64) / 128) + (int((720-(mouse_y - elf_move_window_y) + 64) / 128) * 20)] = ui.cho_tower
                if(ui.cho_tower == 1): #타워1설치
                    i = int((mouse_x - elf_move_window_x - 64) / 128) + (int((720-(mouse_y - elf_move_window_y) + 64) / 128) * 20)
                    arrow_tower = Arrow_tower(i)
                    game_world.add_object(arrow_tower, 2)
                    tile.time[i] = int(get_time())
                    ui.money -= 70 # 돈차감
                elif (ui.cho_tower == 2):  # 타워2설치
                    i = int((mouse_x - elf_move_window_x - 64) / 128) + (int((720 - (mouse_y - elf_move_window_y) + 64) / 128) * 20)
                    magic_tower = Magic_tower(i)
                    game_world.add_object(magic_tower, 2)
                    tile.time[i] = int(get_time())
                    ui.money -= 80  # 돈차감
                elif (ui.cho_tower == 3):  # 타워3설치
                    i = int((mouse_x - elf_move_window_x - 64) / 128) + (int((720 - (mouse_y - elf_move_window_y) + 64) / 128) * 20)
                    buff_tower = Buff_tower(i)
                    game_world.add_object(buff_tower, 2)
                    tile.time[i] = int(get_time())
                    ui.money -= 100  # 돈차감
            ui.left_click = 0
            ui.cho_tower = 0

        else:
            elf.handle_event(event)
コード例 #52
0
ファイル: cooking_state.py プロジェクト: kshg1324/2DGP
def handle_events():
    global cook_stack_1, cook_stack_2, cook_stack_3, cook_stack_4, cook_stack_5, cook_stack_6, cook_type, is_cooking_fail
    events = get_events()
    for event in events:
        if (event.type == SDL_KEYDOWN):
            if event.type == SDL_QUIT:
                game_framework.quit()
            elif (cook_type == 0):
                if ((event.type, event.key) == (SDL_KEYDOWN, SDLK_q)):
                    cook_type = 1
                    main_state.Money -= 5
                elif ((event.type, event.key) == (SDL_KEYDOWN, SDLK_w)):
                    cook_type = 2
                    main_state.Money -= 5
                elif ((event.type, event.key) == (SDL_KEYDOWN, SDLK_e)):
                    cook_type = 3
                    main_state.Money -= 5
                elif ((event.type, event.key) == (SDL_KEYDOWN, SDLK_r)):
                    cook_type = 4
                    main_state.Money -= 5
                elif ((event.type, event.key) == (SDL_KEYDOWN, SDLK_t)):
                    cook_type = 5
                    main_state.Money -= 5
                elif ((event.type, event.key) == (SDL_KEYDOWN, SDLK_y)):
                    cook_type = 6
                    main_state.Money -= 5
            elif (cook_type == 1):
                if ((event.type, event.key)
                        == (SDL_KEYDOWN, SDLK_o)) and cook_stack_1 == 0:
                    cook_stack_1 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_m)) and cook_stack_1 == 1:
                    cook_stack_1 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_e)) and cook_stack_1 == 2:
                    cook_stack_1 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_l)) and cook_stack_1 == 3:
                    cook_stack_1 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_e)) and cook_stack_1 == 4:
                    cook_stack_1 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_t)) and cook_stack_1 == 5:
                    cooking.cooking_sound.play()
                    main_state.food_1_stack += 1
                    cook_stack_1 = 0
                    cook_type = 0
                    game_framework.pop_state()
                else:
                    is_cooking_fail = 1
                    main_state.messeage_timer = 0
                    cook_stack_1 = 0
                    cook_type = 0
                    game_framework.pop_state()
            elif (cook_type == 2):
                if ((event.type, event.key)
                        == (SDL_KEYDOWN, SDLK_h)) and cook_stack_2 == 0:
                    cook_stack_2 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_a)) and cook_stack_2 == 1:
                    cook_stack_2 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_m)) and cook_stack_2 == 2:
                    cook_stack_2 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_b)) and cook_stack_2 == 3:
                    cook_stack_2 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_u)) and cook_stack_2 == 4:
                    cook_stack_2 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_r)) and cook_stack_2 == 5:
                    cook_stack_2 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_g)) and cook_stack_2 == 6:
                    cook_stack_2 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_e)) and cook_stack_2 == 7:
                    cook_stack_2 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_r)) and cook_stack_2 == 8:
                    cooking.cooking_sound.play()
                    main_state.food_2_stack += 1
                    cook_stack_2 = 0
                    cook_type = 0
                    game_framework.pop_state()
                else:
                    is_cooking_fail = 1
                    main_state.messeage_timer = 0
                    cook_stack_2 = 0
                    cook_type = 0
                    game_framework.pop_state()
            elif (cook_type == 3):
                if ((event.type, event.key)
                        == (SDL_KEYDOWN, SDLK_c)) and cook_stack_3 == 0:
                    cook_stack_3 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_o)) and cook_stack_3 == 1:
                    cook_stack_3 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_f)) and cook_stack_3 == 2:
                    cook_stack_3 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_f)) and cook_stack_3 == 3:
                    cook_stack_3 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_e)) and cook_stack_3 == 4:
                    cook_stack_3 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_e)) and cook_stack_3 == 5:
                    cooking.cooking_sound.play()
                    main_state.food_3_stack += 1
                    cook_stack_3 = 0
                    cook_type = 0
                    game_framework.pop_state()
                else:
                    is_cooking_fail = 1
                    main_state.messeage_timer = 0
                    cook_stack_3 = 0
                    cook_type = 0
                    game_framework.pop_state()
            elif (cook_type == 4):
                if ((event.type, event.key)
                        == (SDL_KEYDOWN, SDLK_p)) and cook_stack_4 == 0:
                    cook_stack_4 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_i)) and cook_stack_4 == 1:
                    cook_stack_4 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_z)) and cook_stack_4 == 2:
                    cook_stack_4 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_z)) and cook_stack_4 == 3:
                    cook_stack_4 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_a)) and cook_stack_4 == 4:
                    cooking.cooking_sound.play()
                    main_state.food_4_stack += 1
                    cook_stack_4 = 0
                    cook_type = 0
                    game_framework.pop_state()
                else:
                    is_cooking_fail = 1
                    main_state.messeage_timer = 0
                    cook_stack_4 = 0
                    cook_type = 0
                    game_framework.pop_state()
            elif (cook_type == 5):
                if ((event.type, event.key)
                        == (SDL_KEYDOWN, SDLK_f)) and cook_stack_5 == 0:
                    cook_stack_5 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_i)) and cook_stack_5 == 1:
                    cook_stack_5 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_s)) and cook_stack_5 == 2:
                    cook_stack_5 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_h)) and cook_stack_5 == 3:
                    cooking.cooking_sound.play()
                    main_state.food_5_stack += 1
                    cook_stack_5 = 0
                    cook_type = 0
                    game_framework.pop_state()
                else:
                    is_cooking_fail = 1
                    main_state.messeage_timer = 0
                    cook_stack_5 = 0
                    cook_type = 0
                    game_framework.pop_state()
            elif (cook_type == 6):
                if ((event.type, event.key)
                        == (SDL_KEYDOWN, SDLK_p)) and cook_stack_6 == 0:
                    cook_stack_6 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_u)) and cook_stack_6 == 1:
                    cook_stack_6 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_d)) and cook_stack_6 == 2:
                    cook_stack_6 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_d)) and cook_stack_6 == 3:
                    cook_stack_6 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_i)) and cook_stack_6 == 4:
                    cook_stack_6 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_n)) and cook_stack_6 == 5:
                    cook_stack_6 += 1
                elif ((event.type, event.key)
                      == (SDL_KEYDOWN, SDLK_g)) and cook_stack_6 == 6:
                    cooking.cooking_sound.play()
                    main_state.food_6_stack += 1
                    cook_stack_6 = 0
                    cook_type = 0
                    game_framework.pop_state()
                else:
                    is_cooking_fail = 1
                    main_state.messeage_timer = 0
                    cook_stack_6 = 0
                    cook_type = 0
                    game_framework.pop_state()
コード例 #53
0
def handle_events():
    global player
    global is_collision_box_on, is_invincibility_mode_on
    global bottom_UI

    events = get_events()
    for event in events:

        if event.type == SDL_QUIT:
            game_framework.quit()

        elif event.type == SDL_KEYDOWN:
            if event.key == SDLK_ESCAPE:
                game_framework.quit()
            elif event.key == SDLK_w:
                if game_world.screen_scroll_y == 0:
                    game_world.screen_scroll_y = 1
                elif game_world.screen_scroll_y == -1:
                    game_world.screen_scroll_y = 0
            elif event.key == SDLK_a:
                if game_world.screen_scroll_x == 0:
                    game_world.screen_scroll_x = -1
                elif game_world.screen_scroll_x == 0:
                    game_world.screen_scroll_x = 1
            elif event.key == SDLK_s:
                if game_world.screen_scroll_y == 0:
                    game_world.screen_scroll_y = -1
                elif game_world.screen_scroll_y == 1:
                    game_world.screen_scroll_y = 0
            elif event.key == SDLK_d:
                if game_world.screen_scroll_x == 0:
                    game_world.screen_scroll_x = 1
                elif game_world.screen_scroll_x == -1:
                    game_world.screen_scroll_x = 0
            elif event.key == SDLK_r:
                if is_collision_box_on == True:
                    is_collision_box_on = False
                elif is_collision_box_on == False:
                    is_collision_box_on = True
            elif event.key == SDLK_1:
                if is_invincibility_mode_on == True:
                    is_invincibility_mode_on = False
                elif is_invincibility_mode_on == False:
                    is_invincibility_mode_on = True

        elif event.type == SDL_KEYUP:
            if event.key == SDLK_w:
                if game_world.screen_scroll_y == 0:
                    game_world.screen_scroll_y = -1
                elif game_world.screen_scroll_y == 1:
                    game_world.screen_scroll_y = 0
            elif event.key == SDLK_a:
                if game_world.screen_scroll_x == 0:
                    game_world.screen_scroll_x = 1
                elif game_world.screen_scroll_x == -1:
                    game_world.screen_scroll_x = 0
            elif event.key == SDLK_s:
                if game_world.screen_scroll_y == 0:
                    game_world.screen_scroll_y = 1
                elif game_world.screen_scroll_y == -1:
                    game_world.screen_scroll_y = 0
            elif event.key == SDLK_d:
                if game_world.screen_scroll_x == 0:
                    game_world.screen_scroll_x = -1
                elif game_world.screen_scroll_x == 1:
                    game_world.screen_scroll_x = 0

        if event.type == SDL_MOUSEMOTION:
            # 마우스 좌표 업데이트
            game_world.update_mouse_point(event.x, event.y)

        if event.type == SDL_MOUSEBUTTONDOWN:
            # bottom ui 충돌체크
            bottom_UI_collision_check_result = bottom_UI.collision_check(
                event.x, event.y)

            #미니맵
            if bottom_UI_collision_check_result == 1:
                pass
            #UI
            elif bottom_UI_collision_check_result == 2:
                pass
            else:
                game_world.cursor.get_events()
                player.get_events()
コード例 #54
0
 def exit(menu, event):
     if event == SPACE:
         game_framework.quit()
コード例 #55
0
def handle_events():
    global x, note_1s_extreme, note_2s_extreme, note_3s_extreme, note_4s_extreme, note_5s_extreme, note_6s_extreme, note_7s_extreme, machine_extreme
    global score_1

    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
            game_framework.change_state(title_state_extreme)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_SPACE:
            x = 203
            effect_1.draw()
            update_canvas()
            delay(0.01)
            for note_4_extreme in note_4s_extreme:
                if collide(machine_extreme, note_4_extreme):
                    effect_2.draw()
                    #note_1.remove()
                    score_1 += 100
                    print(score_1)
                    update_canvas()
                    delay(0.01)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_s:
            x = 370
            effect_1.draw()
            update_canvas()
            delay(0.01)
            for note_7_extreme in note_7s_extreme:
                if collide(note_7_extreme, machine_extreme):
                    effect_2.draw()
                    #note_1.remove()
                    score_1 += 100
                    print(score_1)
                    update_canvas()
                    delay(0.01)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_d:
            x = 320
            effect_1.draw()
            update_canvas()
            delay(0.01)
            for note_6_extreme in note_6s_extreme:
                if collide(note_6_extreme, machine_extreme):
                    effect_2.draw()
                    #note_1.remove()
                    score_1 += 100
                    print(score_1)
                    update_canvas()
                    delay(0.01)

        elif event.type == SDL_KEYDOWN and event.key == SDLK_f:
            x = 266
            effect_1.draw()
            update_canvas()
            delay(0.01)
            for note_5_extreme in note_5s_extreme:
                if collide(note_5_extreme, machine_extreme):
                    effect_2.draw()
                    #note_1.remove()
                    score_1 += 100
                    print(score_1)
                    update_canvas()
                    delay(0.01)

        elif event.type == SDL_KEYDOWN and event.key == SDLK_j:
            x = 140
            effect_1.draw()
            update_canvas()
            delay(0.01)
            for note_3_extreme in note_3s_extreme:
                if collide(
                        note_3_extreme,
                        machine_extreme,
                ):
                    effect_2.draw()
                    #note_1.remove()
                    score_1 += 100
                    print(score_1)
                    update_canvas()
                    delay(0.01)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_k:
            x = 87
            effect_1.draw()
            update_canvas()
            delay(0.01)
            for note_2_extreme in note_2s_extreme:
                if collide(note_2_extreme, machine_extreme):
                    effect_2.draw()
                    #note_1.remove()
                    score_1 += 100
                    print(score_1)
                    update_canvas()
                    delay(0.01)
        elif event.type == SDL_KEYDOWN and event.key == SDLK_l:
            x = 37
            effect_1.draw()
            update_canvas()
            delay(0.01)
            for note_1_extreme in note_1s_extreme:
                if collide(note_1_extreme, machine_extreme):
                    effect_2.draw()
                    #note_1.remove()
                    score_1 += 100
                    print(score_1)
                    update_canvas()
                    delay(0.01)
コード例 #56
0
def handle_events():
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
コード例 #57
0
def handle_events():
    events = get_events()
    for key in events:
        if key.type == SDL_QUIT: gf.quit()
        elif (key.type, key.key) == (SDL_KEYDOWN, SDLK_ESCAPE): gf.pop_state()
コード例 #58
0
def handle_events():
    global image, size_x, size_y, mx, my, x, y, inspeed, stop, mode, kind
    events = get_events()
    for event in events:
        if event.type == SDL_KEYDOWN:
            if (event.key == SDLK_t):
                # tile selection
                mode = 't'
                if (kind == 1):
                    image = load_image('basic_tile.png')
                    size_x = 100
                    size_y = 100
                elif (kind == 2):
                    image = load_image('tile2.png')
                    size_x = 70
                    size_y = 20
            if event.key == SDLK_o:
                # obstacle selection
                mode = 'o'
                if (kind == 1):
                    image = load_image('triangle_obstacle.png')
                    size_x = 40
                    size_y = 40
            if (event.key == SDLK_1):
                kind = 1
                if (mode == 't'):
                    image = load_image('basic_tile.png')
                    size_x = 100
                    size_y = 100
                elif (mode == 'o'):
                    image = load_image('triangle_obstacle.png')
                    size_x = 40
                    size_y = 40
            if event.key == SDLK_2:
                kind = 2
                if (mode == 't'):
                    image = load_image('tile2.png')
                    size_x = 70
                    size_y = 20
            if event.key == SDLK_3:
                kind = 3
            if event.key == SDLK_BACKSPACE:
                DeleteBlock()
            if event.key == SDLK_ESCAPE:
                game_framework.quit()
            if event.key == SDLK_s:
                inspeed = 0
                stop = True
            if event.key == SDLK_r:
                inspeed = speed
                stop = False
            if event.key == SDLK_m:
                game_framework.change_state(main_state)
        elif event.type == SDL_MOUSEBUTTONDOWN:
            x = event.x
            y = 510 - event.y - 1
            Create()
        elif event.type == SDL_MOUSEMOTION:
            mx = event.x
            my = 510 - event.y - 1

    pass
コード例 #59
0
ファイル: end_state.py プロジェクト: gic91/2DGP_project
def update():
    global Time_count, Menu
    Time_count += 0.1
    if Time_count >= 40:
        end_sound.stop()
        game_framework.quit()
コード例 #60
0
def handle_events():
    global pl1, pl2
    events = get_events()
    for event in events:
        if event.type == SDL_QUIT:
            game_framework.quit()
        elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
            game_framework.change_state(title_state)
        if event.type == SDL_KEYDOWN and event.key == SDLK_c and pl1.status != 5:
            pl1.drawc += 1
            pl2.drawc2 += 1
            ground.drawc += 1
        if event.type == SDL_KEYUP and event.key == SDLK_c and pl1.status != 5:
            pl1.drawc -= 1
            pl2.drawc2 -= 1
            ground.drawc -= 1
        if event.type == SDL_KEYDOWN and event.key == SDLK_j and pl1.status != 5:
            if pl1.x + 30 >= pl2.x2:
                pl1.x += 0
            else:
                pl1.x += 7
        elif event.type == SDL_KEYDOWN and event.key == SDLK_g and pl1.status != 5:
            pl1.x -= 7
        elif event.type == SDL_KEYDOWN and event.key == SDLK_d and pl1.punchc == 0 and pl1.kickc == 0 and pl1.status != 5 and pl1.jumpc == 0 and pl1.energyc == 0 and pl1.stepc == 0 and pl1.touchc == 0:
            pl1.status = 1
            if pl1.dashc == 1:
                pl1.frame = 0
            if pl1.frame <= 3 and pl1.dashc > 0:
                pl1.status = 1
        elif event.type == SDL_KEYDOWN and event.key == SDLK_a and pl1.kickc == 0 and pl1.dashc == 0 and pl1.status != 5 and pl1.jumpc == 0 and pl1.energyc == 0 and pl1.stepc == 0 and pl1.touchc == 0:
            if collide(pl1, pl2):
                pl2.status2 = 4
                pl2.frame2 = 0
                pl1.status = 2
                if pl1.punchc == 1:
                    pl1.frame = 0
                if pl1.frame <= 6:
                    pl1.status = 2
            else:
                pl1.status = 2
                if pl1.punchc == 1:
                    pl1.frame = 0
                if pl1.frame <= 6 and pl1.punchc > 0:
                    pl1.status = 2
        elif event.type == SDL_KEYDOWN and event.key == SDLK_s and pl1.dashc == 0 and pl1.punchc == 0 and pl1.status != 5 and pl1.jumpc == 0 and pl1.energyc == 0 and pl1.stepc == 0 and pl1.touchc == 0:
            if collide(pl1, pl2):
                pl2.status2 = 4
                pl2.frame2 = 0
                pl1.status = 3
                if pl1.kickc == 1:
                    pl1.frame = 0
                if pl1.frame <= 4:
                    pl1.status = 3
            else:
                pl1.status = 3
                if pl1.kickc == 1:
                    pl1.frame = 0
                if pl1.kickc > 0:
                    pl1.status = 3
        elif event.type == SDL_KEYDOWN and event.key == SDLK_y and pl1.dashc == 0 and pl1.punchc == 0 and pl1.status != 5 and pl1.kickc == 0 and pl1.energyc == 0 and pl1.stepc == 0 and pl1.touchc == 0:
            pl1.status = 6
            if pl1.jumpc == 1:
                pl1.frame = 0
            if pl1.jumpc > 0:
                pl1.status = 6
        elif event.type == SDL_KEYDOWN and event.key == SDLK_w and pl1.dashc == 0 and pl1.punchc == 0 and pl1.status != 5 and pl1.kickc == 0 and pl1.jumpc == 0 and pl1.stepc == 0 and pl1.touchc == 0:
            pl1.exsound.play()
            pl1.status = 7
            if pl1.energyc == 1:
                pl1.frme = 0
            if pl1.energyc > 0:
                pl1.status = 7
        elif event.type == SDL_KEYDOWN and event.key == SDLK_q and pl1.dashc == 0 and pl1.punchc == 0 and pl1.status != 5 and pl1.kickc == 0 and pl1.jumpc == 0 and pl1.energyc == 0 and pl1.touchc == 0:
            pl1.status = 9
            if pl1.stepc == 1:
                pl1.frame = 0
            if pl1.stepc > 0:
                pl1.status = 9
        elif hp1.hp < 0 or pl1.x < 70:
            pl1.status = 5

        if event.type == SDL_KEYDOWN and event.key == SDLK_RIGHT:
            pl2.x2 += 7
        elif event.type == SDL_KEYDOWN and event.key == SDLK_LEFT:
            if pl2.x2 - 30 <= pl1.x:
                pl2.x2 -= 0
            else:
                pl2.x2 -= 7
        elif event.type == SDL_KEYDOWN and event.key == SDLK_b and pl2.punchc == 0 and pl2.kickc == 0 and pl2.jumpc == 0 and pl2.sjumpc == 0 and pl2.stepc == 0 and pl2.gomuc == 0 and pl2.touchc == 0:
            pl2.status2 = 1
            if pl2.dashc == 1:
                pl2.frame2 = 0
            if pl2.frame2 <= 3 and pl2.dashc > 0:
                pl2.status2 = 1

        elif event.type == SDL_KEYDOWN and event.key == SDLK_n and pl2.dashc == 0 and pl2.kickc == 0 and pl2.jumpc == 0 and pl2.sjumpc == 0 and pl2.stepc == 0 and pl2.gomuc == 0 and pl2.touchc == 0:
            if collide(pl1, pl2):
                pl1.status = 4
                pl1.frame = 0
                pl2.status2 = 2
                if pl2.punchc == 1:
                    pl2.frame2 = 0
                if pl2.frame2 < 6:
                    pl2.status2 = 2
            else:
                pl2.status2 = 2
                if pl2.punchc == 1:
                    pl2.frame2 = 0
                if pl2.frame2 < 6 and pl2.punchc > 0:
                    pl2.status2 = 2

        elif event.type == SDL_KEYDOWN and event.key == SDLK_m and pl2.dashc == 0 and pl2.punchc == 0 and pl2.jumpc == 0 and pl2.sjumpc == 0 and pl2.stepc == 0 and pl2.gomuc == 0 and pl2.touchc == 0:
            if collide(pl1, pl2):
                pl1.status = 4
                pl1.frame = 0
                pl2.status2 = 3
                if pl2.kickc == 1:
                    pl2.frame2 = 0
                if pl2.frame2 <= 4:
                    pl2.status2 = 3
            else:
                pl2.status2 = 3
                if pl2.kickc == 1:
                    pl2.frame2 = 0
                if pl2.kickc > 0:
                    pl2.status2 = 3
        elif event.type == SDL_KEYDOWN and event.key == SDLK_UP and pl2.dashc == 0 and pl2.punchc == 0 and pl2.kickc == 0 and pl2.sjumpc == 0 and pl2.stepc == 0 and pl2.gomuc == 0 and pl2.touchc == 0:
            pl2.status2 = 6
            if pl2.jumpc == 1:
                pl2.frame2 = 0
            if pl2.jumpc > 0:
                pl2.status2 = 6
        elif event.type == SDL_KEYDOWN and event.key == SDLK_l and pl2.dashc == 0 and pl2.punchc == 0 and pl2.kickc == 0 and pl2.sjumpc == 0 and pl2.stepc == 0 and pl2.jumpc == 0 and pl2.touchc == 0:
            pl2.status2 = 7
            if pl2.gomuc == 1:
                pl2.frame2 = 0
            if pl2.gomuc > 0:
                pl2.status2 = 7

        elif event.type == SDL_KEYDOWN and event.key == SDLK_k and pl2.dashc == 0 and pl2.punchc == 0 and pl2.kickc == 0 and pl2.jumpc == 0 and pl2.stepc == 0 and pl2.gomuc == 0 and pl2.touchc == 0:
            pl2.status2 = 8
            if pl2.sjumpc == 1:
                pl2.frame2 = 0
            if pl2.sjumpc > 0:
                pl2.status2 = 8
        elif event.type == SDL_KEYDOWN and event.key == SDLK_v and pl2.dashc == 0 and pl2.punchc == 0 and pl2.kickc == 0 and pl2.jumpc == 0 and pl2.sjumpc == 0 and pl2.gomuc == 0 and pl2.touchc == 0:
            pl2.status2 = 9
            if pl2.stepc == 1:
                pl2.frame2 = 0
            if pl2.stepc > 0:
                pl2.status2 = 9
        elif hp2.hp2 < 0 or pl2.x2 > 910:
            pl2.status2 = 5