當前位置: 首頁>>代碼示例>>Python>>正文


Python pygame.K_UP屬性代碼示例

本文整理匯總了Python中pygame.K_UP屬性的典型用法代碼示例。如果您正苦於以下問題:Python pygame.K_UP屬性的具體用法?Python pygame.K_UP怎麽用?Python pygame.K_UP使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在pygame的用法示例。


在下文中一共展示了pygame.K_UP屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: GameStartInterface

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_UP [as 別名]
def GameStartInterface(screen, sounds, cfg):
	dino = Dinosaur(cfg.IMAGE_PATHS['dino'])
	ground = pygame.image.load(cfg.IMAGE_PATHS['ground']).subsurface((0, 0), (83, 19))
	rect = ground.get_rect()
	rect.left, rect.bottom = cfg.SCREENSIZE[0]/20, cfg.SCREENSIZE[1]
	clock = pygame.time.Clock()
	press_flag = False
	while True:
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				pygame.quit()
				sys.exit()
			elif event.type == pygame.KEYDOWN:
				if event.key == pygame.K_SPACE or event.key == pygame.K_UP:
					press_flag = True
					dino.jump(sounds)
		dino.update()
		screen.fill(cfg.BACKGROUND_COLOR)
		screen.blit(ground, rect)
		dino.draw(screen)
		pygame.display.update()
		clock.tick(cfg.FPS)
		if (not dino.is_jumping) and press_flag:
			return True 
開發者ID:CharlesPikachu,項目名稱:Games,代碼行數:26,代碼來源:gamestart.py

示例2: endGame

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_UP [as 別名]
def endGame(screen, sounds, showScore, score, number_images, bird, pipe_sprites, backgroud_image, other_images, base_pos, cfg):
	sounds['die'].play()
	clock = pygame.time.Clock()
	while True:
		for event in pygame.event.get():
			if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
				pygame.quit()
				sys.exit()
			elif event.type == pygame.KEYDOWN:
				if event.key == pygame.K_SPACE or event.key == pygame.K_UP:
					return
		boundary_values = [0, base_pos[-1]]
		bird.update(boundary_values, float(clock.tick(cfg.FPS))/1000.)
		screen.blit(backgroud_image, (0, 0))
		pipe_sprites.draw(screen)
		screen.blit(other_images['base'], base_pos)
		showScore(screen, score, number_images)
		bird.draw(screen)
		pygame.display.update()
		clock.tick(cfg.FPS) 
開發者ID:CharlesPikachu,項目名稱:Games,代碼行數:22,代碼來源:endGame.py

示例3: _map_keys

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_UP [as 別名]
def _map_keys(self):
        key_map = self.io.key_map

        key_map[imgui.KEY_TAB] = pygame.K_TAB
        key_map[imgui.KEY_LEFT_ARROW] = pygame.K_LEFT
        key_map[imgui.KEY_RIGHT_ARROW] = pygame.K_RIGHT
        key_map[imgui.KEY_UP_ARROW] = pygame.K_UP
        key_map[imgui.KEY_DOWN_ARROW] = pygame.K_DOWN
        key_map[imgui.KEY_PAGE_UP] = pygame.K_PAGEUP
        key_map[imgui.KEY_PAGE_DOWN] = pygame.K_PAGEDOWN
        key_map[imgui.KEY_HOME] = pygame.K_HOME
        key_map[imgui.KEY_END] = pygame.K_END
        key_map[imgui.KEY_DELETE] = pygame.K_DELETE
        key_map[imgui.KEY_BACKSPACE] = pygame.K_BACKSPACE
        key_map[imgui.KEY_ENTER] = pygame.K_RETURN
        key_map[imgui.KEY_ESCAPE] = pygame.K_ESCAPE
        key_map[imgui.KEY_A] = pygame.K_a
        key_map[imgui.KEY_C] = pygame.K_c
        key_map[imgui.KEY_V] = pygame.K_v
        key_map[imgui.KEY_X] = pygame.K_x
        key_map[imgui.KEY_Y] = pygame.K_y
        key_map[imgui.KEY_Z] = pygame.K_z 
開發者ID:swistakm,項目名稱:pyimgui,代碼行數:24,代碼來源:pygame.py

示例4: update

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_UP [as 別名]
def update(self):
        pg.display.set_caption(str((self.rect.x, self.rect.y)))
        self.vx, self.vy = 0, 0
        keys = pg.key.get_pressed()
        if keys[pg.K_UP]:
            self.vy = -5
        if keys[pg.K_DOWN]:
            self.vy = 5
        if keys[pg.K_LEFT]:
            self.vx = -5
        if keys[pg.K_RIGHT]:
            self.vx = 5
        # if self.vx != 0 and self.vy != 0:
        #     self.vx *= 0.7071
        #     self.vy *= 0.7071
        self.rect.x += self.vx
        if pg.sprite.spritecollide(self, walls, False, pg.sprite.collide_mask):
            self.rect.x -= self.vx
        self.rect.y += self.vy
        if pg.sprite.spritecollide(self, walls, False, pg.sprite.collide_mask):
            self.rect.y -= self.vy 
開發者ID:kidscancode,項目名稱:pygame_tutorials,代碼行數:23,代碼來源:tilemap_demo2.py

示例5: get_keys

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_UP [as 別名]
def get_keys(self):
        self.rot_speed = 0
        self.vel = vec(0, 0)
        keys = pg.key.get_pressed()
        if keys[pg.K_LEFT] or keys[pg.K_a]:
            self.rot_speed = PLAYER_ROT_SPEED
        if keys[pg.K_RIGHT] or keys[pg.K_d]:
            self.rot_speed = -PLAYER_ROT_SPEED
        if keys[pg.K_UP] or keys[pg.K_w]:
            self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot)
        if keys[pg.K_DOWN] or keys[pg.K_s]:
            self.vel = vec(-PLAYER_SPEED / 2, 0).rotate(-self.rot)
        if keys[pg.K_SPACE]:
            now = pg.time.get_ticks()
            if now - self.last_shot > BULLET_RATE:
                self.last_shot = now
                dir = vec(1, 0).rotate(-self.rot)
                pos = self.pos + BARREL_OFFSET.rotate(-self.rot)
                Bullet(self.game, pos, dir)
                self.vel = vec(-KICKBACK, 0).rotate(-self.rot) 
開發者ID:kidscancode,項目名稱:pygame_tutorials,代碼行數:22,代碼來源:sprites.py

示例6: events

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_UP [as 別名]
def events(self):
        # catch all events here
        for event in pg.event.get():
            if event.type == pg.QUIT:
                self.quit()
            if event.type == pg.KEYDOWN:
                if event.key == pg.K_ESCAPE:
                    self.quit()
                if event.key == pg.K_LEFT:
                    self.player.move(dx=-1)
                if event.key == pg.K_RIGHT:
                    self.player.move(dx=1)
                if event.key == pg.K_UP:
                    self.player.move(dy=-1)
                if event.key == pg.K_DOWN:
                    self.player.move(dy=1) 
開發者ID:kidscancode,項目名稱:pygame_tutorials,代碼行數:18,代碼來源:main.py

示例7: get_keys

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_UP [as 別名]
def get_keys(self):
        self.rot_speed = 0
        self.vel = vec(0, 0)
        keys = pg.key.get_pressed()
        if keys[pg.K_LEFT] or keys[pg.K_a]:
            self.rot_speed = PLAYER_ROT_SPEED
        if keys[pg.K_RIGHT] or keys[pg.K_d]:
            self.rot_speed = -PLAYER_ROT_SPEED
        if keys[pg.K_UP] or keys[pg.K_w]:
            self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot)
        if keys[pg.K_DOWN] or keys[pg.K_s]:
            self.vel = vec(-PLAYER_SPEED / 2, 0).rotate(-self.rot)
        if keys[pg.K_SPACE]:
            now = pg.time.get_ticks()
            if now - self.last_shot > BULLET_RATE:
                self.last_shot = now
                dir = vec(1, 0).rotate(-self.rot)
                pos = self.pos + BARREL_OFFSET.rotate(-self.rot)
                Bullet(self.game, pos, dir)
                self.vel = vec(-KICKBACK, 0).rotate(-self.rot)
                MuzzleFlash(self.game, pos) 
開發者ID:kidscancode,項目名稱:pygame_tutorials,代碼行數:23,代碼來源:sprites.py

示例8: update

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_UP [as 別名]
def update(self):
        self.vx, self.vy = 0, 0
        keystate = pg.key.get_pressed()
        if keystate[pg.K_UP]:
            self.vy = -5
        if keystate[pg.K_DOWN]:
            self.vy = 5
        if keystate[pg.K_LEFT]:
            self.vx = -2
        if keystate[pg.K_RIGHT]:
            self.vx = 1
        if self.vx != 0 and self.vy != 0:
            self.vx /= 1.414
            self.vy /= 1.414
        self.rect.x += self.vx
        self.rect.y += self.vy 
開發者ID:kidscancode,項目名稱:pygame_tutorials,代碼行數:18,代碼來源:movement.py

示例9: update

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_UP [as 別名]
def update(self):
        self.acc = vec(0, 0)
        keys = pygame.key.get_pressed()
        if keys[pygame.K_LEFT]:
            self.acc.x = -0.2
        if keys[pygame.K_RIGHT]:
            self.acc.x = 0.2
        if keys[pygame.K_UP]:
            self.acc.y = -0.2
        if keys[pygame.K_DOWN]:
            self.acc.y = 0.2

        self.vel += self.acc
        self.pos += self.vel + 0.5 * self.acc
        if self.pos.x > WIDTH:
            self.pos.x = 0
        if self.pos.x < 0:
            self.pos.x = WIDTH
        if self.pos.y > HEIGHT:
            self.pos.y = 0
        if self.pos.y < 0:
            self.pos.y = HEIGHT

        self.rect.center = self.pos 
開發者ID:kidscancode,項目名稱:pygame_tutorials,代碼行數:26,代碼來源:motion_demo.py

示例10: _handleKeypress

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_UP [as 別名]
def _handleKeypress(self, key):
		if self._clicked == None or self._moveEvent == None:
			return False
		column = self._clicked[0]
		row = self._clicked[1]

		target = None
		if key == pygame.K_LEFT:
			if column > 0:
				target = (column-1, row)
		elif key == pygame.K_RIGHT:
			if column < self._map.cols - 1:
				target = (column+1, row)
		elif key == pygame.K_UP:
			if row > 0:
				target = (column, row-1)
		elif key == pygame.K_DOWN:
			if row < self._map.rows - 1:
				target = (column, row+1)

		if target != None:
			self._moveEvent(self._clicked, target)
			self._clicked = target 
開發者ID:harrischristiansen,項目名稱:generals-bot,代碼行數:25,代碼來源:viewer.py

示例11: __human_control

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_UP [as 別名]
def __human_control(self, key):
        if self.human_control:
            robot = self.robots[self.human_control_robot]
            if key == pygame.K_LEFT:
                robot.move(GlobalConstants.LEFT_ACTION, self.sprites)
            if key == pygame.K_RIGHT:
                robot.move(GlobalConstants.RIGHT_ACTION, self.sprites)
            if key == pygame.K_UP:
                robot.move(GlobalConstants.UP_ACTION, self.sprites)
            if key == pygame.K_DOWN:
                robot.move(GlobalConstants.DOWN_ACTION, self.sprites)
            if key == pygame.K_a:
                reward = robot.move(GlobalConstants.FIRE_ACTION, self.sprites)
                if reward > 0:
                    self.rewards[self.human_control_robot].append(reward)
                    self.total_score[self.human_control_robot] += reward 
開發者ID:garlicdevs,項目名稱:Fruit-API,代碼行數:18,代碼來源:engine.py

示例12: handle_continuous_action_event

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_UP [as 別名]
def handle_continuous_action_event(cls, action_type: ContinuousAction, event: pygame.event.EventType) -> None:
        action = action_type.last_action.copy()
        steering_index = action_type.space().shape[0] - 1
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT and action_type.lateral:
                action[steering_index] = 0.7
            if event.key == pygame.K_LEFT and action_type.lateral:
                action[steering_index] = -0.7
            if event.key == pygame.K_DOWN and action_type.longitudinal:
                action[0] = -0.7
            if event.key == pygame.K_UP and action_type.longitudinal:
                action[0] = 0.7
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_RIGHT and action_type.lateral:
                action[steering_index] = 0
            if event.key == pygame.K_LEFT and action_type.lateral:
                action[steering_index] = 0
            if event.key == pygame.K_DOWN and action_type.longitudinal:
                action[0] = 0
            if event.key == pygame.K_UP and action_type.longitudinal:
                action[0] = 0
        action_type.act(action) 
開發者ID:eleurent,項目名稱:highway-env,代碼行數:24,代碼來源:graphics.py

示例13: keydown

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_UP [as 別名]
def keydown(self, key):
        """ Update velocities based on key pressed
        Arguments:
            key: pygame key
        """
        if key == pygame.K_UP:  # set forward velocity
            self.for_back_velocity = S
        elif key == pygame.K_DOWN:  # set backward velocity
            self.for_back_velocity = -S
        elif key == pygame.K_LEFT:  # set left velocity
            self.left_right_velocity = -S
        elif key == pygame.K_RIGHT:  # set right velocity
            self.left_right_velocity = S
        elif key == pygame.K_w:  # set up velocity
            self.up_down_velocity = S
        elif key == pygame.K_s:  # set down velocity
            self.up_down_velocity = -S
        elif key == pygame.K_a:  # set yaw counter clockwise velocity
            self.yaw_velocity = -S
        elif key == pygame.K_d:  # set yaw clockwise velocity
            self.yaw_velocity = S 
開發者ID:damiafuentes,項目名稱:DJITelloPy,代碼行數:23,代碼來源:manual-control-pygame.py

示例14: keyup

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_UP [as 別名]
def keyup(self, key):
        """ Update velocities based on key released
        Arguments:
            key: pygame key
        """
        if key == pygame.K_UP or key == pygame.K_DOWN:  # set zero forward/backward velocity
            self.for_back_velocity = 0
        elif key == pygame.K_LEFT or key == pygame.K_RIGHT:  # set zero left/right velocity
            self.left_right_velocity = 0
        elif key == pygame.K_w or key == pygame.K_s:  # set zero up/down velocity
            self.up_down_velocity = 0
        elif key == pygame.K_a or key == pygame.K_d:  # set zero yaw velocity
            self.yaw_velocity = 0
        elif key == pygame.K_t:  # takeoff
            self.tello.takeoff()
            self.send_rc_control = True
        elif key == pygame.K_l:  # land
            not self.tello.land()
            self.send_rc_control = False 
開發者ID:damiafuentes,項目名稱:DJITelloPy,代碼行數:21,代碼來源:manual-control-pygame.py

示例15: handle_event

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import K_UP [as 別名]
def handle_event(self, event):
        if event.type == pygame.QUIT:
            game_over = True

        if event.type == pygame.KEYDOWN:

            if event.key == pygame.K_LEFT:
                self.update('left')
            if event.key == pygame.K_RIGHT:
                self.update('right')
            if event.key == pygame.K_UP:
                self.update('up')
            if event.key == pygame.K_DOWN:
                self.update('down')

        if event.type == pygame.KEYUP:

            if event.key == pygame.K_LEFT:
                self.update('stand_left')
            if event.key == pygame.K_RIGHT:
                self.update('stand_right')
            if event.key == pygame.K_UP:
                self.update('stand_up')
            if event.key == pygame.K_DOWN:
                self.update('stand_down') 
開發者ID:tidus747,項目名稱:Tutoriales_juegos_Python,代碼行數:27,代碼來源:player.py


注:本文中的pygame.K_UP屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。