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


Python Engine.frame方法代码示例

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


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

示例1: open

# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import frame [as 别名]
pauseMenuResume = Image.get('PauseMenuResume')
pauseMenuRestart = Image.get('PauseMenuRestart')
pauseMenuExit = Image.get('PauseMenuExit')
gameOverRetry = Image.get('GameOverRetry')
gameOverExit = Image.get('GameOverExit')
highScoreBackground = Image.get('HighScoreBackground')
highScoresFile = open('scores.txt', 'r+')
sidebar = Sidebar()
game = Engine(screen, sidebar)
Enemy.setSidebar(sidebar)
player = Player(game)


# Initializing stuff on boot
clock = pygame.time.Clock()
game.frame = 0
gameOpen = True
currentMenuScreen = mainMenuNewGame
currentPauseScreen = pauseMenuResume
currentQuitScreen = gameOverRetry
screenSelect = [True, False]
pauseSelect = [True, False, False]
quitSelect = [True, False]
highScores = []
for score in highScoresFile:
	highScores.append(score)
	
scoresFont = pygame.font.SysFont("monospace", 18)

def gameOverScreen():
	currentQuitScreen = gameOverRetry
开发者ID:Brolita,项目名称:GameDevProject1,代码行数:33,代码来源:game.py

示例2: Game

# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import frame [as 别名]
class Game(object):
    """Game logic class.

    Manage all the logics related with single and multi games."""

    def __init__(self):

        # First tank is always the player tank
        self.tanks = []
        self.shoots = []
        self.gametype = GAMETYPE_SINGLE

    def single(self):
        """Starts a single player mode."""

        # Prepare pygame, screen and clock.
        pygame.init()
        self.engine = Engine()
        self.screen_size = self.engine.screen_size
        self.clock = pygame.time.Clock()

        # Used by the keyboard input filter
        self.player_keys = [False, False, False, False]

        # Spawns the player tank in the upper-left corner.
        player_tank = Tank(
            self,
            [TANK_RADIUS + TANK_MARGIN, TANK_RADIUS + TANK_MARGIN],
            FACING_EAST,
            SPRITE_PLAYER
        )

        # Spawns a single enemy in the bottom-right corner.
        enemy_tank = Tank(
            self,
            [self.screen_size[0] - TANK_RADIUS + TANK_MARGIN,
                self.screen_size[1] - TANK_RADIUS + TANK_MARGIN],
            FACING_WEST,
            SPRITE_ENEMY
        )

        # Append the tanks and start the game
        self.tanks.append(player_tank)
        self.tanks.append(enemy_tank)
        self.running = True
        self.game_loop()

    def game_loop(self):
        """Main game loop."""

        while self.running:
            self.manage_events()
            self.update()
            self.engine.frame()
            self.clock.tick(GAME_TPS)

    def update(self):
        """Update all the game entities (tick)."""

        # Update tanks
        for tank in self.tanks:
            tank.update()

        # Update shoots
        for shoot in self.shoots:
            shoot.update()

    def manage_events(self):
        """Manage pygame events."""

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.running = False
            elif event.type == pygame.KEYDOWN or event.type == pygame.KEYUP:
                self.keyboard_event(event)

    def keyboard_event(self, event):
        """
        Manage pygame events related with the keyboard.

        Pretty UP DOWN LEFT RIGHT arrows filter here. The trick is done with
        an instance variable holding the last status between key events.
        """

        if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
            if self.tanks[0].ball_reload < 1:
                if self.tanks[0].orientation == FACING_EAST:
                    new_shoot = Shoot(
                        self,
                        [self.tanks[0].position[0] + TANK_RADIUS + 1,
                        self.tanks[0].position[1]],
                        FACING_EAST
                    )
                elif self.tanks[0].orientation == FACING_SOUTH:
                    new_shoot = Shoot(
                        self,
                        [self.tanks[0].position[0],
                        self.tanks[0].position[1] + TANK_RADIUS + 1],
                        FACING_SOUTH
                    )
#.........这里部分代码省略.........
开发者ID:fjfnaranjo,项目名称:KillDaTank,代码行数:103,代码来源:game.py


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