本文整理汇总了Python中world.World.update方法的典型用法代码示例。如果您正苦于以下问题:Python World.update方法的具体用法?Python World.update怎么用?Python World.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类world.World
的用法示例。
在下文中一共展示了World.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ExploreScreen
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import update [as 别名]
class ExploreScreen(GameScreen):
def __init__(self, app):
GameScreen.__init__(self, app)
utilities.setApp(self.app)
self.world = World(10)
self.app.taskMgr.add(self.update, "update")
self.app.accept("a", self.world.player.moveLeft, [True])
self.app.accept("a-up", self.world.player.moveLeft, [False])
self.app.accept("d", self.world.player.moveRight, [True])
self.app.accept("d-up", self.world.player.moveRight, [False])
self.app.accept("space", self.world.player.jump, [True])
self.app.accept("space-up", self.world.player.jump, [False])
self.app.accept("c", self.world.player.crouch, [True])
self.app.accept("c-up", self.world.player.crouch, [False])
self.app.accept("mouse1", self.world.player.activate, [])
self.app.accept("escape", sys.exit, [])
#self.app.accept("h", self.showDBG, [True])
#self.app.accept("h-up", self.showDBG, [False])
self.prevTime = 0
self.app.mousePos = Point2()
self.app.disableMouse()
self.app.rl = base.camLens.makeCopy()
#bullet testing
#debugNode = BulletDebugNode('Debug')
#debugNode.showWireframe(True)
#debugNode.showConstraints(True)
#debugNode.showBoundingBoxes(False)
#debugNode.showNormals(False)
#self.debugNP = render.attachNewNode(debugNode)
#self.debugNP.show()
#self.world.bw.setDebugNode(self.debugNP.node())
def update(self, task):
delta = task.time - self.prevTime
self.prevTime = task.time
if(self.app.mouseWatcherNode.hasMouse()):
self.app.mousePos.x = self.app.mouseWatcherNode.getMouseX()
self.app.mousePos.y = self.app.mouseWatcherNode.getMouseY()
self.world.update(delta)
return Task.cont
示例2: MainGameState
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import update [as 别名]
class MainGameState(object):
def __init__(self):
self.background = backgrounds.Cave()
self.world = World()
self.player = Player(self.world, (-100, 52.4))
self.camera = Camera((0, 100.0), tracking=self.player)
def update(self, delta):
for event in pygame.event.get():
if event.type == QUIT:
sys.exit(0)
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
raise states.StateChange(states.PauseMenuState(self))
self.world.center = self.player.pos
self.background.update(delta)
self.world.update(delta)
self.player.update(delta)
self.camera.update(delta)
def render(self, screen):
self.background.render(screen, self.camera)
self.world.render(screen, self.camera)
self.player.render(screen, self.camera)
示例3: Game
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import update [as 别名]
class Game(object):
def __init__(self):
pygame.init()
self.caption = "Zelda Love Candy"
self.resolution = (640, 480)
self.screen = pygame.display.set_mode(self.resolution)
pygame.display.set_caption(self.caption)
self.clock = pygame.time.Clock()
self.isGameOver = False
self.world = World()
def update(self):
"""overide this to add neccessary update
"""
self.world.update()
self.world.render(self.screen)
def start(self):
""" start the game
"""
while not self.isGameOver:
self.clock.tick(30)
for events in pygame.event.get():
if events.type == pygame.QUIT:
self.isGameOver = True
self.update()
pygame.display.flip()
pygame.quit()
示例4: main
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import update [as 别名]
def main():
"""The main game loop."""
world = World()
painter = Painter()
player = world.player
while not libtcod.console_is_window_closed():
world.update()
painter.paint(world)
player.interact(world)
if player.exit:
break
painter.new_canvas()
示例5: Splash
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import update [as 别名]
class Splash(GameState):
"""Splash/Title screen"""
def __init__(self):
super(Splash, self).__init__()
self.next_state = "SHOOTING"
self.animations = pg.sprite.Group()
with open(os.path.join("resources", "clay_spots.json"), "r") as f:
skeet_spots = json.load(f)
self.all_sprites = pg.sprite.LayeredUpdates()
self.clays = pg.sprite.OrderedUpdates()
delay = 0
duration = 500
depth = 5000
for spot in skeet_spots:
clay = ClayPigeon((640, 750), 7, 0, False, self.clays, self.all_sprites)
clay.rect.center = 640, 750
clay.z = depth
x, y = spot
ani = Animation(centerx=x, centery=y, duration=duration, delay=delay, round_values=True)
ani.start(clay.rect)
self.animations.add(ani)
delay += 15
depth -= 1
self.world = World(False)
for s in self.all_sprites:
self.all_sprites.change_layer(s, -s.z)
try:
with open(os.path.join("resources", "high_scores.json"), "r") as f:
high_scores = json.load(f)
except IOError:
with open(os.path.join("resources", "high_scores.json"), "w") as f:
json.dump([], f)
def startup(self, persistent):
self.persist = persistent
def get_event(self, event):
if event.type == pg.QUIT:
self.quit = True
elif event.type == pg.MOUSEBUTTONUP:
self.done = True
def update(self, dt):
self.animations.update(dt)
self.world.update(dt)
def draw(self, surface):
surface.fill(self.world.sky)
surface.fill(self.world.grass, self.world.ground_rect)
self.all_sprites.draw(surface)
示例6: __init__
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import update [as 别名]
class Game:
def __init__(self):
self.init_window()
self.world = World()
self.bot = Bot(SimpleController())
self.bot.position = self.world.size * 0.5
self.world.add_bot(self.bot)
clock.schedule(self.update)
def init_window(self):
config = pyglet.gl.Config(sample_buffers=1, samples=4)
self.window = pyglet.window.Window(config=config, resizable=True)
self.window.set_size(1024, 768)
self.window.on_draw = self.on_draw
self.window.on_mouse_press = self.on_mouse_press
def update(self, dt):
self.world.update(dt)
def run(self):
pyglet.app.run()
def on_draw(self):
self.window.clear()
self.world.render()
# pyglet.gl.glColor4f(1.0,0,0,1.0)
# glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
# glEnable (GL_BLEND)
# glEnable (GL_LINE_SMOOTH);
# glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE)
# glLineWidth (3)
# pyglet.graphics.draw(2, pyglet.gl.GL_LINES,
# ('v2i', (10, 15, 300, 305))
# )
def on_mouse_press(self, x, y, button, modifiers):
self.bot.target.x = (float(x) / self.window.width) * 520.0 - 10.0
self.bot.target.y = (float(y) / self.window.height) * 520.0 - 10.0
#self.bot.position = self.bot.target
print self.bot.target
pass
示例7: main
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import update [as 别名]
def main():
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_LENGTH), 0, 32)
world = World(SCREEN_LENGTH,SCREEN_WIDTH)
world.set_ball_list(NUMBER_OF_BALLS)
clock = pygame.time.Clock()
# Game loop:
while True:
for event in pygame.event.get():
if event.type == QUIT:
exit()
time_passed_seconds = clock.tick()/ 1000.0
world.update(time_passed_seconds)
world.render(screen)
pygame.display.update()
示例8: run
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import update [as 别名]
def run():
'''
The main program loop. Manage the interface between the bot and the game
engine.
'''
world = World()
bot = Bot(world)
# The following 2 calls are not conditional to RUNS_LOCALLY as they do
# stuff either way...
set_world_profiling(world)
set_bot_profiling(bot)
if RUNS_LOCALLY:
import logging
log = logging.getLogger('main')
log.debug('# LOGGER STARTED')
# the overlay works like the logging: the overlay.overlay object is
# the Overlay() intantiation
overlay.target_bot(bot)
data = []
while(True):
try:
current_line = sys.stdin.readline().strip().lower()
if not current_line:
continue #skip empty lines
if current_line == 'ready':
world.setup(data)
bot.do_setup()
world.finish_turn()
data = []
elif current_line == 'go':
world.update(data)
bot.do_turn()
world.finish_turn()
data = []
else:
data.append(current_line)
except EOFError as e: # game is over or game engine has crashed
print(e)
break
except KeyboardInterrupt: # local user is stopping the game
print('\nEXECUTION STOPPED BY USER\n')
except: # try to stay alive! [don't raise or exit]
import traceback
traceback.print_exc(file=sys.stderr)
sys.stderr.flush()
finally:
if RUNS_LOCALLY:
logging.shutdown()
示例9: SurfaceGenState
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import update [as 别名]
class SurfaceGenState(object):
def __init__(self):
self.world = World()
self.heightmap = heightmap_1d(14)
self.camera = Camera()
self.x = 0
try:
shutil.rmtree("data/world")
except OSError:
pass
os.makedirs("data/world")
def update(self, delta):
for event in pygame.event.get():
if event.type == QUIT:
sys.exit(0)
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
self.world.unload()
raise states.StateChange(states.PauseMenuState(self))
left = self.heightmap[self.x] * 51.2
right = self.heightmap[(self.x + 20) % 16384] * 51.2
self.world.center = (self.x / 10.0, left)
self.world.update(0.0)
body = self.world.b2world.CreateStaticBody(
shapes=b2PolygonShape(vertices=(
(self.x / 10.0, left),
(self.x / 10.0 + 2.0, right),
(self.x / 10.0 + 2.0, right + 200.0),
(self.x / 10.0, right + 200.0)
)
))
self.world.carve(body)
self.world.b2world.DestroyBody(body)
self.camera.pos = self.world.center
self.x += 5
if self.x > len(self.heightmap) - 5:
self.world.unload()
raise states.StateChange(CaveGenState(self.world))
def render(self, screen):
self.world.render(screen, self.camera)
示例10: Game
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import update [as 别名]
class Game(object):
def __init__(self):
self.clock = pygame.time.Clock()
self.world = World()
self.world.setup(4, 3, 64)
self.player = Player()
self.world.addPlayer(self.player)
area = AreaTest(64, 64)
area2 = AreaTest2(64, 64)
area3 = AreaTest3(64, 64)
self.world.addArea(area)
self.world.addArea(area2)
self.world.addArea(area3)
self.world.loadStartArea(area)
self.keyPressed = None
def controls(self):
self.keyPressed = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == QUIT:
self.quitGame()
elif event.type == KEYDOWN:
if event.key == K_SPACE: #Action key
d = self.player.facingDirection
if not self.player.direction:
#return node that the player is facing towards
print self.player.mover.getNeighborNode(d)
def readObjectText(self):
pass
def pause(self):
pass
def quitGame(self):
'''Quit the game'''
exit()
def gameLoop(self):
while True:
dt = self.clock.tick(30) / 1000.0
self.controls()
self.world.update(dt, self.keyPressed)
self.world.render()
pygame.display.update()
示例11: App
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import update [as 别名]
class App():
def __init__(self, visualization='3d', update_rate=30.0):
if(visualization == '2d'):
self.renderer = Plot2D(self)
elif(visualization == '3d'):
self.renderer = Plot3D(self)
self.update_rate_ms = 1.0/update_rate
self.last_frame_time = time.time()
self.delta = 0
self.state = 0
self.STATE_RUNNING = 0
self.STATE_PAUSED = 1
self.STATE_QUITTING = 2
def create_world(self, size):
self.world = World(size)
def start(self):
while True:
if(self.state == self.STATE_RUNNING):
# Compute delta time
current_time = time.time()
self.delta += current_time - self.last_frame_time
self.last_frame_time = current_time
# Update world based on passed time between frames
while(self.delta >= self.update_rate_ms):
self.world.update(self.delta)
self.delta -= self.update_rate_ms
# Draw the world
self.renderer.draw(self.world)
elif(self.state == self.STATE_PAUSED):
self.last_frame_time = time.time()
self.renderer.draw(self.world)
elif(self.state == self.STATE_QUITTING):
self.renderer.close()
break
示例12: Game
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import update [as 别名]
class Game(pyglet.window.Window):
def __init__(self, thinker_colors, thinkers):
config = pyglet.gl.Config(buffer_size=32,
alpha_size=8,
double_buffer=True)
super(Game, self).__init__(width=1024, height=768,
config=config, resizable=True)
self.world = World(10, 8)
self.thinker_colors = thinker_colors
self.thinkers = thinkers
self.world.add_tanks(thinker_colors)
pyglet.clock.schedule_interval(self.update_closure(), 1.0/60.0)
font = pyglet.font.load("terminal", bold=True)
color = (0.0, 1.0, 1.0, 1.0)
fmt = '%(fps).1f'
self.fps_display = pyglet.clock.ClockDisplay(font=font,
color=color,
format=fmt)
self.keys = key.KeyStateHandler()
self.push_handlers(self.keys)
def update_closure(self):
def update(dt):
for tank, thinker in zip(self.world.tanks, self.thinkers):
# only think on tanks that aren't doing anything
if tank.brain and tank.is_idle():
thinker_think(tank, thinker)
self.world.update(dt)
return update
def on_draw(self):
self.clear()
self.world.draw()
self.fps_display.draw()
示例13: MainApp
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import update [as 别名]
class MainApp(App):
settings = ObjectProperty(Settings())
def build(self):
self.running = False
self._register_keyboard()
self.world = World()
self.world.build(self.settings)
self.screen = Screen(size_hint_x=2)
self.screen.build(self.settings, self.world)
sync_property(self.screen, 'size', self.settings, 'world_size')
self.root.add_widget(self.screen)
return self.root
def gameloop(self, dt):
if self.running:
self.world.update(dt)
self.screen.update(dt)
def on_start(self):
# start after 0.5sec
Clock.schedule_once(self._toggle_running, 1)
Clock.schedule_interval(self.gameloop, 1/60.)
def _toggle_running(self, *args):
self.running = not self.running
def _register_keyboard(self):
self._keyboard = Window.request_keyboard(self._keyboard_closed, self.root, 'text')
self._keyboard.bind(on_key_down=self._on_keyboard_down)
def _keyboard_closed(self):
self._keyboard.unbind(on_key_down=self._on_keyboard_down)
self._keyboard = None
def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
if (keycode[1] == 'spacebar'):
self._toggle_running()
return True
示例14: main
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import update [as 别名]
def main():
pygame.init()
world = World(pygame.display.set_mode(SCREEN_SIZE))
pygame.display.set_caption('Gatherers')
background = pygame.Surface(world.screen.get_size())
background = background.convert()
background.fill(BACKGROUND_COLOR)
world.screen.blit(background, (0,0))
pygame.display.flip()
clock = pygame.time.Clock()
gatherers = pygame.sprite.Group()
for i in range(20):
x = random.randint(0,world.screen.get_width())
y = random.randint(0,world.screen.get_height())
world.addGoody((x,y))
while 1:
clock.tick(30)
for event in pygame.event.get():
if event.type == QUIT:
return
elif event.type == KEYDOWN and event.key == K_ESCAPE:
return
elif event.type == MOUSEBUTTONDOWN:
m = pygame.mouse.get_pressed()
if m[0]:
world.addGatherer(pygame.mouse.get_pos())
if m[2]:
world.addEnemy(pygame.mouse.get_pos())
world.update()
world.screen.blit(background, (0,0))
world.draw()
pygame.display.flip()
示例15: Game
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import update [as 别名]
class Game(object):
FPS = 30
def __init__(self):
pygame.init()
pygame.display.set_caption("RPG Game")
self.seed = 26281376
self.world = World(self.seed, SoundCache())
self.user = Player(self)
self.view = Gameview(self.world, self.user, ImageCache(), self.debug)
self.clock = pygame.time.Clock()
self.renderTime = 0
self.processTime = 0
def run(self):
while(True):
self.clock.tick(Game.FPS)
t = time.time()
self.view.draw()
self.renderTime = time.time() - t
t = time.time()
if not self.world.update():
continue
if self.user.turn():
continue
self.world.turn()
self.user.save()
self.processTime = time.time() - t
def debug(self):
msg = []
msg.append(['FPS: ' + str(int(self.clock.get_fps()))])
msg.append(['Mobs: ' + str(len(self.world.mobManager.mobs))])
msg.append(['Chunks: ' + str(len(self.world.chunkManager.chunkCache))])
msg.append(['Render: ' + str(int(self.renderTime * 1000)) + 'ms'])
msg.append(['World: ' + str(int(self.processTime * 1000)) + 'ms'])
msg.append(['Time: ' + str(self.world.time)])
return msg