def change_window_size(self, old_width, old_height, new_width, new_height): self.view_port = vecrec.Rect(left=self.view_port.left, bottom=self.view_port.bottom, width=new_width, height=new_height) self.clip_port = vecrec.Rect( left=self.clip_port.left, bottom=self.clip_port.bottom, width=round(self.clip_port.width * (new_width / old_width)), height=round(self.clip_port.height * (new_height / old_height))) self.update()
def zoom(self, level_diff, x, y): self.zoom_level *= level_diff scale = (level_diff - 1) / level_diff x_ = self.clip_port.width * x / self.view_port.width y_ = self.clip_port.height * y / self.view_port.height self.clip_port = vecrec.Rect( left=int(self.clip_port.left + x_ * scale), bottom=int(self.clip_port.bottom + y_ * scale), width=round(self.clip_port.width / level_diff), height=round(self.clip_port.height / level_diff)) self.update()
def __init__(self, width, height, zoom=1.0): super().__init__() self.view_port = vecrec.Rect(left=0, bottom=0, width=width, height=height) self.clip_port = self.view_port self.zoom_level = zoom self._view = None self.program = pyglet.graphics.get_default_shader() self.update()
def __init__(self, x=0, y=0, batch=None, group=None, uuid=None, meta={}): self.uuid = str(uuid4()) if (uuid == None) else uuid if (not hasattr(self, 'image')): self.image = self.entity_id if (not hasattr(self, 'width')): self.width = 1 if (not hasattr(self, 'height')): self.height = 1 self.collider = vecrec.Rect(x - self.width / 2, y - self.height / 2, self.width, self.height) self.sprite = pyglet.sprite.Sprite(api.images[self.image], x=self.x * api.TILE_WIDTH, y=self.y * api.TILE_WIDTH, batch=batch, group=group) self.vx = 0 self.vy = 0 self.dx = 0 self.dy = 0
#!/usr/bin/env python3 import pyglet import glooey import vecrec window = pyglet.window.Window() batch = pyglet.graphics.Batch() full = vecrec.Rect.from_pyglet_window(window) left = vecrec.Rect(full.left, full.bottom, full.width / 2, full.height) right = vecrec.Rect(full.left, full.bottom, full.width / 2, full.height) right.left = left.right left.shrink(50) right.shrink(50) glooey.drawing.Rectangle(left, batch=batch) glooey.drawing.Rectangle(right, batch=batch) @window.event def on_draw(): window.clear() batch.draw() pyglet.app.run()
def rect(self): return vecrec.Rect(left=min(self.origin[0], self.dest[0]), bottom=min(self.origin[1], self.dest[1]), width=abs(self.origin[0] - self.dest[0]), height=abs(self.origin[1] - self.dest[1]))