本文整理汇总了Python中GameEngine.GameEngine.run方法的典型用法代码示例。如果您正苦于以下问题:Python GameEngine.run方法的具体用法?Python GameEngine.run怎么用?Python GameEngine.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameEngine.GameEngine
的用法示例。
在下文中一共展示了GameEngine.run方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SvgTest
# 需要导入模块: from GameEngine import GameEngine [as 别名]
# 或者: from GameEngine.GameEngine import run [as 别名]
class SvgTest(unittest.TestCase):
def testRendering(self):
self.svg.transform.translate(256, 256)
self.svg.transform.rotate(3.141592)
self.svg.draw()
self.e.video.flip()
def testRenderToTexture(self):
scale = 4
fullwidth, fullheight = 512, 512
width, height = int(fullwidth / scale), int(fullheight / scale)
t = Texture()
self.e.svg.setProjection((0, 0, fullwidth, fullheight))
glViewport(0, 0, width, height)
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
self.svg.transform.translate(width * scale / 2, height * scale / 2)
self.svg.transform.rotate(3.141592)
self.svg.draw()
glViewport(0, 0, fullwidth, fullheight)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(0.0, 1.0, 0.0, 1.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
t.bind()
glEnable(GL_TEXTURE_2D)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(1.0, 1.0, 1.0)
glBegin(GL_TRIANGLE_STRIP)
glTexCoord2f(0.0, 0.0)
glVertex2f(0.0, 0.0)
glTexCoord2f(1.0, 0.0)
glVertex2f(1.0, 0.0)
glTexCoord2f(0.0, 1.0)
glVertex2f(0.0, 1.0)
glTexCoord2f(1.0, 1.0)
glVertex2f(1.0, 1.0)
glEnd()
self.e.video.flip()
import time
time.sleep(2)
def setUp(self):
config = Config.load(Version.appName() + ".ini", setAsDefault = True)
self.e = GameEngine(config)
self.e.loadImgDrawing(self, "svg", "mfhlogo.png")
while not self.svg:
self.e.run()
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
示例2: testNetworking
# 需要导入模块: from GameEngine import GameEngine [as 别名]
# 或者: from GameEngine.GameEngine import run [as 别名]
def testNetworking(self):
config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini", setAsDefault = True)
e1 = GameEngine(config)
e1.startServer()
session1 = e1.connect("localhost")
session2 = e1.connect("localhost")
while not session1.isConnected() or not session2.isConnected():
e1.run()
session1.world.createPlayer("mario")
session2.world.createPlayer("luigi")
for i in range(10):
e1.run()
assert len(e1.server.world.players) == 2
assert len(session1.world.players) == 2
assert len(session2.world.players) == 2
session3 = e1.connect("localhost")
for i in range(10):
e1.run()
assert len(session3.world.players) == 2
session1.disconnect()
for i in range(10):
e1.run()
assert len(e1.server.world.players) == 1
assert len(session2.world.players) == 1
e1.quit()
示例3: testNetworking
# 需要导入模块: from GameEngine import GameEngine [as 别名]
# 或者: from GameEngine.GameEngine import run [as 别名]
def testNetworking(self):
e1 = GameEngine()
e1.startServer()
session1 = e1.connect("localhost")
session2 = e1.connect("localhost")
while not session1.isConnected() or not session2.isConnected():
e1.run()
session1.world.createPlayer("mario")
session2.world.createPlayer("luigi")
for i in range(10):
e1.run()
assert len(e1.server.world.players) == 2
assert len(session1.world.players) == 2
assert len(session2.world.players) == 2
session3 = e1.connect("localhost")
for i in range(10):
e1.run()
assert len(session3.world.players) == 2
session1.disconnect()
for i in range(10):
e1.run()
assert len(e1.server.world.players) == 1
assert len(session2.world.players) == 1
e1.quit()
示例4: main
# 需要导入模块: from GameEngine import GameEngine [as 别名]
# 或者: from GameEngine.GameEngine import run [as 别名]
#.........这里部分代码省略.........
if nbrplayers == 1:
engine.cmdMode = nbrplayers, mode, 0
else:
engine.cmdMode = nbrplayers, 0, mode
encoding = Config.get("game", "encoding")
if encoding is not None:
#stump: XXX: Everything I have seen indicates that this is a
# horrible, horrible hack. Is there another way? Do we even need this?
reload(sys)
sys.setdefaultencoding(encoding)
# Play the intro video if it is present, we have the capability, and
# we are not in one-shot mode.
videoLayer = False
if videoAvailable and not engine.cmdPlay:
# TODO: Parameters to add to theme.ini:
# - intro_video_file
# - intro_video_start_time
# - intro_video_end_time
themename = Config.get("coffee", "themename")
vidSource = os.path.join(Version.dataPath(), 'themes', themename, \
'menu', 'intro.mp4')
if os.path.isfile(vidSource):
winWidth, winHeight = engine.view.geometry[2:4]
songVideoStartTime = 0
songVideoEndTime = None
vidPlayer = VideoPlayer(-1, vidSource, (winWidth, winHeight),
startTime = songVideoStartTime,
endTime = songVideoEndTime)
if vidPlayer.validFile:
engine.view.pushLayer(vidPlayer)
videoLayer = True
try:
engine.ticksAtStart = pygame.time.get_ticks()
while not vidPlayer.finished:
engine.run()
engine.view.popLayer(vidPlayer)
engine.view.pushLayer(MainMenu(engine))
except KeyboardInterrupt:
engine.view.popLayer(vidPlayer)
engine.view.pushLayer(MainMenu(engine))
if not videoLayer:
engine.setStartupLayer(MainMenu(engine))
#stump: make psyco optional
if Config.get("performance", "use_psyco"):
try:
import psyco
psyco.profile()
except:
Log.error("Unable to enable psyco as requested: ")
# Run the main game loop.
try:
engine.ticksAtStart = pygame.time.get_ticks()
while engine.run():
pass
except KeyboardInterrupt:
Log.notice("Left mainloop due to KeyboardInterrupt.")
# don't reraise
# Restart the program if the engine is asking that we do so.
if engine.restartRequested:
Log.notice("Restarting.")
engine.audio.close()
try:
# Extra arguments to insert between the executable we call and our
# command line arguments.
args = []
# Figure out what executable to call.
if hasattr(sys, "frozen"):
if os.name == "nt":
# When py2exe'd, sys.executable is the name of the EXE.
exe = os.path.abspath(unicode(sys.executable, sys.getfilesystemencoding()))
elif sys.frozen == "macosx_app":
# When py2app'd, sys.executable is a Python interpreter copied
# into the same dir where we live.
exe = os.path.join(os.path.dirname(sys.executable), 'FoFiX') # FIXME: don't hard-code "FoFiX" here
else:
raise RuntimeError, "Don't know how to restart when sys.frozen is %s" % repr(sys.frozen)
else:
# When running from source, sys.executable is the Python interpreter
# being used to run the program.
exe = sys.executable
# Pass the optimization level on iif python version >= 2.6.0 as
# sys.flags has been introduced in 2.6.0.
if sys.version_info[:3] >= (2,6,0) and sys.flags.optimize > 0:
args.append('-%s' % ('O' * sys.flags.optimize))
args.append(sys.argv[0])
os.execv(exe, [sys.executable] + args + sys.argv[1:])
except:
Log.error("Restart failed: ")
raise
# evilynux - MainMenu class already calls this - useless?
engine.quit()
示例5: VideoPlayerTest
# 需要导入模块: from GameEngine import GameEngine [as 别名]
# 或者: from GameEngine.GameEngine import run [as 别名]
class VideoPlayerTest(unittest.TestCase):
# Simplest way to use the video player, use it as a Layer
def testVideoPlayerLayer(self):
config = Config.load(Version.appName() + ".ini", setAsDefault = True)
self.e = GameEngine(config)
winWidth, winHeight = (self.e.view.geometry[2], self.e.view.geometry[3])
vidPlayer = VideoPlayer(framerate, self.src, (winWidth, winHeight),
loop = False)
self.e.view.pushLayer(vidPlayer)
while not vidPlayer.finished:
self.e.run()
self.e.view.popLayer(vidPlayer)
self.e.audio.close()
self.e.quit()
# Keep tight control over the video player
def testVideoPlayerSlave(self):
winWidth, winHeight = 800, 600
pygame.init()
flags = DOUBLEBUF|OPENGL|HWPALETTE|HWSURFACE
pygame.display.set_mode((winWidth, winHeight), flags)
vidPlayer = VideoPlayer(framerate, self.src, (winWidth, winHeight))
glViewport(0, 0, winWidth, winHeight) # Both required as...
glScissor(0, 0, winWidth, winHeight) # ...GameEngine changes it
glClearColor(0, 0, 0, 1.)
while not vidPlayer.finished:
vidPlayer.run()
vidPlayer.render()
pygame.display.flip()
pygame.quit()
# Grab the texture, use the CallList and do whatever we want with it;
# We could also _just_ use the texture and take care of the polygons ourselves
def testVideoPlayerSlaveShowOff(self):
winWidth, winHeight = 500, 500
pygame.init()
flags = DOUBLEBUF|OPENGL|HWPALETTE|HWSURFACE
pygame.display.set_mode((winWidth, winHeight), flags)
vidPlayer = VideoPlayer(-1, self.src, (winWidth, winHeight))
glViewport(0, 0, winWidth, winHeight) # Both required as...
glScissor(0, 0, winWidth, winHeight) # ...GameEngine changes it
glClearColor(0, 0, 0, 1.)
x, y = 0.0, 1.0
fx, fy, ftheta = 1, 1, 1
theta = 0.0
time = 0.0
clock = pygame.time.Clock()
while not vidPlayer.finished:
vidPlayer.run()
vidPlayer.textureUpdate()
# Save and clear both transformation matrices
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(1., 1., 1.)
glBindTexture(GL_TEXTURE_2D, vidPlayer.videoTex)
glTranslatef(x, y, 0)
glRotatef(theta, 0, 0, 1.)
glScalef(.5, .5, 1.)
glCallList(vidPlayer.videoList)
# Restore both transformation matrices
glPopMatrix()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
pygame.display.flip()
x = (x + fx*time)
y = (y + fy*time)
theta = theta + ftheta
if x > 1.0 or x < -1.0:
fx = fx * -1
if y > 1.0 or y < -1.0:
fy = fy * -1
if theta > 90 or theta < -90:
ftheta = ftheta * -1
time = time + 0.00001
clock.tick(60)
pygame.quit()
def setUp(self):
self.src = os.path.join(Version.dataPath(), vidSource)
self.assert_(os.path.exists(self.src), "File %s does not exist!" % self.src)
def tearDown(self):
pass
示例6: reload
# 需要导入模块: from GameEngine import GameEngine [as 别名]
# 或者: from GameEngine.GameEngine import run [as 别名]
encoding = Config.get("game", "encoding")
if encoding != None:
reload(sys)
sys.setdefaultencoding(encoding)
engine.setStartupLayer(MainMenu(engine))
try:
import psyco
psyco.profile()
except:
Log.warn("Unable to enable psyco.")
try:
while engine.run():
pass
except KeyboardInterrupt:
pass
if engine.restartRequested:
Log.notice("Restarting.")
engine.audio.close()
try:
# Determine whether were running from an exe or not
if hasattr(sys, "frozen"):
if os.name == "nt":
os.execl("FretsOnFire.exe", "FretsOnFire.exe", *sys.argv[1:])
else:
os.execl("./FretsOnFire", "./FretsOnFire", *sys.argv[1:])
else:
if os.name == "nt":
示例7: main
# 需要导入模块: from GameEngine import GameEngine [as 别名]
# 或者: from GameEngine.GameEngine import run [as 别名]
def main():
"""Main thread"""
try:
opts, args = getopt.getopt(sys.argv[1:], "vdc:p:D:P:m:N:", ["verbose", "debug", "config=", "play=", "diff=", "part=", "mode=", "nbrplayers="])
except getopt.GetoptError:
print usage
sys.exit(1)
playing = None
configFile = None
debug = False
difficulty = 0
part = 0
mode = 0
nbrplayers = 1
for opt, arg in opts:
if opt in ["--verbose", "-v"]:
Log.quiet = False
if opt in ["--debug", "-d"]:
debug = True
if opt in ["--config", "-c"]:
configFile = arg
if opt in ["--play", "-p"]:
playing = arg
if opt in ["--diff", "-D"]:
difficulty = arg
if opt in ["--part", "-P"]:
part = arg
#evilynux - Multiplayer and mode selection support
if opt in ["--mode", "-m"]:
mode = int(arg)
if opt in ["--nbrplayers", "-N"]:
nbrplayers = int(arg)
while True:
if configFile != None:
if configFile.lower() == "reset":
fileName = os.path.join(Resource.getWritableResourcePath(), Version.appName() + ".ini")
os.remove(fileName)
config = Config.load(Version.appName() + ".ini", setAsDefault = True)
else:
config = Config.load(configFile, setAsDefault = True)
else:
config = Config.load(Version.appName() + ".ini", setAsDefault = True)
engine = GameEngine(config)
engine.cmdPlay = 0
if playing != None:
Config.set("game", "selected_library", "songs")
Config.set("game", "selected_song", playing)
engine.cmdPlay = 1
engine.cmdDiff = int(difficulty)
engine.cmdPart = int(part)
#evilynux - Multiplayer and mode selection support
Config.set("game", "players", nbrplayers)
Config.set("player0","mode_1p", mode)
Config.set("player1","mode_2p", mode)
if debug == True:
engine.setDebugModeEnabled(not engine.isDebugModeEnabled())
engine.debugLayer.debugOut(engine)
engine.quit()
break
encoding = Config.get("game", "encoding")
if encoding != None:
reload(sys)
sys.setdefaultencoding(encoding)
engine.setStartupLayer(MainMenu(engine))
try:
import psyco
psyco.profile()
except:
Log.warn("Unable to enable psyco.")
try:
while engine.run():
pass
except KeyboardInterrupt:
pass
if engine.restartRequested:
Log.notice("Restarting.")
engine.audio.close()
try:
# Determine whether were running from an exe or not
if hasattr(sys, "frozen"):
if os.name == "nt":
os.execl("FretsOnFire.exe", "FretsOnFire.exe", *sys.argv[1:])
elif sys.frozen == "macosx_app":
import string
import subprocess
appname = string.join(string.split(sys.executable, '/')[:-1], '/')
appname = appname+"/Frets on Fire"
subprocess.Popen(`appname`, shell=True)
else:
os.execl("./FretsOnFire", "./FretsOnFire", *sys.argv[1:])
else:
if os.name == "nt":
#.........这里部分代码省略.........
示例8: main
# 需要导入模块: from GameEngine import GameEngine [as 别名]
# 或者: from GameEngine.GameEngine import run [as 别名]
#.........这里部分代码省略.........
if configFile.lower() == "reset":
fileName = os.path.join(Resource.getWritableResourcePath(), Version.appName() + ".ini")
os.remove(fileName)
config = Config.load(Version.appName() + ".ini", setAsDefault = True)
else:
config = Config.load(configFile, setAsDefault = True)
else:
config = Config.load(Version.appName() + ".ini", setAsDefault = True)
#Lysdestic - Allow support for manipulating fullscreen via CLI
if fullscreen != None:
Config.set("video", "fullscreen", fullscreen)
#Lysdestic - Change resolution from CLI
if resolution != None:
Config.set("video", "resolution", resolution)
#Lysdestic - Alter theme from CLI
if theme != None:
Config.set("coffee", "themename", theme)
if playing != None:
library = Config.get("game","base_library")
basefolder = os.path.join(Version.dataPath(),library,"songs",playing)
if not (os.path.exists(os.path.join(basefolder, "song.ini")) and (os.path.exists(os.path.join(basefolder, "notes.mid")) or os.path.exists(os.path.join(basefolder, "notes-unedited.mid"))) and (os.path.exists(os.path.join(basefolder, "song.ogg")) or os.path.exists(os.path.join(basefolder, "guitar.ogg")))):
Log.warn("Song directory provided ('%s') is not a valid song directory. Starting up FoFiX in standard mode." % playing)
playing = None
engine = GameEngine(config)
engine.cmdPlay = 0
if playing != None:
Config.set("game", "selected_library", "songs")
Config.set("game", "selected_song", playing)
engine.cmdPlay = 1
if difficulty is not None:
engine.cmdDiff = int(difficulty)
if part is not None:
engine.cmdPart = int(part)
#evilynux - Multiplayer and mode selection support
Config.set("game", "players", nbrplayers)
if nbrplayers == 1:
Config.set("game", "game_mode", mode)
else:
Config.set("game", "game_mode", 0)
Config.set("game", "multiplayer_mode", mode)
if debug == True:
engine.setDebugModeEnabled(not engine.isDebugModeEnabled())
engine.debugLayer.debugOut(engine)
engine.quit()
break
encoding = Config.get("game", "encoding")
if encoding != None:
reload(sys)
sys.setdefaultencoding(encoding)
engine.setStartupLayer(MainMenu(engine))
#stump: make psyco optional
if Config.get("performance", "use_psyco"):
try:
import psyco
psyco.profile()
except:
Log.warn("Unable to enable psyco.")
try:
engine.ticksAtStart = pygame.time.get_ticks()
while engine.run():
pass
except KeyboardInterrupt:
pass
if engine.restartRequested:
Log.notice("Restarting.")
engine.audio.close()
try:
# Determine whether were running from an exe or not
if hasattr(sys, "frozen"):
if os.name == "nt":
os.execl("FoFiX.exe", "FoFiX.exe", *sys.argv[1:])
elif sys.frozen == "macosx_app":
import string
import subprocess
appname = string.join(string.split(sys.executable, '/')[:-1], '/')
appname = appname+"/FoFiX"
subprocess.Popen(`appname`, shell=True)
else:
os.execl("./FoFiX", "./FoFiX", *sys.argv[1:])
else:
# stump: sys.executable points to the active python interpreter
os.execl(sys.executable, sys.executable, "FoFiX.py", *sys.argv[1:])
except:
Log.warn("Restart failed.")
raise
break
else:
break
# evilynux - MainMenu class already calls this - useless?
engine.quit()
示例9: GameEngine
# 需要导入模块: from GameEngine import GameEngine [as 别名]
# 或者: from GameEngine.GameEngine import run [as 别名]
'''
Created on 9 Sep 2012
@author: Callum
'''
from GameEngine import GameEngine
import pygame
from pygame.locals import *
if __name__ == '__main__':
### Start!
pygameDisplay=pygame.display.set_mode((800,800),RESIZABLE)
pygame.display.set_caption("PiCore")
engine = GameEngine(pygameDisplay) #Create engine
engine.run() #Get going....
pass
示例10: SvgTest
# 需要导入模块: from GameEngine import GameEngine [as 别名]
# 或者: from GameEngine.GameEngine import run [as 别名]
class SvgTest(unittest.TestCase):
def testRendering(self):
self.svg.transform.translate(256, 256)
self.svg.transform.rotate(3.141592)
self.svg.draw()
self.e.video.flip()
def testRenderToTexture(self):
scale = 4
fullwidth, fullheight = 512, 512
width, height = int(fullwidth / scale), int(fullheight / scale)
t = Texture()
self.e.svg.setProjection((0, 0, fullwidth, fullheight))
t.prepareRenderTarget(width, height)
t.setAsRenderTarget()
glViewport(0, 0, width, height)
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
self.svg.transform.translate(width * scale / 2, height * scale / 2)
self.svg.transform.rotate(3.141592)
self.svg.draw()
t.resetDefaultRenderTarget()
glViewport(0, 0, fullwidth, fullheight)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(0.0, 1.0, 0.0, 1.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
t.bind()
glEnable(GL_TEXTURE_2D)
if not t.framebuffer.emulated:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(1.0, 1.0, 1.0)
glBegin(GL_TRIANGLE_STRIP)
glTexCoord2f(0.0, 0.0)
glVertex2f(0.0, 0.0)
glTexCoord2f(1.0, 0.0)
glVertex2f(1.0, 0.0)
glTexCoord2f(0.0, 1.0)
glVertex2f(0.0, 1.0)
glTexCoord2f(1.0, 1.0)
glVertex2f(1.0, 1.0)
glEnd()
self.e.video.flip()
import time
time.sleep(2)
def setUp(self):
self.e = GameEngine()
self.e.loadSvgDrawing(self, "svg", "koopa.svg")
while not self.svg:
self.e.run()
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
示例11: main
# 需要导入模块: from GameEngine import GameEngine [as 别名]
# 或者: from GameEngine.GameEngine import run [as 别名]
#.........这里部分代码省略.........
if theme is not None:
Config.set("coffee", "themename", theme)
engine = GameEngine(config)
engine.cmdPlay = 0
# Check for a valid invocation of one-shot mode.
if playing is not None:
Log.debug('Validating song directory for one-shot mode.')
library = Config.get("game","base_library")
basefolder = os.path.join(Version.dataPath(),library,"songs",playing)
if not (os.path.exists(os.path.join(basefolder, "song.ini")) and (os.path.exists(os.path.join(basefolder, "notes.mid")) or os.path.exists(os.path.join(basefolder, "notes-unedited.mid"))) and (os.path.exists(os.path.join(basefolder, "song.ogg")) or os.path.exists(os.path.join(basefolder, "guitar.ogg")))):
Log.warn("Song directory provided ('%s') is not a valid song directory. Starting up FoFiX in standard mode." % playing)
engine.startupMessages.append(_("Song directory provided ('%s') is not a valid song directory. Starting up FoFiX in standard mode.") % playing)
playing = None
# Set up one-shot mode if the invocation is valid for it.
if playing is not None:
Log.debug('Entering one-shot mode.')
Config.set("game", "selected_library", "songs")
Config.set("game", "selected_song", playing)
engine.cmdPlay = 1
if difficulty is not None:
engine.cmdDiff = int(difficulty)
if part is not None:
engine.cmdPart = int(part)
#evilynux - Multiplayer and mode selection support
Config.set("game", "players", nbrplayers)
if nbrplayers == 1:
Config.set("game", "game_mode", mode)
else:
Config.set("game", "game_mode", 0)
Config.set("game", "multiplayer_mode", mode)
if debug:
engine.setDebugModeEnabled(not engine.isDebugModeEnabled())
engine.debugLayer.debugOut(engine)
engine.quit()
return
encoding = Config.get("game", "encoding")
if encoding is not None:
#stump: XXX: Everything I have seen indicates that this is a
# horrible, horrible hack. Is there another way? Do we even need this?
reload(sys)
sys.setdefaultencoding(encoding)
engine.setStartupLayer(MainMenu(engine))
#stump: make psyco optional
if Config.get("performance", "use_psyco"):
try:
import psyco
psyco.profile()
except:
Log.error("Unable to enable psyco as requested: ")
# Run the main game loop.
try:
engine.ticksAtStart = pygame.time.get_ticks()
while engine.run():
pass
except KeyboardInterrupt:
Log.notice("Left mainloop due to KeyboardInterrupt.")
# don't reraise
# Restart the program if the engine is asking that we do so.
if engine.restartRequested:
Log.notice("Restarting.")
engine.audio.close()
try:
# Extra arguments to insert between the executable we call and our
# command line arguments.
args = []
# Figure out what executable to call.
if hasattr(sys, "frozen"):
if os.name == "nt":
# When py2exe'd, sys.executable is the name of the EXE.
exe = os.path.abspath(unicode(sys.executable, sys.getfilesystemencoding()))
elif sys.frozen == "macosx_app":
# When py2app'd, sys.executable is a Python interpreter copied
# into the same dir where we live.
exe = os.path.join(os.path.dirname(sys.executable), 'FoFiX') # FIXME: don't hard-code "FoFiX" here
else:
raise RuntimeError, "Don't know how to restart when sys.frozen is %s" % repr(sys.frozen)
else:
# When running from source, sys.executable is the Python interpreter
# being used to run the program.
exe = sys.executable
# Pass the optimization level on.
if sys.flags.optimize > 0:
args.append('-%s' % ('O' * sys.flags.optimize))
args.append(__file__)
os.execv(exe, [sys.executable] + args + sys.argv[1:])
except:
Log.error("Restart failed: ")
raise
# evilynux - MainMenu class already calls this - useless?
engine.quit()
示例12: AnimationPlayerTest
# 需要导入模块: from GameEngine import GameEngine [as 别名]
# 或者: from GameEngine.GameEngine import run [as 别名]
class AnimationPlayerTest(unittest.TestCase):
# Simplest way to use the Animation player, use it as a Layer
def testAnimationPlayerLayer(self):
loop = 10
config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini", setAsDefault = True)
self.e = GameEngine(config)
animPlayer = AnimationPlayer(framerate, self.path, self.basename,
(self.e.view.geometry[2],
self.e.view.geometry[3]), loop = loop)
print "Rendering as a GameEngine Layer for %d loops." % loop
self.e.view.pushLayer(animPlayer)
startTime = pygame.time.get_ticks()
while not animPlayer.finished:
self.e.run()
stopTime = pygame.time.get_ticks()
totalTime = stopTime - startTime
print "nbrFrames: %d, nbrLoops: %d, Total time: %.02f s, Average fps: %.02f" % \
(animPlayer.nbrFrames, loop, totalTime/1000.0, \
(float(1000.0*animPlayer.nbrFrames*(loop+1)) / float(totalTime)))
self.e.view.popLayer(animPlayer)
self.e.quit()
# Keep tight control over the Animation player
def testAnimationPlayerSlave(self):
loop = 5
winWidth, winHeight = 800, 600
pygame.init()
flags = DOUBLEBUF|OPENGL|HWPALETTE|HWSURFACE
pygame.display.set_mode((winWidth, winHeight), flags)
animPlayer = AnimationPlayer(framerate, self.path, self.basename,
(winWidth, winHeight), loop = loop)
glViewport(0, 0, winWidth, winHeight) # Both required as...
glScissor(0, 0, winWidth, winHeight) # ...GameEngine changes it
glClearColor(0, 0, 0, 1.)
print "Rendering independently and fullscreen for %d loops." % loop
clock = pygame.time.Clock()
startTime = pygame.time.get_ticks()
while not animPlayer.finished:
ticks = clock.get_time()
animPlayer.run(ticks)
animPlayer.render()
pygame.display.flip()
clock.tick()
stopTime = pygame.time.get_ticks()
totalTime = stopTime - startTime
print "nbrFrames: %d, nbrLoops: %d, Total time: %.02f s, Average fps: %.02f" % \
(animPlayer.nbrFrames, loop, totalTime/1000.0,
1000.0*animPlayer.nbrFrames*(loop+1) / float(totalTime))
# Testing animation change
# FIXME: another set of files would be more relevant (e.g. diff. resolution)
loop = 5
print "Let's go for another ride of %d loops." % loop
animPlayer.loop = loop
animPlayer.loadAnimation(self.path, self.basename)
startTime = pygame.time.get_ticks()
while not animPlayer.finished:
ticks = clock.get_time()
animPlayer.run(ticks)
animPlayer.render()
pygame.display.flip()
clock.tick()
stopTime = pygame.time.get_ticks()
totalTime = stopTime - startTime
print "nbrFrames: %d, nbrLoops: %d, Total time: %.02f s, Average fps: %.02f" % \
(animPlayer.nbrFrames, loop, totalTime/1000.0,
1000.0*animPlayer.nbrFrames*(loop+1) / float(totalTime))
pygame.quit()
# Grab the texture, use the CallList and do whatever we want with it;
# We could also _just_ use the texture and take care of the polygons ourselves
def testAnimationPlayerSlaveShowOff(self):
winWidth, winHeight = 500, 500
loop = 4
pygame.init()
flags = DOUBLEBUF|OPENGL|HWPALETTE|HWSURFACE
pygame.display.set_mode((winWidth, winHeight), flags)
animPlayer = AnimationPlayer(framerate, self.path, self.basename,
(winWidth, winHeight), loop = loop)
print "Rendering ourselves, doing what we want with the texture, for %d loops." % loop
glViewport(0, 0, winWidth, winHeight) # Both required as...
glScissor(0, 0, winWidth, winHeight) # ...GameEngine changes it
glClearColor(0, 0, 0, 1.)
x, y = 0.0, 1.0
fx, fy, ftheta = 1, 1, 1
theta = 0.0
time = 0.0
clock = pygame.time.Clock()
startTime = pygame.time.get_ticks()
while not animPlayer.finished:
ticks = clock.get_time()
animPlayer.run(ticks)
texture = animPlayer.getTexture()
# Save and clear both transformation matrices
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
#.........这里部分代码省略.........