当前位置: 首页>>代码示例>>Python>>正文


Python pygame.K_r方法代码示例

本文整理汇总了Python中pygame.K_r方法的典型用法代码示例。如果您正苦于以下问题:Python pygame.K_r方法的具体用法?Python pygame.K_r怎么用?Python pygame.K_r使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygame的用法示例。


在下文中一共展示了pygame.K_r方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __endInterface

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_r [as 别名]
def __endInterface(self, is_win):
		if is_win:
			text1 = 'Congratulations! You win!'
		else:
			text1 = 'Game Over! You fail!'
		text2 = 'Press <R> to restart the game'
		text3 = 'Press <Esc> to quit the game.'
		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(-1)
				if event.type == pygame.KEYDOWN and event.key == pygame.K_r:
					return
			self.screen.fill(self.cfg.AQUA)
			text_render1 = self.font_big.render(text1, False, self.cfg.BLUE)
			text_render2 = self.font_big.render(text2, False, self.cfg.BLUE)
			text_render3 = self.font_big.render(text3, False, self.cfg.BLUE)
			self.screen.blit(text_render1, ((self.cfg.SCREENWIDTH-text_render1.get_rect().width)//2, (self.cfg.SCREENHEIGHT-text_render1.get_rect().height)//4))
			self.screen.blit(text_render2, ((self.cfg.SCREENWIDTH-text_render2.get_rect().width)//2, (self.cfg.SCREENHEIGHT-text_render2.get_rect().height)//2))
			self.screen.blit(text_render3, ((self.cfg.SCREENWIDTH-text_render3.get_rect().width)//2, (self.cfg.SCREENHEIGHT-text_render2.get_rect().height)//1.5))
			pygame.display.flip()
			clock.tick(30) 
开发者ID:CharlesPikachu,项目名称:Games,代码行数:26,代码来源:game.py

示例2: update

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_r [as 别名]
def update(self):

        self.cameraControls.update()

        if self.input.resize():
            size = self.input.getWindowSize()
            self.camera.setAspectRatio( size["width"]/size["height"] )
            self.renderer.setViewportSize(size["width"], size["height"])

        if self.input.isKeyDown(pygame.K_s):
            self.engine.stop()

        if self.input.isKeyDown(pygame.K_r):
            self.engine.reset()


        self.engine.update( self.deltaTime )
        
        self.renderer.render(self.scene, self.camera)
                    
# instantiate and run the program 
开发者ID:stemkoski,项目名称:three.py,代码行数:23,代码来源:TestParticleEngine.py

示例3: check_keypress

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_r [as 别名]
def check_keypress():
    try:
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_q or event.key == pygame.K_a or event.key == pygame.K_KP_DIVIDE or event.key == pygame.K_BACKSPACE:
                    logger.debug("Keypress 'a' or 'q' or 'backspace' or 'keypad /' detected.")
                    return "end_event"
                if event.key == pygame.K_n or event.key == pygame.K_SPACE or event.key == pygame.K_KP_PLUS:
                    logger.debug("Keypress 'n' or 'space' or 'keypad +' detected.")
                    return "next_event"
                if event.key == pygame.K_r or event.key == pygame.K_KP_PERIOD or event.key == pygame.K_COMMA:
                    logger.debug("Keypress 'r' or ',' or 'keypad .' detected")
                    return "resume_rotation"
                if event.key == pygame.K_p or event.key == pygame.K_KP_MULTIPLY:
                    logger.debug("Keypress 'p' or 'keypad *' detected")
                    return "pause_rotation"
                for numeric_key_counter, key in enumerate([pygame.K_F1,pygame.K_F2,pygame.K_F3,pygame.K_F4,pygame.K_F5,pygame.K_F6,pygame.K_F7,pygame.K_F8,pygame.K_F9,pygame.K_F10,pygame.K_F11,pygame.K_F12]):
                    if event.key == key:
                        logger.debug("Keypress 'F" + str(numeric_key_counter + 1) + "' detected")
                        return numeric_key_counter
                for numeric_key_counter, key in enumerate([pygame.K_KP0,pygame.K_KP1,pygame.K_KP2,pygame.K_KP3,pygame.K_KP4,pygame.K_KP5,pygame.K_KP6,pygame.K_KP7,pygame.K_KP8,pygame.K_KP9]):
                    if event.key == key:
                        logger.debug("Keypress 'keypad " + str(numeric_key_counter + 1) + "' detected")
                        return numeric_key_counter
                else:
                    return None
    except pygame.error as e:
        logger.debug("Exception " + repr(e))
        exit(0) 
开发者ID:SvenVD,项目名称:rpisurv,代码行数:31,代码来源:draw.py

示例4: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_r [as 别名]
def __init__(self, mqtt_client, is_debug=False):
        # 是否开启调试模式
        self.is_debug = is_debug
        # MQTT的客户端
        self.mqtt_client = mqtt_client
        # 设置小车的默认速度
        self.speed = self.DEFAULT_CAR_SPEED
        # 设置默认的舵机云台角度变换值
        self.cp_delta_angle = self.DEFAULT_CP_DELTA_ANGLE
        # 记录当前底部舵机的角度
        self.bottom_servo_angle = self.BOTTOM_SERVO_DEFAULT_ANGLE
        # 记录顶部舵机的角度
        self.top_servo_angle = self.TOP_SERVO_DEFAULT_ANGLE
            
        # 键盘事件映射字典
        self.KEY_FUNC_MAP = {
            pygame.K_LEFT: self.turn_left,
            pygame.K_RIGHT: self.turn_right,
            pygame.K_UP: self.go_forward,
            pygame.K_DOWN: self.go_backward,
            pygame.K_a: self.cp_left,
            pygame.K_d: self.cp_right,
            pygame.K_w: self.cp_up,
            pygame.K_s: self.cp_down,
            pygame.K_r: self.cp_reset
        }
        
        # 小车停止
        self.stop()
        # 舵机复位
        self.cp_reset() 
开发者ID:1zlab,项目名称:1ZLAB_PyEspCar,代码行数:33,代码来源:pyespcar_sdk.py

示例5: get_order

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_r [as 别名]
def get_order(self): 
        # get order from controler
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return True
        pressed = pygame.key.get_pressed()
        if pressed[pygame.K_1]: self.n = 0
        if pressed[pygame.K_2]: self.n = 1
        if pressed[pygame.K_3]: self.n = 2
        if pressed[pygame.K_4]: self.n = 3
        self.orders[self.n] = 0
        if pressed[pygame.K_w]: self.orders[self.n, 0] += 1
        if pressed[pygame.K_s]: self.orders[self.n, 0] -= 1
        if pressed[pygame.K_q]: self.orders[self.n, 1] -= 1
        if pressed[pygame.K_e]: self.orders[self.n, 1] += 1
        if pressed[pygame.K_a]: self.orders[self.n, 2] -= 1
        if pressed[pygame.K_d]: self.orders[self.n, 2] += 1
        if pressed[pygame.K_b]: self.orders[self.n, 3] -= 1
        if pressed[pygame.K_m]: self.orders[self.n, 3] += 1
        if pressed[pygame.K_SPACE]: self.orders[self.n, 4] = 1
        else: self.orders[self.n, 4] = 0
        if pressed[pygame.K_f]: self.orders[self.n, 5] = 1
        else: self.orders[self.n, 5] = 0
        if pressed[pygame.K_r]: self.orders[self.n, 6] = 1
        else: self.orders[self.n, 6] = 0
        if pressed[pygame.K_n]: self.orders[self.n, 7] = 1
        else: self.orders[self.n, 7] = 0
        if pressed[pygame.K_TAB]: self.dev = True
        else: self.dev = False
        return False 
开发者ID:LoveThinkinghard,项目名称:RoboMaster-AI-Challenge-Simulator-2D,代码行数:32,代码来源:kernal.py

示例6: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_r [as 别名]
def __init__(self, input, target):
        
        super().__init__()
    
        self.input = input
        self.target = target
        
        # forward vector stays level with horizontal plane
        self.forward = np.array( [0, 0, -1] )
        # up vector is constant
        self.up = np.array( [0,1,0] )
        # recalculate right vector whenever forward vector changes
        self.right = np.cross( self.forward, self.up )
        
        # control rate of movement
        self.deltaTime = 1.0/60.0 # TODO: get actual number from input? 
        self.unitsPerSecond = 1
        self.moveAmount = self.unitsPerSecond * self.deltaTime
        self.degreesPerSecond = 60
        self.turnAmount = self.degreesPerSecond * (3.1415926 / 180) * self.deltaTime

        # customizable key mappings
        # standard controls (WASDRF, QETG)     

        self.KEY_MOVE_FORWARDS  = pygame.K_w
        self.KEY_MOVE_BACKWARDS = pygame.K_s
        self.KEY_MOVE_LEFT      = pygame.K_a
        self.KEY_MOVE_RIGHT     = pygame.K_d
        self.KEY_MOVE_UP        = pygame.K_r
        self.KEY_MOVE_DOWN      = pygame.K_f
        self.KEY_TURN_LEFT      = pygame.K_q
        self.KEY_TURN_RIGHT     = pygame.K_e
        self.KEY_LOOK_UP        = pygame.K_t
        self.KEY_LOOK_DOWN      = pygame.K_g 
开发者ID:stemkoski,项目名称:three.py,代码行数:36,代码来源:FirstPersonController.py

示例7: main

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_r [as 别名]
def main():
	pygame.init()
	screen = pygame.display.set_mode((WIDTH, HEIGHT))
	pygame.display.set_caption('Gemgem-微信公众号: Charles的皮卡丘')
	# 加载背景音乐
	pygame.mixer.init()
	pygame.mixer.music.load(os.path.join(ROOTDIR, "resources/audios/bg.mp3"))
	pygame.mixer.music.set_volume(0.6)
	pygame.mixer.music.play(-1)
	# 加载音效
	sounds = {}
	sounds['mismatch'] = pygame.mixer.Sound(os.path.join(ROOTDIR, 'resources/audios/badswap.wav'))
	sounds['match'] = []
	for i in range(6):
		sounds['match'].append(pygame.mixer.Sound(os.path.join(ROOTDIR, 'resources/audios/match%s.wav' % i)))
	# 加载字体
	font = pygame.font.Font(os.path.join(ROOTDIR, 'resources/font.TTF'), 25)
	# 图片加载
	gem_imgs = []
	for i in range(1, 8):
		gem_imgs.append(os.path.join(ROOTDIR, 'resources/images/gem%s.png' % i))
	# 主循环
	game = gemGame(screen, sounds, font, gem_imgs)
	while True:
		score = game.start()
		flag = False
		# 一轮游戏结束后玩家选择重玩或者退出
		while True:
			for event in pygame.event.get():
				if event.type == pygame.QUIT or (event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE):
					pygame.quit()
					sys.exit()
				elif event.type == pygame.KEYUP and event.key == pygame.K_r:
					flag = True
			if flag:
				break
			screen.fill((135, 206, 235))
			text0 = 'Final score: %s' % score
			text1 = 'Press <R> to restart the game.'
			text2 = 'Press <Esc> to quit the game.'
			y = 150
			for idx, text in enumerate([text0, text1, text2]):
				text_render = font.render(text, 1, (85, 65, 0))
				rect = text_render.get_rect()
				if idx == 0:
					rect.left, rect.top = (212, y)
				elif idx == 1:
					rect.left, rect.top = (122.5, y)
				else:
					rect.left, rect.top = (126.5, y)
				y += 100
				screen.blit(text_render, rect)
			pygame.display.update()
		game.reset() 
开发者ID:CharlesPikachu,项目名称:Games,代码行数:56,代码来源:Game15.py


注:本文中的pygame.K_r方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。