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


Python Window.get_size方法代码示例

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


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

示例1: __init__

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import get_size [as 别名]
class Engine:

  def __init__(self):
    self.updateRate = 1/300. # real-time between physics ticks in seconds. the lower this is the more accurete the physics is
    self.initialSpeed = 0.3
    #self.timestep = self.updateRate * self.initialSpeed # how much game time each simulation represents

    # groups of entities
    self.groups = {
      'all'       : set(),
      'updating'  : set(), # all that have a update function
    }

    self.entityAddQueue = []
    self.entityDelQueue = []

    # layers specify the order in which they are drawn. (ordered back to front)
    self.drawLayerNames = [
      'background',
      'game',
      'foreground',
      # UI ones from here on
      # UI Entities will be drawn in camera space
      'UI_pauseMenu',
      'UI_debug',
    ]

    # A dict from drawLayerNames to a Batch of entities. they are mutually exclusive
    self.drawLayers = { name : Batch()  for name in self.drawLayerNames }
    self.drawCalls =  { name : []       for name in self.drawLayerNames }

    self.levelStartTime = time.time()
    self.levelTime = 0. # TODO proper pausing (maybe move to gameState or some level class)

    self.accumulatedFrameTime = 0.


    # Window
    config = gl.Config(
      sample_buffers=1, samples=4   # antialiasing
    )
    self.window = Window(
      config = config,
      #fullscreen = True,
      vsync = False,
      style = Window.WINDOW_STYLE_BORDERLESS,
    )

    # opengl flags
    gl.glEnable(gl.GL_BLEND) #enables transparency
    # gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)


    # mouse position
    self.windowCenter = Vec2d(self.window.get_size()) / 2
    self.mousePos = Vec2d(self.windowCenter)
    @self.window.event
    def on_mouse_motion(x, y, dx, dy):
      self.mousePos.x = x
      self.mousePos.y = y
    @self.window.event
    def on_mouse_drag(x, y, dx, dy, buttons, modifiers):
      self.mousePos.x = x
      self.mousePos.y = y

    # DEBUG: drop us into a debug shell when
    @self.window.event
    def on_key_press(symbol, modifiers):
      if symbol==key.QUOTELEFT and modifiers & key.MOD_CTRL:
        liveInspect(self)
      elif symbol==key.UP:   self.initialSpeed *= 2.
      elif symbol==key.DOWN: self.initialSpeed *= 0.5

    self.fps_display = clock.ClockDisplay()

    # camera
    self.camera = Camera()


    # shedule our main loop so we don't need to manually deal with time
    clock.schedule(self.run)


  # our main game loop
  def run(self, dt):
    self.timestep = self.updateRate * (self.initialSpeed*2**(self.levelTime*0.2))

    ## UPDATE ##
    # timestep ala http://gafferongames.com/game-physics/fix-your-timestep/
    if dt > .25: # avoid spiral of death (updating taking longer than framerate)
      dt = .25
    self.accumulatedFrameTime += dt
    while self.accumulatedFrameTime >= self.updateRate:
      self.accumulatedFrameTime -= self.updateRate
      self.levelTime = time.time() - self.levelStartTime
      shots = []
      for entity in self.groups['updating']:
        # update all entities, this should not change the state
        shot = entity.update(self.timestep)
        if shot:
#.........这里部分代码省略.........
开发者ID:DomNomNom,项目名称:osbot,代码行数:103,代码来源:Engine.py

示例2: Game

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import get_size [as 别名]
class Game(object):
    def __init__(self):
        self.win = Window(fullscreen=True, visible=False)
        self.clockDisplay = clock.ClockDisplay()
        glClearColor(0.2, 0.2, 0.2, 1)
        self.camera = Camera((0, 0), 250)

        self.space = pymunk.Space() #2
        self.space.gravity = (0, -500.0)
        self.space.damping = 0.999

        self.map = alone.Map(self.space)

        self.player = alone.Player(*self.map.to_world(1,2))
        self.space.add(self.player.box, self.player.body)
        self.space.add_collision_handler(0, 0, None, None, self.print_collision, None)

        self.balls = []

        self.lamps = [alone.Lamp(*self.map.to_world(4, 3))]

        #self.powerups = [alone.Powerup(*self.map.to_world(1, 4))]

        darkImage = pyglet.resource.image('dark.png')
        winSize = self.win.get_size()

        self.darkness = pyglet.sprite.Sprite(darkImage, x=0, y=0)
        self.darkness.scale = winSize[0]/darkImage.width
        
        backgroundImage = pyglet.resource.image('background.png')
        self.background = pyglet.sprite.Sprite(backgroundImage, x=0, y=0)
        self.background.scale = winSize[0]/backgroundImage.width

        self.camera.setTarget(0, 0)

    def print_collision(self, arb, surface):
        if self.player.box in surface.shapes:
            #check to see if the player is touching an object
            self.player.touchingObject = True

    def move_camera(self):
        self.camera.setTarget(*self.player.center)

    def set_camera_dx(self, dx):
        self.dx_camera = dx

    def set_camera_dy(self, dy):
        self.dy_camera = dy

    def add_ball(self, x=0, y=0):
        mass = 1
        radius = 4
        inertia = pymunk.moment_for_circle(mass, 0, radius)
        body = pymunk.Body(mass, inertia)
        if not x:
            x = random.randint(120,380) / 10.0
        if not y:
            y = 100
        body.position = x, y
        #shape = pymunk.Circle(body, radius) # 4
        shape = pymunk.Poly(body, (
            (-4, -4),
            (+0, +4),
            (+4, -4)))
        shape.friction = 0.5
        self.space.add(body, shape)
        return shape

    def draw_ball(self, ball):
        p = int(ball.body.position.x), int(ball.body.position.y)
        glBegin(GL_POLYGON)
        glColor3ub(255, 255, 000)

        points = ((-4 + p[0], -4 + p[1]),
                  (+0 + p[0], +4 + p[1]),
                  (+4 + p[0], -4 + p[1]))
        glVertex2f(*points[0])
        glVertex2f(*points[1])
        glVertex2f(*points[2])
        glEnd()

    def update_objects(self):
        self.move_camera()

        self.player.update_position()

        self.space.step(1/30.0)

    def draw(self):
        glClear(GL_COLOR_BUFFER_BIT)
        self.camera.update()
        self.background.draw()
        self.camera.focus(self.win.width, self.win.height)

        self.map.draw()

        for ball in self.balls:
            self.draw_ball(ball)

        for lamp in self.lamps:
#.........这里部分代码省略.........
开发者ID:kragniz,项目名称:ld48-22,代码行数:103,代码来源:main.py

示例3: in

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import get_size [as 别名]
class Engine:

  updateRate = 1/120. # how often our physics will kick in (in seconds)

  def __init__(self):

    # dictionary from group to list of Entities. they are NOT mutually exclusive
    # don't manually add to this directly! use addEntity/removeEntity.
    self.groups = {
      'all':      set(), # all entities should be in here
      'updating': set(), # everything that wants to be updated goes in here
      'level':    set(),
      'player':   set(),
      'physics':  set(),
      'rockets':  set(),
      'game':     set(), # will draw dependent   on camera movement
      'UI':       set(), # will draw independent of camera movement
      'UI_editor': set(), # entites that are part of the editor UI
    }

    self.entityAddQueue = set()
    self.entityDelQueue = set()

    # layers specify the order in which they are drawn. (ordered back to front)
    self.drawLayerNames = [
      'background',
      'game',
      'player',
      # UI ones from here on
      'UI_editor',
      'UI_pauseMenu',
      'UI_debug',
    ]

    # A dict from drawLayerNames to a list of entities. they are mutually exclusive
    self.drawLayers = {}
    self.drawLayersBatch = {} #a dict from drawLayerNames to a list of batches
    for name in self.drawLayerNames:
      self.drawLayers[name] = set()
      self.drawLayersBatch[name] = Batch()

    self.levelStartTime = time.time()
    self.levelTime = 0. # TODO proper pausing (maybe move to gameState or some level class)

    self.accumulatedFrameTime = 0.

    self.shapeToEntity = {} # a dict that gives the entity that contains the keyed shape

    # Window
    config = gl.Config(
      sample_buffers=1, samples=4   # antialiasing
    )
    self.window = Window(
      config = config,
      #fullscreen = True,
      vsync = False,
      style = Window.WINDOW_STYLE_BORDERLESS,
    )
    self.windowCenter = Vec2d(self.window.get_size()) / 2
    self.mousePos = Vec2d(self.windowCenter)

    # opengl flags
    gl.glEnable(gl.GL_BLEND) #enables transparency


    # camera
    self.camera = Camera()

    @self.window.event
    def on_mouse_motion(x, y, dx, dy):
      self.mousePos.x = x
      self.mousePos.y = y
    @self.window.event
    def on_mouse_drag(x, y, dx, dy, buttons, modifiers):
      self.mousePos.x = x
      self.mousePos.y = y

    self.fps_display = clock.ClockDisplay()

    # shedule our main loop so we don't need to manually deal with time
    clock.schedule(self.run)

    def makeConsole():
      ic = InteractiveConsole(globals())
      try:
        ic.interact("Welcome to the scripting console! press ctrl+D to resume the game")
      except SystemExit, e:
        exit()
    @self.window.event
    def on_key_press(symbol, modifiers):
      if symbol==key.QUOTELEFT and modifiers & key.MOD_CTRL:
        makeConsole()
开发者ID:DomNomNom,项目名称:Jumpy2D,代码行数:94,代码来源:Engine.py

示例4: set_xticklabels

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import get_size [as 别名]
        self._set_yticks(yticks, ylabels)

    def set_xticklabels(self, xlabels):
        self._set_xticks(self._xticks, xlabels)

    def set_yticklabels(self, ylabels):
        self._set_yticks(self._yticks, ylabels)

if __name__ == "__main__":

    import pyglet
    from pyglet.window import Window
    import numpy

    window = Window()
    width, height = window.get_size()

    figure = GLFigure()
    figure.set_rect([0, 0, width, height])

    x = numpy.linspace(0, 2*numpy.pi, 1024)
    y = numpy.sin(x) + 0.1 * numpy.random.random(x.shape)
    ax = figure.add_axes([0.1, 0.1, 0.8, 0.8])
    ax.plot(x, y, 'g')

    @window.event
    def on_draw():
        figure._draw()

    pyglet.app.run()
开发者ID:oscarbenjamin,项目名称:electro,代码行数:32,代码来源:glfigure.py


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