當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。