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


Python pygame.K_SPACE属性代码示例

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


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

示例1: get_keys

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_SPACE [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)
                choice(self.game.weapon_sounds['gun']).play()
                MuzzleFlash(self.game, pos) 
开发者ID:kidscancode,项目名称:pygame_tutorials,代码行数:24,代码来源:sprites.py

示例2: GameStartInterface

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_SPACE [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

示例3: endGame

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_SPACE [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

示例4: _event_looper

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_SPACE [as 别名]
def _event_looper(self, force=False):
        has_quit = False
        if self._deactivate_display:
            return force, has_quit
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                has_quit = True
                return force, has_quit
                # pygame.quit()
                # exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    has_quit = True
                    return force, has_quit
                if event.key == pygame.K_SPACE:
                    self._get_plot_pause()
                    # pause_surface = self.draw_plot_pause()
                    # self.screen.blit(pause_surface, (320 + self.left_menu_shape[0], 320))
                    return not force, has_quit
        return force, has_quit 
开发者ID:rte-france,项目名称:Grid2Op,代码行数:22,代码来源:PlotPyGame.py

示例5: _press_key_to_quit

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_SPACE [as 别名]
def _press_key_to_quit(self):
        """
        This utility function waits for the player to press a key to exit the renderer (called when the episode is done)

        Returns
        -------
        res: ``bool``, ``bool``
            ``True`` if the human player closed the window, in this case it will stop the computation: no other episode
            will be computed. ``False`` otherwise.

        """
        if self._deactivate_display:
            return
        has_quit = False
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                has_quit = True
                return True, has_quit
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    has_quit = True
                    return True, has_quit
                if event.key == pygame.K_SPACE:
                    return True, has_quit
        return False, has_quit 
开发者ID:rte-france,项目名称:Grid2Op,代码行数:27,代码来源:PlotPyGame.py

示例6: update

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_SPACE [as 别名]
def update(self):
        # timeout for powerups
        if self.power >= 2 and pygame.time.get_ticks() - self.power_time > POWERUP_TIME:
            self.power -= 1
            self.power_time = pygame.time.get_ticks()

        # unhide if hidden
        if self.hidden and pygame.time.get_ticks() - self.hide_timer > 1000:
            self.hidden = False
            self.rect.centerx = WIDTH / 2
            self.rect.bottom = HEIGHT - 10

        self.speedx = 0
        keystate = pygame.key.get_pressed()
        if keystate[pygame.K_LEFT]:
            self.speedx = -8
        if keystate[pygame.K_RIGHT]:
            self.speedx = 8
        if keystate[pygame.K_SPACE]:
            self.shoot()
        self.rect.x += self.speedx
        if self.rect.right > WIDTH:
            self.rect.right = WIDTH
        if self.rect.left < 0:
            self.rect.left = 0 
开发者ID:kidscancode,项目名称:pygame_tutorials,代码行数:27,代码来源:shmup-14.py

示例7: update

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_SPACE [as 别名]
def update(self):
        # unhide if hidden
        if self.hidden and pygame.time.get_ticks() - self.hide_timer > 1000:
            self.hidden = False
            self.rect.centerx = WIDTH / 2
            self.rect.bottom = HEIGHT - 10

        self.speedx = 0
        keystate = pygame.key.get_pressed()
        if keystate[pygame.K_LEFT]:
            self.speedx = -8
        if keystate[pygame.K_RIGHT]:
            self.speedx = 8
        if keystate[pygame.K_SPACE]:
            self.shoot()
        self.rect.x += self.speedx
        if self.rect.right > WIDTH:
            self.rect.right = WIDTH
        if self.rect.left < 0:
            self.rect.left = 0 
开发者ID:kidscancode,项目名称:pygame_tutorials,代码行数:22,代码来源:shmup-11.py

示例8: get_keys

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_SPACE [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

示例9: get_keys

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_SPACE [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

示例10: check_keydown_events

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_SPACE [as 别名]
def check_keydown_events(event: EventType, ai_settings: Settings
                         , stats: GameStats, game_items: GameItems):
    """Respond when key is being pressed."""
    if event.key == pygame.K_RIGHT:
        # Move ship to the right.
        game_items.ship.moving_right = True

    elif event.key == pygame.K_LEFT:
        # Move ship to the left.
        game_items.ship.moving_left = True

    elif event.key == pygame.K_SPACE:
        fire_bullet(ai_settings, game_items)

    elif event.key == pygame.K_q:
        quit_game(stats)

    elif event.key == pygame.K_RETURN:  # ENTER key
        start_new_game(ai_settings, stats, game_items) 
开发者ID:goswami-rahul,项目名称:alien-invasion-game,代码行数:21,代码来源:game_functions.py

示例11: endGame

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_SPACE [as 别名]
def endGame(screen, sounds, showScore, score, number_images, bird, pipe_sprites, backgroud_image, other_images, base_pos, cfg, mode):
	if mode == 'train':
		return
	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)
		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,项目名称:AIGames,代码行数:24,代码来源:endGame.py

示例12: normal_update

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_SPACE [as 别名]
def normal_update(self, keys):
        if self.allow_input:
            if keys[pg.K_DOWN] and self.arrow.index == 0:
                self.arrow.index = 1
                self.notify(c.CLICK)
                self.allow_input = False
            elif keys[pg.K_UP] and self.arrow.index == 1:
                self.arrow.index = 0
                self.notify(c.CLICK)
                self.allow_input = False
            elif keys[pg.K_SPACE]:
                if self.arrow.index == 0:
                    self.game_data = pickle.load(open("save.p", "rb"))
                    self.next = c.TOWN
                    self.state = c.TRANSITION_OUT
                else:
                    self.next = c.OVERWORLD
                    self.state = c.TRANSITION_OUT
                self.notify(c.CLICK2)

            self.arrow.rect.y = self.arrow.pos_list[self.arrow.index]  

        if not keys[pg.K_DOWN] and not keys[pg.K_UP]:
            self.allow_input = True 
开发者ID:justinmeister,项目名称:The-Stolen-Crown-RPG,代码行数:26,代码来源:main_menu.py

示例13: handle_event

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_SPACE [as 别名]
def handle_event(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_BACKSPACE:
                self.reset()
            if event.key == pygame.K_SPACE:
                self.speed_y = -20
            if event.key == pygame.K_LEFT:                        
                self.speed_x -= 10
            elif event.key == pygame.K_RIGHT:                        
                self.speed_x += 10
            elif event.key == pygame.K_DOWN:                        
                self.gravity += 10
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT:                        
                self.speed_x -= -10
            elif event.key == pygame.K_RIGHT:                        
                self.speed_x += -10
            elif event.key == pygame.K_DOWN:                        
                self.gravity += -10 
开发者ID:furas,项目名称:python-examples,代码行数:21,代码来源:main-2-class-move.py

示例14: GameEndInterface

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_SPACE [as 别名]
def GameEndInterface(screen, cfg):
	replay_image = pygame.image.load(cfg.IMAGE_PATHS['replay'])
	replay_image = pygame.transform.scale(replay_image, (35, 31))
	replay_image_rect = replay_image.get_rect()
	replay_image_rect.centerx = cfg.SCREENSIZE[0] / 2
	replay_image_rect.top = cfg.SCREENSIZE[1] * 0.52
	gameover_image = pygame.image.load(cfg.IMAGE_PATHS['gameover'])
	gameover_image = pygame.transform.scale(gameover_image, (190, 11))
	gameover_image_rect = gameover_image.get_rect()
	gameover_image_rect.centerx = cfg.SCREENSIZE[0] / 2
	gameover_image_rect.centery = cfg.SCREENSIZE[1] * 0.35
	clock = pygame.time.Clock()
	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:
					return True
			elif event.type == pygame.MOUSEBUTTONDOWN:
				mouse_pos = pygame.mouse.get_pos()
				if replay_image_rect.collidepoint(mouse_pos):
					return True
		screen.blit(replay_image, replay_image_rect)
		screen.blit(gameover_image, gameover_image_rect)
		pygame.display.update()
		clock.tick(cfg.FPS) 
开发者ID:CharlesPikachu,项目名称:Games,代码行数:30,代码来源:gameend.py

示例15: startGame

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_SPACE [as 别名]
def startGame(screen, sounds, bird_images, other_images, backgroud_image, cfg):
	base_pos = [0, cfg.SCREENHEIGHT*0.79]
	base_diff_bg = other_images['base'].get_width() - backgroud_image.get_width()
	msg_pos = [(cfg.SCREENWIDTH-other_images['message'].get_width())/2, cfg.SCREENHEIGHT*0.12]
	bird_idx = 0
	bird_idx_change_count = 0
	bird_idx_cycle = itertools.cycle([0, 1, 2, 1])
	bird_pos = [cfg.SCREENWIDTH*0.2, (cfg.SCREENHEIGHT-list(bird_images.values())[0].get_height())/2]
	bird_y_shift_count = 0
	bird_y_shift_max = 9
	shift = 1
	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 {'bird_pos': bird_pos, 'base_pos': base_pos, 'bird_idx': bird_idx}
		sounds['wing'].play()
		bird_idx_change_count += 1
		if bird_idx_change_count % 5 == 0:
			bird_idx = next(bird_idx_cycle)
			bird_idx_change_count = 0
		base_pos[0] = -((-base_pos[0] + 4) % base_diff_bg)
		bird_y_shift_count += 1
		if bird_y_shift_count == bird_y_shift_max:
			bird_y_shift_max = 16
			shift = -1 * shift
			bird_y_shift_count = 0
		bird_pos[-1] = bird_pos[-1] + shift
		screen.blit(backgroud_image, (0, 0))
		screen.blit(list(bird_images.values())[bird_idx], bird_pos)
		screen.blit(other_images['message'], msg_pos)
		screen.blit(other_images['base'], base_pos)
		pygame.display.update()
		clock.tick(cfg.FPS) 
开发者ID:CharlesPikachu,项目名称:Games,代码行数:40,代码来源:startGame.py


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