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

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

项目:tensorflow_dqn_supermario    作者:JSDanielPark    | 项目源码 | 文件源码
def update_cursor(self, keys):
        """Update the position of the cursor"""
        input_list = [pg.K_RETURN, pg.K_a, pg.K_s]

        if self.cursor.state == c.PLAYER1:
            self.cursor.rect.y = 358
            if keys[pg.K_DOWN]:
                self.cursor.state = c.PLAYER2
            for input in input_list:
                if keys[input]:
                    self.reset_game_info()
                    self.done = True
        elif self.cursor.state == c.PLAYER2:
            self.cursor.rect.y = 403
            if keys[pg.K_UP]:
                self.cursor.state = c.PLAYER1
项目:pyDino    作者:lucaspbordignon    | 项目源码 | 文件源码
def show(self):
        """
        Shows the game over panel.
        """
        self.display.set_screen_caption('Game Over')
        for event in pygame.event.get():
            if (event.type == pygame.KEYDOWN):
                if (event.key == pygame.K_RETURN):
                    return (True, "main_menu", None)
                if (event.key == pygame.K_s):
                    return (True, "save_progress", None)
            if (event.type == pygame.QUIT):
                return (False, '', None)

        self.display.display_single_image(self.resources['game_over_msg'],
                                          self.resources['game_over_pos'])
        self.display.display_single_image(self.resources['game_over_char'],
                                          self.resources['game_over_pos'])
        self.display.display_single_image(self.resources['press_enter'],
                                          self.resources['press_enter_pos'])
        self.display.display_single_image(self.resources['save_msg'],
                                          self.resources['save_msg_pos'])
        return (True, 'game_over', None)
项目:pyweek-game-poor-man-medal-of-honor-game    作者:ReekenX    | 项目源码 | 文件源码
def movement(self, obstacles, offset, i):
        self.rect[i] += offset
        collisions = pg.sprite.spritecollide(self, obstacles, False)
        callback = pg.sprite.collide_mask
        while pg.sprite.spritecollideany(self, collisions, callback):
            self.rect[i] += (1 if offset<0 else -1)
            self.remainder[i] = 0
            rand_move = random.choice([pg.K_s, pg.K_a, pg.K_w, pg.K_d])
            while rand_move == self.direction:
                rand_move = random.choice([pg.K_s, pg.K_a, pg.K_w, pg.K_d])
                pass
            self.direction = rand_move
            if self.direction == pg.K_a:
                self.direction = pg.K_a
                self.vector = [-1, 0]
            elif self.direction == pg.K_w:
                self.direction = pg.K_w
                self.vector = [0, -1]
            elif self.direction == pg.K_s:
                self.direction = pg.K_s
                self.vector = [0, 1]
            elif self.direction == pg.K_d:
                self.direction = pg.K_d
                self.vector = [1, 0]
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def run():
    global FAST_FORWARD

    if Input.key_typed(pygame.K_s):
        FAST_FORWARD = not FAST_FORWARD

    if not FAST_FORWARD:
        if not ENTITIES_STILL_ALIVE:
            evolve()

        tick()
        render()
    else:
        while ENTITIES_STILL_ALIVE:
            tick()
        evolve()
项目:SerialGraphicator    作者:newtonis    | 项目源码 | 文件源码
def Refresh(self):
        self.screen.fill((255,255,255))
        self.App.Refresh()
        pygame.display.update()
        if not pygame.key.get_pressed()[pygame.K_LCTRL]:
            self.flag = False
        if not pygame.key.get_pressed()[pygame.K_LCTRL]:
            self.flag = False
        if pygame.key.get_pressed()[pygame.K_LCTRL] and pygame.key.get_pressed()[pygame.K_s] and not self.flag:
            self.flag = True
            name =  str( time.time() )+ ".png"
            pygame.image.save(self.screen , str( time.time() )+ ".png")
            print "screenshot ",name," saved"

        if pygame.key.get_pressed()[ pygame.K_F11 ] and not self.lastpresssed:
            self.lastpresssed = True
            if self.fullscreen == 0:
                self.screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT),pygame.FULLSCREEN)
                self.fullscreen = 1
            else:
                self.fullscreen = 0
                self.screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT))

        if not pygame.key.get_pressed()[pygame.K_F11]:
            self.lastpresssed  = False
项目:SerialGraphicator    作者:newtonis    | 项目源码 | 文件源码
def Refresh(self):
        self.screen.fill((255,255,255))
        self.App.Refresh()
        pygame.display.update()
        if not pygame.key.get_pressed()[pygame.K_LCTRL]:
            self.flag = False
        if not pygame.key.get_pressed()[pygame.K_LCTRL]:
            self.flag = False
        if pygame.key.get_pressed()[pygame.K_LCTRL] and pygame.key.get_pressed()[pygame.K_s] and not self.flag:
            self.flag = True
            name =  str( time.time() )+ ".png"
            pygame.image.save(self.screen , str( time.time() )+ ".png")
            print "screenshot ",name," saved"

        if pygame.key.get_pressed()[ pygame.K_F11 ] and not self.lastpresssed:
            self.lastpresssed = True
            if self.fullscreen == 0:
                self.screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT),pygame.FULLSCREEN)
                self.fullscreen = 1
            else:
                self.fullscreen = 0
                self.screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT))

        if not pygame.key.get_pressed()[pygame.K_F11]:
            self.lastpresssed  = False
项目:SerialGraphicator    作者:newtonis    | 项目源码 | 文件源码
def Refresh(self):
        self.screen.fill((255,255,255))
        self.App.Refresh()
        pygame.display.update()
        if not pygame.key.get_pressed()[pygame.K_LCTRL]:
            self.flag = False
        if not pygame.key.get_pressed()[pygame.K_LCTRL]:
            self.flag = False
        if pygame.key.get_pressed()[pygame.K_LCTRL] and pygame.key.get_pressed()[pygame.K_s] and not self.flag:
            self.flag = True
            name =  str( time.time() )+ ".png"
            pygame.image.save(self.screen , str( time.time() )+ ".png")
            print "screenshot ",name," saved"

        if pygame.key.get_pressed()[ pygame.K_F11 ] and not self.lastpresssed:
            self.lastpresssed = True
            if self.fullscreen == 0:
                self.screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT),pygame.FULLSCREEN)
                self.fullscreen = 1
            else:
                self.fullscreen = 0
                self.screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT))

        if not pygame.key.get_pressed()[pygame.K_F11]:
            self.lastpresssed  = False
项目: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()
项目:Physics-2.0    作者:rschwa6308    | 项目源码 | 文件源码
def __init__(self):
        self.down, self.map, self.val, self.scale = [0, 0, 0, 0], [pg.K_a, pg.K_w, pg.K_d, pg.K_s], V2(0, 0), 1
项目:TicTacTio    作者:DevelopForLizardz    | 项目源码 | 文件源码
def setControls(self):
        """
        Setups the controls for the class. setGame must be called first in order for this to run correctly
        """

        self.controls = []
        self.values = [self.game.board.callable, self.game.board.mvCurUp, self.game.board.mvCurDown,
                       self.game.board.mvCurLeft, self.game.board.mvCurRight]
        if self.control_set == "arrows":
            self.keys = [pygame.K_RETURN, pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT, pygame.K_RIGHT]
        else:
            self.keys = [pygame.K_SPACE, pygame.K_w, pygame.K_s, pygame.K_a, pygame.K_d]

        for i in range(len(self.keys)):
            self.controls.append([self.keys[i], self.values[i]])
项目:pyweek-game-poor-man-medal-of-honor-game    作者:ReekenX    | 项目源码 | 文件源码
def __init__(self, rect, speed, direction=pg.K_s):
        self.rect = pg.Rect(rect)
        self.vector = [0, 1]
        self.remainder = [0, 0]
        self.mask = self.make_mask()
        self.speed = speed
        self.direction = direction
        self.old_direction = None
        self.direction_stack = []
        self.redraw = False
        self.image = None

        self.sprites = pg.image.load(settings.IMG_DIR + "/enemy" + str(random.randint(1, 3)) + ".png").convert_alpha()

        self.shooting_time = pg.time.get_ticks()

        self.frame  = 0
        self.frames = self.get_frames()
        self.animate_timer = 0.0
        self.animate_fps = 7.0
        self.walkframes = []
        self.walkframe_dict = self.make_frame_dict()
        self.adjust_images()
        self.visible = True

        self.killed = False
项目:pyweek-game-poor-man-medal-of-honor-game    作者:ReekenX    | 项目源码 | 文件源码
def make_frame_dict(self):
        frames = {pg.K_a: [self.frames[0], self.frames[1], self.frames[2], self.frames[3]],
                  pg.K_d: [self.frames[0], self.frames[1], self.frames[2], self.frames[3]],
                  pg.K_s: [self.frames[0], self.frames[1], self.frames[2], self.frames[3]],
                  pg.K_w: [self.frames[0], self.frames[1], self.frames[2], self.frames[3]]}
        return frames
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def init():
    add_key(pygame.K_w)
    add_key(pygame.K_s)
    add_key(pygame.K_a)
    add_key(pygame.K_d)
    add_key(pygame.K_c)
    add_key(pygame.K_r)
    add_key(pygame.K_q)
    add_key(pygame.K_e)
    add_key(pygame.K_g)
    add_key(pygame.K_t)


# Adds a new key to be tracked for input
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def init():
    add_key(pygame.K_w)
    add_key(pygame.K_s)
    add_key(pygame.K_a)
    add_key(pygame.K_d)
    add_key(pygame.K_c)
    add_key(pygame.K_r)
    add_key(pygame.K_q)
    add_key(pygame.K_e)
    add_key(pygame.K_g)
    add_key(pygame.K_t)


# Adds a new key to be tracked for input
项目:Snakis    作者:fbessou    | 项目源码 | 文件源码
def __init__(self):
        self._mapping = [
                { # Player 
                    pygame.K_d:"right",
                    pygame.K_s:"down",
                    pygame.K_q:"left",
                    pygame.K_z:"up"
                },
                { # Player 1
                    pygame.K_RIGHT:"right",
                    pygame.K_DOWN:"down",
                    pygame.K_LEFT:"left",
                    pygame.K_UP:"up"
                }
        ]
项目:CoolesSpiel    作者:AlinaGri    | 项目源码 | 文件源码
def update(self, gamemap):
        '''
        updated die Playerbewegungen beim (knopfdruck events)
        Parameter:      Spielobjekt, gamemap
        return Value:   -
        '''
        keys = pygame.key.get_pressed()
        newRect = self.rect
        if keys[pygame.K_w]:
            newRect = self.rect.move(0, -self.speed)
            if gamemap.isRectValid(newRect):
                self.rect = newRect
        if keys[pygame.K_s]:
            newRect = self.rect.move(0, self.speed)
            if gamemap.isRectValid(newRect):
                self.rect = newRect
        if keys[pygame.K_a]:
            newRect = self.rect.move(-self.speed, 0)
            if gamemap.isRectValid(newRect):
                self.rect = newRect
        if keys[pygame.K_d]:
            newRect = self.rect.move(self.speed, 0)
            if gamemap.isRectValid(newRect):
                self.rect = newRect
        if keys[pygame.K_x]:
            print self.rect.center, self.room

    #def shot(self, xPos, yPos, eventPos):
项目:jackit    作者:vix597    | 项目源码 | 文件源码
def __init__(self):
        super(JackitConfigControls, self).__init__()
        self.up = pygame.K_w
        self.down = pygame.K_s
        self.left = pygame.K_a
        self.right = pygame.K_d
        self.jump = pygame.K_SPACE
        self.interact = pygame.K_e
        self.push = pygame.K_LSHIFT
        self.reset_code = pygame.K_q
        self.toggle_sound = pygame.K_m
        self.kill_self = pygame.K_k
        self.reset_game = pygame.K_n
项目:jackit    作者:vix597    | 项目源码 | 文件源码
def from_json(self, raw):
        '''
        Load the object from JSON loaded from config file
        '''

        # First pass make sure all are valid
        for key in raw:
            if isinstance(raw[key], str):
                if not hasattr(pygame, raw[key]):
                    raise ConfigError(
                        "Invalid control for {}. Must be a valid pygame key constant".format(key)
                    )
                else:
                    raw[key] = getattr(pygame, raw[key])
            elif isinstance(raw[key], int):
                pass
            else:
                raise ConfigError(
                    "Controls must be a valid pygame key constant as a string or integer"
                )

        # Check for duplicates
        values = list(raw.values())
        values_set = set(values)

        if len(values) != len(values_set):
            raise ConfigError("Cannot have duplicate controls")

        self.up = raw.get('up', getattr(pygame, 'K_w'))
        self.down = raw.get('down', getattr(pygame, 'K_s'))
        self.left = raw.get('left', getattr(pygame, 'K_a'))
        self.right = raw.get('right', getattr(pygame, 'K_d'))
        self.jump = raw.get('jump', getattr(pygame, 'K_SPACE'))
        self.interact = raw.get('interact', getattr(pygame, 'K_e'))
        self.push = raw.get("push", getattr(pygame, "K_LSHIFT"))
        self.reset_code = raw.get("reset_code", getattr(pygame, "K_q"))
        self.toggle_sound = raw.get("toggle_sound", getattr(pygame, "K_m"))
        self.kill_self = raw.get("kill_self", getattr(pygame, "K_k"))
        self.reset_game = raw.get("reset_game", getattr(pygame, "K_n"))
项目:Space-Invaders-Python-game    作者:AlexSergey    | 项目源码 | 文件源码
def getControls():
    up = pygame.key.get_pressed()[pygame.K_UP]
    down = pygame.key.get_pressed()[pygame.K_DOWN]
    w = pygame.key.get_pressed()[pygame.K_w]
    s = pygame.key.get_pressed()[pygame.K_s]
    space = pygame.key.get_pressed()[pygame.K_SPACE]

    return (up, down, w, s, space)
项目:Flappy-Bird-Remake    作者:georgecoopers    | 项目源码 | 文件源码
def show_go_screen(self):
        # Game Over Screen
        gameStart = False
        SWOOSH_SOUND.play()
        while not gameStart:
            self.display_text("Flappy Bird",WIDTH / 3, HEIGHT / 3, 30, WHITE)
            self.display_text("Press S to Start...",WIDTH/3, HEIGHT / 2, 30, WHITE)
            pg.display.flip()
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    gameStart = True
                    self.running = False
                if event.type == pg.KEYDOWN and event.key == pg.K_s:
                    gameStart = True
项目:Flappy-Bird-Remake    作者:georgecoopers    | 项目源码 | 文件源码
def show_start_screen(self):
        # Game Over Screen
        gameStart = False
        while not gameStart:
            self.screen.blit(Background, [0,0])
            self.display_text("Flappy Bird",WIDTH / 3, HEIGHT / 3, 30, WHITE)
            self.display_text("Press S to Start...",WIDTH/3, HEIGHT / 2, 30, WHITE)
            pg.display.flip()
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    gameStart = True
                    self.running = False
                if event.type == pg.KEYDOWN and event.key == pg.K_s:
                    gameStart = True
项目:GameToy    作者:rukai    | 项目源码 | 文件源码
def keyEvent(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_DOWN:
                self.down = 0
            if event.key == pygame.K_UP:
                self.up = 0
            if event.key == pygame.K_LEFT:
                self.left = 0
            if event.key == pygame.K_RIGHT:
                self.right = 0
            if event.key == pygame.K_a:
                self.start = 0
            if event.key == pygame.K_s:
                self.select = 0
            if event.key == pygame.K_x:
                self.b = 0
            if event.key == pygame.K_z:
                self.a = 0

        if event.type == pygame.KEYUP:
            if event.key == pygame.K_DOWN:
                self.down = 1
            if event.key == pygame.K_UP:
                self.up = 1
            if event.key == pygame.K_LEFT:
                self.left = 1
            if event.key == pygame.K_RIGHT:
                self.right = 1
            if event.key == pygame.K_a:
                self.start = 1
            if event.key == pygame.K_s:
                self.select = 1
            if event.key == pygame.K_x:
                self.b = 1
            if event.key == pygame.K_z:
                self.a = 1
项目:Python-Platformer---Map-editor    作者:billy-yoyo    | 项目源码 | 文件源码
def update(self, button):
        keys = pygame.key.get_pressed()
        if focus == main:
            elapsed = min(1, self.cds.elapsed("move_keys"))
            if keys[pygame.K_LEFT] or keys[pygame.K_a]:
                self.offset[0] = self.offset[0] - (self.key_velocity[0] * elapsed)
                self.change = True
            if keys[pygame.K_RIGHT] or keys[pygame.K_d]:
                self.offset[0] = self.offset[0] + (self.key_velocity[0] * elapsed)
                self.change = True
            if keys[pygame.K_UP] or keys[pygame.K_w]:
                self.offset[1] = self.offset[1] - (self.key_velocity[1] * elapsed)
                self.change = True
            if keys[pygame.K_DOWN] or keys[pygame.K_s]:
                self.offset[1] = self.offset[1] + (self.key_velocity[1] * elapsed)
                self.change = True
            self.cds.start()

            if self.cds.check("save_load"):
                if keys[pygame.K_q]:
                    save(fnbox.text)
                    self.cds.start()
                if keys[pygame.K_e]:
                    load(fnbox.text)
                    self.cds.start()
                if keys[pygame.K_r]:
                    self.new()

        if self.mmb_down and self.cds.check("navigate"):
            mpos = pygame.mouse.get_pos()
            diffx = (mpos[0] - self.mmb_start[0]) / 10
            diffy = (mpos[1] - self.mmb_start[1]) / 10
            self.offset = [ self.offset[0] + diffx, self.offset[1] + diffy ]
            self.cds.start()
            self.change = True
项目:SerialGraphicator    作者:newtonis    | 项目源码 | 文件源码
def Refresh(self):
        self.screen.fill((255,255,255))
        self.App.Refresh()
        pygame.display.update()
        if not pygame.key.get_pressed()[pygame.K_LCTRL]:
            self.flag = False
        if not pygame.key.get_pressed()[pygame.K_LCTRL]:
            self.flag = False
        if pygame.key.get_pressed()[pygame.K_LCTRL] and pygame.key.get_pressed()[pygame.K_s] and not self.flag:
            self.flag = True
            name =  str( time.time() )+ ".png"
            pygame.image.save(self.screen , str( time.time() )+ ".png")
            print "screenshot ",name," saved"
项目: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
项目:LD39    作者:Bobsleigh    | 项目源码 | 文件源码
def handleInput(self, sprite, event):
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT or event.key == pygame.K_d:
                sprite.updateSpeedRight()
                sprite.rightPressed = True
            elif event.key == pygame.K_LEFT or event.key == pygame.K_a:
                sprite.updateSpeedLeft()
                sprite.leftPressed = True
            elif event.key == pygame.K_DOWN or event.key == pygame.K_s:
                sprite.updateSpeedDown()
                sprite.downPressed = True
            elif event.key == pygame.K_UP or event.key == pygame.K_w:
                sprite.updateSpeedUp()
                sprite.upPressed = True
            elif event.key == pygame.K_LSHIFT:
                sprite.leftShiftPressed = True

        if event.type == pygame.KEYUP:
            if event.key == pygame.K_RIGHT or event.key == pygame.K_d:
                sprite.rightPressed = False
            elif event.key == pygame.K_LEFT or event.key == pygame.K_a:
                sprite.leftPressed = False
            elif event.key == pygame.K_UP or event.key == pygame.K_w:
                sprite.upPressed = False
            elif event.key == pygame.K_DOWN or event.key == pygame.K_s:
                sprite.downPressed = False
            elif event.key == pygame.K_LSHIFT:
                sprite.leftShiftPressed = False
            elif event.key == pygame.K_SPACE:
                sprite.spacePressed = False

        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == MOUSE_LEFT:
                sprite.leftMousePressed = True
            elif event.button == MOUSE_RIGHT:
                sprite.rightMousePressed = True

        elif event.type == pygame.MOUSEBUTTONUP:
            if event.button == MOUSE_LEFT:
                sprite.leftMousePressed = False
            elif event.button == MOUSE_RIGHT:
                sprite.rightMousePressed = False
项目:pytari2600    作者:ajgrah2000    | 项目源码 | 文件源码
def handle_events(self, event):
        if event.type== pygame.KEYDOWN:
            if event.key   == pygame.K_UP:
                self.swcha ^= 0x10
            elif event.key == pygame.K_DOWN:
                self.swcha ^= 0x20
            elif event.key == pygame.K_LEFT:
                self.swcha ^= 0x40
                self.paddle0 = 1
            elif event.key == pygame.K_RIGHT:
                self.swcha ^= 0x80
                self.paddle0 = -1
            elif event.key == pygame.K_s: # Game select
                self.swchb ^= 0x1
            elif event.key == pygame.K_r: # Game reset
                self.swchb ^= 0x2
            elif event.key == pygame.K_1:
                self.swchb ^= 0x40
                print("P0 dificulty %s"%(("hard", "easy")[self.swchb & 0x40 != 0]))
            elif event.key == pygame.K_2:
                self.swchb ^= 0x80
                print("P1 dificulty %s"%(("hard", "easy")[self.swchb & 0x80 != 0]))
            elif event.key == pygame.K_c: # toggle black and white
                self.swchb ^= 0x8
            elif event.key == pygame.K_z: # toggle black and white
                self.input7 &= 0x7F
            elif event.key == pygame.K_q: # Dodgy quit
                self.quit = 0x1
                pygame.quit()
                sys.exit()

            # Custom key events
            elif event.key   == pygame.K_LEFTBRACKET:
                self._save_state = 0x1
            elif event.key   == pygame.K_RIGHTBRACKET:
                self._restore_state = 0x1
        elif event.type== pygame.KEYUP:
            if event.key   == pygame.K_UP:
                self.swcha |= 0x10
            elif event.key == pygame.K_DOWN:
                self.swcha |= 0x20
            elif event.key == pygame.K_LEFT:
                self.swcha |= 0x40
                self.paddle0 = 0
            elif event.key == pygame.K_RIGHT:
                self.swcha |= 0x80
                self.paddle0 = 0
            elif event.key == pygame.K_s: # Game select
                self.swchb |= 0x1
            elif event.key == pygame.K_r: # Game reset
                self.swchb |= 0x2
            elif event.key == pygame.K_z: # toggle black and white
                self.input7 |= 0x80

            # Custom key events
            elif event.key   == pygame.K_LEFTBRACKET:
                self._save_state = 0x0
            elif event.key   == pygame.K_RIGHTBRACKET:
                self._restore_state = 0x0
项目:dasRepo    作者:MrGloriousFast    | 项目源码 | 文件源码
def userInput(camera, display):
    deltaT = display.deltaT
    #keyboard down presses
    pressed = pygame.key.get_pressed()    

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()

        if event.type == pygame.KEYDOWN:
            if event.key ==pygame.K_ESCAPE:
                pygame.quit()
                quit()

        if event.type == pygame.MOUSEMOTION:

            x, y = event.rel
            event.pos = (display.w/2,display.h/2)

            #look around
            if( abs(x)>1 ):
                camera.turnRight( -x*deltaT)
            if( abs(y)>1 ):
                camera.turnUp(    -y*deltaT)

            #capture mouse
            pygame.mouse.set_pos(display.w/2., display.w/2)
            pygame.event.get(pygame.MOUSEMOTION) #steal the new mouse event and do nothing with it to reset it
            #print()
            #print(camera.posWorld.getString())
            #print(camera.view())

    #back forth
    if pressed[pygame.K_w]:
        camera.forward(deltaT)
    if pressed[pygame.K_s]:
        camera.forward(-deltaT)

    #up, down
    if pressed[pygame.K_SPACE]:
        camera.upward(-deltaT)
    if pressed[pygame.K_LSHIFT]:
        camera.upward(deltaT)

    #left right
    if pressed[pygame.K_a]:
        camera.sideward(deltaT)
    if pressed[pygame.K_d]:
        camera.sideward(-deltaT)

    #change openGL polygon mode
    if pressed[pygame.K_1]:
        glPolygonMode(GL_FRONT_AND_BACK, GL_POINT)
    if pressed[pygame.K_2]:
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    if pressed[pygame.K_3]:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)


#start the main
项目:TicTacTio    作者:DevelopForLizardz    | 项目源码 | 文件源码
def start(self):
        """
        Starts up the game menu, allowing the user to navigate through it.
        """

        logging.info("Starting main loop for start menu")
        self.currentMenu.draw()

        while not self.exit:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.exit = True
                elif event.type == pygame.KEYDOWN:
                    if event.key not in [pygame.K_RETURN, pygame.K_SPACE]:
                        if event.key in [pygame.K_DOWN, pygame.K_s]:
                            self.showMouse = False
                            self.updateMouseVisibility()
                            if self.currentItem < len(self.currentMenu.items) - 1:
                                self.currentMenu.items[self.currentItem].hovered = False
                                self.currentItem += 1
                                self.currentMenu.items[self.currentItem].hovered = True
                        elif event.key in [pygame.K_UP, pygame.K_w]:
                            self.showMouse = False
                            self.updateMouseVisibility()
                            if self.currentItem > 0:
                                self.currentMenu.items[self.currentItem].hovered = False
                                self.currentItem -= 1
                                self.currentMenu.items[self.currentItem].hovered = True
                    else:
                        self.currentMenu.items[self.currentItem].hovered = False
                        self.showMouse = True
                        self.updateMouseVisibility()
                        self.currentMenu.items[self.currentItem].clicked()
                        self.currentItem = 0
                elif self.showMouse:
                    for item in self.currentMenu.items:
                        # hover state will always be checked
                        if item.checkHovered() and event.type == pygame.MOUSEBUTTONDOWN:
                            item.clicked()
                            break

                self.currentMenu.draw()
                pygame.display.flip()
                self.clock.tick(self.fps)

        logging.info("Ending main loop of start menu")
项目: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()
项目: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()
项目:WasIstDasFuer1Drone    作者:magnusja    | 项目源码 | 文件源码
def handle_controls(drone, event, pid):

    # takeoff / land
    if event.key == pygame.K_RETURN:
        drone.takeoff()
    elif event.key == pygame.K_SPACE:
        drone.land()
    # emergency
    elif event.key == pygame.K_BACKSPACE:
         drone.reset()
    # forward / backward
    elif event.key == pygame.K_w:
        drone.move_forward()
    elif event.key == pygame.K_s:
        drone.move_backward()
    # left / right
    elif event.key == pygame.K_a:
        drone.move_left()
    elif event.key == pygame.K_d:
        drone.move_right()
    # up / down
    elif event.key == pygame.K_UP:
        drone.move_up()
    elif event.key == pygame.K_DOWN:
        drone.move_down()
    # turn left / turn right
    elif event.key == pygame.K_LEFT:
        drone.turn_left()
    elif event.key == pygame.K_RIGHT:
        drone.turn_right()
    # speed
    elif event.key == pygame.K_1:
        drone.speed = 0.1
    elif event.key == pygame.K_2:
        drone.speed = 0.2
    elif event.key == pygame.K_3:
        drone.speed = 0.3
    elif event.key == pygame.K_4:
        drone.speed = 0.4
    elif event.key == pygame.K_5:
        drone.speed = 0.5
    elif event.key == pygame.K_6:
        drone.speed = 0.6
    elif event.key == pygame.K_7:
        drone.speed = 0.7
    elif event.key == pygame.K_8:
        drone.speed = 0.8
    elif event.key == pygame.K_9:
        drone.speed = 0.9
    elif event.key == pygame.K_0:
        drone.speed = 1.0
    elif event.key == pygame.K_u:
        pid.enabled = True