本文整理汇总了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
示例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
)
#.........这里部分代码省略.........