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


Python World.step方法代码示例

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


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

示例1: run

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import step [as 别名]
def run():
    WIDTH = 640
    HEIGHT = 480

    running = True
    clock = pygame.time.Clock()
    screen = pygame.display.set_mode( (WIDTH,HEIGHT) )
    w = World()

    c = Camera(screen, (0,0), 3.0, HEIGHT)
    c.set_world(w)

    b = BallEntity((100,100), {'radius': 10, 'density': 10, 'restitution': 0.1,
                               'static': True, 'line-width': 5})
    w.add_entity(b)

    b2 = BallEntity((100,60), {'radius': 20, 'density': 100, 'restitution': 1.0})
    w.add_entity(b2)
    b2.body.SetLinearVelocity((0,40))

    base = BoxEntity((20,20), {'width': 100, 'height': 10})#, 'static': True})
    w.add_entity(base)

    while running:
        screen.fill((255,255,255))
        c.draw()
        pygame.display.flip()

        w.step(dt)
        clock.tick(hz)
开发者ID:bavardage,项目名称:proto,代码行数:32,代码来源:test1.py

示例2: __init__

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import step [as 别名]
class WorldControl:
    world_size = WORLD_SIZE         # world dimension
    cell_pixels = CELL_PIXELS       # pixels per cell

    def __init__(self, canvas, use_images=True):
        self.canvas = canvas
        self.world = World(WorldControl.world_size)
        #self.world.randomly_populate_cells()
        self.world.populate_cells()
        self.use_images = use_images
        self.done = False

    def draw(self):
        if self.canvas is None:
            return

        try:
            self.canvas.delete('all')
        except TclError as e:
            print 'deleting failed... not sure why'

        i=0
        for row in self.world.cells:
            j=0
            for cell in row:
                # top left coords
                x0 = j * self.cell_pixels
                y0 = i * self.cell_pixels

                # bottom right coords
                x1 = (j+1)*self.cell_pixels
                y1 = (i+1)*self.cell_pixels

                cell.draw(self.canvas, x0, y0, x1, y1, self.use_images)
                j+=1
            i+=1
        self.canvas.pack()

    def step(self, draw=True):
        if self.done:
            return

        self.world.step()
        if draw:
            self.draw()

        if self.world.all_dead():
            self.world.print_animal_stats()
            self.done = True
            self.draw()
            return

    def get_steps(self):
        return self.world.steps

    def cell_at(self, x, y):
        return self.world.get_cell(int(y/self.cell_pixels), int(x/self.cell_pixels))
开发者ID:cnoziere,项目名称:DynamicWorld,代码行数:59,代码来源:world_control.py

示例3: App

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import step [as 别名]
class App(object):

    def __init__(self):
        self.world = World()
        self.win = pyglet.window.Window(fullscreen=True, vsync=True)
        self.win.set_exclusive_keyboard()

        for i in dir(self):
            if i.startswith('on_'):
                setattr(self.win, i, getattr(self, i))

        self.camera = Camera(self.win, zoom=100.0)
        self.hud = Hud(self.win)
        clock.set_fps_limit(60)

    def on_mouse_drag(self, x, y, dx, dy, buttons, mods):
        pass

    def on_mouse_motion(self, x, y, dx, dy):
        pass

    def on_mouse_press(self, x, y, button, mods):
        pass

    def on_mouse_release(self, x, y, button, mods):
        pass

    def mainLoop(self):
        while not self.win.has_exit:
            try:
                self.win.dispatch_events()

                self.world.step()

                self.camera.worldProjection()
                self.world.draw()

                self.camera.hudProjection()
                self.hud.draw()

                clock.tick()
                self.win.flip()
            except (SystemExit):
                sys.exit(0)
            except:
                pass
开发者ID:bjmgeek,项目名称:babytux,代码行数:48,代码来源:app.py

示例4: Simulation

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import step [as 别名]
class Simulation():
    def __init__(self, world_width=WORLD_WIDTH, world_height = WORLD_HEIGHT, num_foods=NUM_FOODS):
        self.world = World(world_width, world_height, num_foods)
        self.world_handlers = []             # List of world handler callbacks

    def add_world_handler(self, handler):
        self.world_handlers.append(handler)

    def add_crab_handler(self, handler):
        self.world.add_crab_handler(handler)

    def fire_world_handler(self):
        for handler in self.world_handlers:
            handler()

    def step(self):
        # Process water
        self.world.step()

        # Update world
        self.fire_world_handler()
开发者ID:bederson,项目名称:BaySim,代码行数:23,代码来源:simulation.py

示例5: __init__

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import step [as 别名]

#.........这里部分代码省略.........
        self.background.addLayer(layer)
    
  def setupShip(self,filename):
    domLevel = parse(filename)
    shipNodes = domLevel.getElementsByTagName("ship")
    shipNode = shipNodes[0]
    self.mainbody = Body()
    for node in shipNode.childNodes:
      if node.localName == "position":
        position = node.getAttribute('value')
        values = position.split(',')
        self.mainbody.setPosition(float(values[0]),float(values[1]))
      if node.localName == "mobile":
        m = Mobile()
        for childnode in node.childNodes:
          if childnode.localName == "position":
            values = childnode.getAttribute('value').split(',')
            m.setPosition(float(values[0]),float(values[1]))
          if childnode.localName == "velocity":
            values = childnode.getAttribute('value').split(',')
            m.setVelocity(float(values[0]),float(values[1]))
          if childnode.localName == "thrust":
            values = childnode.getAttribute('value').split(',')
            m.setThrustVector(float(values[0]),float(values[1]))
            m.setInitialThrustVector(float(values[0]),float(values[1]))                          
          if childnode.localName == "mass":
            value = childnode.getAttribute('value')
            m.setMass(float(value))      
          if childnode.localName == "radius":
            value = childnode.getAttribute('value')
            m.setRadius(float(value))  
          if childnode.localName == "texture":
            value = childnode.getAttribute('value')
            m.setTexture(TextureHelper.loadTextureFromFile(value))
          #if childnode.localName == "physicalPoints":
          #  for ppointnode in childnode.childNodes:
          #    if ppointnode.localName == "point":
          #      values = ppointnode.getAttribute('value').split(',')
          #      m.addPhysicalPoint(Vector2d(float(values[0]),float(values[1])))
        m.setupPhysicalPoint()
        self.mainbody.addMobile(m)
    self.mainbody.init()
    focus_position = self.mainbody.getPosition()
    self.world.addMobile(self.mainbody)

  def setupWorld(self,filename):
    self.world.reset()
    domLevel = parse(filename)
    worldNodes = domLevel.getElementsByTagName("world")
    for node in worldNodes[0].childNodes:
      if node.localName == "gravity":
        values = node.getAttribute('value').split(',')
        self.world.setGravity(float(values[0]),float(values[1]))
      if node.localName == "landingzone":
        values = node.getAttribute('value').split(',')
        self.world.setLandingzone(Landingzone(float(values[0]),float(values[1]),float(values[2]),float(values[3]),TextureHelper.loadTextureFromFile('checker.png')))

    h = Config.getint('graphics', 'height')
    w = Config.getint('graphics', 'width')
    p0 = Plane(1,0,-10)
    p1 = Plane(0,-1,h-10)
    p2 = Plane(-1,0,w-10)
    p3 = Plane(0,1,-64)
    self.world.addPlane(p0)
    self.world.addPlane(p1)
    self.world.addPlane(p2)
    self.world.addPlane(p3)

    #self.world.setGravity(0.0,-1.8)

  def setupGame(self):
    self.setupMenu()

  def updateGame(self,canvas):
    if self.mainbody != 0:
      self.camera.follow(self.mainbody)
    self.camera.setup(canvas)
    self.background.draw(canvas)

    
    self.world.draw(canvas)

    self.gui.draw(canvas)
    self.world.step(1/60.)
    if self.gameIsRunning():
      res = self.checkVictoryCondition()
      if res != 0:
        if res == -1:
          self.gui.messaging.displayText('FAIL ! !',200) 
          self.gameResult = -1
          Clock.schedule_once(self.setupLevel, 5)
        if res == 1:
          self.gui.messaging.displayText('SUCCESS ! !',200)
          self.gameResult = 1
          self.currentLevel += 1 
          Clock.schedule_once(self.setupLevel, 5)
  def on_touch_down(self, touch):
    worldpos = self.camera.screenToWorld(touch.pos[0],touch.pos[1])
    self.world.on_touch_down(worldpos)
    self.gui.on_touch_down(touch)
开发者ID:drumbumLOLcatz,项目名称:LandingZone,代码行数:104,代码来源:main.py

示例6: GreedyController

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import step [as 别名]
class Simulation:
  width = 100
  height = 100
  amount_food = 100
  num_worms = 100
  start_health = 100
  smell_range = 10
  controllers = []
  finished = False
  sim_world = None
  slomo = 0
  enable_visualization = False
  test_controller = GreedyController()
  def assign_controllers(self, generation):
    for worm in generation.worms:
      self.controllers[0].control_worm(worm)
  
  def stop_controllers(self):
    for controller in self.controllers:
      controller.stop()
      
  def stop(self):
    self.sim_world.stop()
    
  def start(self):    
    self.controllers.append(self.test_controller)
    
    # this will block until self.finished == True
    if self.enable_visualization:
      self.thread = Thread(None, self.run, "World").start()
      self.sim_visualization = Visualization(self)
      self.sim_visualization.run()
    else:
      self.run()

  def initialize_generation(self):
    # a new world
    self.sim_world = World(self.width, self.height, self.amount_food)
    # a generation to live in it
    self.sim_generation = Generation(self.num_worms, self.sim_world, self.start_health, self.smell_range)
    # some controllers that control the worms
    self.assign_controllers(self.sim_generation)
    
  def run(self):
    # TODO implement generation iteration
    self.initialize_generation()
    self.run_world()
    print("Bye")
    self.stop_controllers()
    self.finished = True
  
  def run_world(self):  
    while True:
      try:
        if self.slomo: sleep(self.slomo)
        self.sim_world.step()
      except:
        print("ERRORRRR")
      if self.sim_world.alive_count == 0: break
    print("WormWorld just became very silent")
    self.sim_world.stop()
开发者ID:richmans,项目名称:worm_world,代码行数:63,代码来源:simulation.py


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