Python pygame 模块,K_p() 实例源码

我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用pygame.K_p()

项目:solarwolf    作者:pygame    | 项目源码 | 文件源码
def event(self, e):
        if e.type == pygame.KEYDOWN:
            #What are you doing? Looking for Cheats?
            #shame shame
            if input.Cheatstring == "wheat":
                snd.play('gameover')
                snd.play('delete')
                game.player.cheater = 1
                self.textobjs.append(objtext.Text('"wheat" Cheat: Extra Lives'))
                self.lives_left += 10
                self.hud.drawlives(self.lives_left)
            elif input.Cheatstring == "shred":
                snd.play('gameover')
                snd.play('delete')
                game.player.cheater = 1
                self.grabbedboxes = 0 #less not give any fake complements
                self.levelnum = 49
                self.textobjs.append(objtext.Text('"shred" Cheat: Warp Level 50'))
                self.changestate('levelend')
            if e.key == pygame.K_PAUSE or e.key == pygame.K_p:
                if game.handler is self: #just in case some "help" gets in first?
                    game.handler = gamepause.GamePause(self)
项目:OfMagesAndMagic    作者:munnellg    | 项目源码 | 文件源码
def handle_event(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                self.root.trigger_exit_to_main()
            elif event.key == pygame.K_p:
                self.toggle_pause()
            elif not self.paused:
                if event.key == pygame.K_SPACE:
                    self.skip_turn = True
                elif event.key == pygame.K_RETURN:
                    self.skip_game = True
                elif event.key in [pygame.K_LEFT, pygame.K_1]:
                    self.parent.battle.award_victory(1)
                    self.skip_game = True
                elif event.key in [pygame.K_RIGHT, pygame.K_2]:
                    self.parent.battle.award_victory(2)
                    self.skip_game = True
项目:renpy-shader    作者:bitsawer    | 项目源码 | 文件源码
def update(self, frameNumber, editor):
        for event, pos in editor.context.events:
            if event.type == pygame.KEYDOWN:
                bone = editor.getActiveBone()
                key = event.key
                if key == pygame.K_i:
                    if bone:
                        if event.mod & pygame.KMOD_ALT:
                            if bone.name in self.frames[frameNumber].keys:
                                del self.frames[frameNumber].keys[bone.name]
                        else:
                            key = self.frames[frameNumber].getBoneKey(bone.name)
                            copyKeyData(bone, key)
                        self.dirty = True
                elif key == pygame.K_o:
                    if bone:
                        data = self.getBoneData(bone.name)
                        data.repeat = not data.repeat
                        self.dirty = True
                elif key == pygame.K_p:
                    if bone:
                        data = self.getBoneData(bone.name)
                        data.reversed = not data.reversed
                        self.dirty = True
项目:alienInvasionGame    作者:NilanjanaLodh    | 项目源码 | 文件源码
def game_over(self):
        print("game over")
        font = pygame.font.Font(None, 100)
        text = font.render("GAME OVER", True, WHITE)
        text_rect = text.get_rect()
        text_x = self.screen.get_width() // 2 - text_rect.width / 2
        text_y = self.screen.get_height() // 2 - text_rect.height / 2
        self.screen.blit(text, [text_x, text_y])
        pygame.display.flip()
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_q:
                        sys.exit()
                    elif event.key == pygame.K_p:
                        self.restart_game()
项目:alien_invasion    作者:samnew    | 项目源码 | 文件源码
def check_keydown_events(event, ai_settings, screen, stats, sb, ship, aliens, bullets):
    """????"""
    if event.key == pygame.K_RIGHT:
        ship.moving_right = True
    if event.key == pygame.K_LEFT:
        ship.moving_left = True
    elif event.key == pygame.K_SPACE:
        fire_bullet(ai_settings, screen, ship, bullets)
    elif event.key == pygame.K_q:
            stats.save_high_score()
            sys.exit() 
    elif event.key == pygame.K_p and not stats.game_active:
        start_game(ai_settings, screen, stats, sb, ship, aliens, bullets)
项目:cs6244_motionplanning    作者:chenmin1107    | 项目源码 | 文件源码
def keyboard_loop(self):
        while not rospy.is_shutdown():
            acc = 0
            yaw = 0

            keys = pygame.key.get_pressed()
            for event in pygame.event.get():
                if event.type==pygame.QUIT:sys.exit()

            if(keys[pygame.K_s]):
                self.send_highway_start(1)

            if(keys[pygame.K_t]):
                self.send_highway_start(2)

            if(keys[pygame.K_UP]):
                acc = self.acc
            elif(keys[pygame.K_DOWN]):
                acc = -self.acc
            if(keys[pygame.K_LEFT]):
                yaw = self.yaw
            elif(keys[pygame.K_RIGHT]):
                yaw = -self.yaw
            if(keys[pygame.K_r]):
                state = 1
                self.send_record_state(state)
            elif(keys[pygame.K_q]):
                state = 2
                self.send_record_state(state)
            elif(keys[pygame.K_p]):
                state = 0
                self.send_record_state(state)

            self.send_control(acc, yaw)
            self.rate.sleep()
项目:Write-Chinese-Calligraphy-with-Palletizing-Robot-and-SVG-Files    作者:amjltc295    | 项目源码 | 文件源码
def generate_path(self, pointList, up_Z=-1, down_Z=-1):
        """ Generate path for a line of the image. """
        count = 0
        toEnd = NOT_ADJUST_THICKNESS
        start_point = self.robotCoorToPygameCoor( pointList[0] )
        for (x, y) in pointList:
            upZ = self.up_z if up_Z == -1 else up_Z
            downZ = self.down_z if down_Z == -1 else down_Z
            if_draw = True

            end_point = self.robotCoorToPygameCoor( (x, y) )
            pygame.draw.line(self.screen, BLACK, start_point, end_point, PYGAME_LINE_WIDTH)
            pygame.display.update()
            if not toEnd:
                pressed_key = self.pygame_wait()
                if (pressed_key == pygame.K_a):
                    downZ -= Z_THICK_ADJUST
                    pygame.draw.line(self.screen, BLACK, start_point, end_point, PYGAME_THICK_LINE_WIDTH)
                    pygame.display.update()
                elif (pressed_key == pygame.K_d):
                    downZ += Z_THIN_ADJUST
                    pygame.draw.line(self.screen, WHITE, start_point, end_point, PYGAME_LINE_WIDTH)
                    pygame.draw.line(self.screen, BLACK, start_point, end_point, PYGAME_THIN_LINE_WIDTH)
                elif (pressed_key == pygame.K_e):
                    toEnd = True
                elif (pressed_key == pygame.K_p):
                    pygame.draw.line(self.screen, WHITE, start_point, end_point, PYGAME_LINE_WIDTH)
                    if_draw = False
            start_point = end_point

            if if_draw:
                """ Move to the stating point. """
                if count == 0:
                    self.create_robot_point(x, y, upZ)
                self.create_robot_point(x, y, downZ)
                """ Move to the last point. """
                if count == len(pointList) -1:
                    self.create_robot_point(x, y, upZ)
            count += 1
项目:CritterEvolution    作者:apockill    | 项目源码 | 文件源码
def updateKeys(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key == K_r:
                keys["r"] = True
            elif event.key == pygame.K_e:
                keys["e"] = True
            elif event.key == pygame.K_p:
                keys["p"] = True
            elif event.key == pygame.K_n:
                keys["n"] = True

        if event.type == pygame.KEYUP:
            if event.key == pygame.K_r:
                keys["r"] = False
            elif event.key == pygame.K_e:
                keys["e"] = False
            elif event.key == pygame.K_p:
                keys["p"] = False
            elif event.key == pygame.K_n:
                keys["n"] = False

        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:  # Left Mouse
                keys["mouseL"] = True
            if event.button == 3:  # Right Mouse
                keys["mouseR"] = True

        if event.type == pygame.MOUSEBUTTONUP:
            if event.button == 1:  # Left Mouse
                keys["mouseL"] = False
            if event.button == 3:  # Right Mouse
                keys["mouseR"] = False

        keys["mousePos"] =  pygame.mouse.get_pos()
项目:pytetris    作者:catalinc    | 项目源码 | 文件源码
def process_input(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if self.state.paused:
                    if event.key == pygame.K_r:
                        self.state.paused = False
                if self.state.game_over:
                    if event.key == pygame.K_r:
                        self.state = State(self.ROWS, self.COLS)
                    if event.key == pygame.K_ESCAPE:
                        sys.exit()
                if self.state.running:
                    if event.key == pygame.K_DOWN:
                        self.state.move_piece(board.DIRECTION_DOWN)
                    if event.key == pygame.K_LEFT:
                        self.state.move_piece(board.DIRECTION_LEFT)
                    if event.key == pygame.K_RIGHT:
                        self.state.move_piece(board.DIRECTION_RIGHT)
                    if event.key == pygame.K_x:
                        self.state.rotate_piece()
                    if event.key == pygame.K_z:
                        self.state.rotate_piece(True)
                    if event.key == pygame.K_SPACE:
                        self.state.drop_piece()
                    if event.key == pygame.K_p:
                        self.state.paused = True
项目:c64-remakes    作者:DealPete    | 项目源码 | 文件源码
def get_input():
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()
        if event.type == pygame.KEYUP and event.key == pygame.K_DOWN \
            and state.state == "falling":
            state.state = "playing"
        if event.type == pygame.KEYDOWN:
            if state.state == "playing":
                if event.key == pygame.K_p:
                    state.state = "paused"
                if event.key == pygame.K_LEFT:
                    if valid(state.X - 1, state.Y, state.piece.form):
                        state.X -= 1
                if event.key == pygame.K_RIGHT:
                    if valid(state.X + 1, state.Y, state.piece.form):
                        state.X += 1
                if event.key == pygame.K_UP or event.key == pygame.K_SPACE:
                    new_form = Pentomino.rotate_right(state.piece.form,
                        state.piece.size)
                    if valid(state.X, state.Y, new_form):
                        state.piece.form = new_form
                if event.key == pygame.K_DOWN:
                    state.state = "falling"
            elif state.state == "paused":
                if event.key == pygame.K_p:
                    state.state = "playing"
            elif state.state == "lost":
                if event.key in [pygame.K_SPACE, pygame.K_RETURN]:
                    state.start_game()
项目:gluttonous_snake    作者:tandf    | 项目源码 | 文件源码
def check_key_down(event, stats, snake_head, snake_parts, foods):
    if event.key == pygame.K_ESCAPE:
        sys.exit()
    elif event.key == pygame.K_p:
        if stats.game_active:
            if stats.pause_game:
                stats.pause_game = False
            else:
                stats.pause_game = True
        else:
            stats.game_active = True
            stats.first_start = False

            initialize_game(stats, snake_head, snake_parts, foods)

    elif not stats.moved and not stats.pause_game:
        if event.key == pygame.K_s:
            if snake_head.facing != "up":
                snake_head.facing = "down"
                stats.moved = True
        elif event.key == pygame.K_w:
            if snake_head.facing != "down":
                snake_head.facing = "up"
                stats.moved = True
        elif event.key == pygame.K_a:
            if snake_head.facing != "right":
                snake_head.facing = "left"
                stats.moved = True
        elif event.key == pygame.K_d:
            if snake_head.facing != "left":
                snake_head.facing = "right"
                stats.moved = True
项目:TetrisAI    作者:bbergrobots    | 项目源码 | 文件源码
def eventCheck( self ):
        for event in gui.event.get( ):
            if event.type == gui.QUIT:
                self.abort = True
            if event.type == gui.KEYDOWN:
                if event.key == gui.K_ESCAPE:
                    gui.event.post( gui.event.Event( gui.QUIT ) )
                if event.key == gui.K_LEFT:
                    self.cTile.decX( )
                if event.key == gui.K_RIGHT:
                    self.cTile.incX( )
                if event.key == gui.K_DOWN:
                    self.cTile.incY( )
                if event.key == gui.K_COMMA:
                    self.cTile.rotACW( )
                if event.key == gui.K_PERIOD:
                    self.cTile.rotCW( )
                if event.key == gui.K_RETURN:
                    self.cTile.drop( )
                if event.key == gui.K_p:
                    self.time.incSpeed( )
                if event.key == gui.K_o:
                    self.time.decSpeed( )
                if event.key == gui.K_a:
                    self.aiState = not self.aiState
            if event.type == gui.MOUSEBUTTONUP:
                if event.button == 1:
                    if gui.Rect( 480, 630, 101, 30 ).collidepoint( event.pos ):
                        self.infoMode = 0
                    if gui.Rect( 580, 630, 101, 30 ).collidepoint( event.pos ):
                        self.infoMode = 1
                    if gui.Rect( 680, 630, 101, 30 ).collidepoint( event.pos ):
                        self.infoMode = 2
                    if self.infoMode == 1:
                        if gui.Rect( 630, 405, 39, 30 ).collidepoint( event.pos ):
                            self.genomeScreen[ 0 ] = max( 0, self.genomeScreen[ 0 ]-1 )
                        if gui.Rect( 668, 405, 39, 30 ).collidepoint( event.pos ):
                            self.genomeScreen[ 0 ] = min( len( self.ai.population.generations )-1, self.genomeScreen[ 0 ]+1 )
                        if gui.Rect( 706, 405, 39, 30 ).collidepoint( event.pos ):
                            self.genomeScreen[ 1 ] = max( -1, self.genomeScreen[ 1 ]-1 )
                        if gui.Rect( 744, 405, 39, 30 ).collidepoint( event.pos ):
                            self.genomeScreen[ 1 ] = min( 39, self.genomeScreen[ 1 ]+1 )
项目:pygame-event-calendar-and-pianobar    作者:scottpcrawford    | 项目源码 | 文件源码
def __init__(self, screen):
        self.done = False
        self.screen = screen
        self.clock = pg.time.Clock()
        self.fps = 60
        self.RADIO_STATION = '39' # or 1591330390268116913
        self.BACKGROUND_IMG = 'img/bg/day_tree.png'
        self.SCREEN_WIDTH = SCREEN_WIDTH
        self.SCREEN_HEIGHT = SCREEN_HEIGHT
        self.RADIO_RUNNING = False
        self.RESTING = False
        self.SHOWGOALS = False
        self.grass = 'img/bg/day_grass.png'
        self.day_clouds = pg.sprite.RenderUpdates()
        self.night_clouds = pg.sprite.RenderUpdates()
        self.all_sprites_list = pg.sprite.RenderUpdates()
        self.quote_list = return_list('quotes.txt')
        self.contributions = return_list('contributions.txt')
        self.goals = return_list('goals.txt')
        self.weather = Weather()
        self.weather_observation = {}
        self.phrase = random.choice(self.quote_list)
        #self.cwd = os.getcwd() #windows
        self.cwd = '/home/pi/.config/pianobar' # linux
        ## DAIYE COLORS ###
        self.HEADER_COLOR = pg.Color('black')
        self.CONTENT_COLOR = pg.Color('indianred4')
        self.BG_COLOR = pg.Color('skyblue')
        self.current_events = []
        self.upcoming_events = []

        # User events:
        self.UPDATECALENDAR = pg.USEREVENT + 1
        self.UPDATEQUOTE = pg.USEREVENT + 2
        self.NIGHTRADIO = pg.USEREVENT + 3
        self.CHANGESTATE = pg.USEREVENT + 4
        self.UPDATEWEATHER = pg.USEREVENT + 5
        #self.SHOWGOALS = pg.USEREVENT + 6
        pg.time.set_timer(self.UPDATECALENDAR, 60000) #update calendar every 60 seconds     
        pg.time.set_timer(self.UPDATEQUOTE, 20000) #update quote every 20 seconds
        pg.time.set_timer(self.NIGHTRADIO,300000) # check for relaxation radio time
        pg.time.set_timer(self.UPDATEWEATHER, 600000)
        pg.time.set_timer(self.CHANGESTATE, 300000)
        #pg.time.set_timer(self.SHOWGOALS, 6000)

        self.DAYGFX = load_gfx(os.path.join("img", "clouds", "day"))
        self.NTGFX = load_gfx(os.path.join("img", "clouds", "night"))
        self.BGIMG  = load_gfx(os.path.join('img', 'bg'))
        self.keymap_dict = {pg.K_n: 'n', pg.K_PLUS: '+', pg.K_KP_PLUS: '+', pg.K_EQUALS: '+', pg.K_MINUS: '-', pg.K_KP_MINUS: '-', 
                            pg.K_p: 'p', pg.K_SPACE: 'p', pg.K_q: 'q', pg.K_r: 'r', pg.K_s: 's', pg.K_1: 's6\n', pg.K_2: 's4\n', 
                            pg.K_3: 's15\n', pg.K_4: 's25\n', pg.K_5: 's48\n', pg.K_6: 's37\n', pg.K_7: 's52\n', pg.K_8: 's16\n'}
项目:c64-remakes    作者:DealPete    | 项目源码 | 文件源码
def get_input():
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()
        if event.type == pygame.KEYUP and event.key == pygame.K_s:
            state.falling[0] = False
        if event.type == pygame.KEYUP and event.key == pygame.K_DOWN:
            state.falling[1] = False
        if event.type == pygame.KEYDOWN:
            if state.state == "playing":
                if event.key == pygame.K_p:
                    state.state = "paused"
                if event.key == pygame.K_a:
                    if valid(state.X[0] - 1, state.Y[0], state.piece[0].form, 0):
                        state.X[0] -= 1
                if event.key == pygame.K_d:
                    if valid(state.X[0] + 1, state.Y[0], state.piece[0].form, 0):
                        state.X[0] += 1
                if event.key == pygame.K_LEFT:
                    if valid(state.X[1] - 1, state.Y[1], state.piece[1].form, 1):
                        state.X[1] -= 1
                if event.key == pygame.K_RIGHT:
                    if valid(state.X[1] + 1, state.Y[1], state.piece[1].form, 1):
                        state.X[1] += 1
                if event.key == pygame.K_w:
                    new_form = Polyomino.rotate_right(state.piece[0].form,
                        state.piece[0].size)
                    if valid(state.X[0], state.Y[0], new_form, 0):
                        state.piece[0].form = new_form
                if event.key == pygame.K_UP:
                    new_form = Polyomino.rotate_right(state.piece[1].form,
                        state.piece[1].size)
                    if valid(state.X[1], state.Y[1], new_form, 1):
                        state.piece[1].form = new_form
                if event.key == pygame.K_s:
                    state.falling[0] = True
                if event.key == pygame.K_DOWN:
                    state.falling[1] = True
            elif state.state == "paused":
                if event.key == pygame.K_p:
                    state.state = "playing"
            elif state.state == "entering high score":
                if event.key == pygame.K_BACKSPACE and state.cursorpos > 0:
                    state.cursorpos -= 1
                    state.hiscores[state.scorepos][0] = \
                        state.hiscores[state.scorepos][0][:state.cursorpos]
                elif event.key == pygame.K_RETURN:
                    scorefile = open("hiscores_duo.csv", "w")
                    writer = csv.writer(scorefile, dialect = csv.unix_dialect)
                    for row in state.hiscores:
                        writer.writerow(row)
                    scorefile.close()
                    state.start_game()
                elif (event.unicode.isalpha() or event.key == pygame.K_SPACE) \
                    and state.cursorpos < INFO_WIDTH - 3 - len(str(state.score)):
                    state.hiscores[state.scorepos][0] = \
                        state.hiscores[state.scorepos][0][:state.cursorpos] \
                        + event.unicode
                    state.cursorpos += 1
            elif state.state == "lost":
                if event.key in [pygame.K_SPACE, pygame.K_RETURN]:
                    state.start_game()
项目:c64-remakes    作者:DealPete    | 项目源码 | 文件源码
def get_input():
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()
        if event.type == pygame.KEYUP and event.key == pygame.K_DOWN \
            and state.state == "falling":
            state.state = "playing"
        if event.type == pygame.KEYDOWN:
            if state.state == "playing":
                if event.key == pygame.K_p:
                    state.state = "paused"
                if event.key == pygame.K_LEFT:
                    if valid(state.X - 1, state.Y, state.piece.form):
                        state.X -= 1
                if event.key == pygame.K_RIGHT:
                    if valid(state.X + 1, state.Y, state.piece.form):
                        state.X += 1
                if event.key == pygame.K_UP or event.key == pygame.K_SPACE:
                    new_form = Polyomino.rotate_right(state.piece.form,
                        state.piece.size)
                    if valid(state.X, state.Y, new_form):
                        state.piece.form = new_form
                if event.key == pygame.K_DOWN:
                    state.state = "falling"
            elif state.state == "paused":
                if event.key == pygame.K_p:
                    state.state = "playing"
            elif state.state == "entering high score":
                if event.key == pygame.K_BACKSPACE and state.cursorpos > 0:
                    state.cursorpos -= 1
                    state.hiscores[state.scorepos][0] = \
                        state.hiscores[state.scorepos][0][:state.cursorpos]
                elif event.key == pygame.K_RETURN:
                    scorefile = open("hiscores.csv", "w")
                    writer = csv.writer(scorefile, dialect = csv.unix_dialect)
                    for row in state.hiscores:
                        writer.writerow(row)
                    scorefile.close()
                    state.start_game()
                elif (event.unicode.isalpha() or event.key == pygame.K_SPACE) \
                    and state.cursorpos < INFO_WIDTH - 3 - len(str(state.score)):
                    state.hiscores[state.scorepos][0] = \
                        state.hiscores[state.scorepos][0][:state.cursorpos] \
                        + event.unicode
                    state.cursorpos += 1
            elif state.state == "lost":
                if event.key in [pygame.K_SPACE, pygame.K_RETURN]:
                    state.start_game()
项目:spassouno-py    作者:OfficineArduinoTorino    | 项目源码 | 文件源码
def keyboard_interaction():
    global current_text_tag,last_time_text,animation_speed,NEXT_CRITICAL_ACTION
    if IS_RASPBERRY:
        check_hardware_buttons()
    for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    exit()
                elif event.key == pygame.K_SPACE:
                    camera.save_frame(frameManager)
                    current_text_tag="scattato"
                elif event.key == pygame.K_UP:
                    NEXT_CRITICAL_ACTION="changetosession"+str(frameManager.current_session+1)
                    current_text_tag="cambio sessione"
                elif event.key == pygame.K_DOWN:
                    NEXT_CRITICAL_ACTION="changetosession"+str(frameManager.current_session-1)
                    current_text_tag="cambio sessione"
                elif event.key == pygame.K_x:
                    frameManager.remove_frame()
                    current_text_tag="rimosso"
                elif event.key == pygame.K_s:
                    NEXT_CRITICAL_ACTION="save"
                    current_text_tag="saving"
                elif event.key == pygame.K_r:
                    camera.ruota()
                elif event.key == pygame.K_DELETE:
                    frameManager.delete_all()
                elif event.key == pygame.K_BACKSPACE:
                    frameManager.delete_current_scene()
                elif event.key == pygame.K_p:
                    animation_speed/=2.0
                    if animation_speed<0.003125:
                        animation_speed=0.003125
                elif event.key == pygame.K_o:
                    animation_speed*=2.0
                    if animation_speed>3.2:
                        animation_speed=3.2
                else:
                    for n in range(10):
                        if event.key == pygame.__dict__["K_"+str(n)]:
                            nf=n-1
                            if nf<0:
                                nf=9
                            NEXT_CRITICAL_ACTION="changetosession"+str(nf)
                            current_text_tag="cambio sessione"
                last_time_text=time.time()