def __init__(self, text, color, x, y, width): win_width, win_height = get_size() self.batch = Batch() self._doc = pyglet.text.document.UnformattedDocument(text) self._doc.set_style( 0, len(self._doc.text), dict(color=(255, 255, 255, 255), font_name='minecraftia')) font = self._doc.get_font() height = font.ascent - font.descent pad = 2 self._outline = Rectangle(x - pad, y - pad, width + pad, height + pad, color=color[:3]) self._outline.opacity = color[-1] self._layout = IncrementalTextLayout(self._doc, width, height, multiline=False, batch=self.batch) self._caret = Caret(self._layout, color=(255, 255, 255)) self._caret.visible = False self._layout.x = x self._layout.y = y self._focus = False self._press = False super().__init__(x, y, width, height) self.last_char = ''
def __init__(self): win_width, win_height = get_size() self.batch = Batch() self._doc = pyglet.text.document.UnformattedDocument('') self._doc.set_style(0, len(self._doc.text), dict(color=(255, 255, 255, 255))) font = self._doc.get_font() self.text_height = font.ascent - font.descent self.pad = 2 self._outline = Rectangle(5, 5 + self.pad, get_size()[0] - self.pad - 10, self.text_height + self.pad, color=(0, 0, 0)) self._outline.opacity = 150 self._layout = IncrementalTextLayout(self._doc, get_size()[0] - 14, self.text_height, multiline=False, batch=self.batch) self._caret = Caret(self._layout, color=(255, 255, 255)) self._caret.visible = False self._layout.x = 5 self._layout.y = 5 + self.pad self._focus = False self._press = False self.last_press = [0, 0] super().__init__(5, 5 + self.pad, get_size()[0] - self.pad - 10, self.text_height + self.pad)
def to_drawable(self, x, y, batch, square_size, color): r = Rectangle(x, y, square_size, square_size, color=(10, 10, 10), batch=batch) return r
def __init__(self): width, height = get_size() GUI.__init__(self, width, height) self._element = {} self._element['panel'] = Rectangle(x=(width - 600) / 2, y=(height - 400) / 2, width=600, height=400, color=(0, 0, 0)) self._element['panel'].opacity = 200
def to_drawable(self, x, y, batch, square_size, color): """Return a drawable 2D representation of the piece as a pyglet supported object. Defaults to a square. :param x: x position that the piece should be drawn at. :param y: y position that the piece should be drawn at. :param batch: pyglet Batch that the drawable should be added to. :param square_size: size of a square on the grid that the piece will be drawn on. :param color: color the piece should have. :return: a drawable pyglet object that holds a reference/was added to `batch`. """ r = Rectangle(x, y, square_size, square_size, color=color, batch=batch) return r
def __init__(self, items, box, batch, groups): super().__init__(items) self.box = box self.rect = Rectangle(0, 0, 1, 1, color=DRAWER_COLOR, batch=batch, group=groups[1]) self.handle = batch.add(TRIANGLE_COUNT * 3, GL_TRIANGLES, groups[2], 'v2f', 'c3B') self.handle.colors = HANDLE_COLOR * TRIANGLE_COUNT * 3
def __init__(self, x, y, index=None): y = get_size()[1] - y super().__init__(x, y, 32, 32) self._index = index self._on = False self._item = self._item_name = None self._state = {'set': True, 'get': True} self._rect = Rectangle(self.x, get_size()[1] - self.y - 32, 32, 32, color=(255, ) * 3) self._rect.opacity = 100
def __init__(self): self.batch = Batch() self.background = Rectangle(0, 0, 0, 0) self.window = Window() self.window.push_handlers(self) self.on_resize(self.window.width, self.window.height) clock.schedule_interval(self.update, 1 / 60) clock.schedule_interval(self.log, 1) self.sounds = { 'fail': media.load('resources/failure.mp3', streaming=False), 'jump': media.load('resources/jump.wav', streaming=False), 'score': media.load('resources/score.wav', streaming=False), } self.reset()
def __init__(self, organizer, batch, groups): # draw organizer background self.rect = Rectangle(0, 0, 100, 100, color=BOX_COLOR, batch=batch, group=groups[0]) # create list of BoxGUI objects from boxes boxes_gui = [] for box in organizer.subelems: boxes_gui.append( BoxGUI(box.subelems, box.x, box.y, box.w, box.h, batch, groups)) # intialize parent class with newly created drawers_gui super().__init__(boxes_gui) self.w = organizer.w self.h = organizer.h
def to_drawable(self, x, y, batch, square_size, color): """A city is represented as square containing a smaller square. """ shapes = [] r = super().to_drawable(x, y, batch, square_size, color) shapes.append(r) w = h = square_size * .4 offset = square_size * .5 r_inner = Rectangle(x + offset, y + offset, w, h, color=(0, 0, 0), batch=batch) r_inner.anchor_position = (w * .5, h * .5) r_inner.opacity = 128 shapes.append(r_inner) return shapes
def _rebuild_hotbar(self): self._hotbar_sprites = [] self.hotbar_background.x = self.hotbar_x self.hotbar_background.y = self.hotbar_y self.hotbar_background.width = self.size_x self.hotbar_background.height = self.size_y for i in range(HOTBAR_SIZE): slot_x = ((self.size_x / HOTBAR_SIZE) * i) + self.hotbar_x if len(self._hotbar) <= i: empty_slot = Rectangle(slot_x, self.hotbar_y, PREVIEW_SIZE, PREVIEW_SIZE, (200, 200, 200), batch=self._hotbar_batch, group=self.hud_group) empty_slot.opacity = 100 self._hotbar_sprites.append(empty_slot) else: self._draw_inventory_slot(slot_x, self.hotbar_y, self._hotbar[i].get_block_image(), self._hotbar_batch, self._hotbar_sprites)
def __init__(self, window_width, window_height, score, kill_count, total_enemies): self.win_width = window_width self.win_height = window_height self.score = score self.kill_count = kill_count self.button_width = 300 self.button_height = 50 self.x = (self.win_width / 2) - (self.button_width / 2) self.y = (self.win_height / 2) - (self.button_height / 2) self.pop_up = Rectangle(self.x - 100, self.y - 300, 500, 800, (50, 50, 50)) self.title = Label('G A M E O V E R!', self.x + 5, self.y + 90, (150, 1, 1, 255)) self.info_label_score = Label(f'SCORE: {self.score}', self.x + 50, self.y, (60, 135, 50, 255)) self.info_label_kills = Label( f'KILLS: {self.kill_count} / {total_enemies}', self.x + 15, self.y - 50, (60, 135, 50, 255)) self.menu_button = Button(self.button_width, self.button_height, self.x, self.y - 150, 3.4, 5, 'M E N U', (1, 1, 1), (60, 235, 50, 255))
def test_aabb_with_result(): result = Rectangle(0, 0, 0, 0) assert utils.rect_equal(Rectangle(1, 2, 30, 30), Rectangle(1, 2, 30, 30)) is True assert utils.rect_equal(Rectangle(1, 2, 30, 31), Rectangle(1, 2, 30, 30)) is False assert collision.aabb_with_result(Rectangle( 0, 0, 10, 10), Rectangle(10, 0, 10, 20), result) is False assert utils.rect_empty(result) is True assert collision.aabb_with_result(Rectangle( -20, -10, 10, 10), Rectangle(40, -5, 10, 20), result) is False assert collision.aabb_with_result(Rectangle( 40, -5, 10, 20), Rectangle(-20, -10, 10, 10), result) is False assert collision.aabb_with_result(Rectangle( 10, 20, 25, 25), Rectangle(-30, 0, 40, 20), result) is False assert collision.aabb_with_result(Rectangle( 9, 20, 25, 25), Rectangle(-30, 0, 40, 20), result) is False assert collision.aabb_with_result(Rectangle( 9, 20, 25, 25), Rectangle(-30, 0, 40, 21), result) is True assert utils.rect_equal(result, Rectangle(9, 20, 1, 1)) is True assert collision.aabb_with_result(Rectangle( 9, 20, 25, 25), Rectangle(-30, 0, 40, 26), result) is True assert utils.rect_equal(result, Rectangle(9, 20, 1, 6)) is True assert collision.aabb_with_result(Rectangle( 50, 50, 50, 50), Rectangle(49, 50, 50, 50), result) is True assert utils.rect_equal(result, Rectangle(50, 50, 49, 50)) is True assert collision.aabb_with_result(Rectangle( 0, 50, 50, 50), Rectangle(49, 50, 50, 50), result) is True assert utils.rect_equal(result, Rectangle(49, 50, 1, 50)) is True assert collision.aabb_with_result(Rectangle( 20, 30, 15, 20), Rectangle(30, 35, 10, 20), result) is True assert utils.rect_equal(result, Rectangle(30, 35, 5, 15)) is True
def test_aabb(): assert collision.aabb(Rectangle(0, 0, 10, 10), Rectangle(10, 0, 10, 20)) is False assert collision.aabb(Rectangle(-20, -10, 10, 10), Rectangle( 40, -5, 10, 20)) is False assert collision.aabb(Rectangle(40, -5, 10, 20), Rectangle( -20, -10, 10, 10)) is False assert collision.aabb(Rectangle(10, 20, 25, 25), Rectangle(-30, 0, 40, 20)) is False assert collision.aabb(Rectangle(9, 20, 25, 25), Rectangle(-30, 0, 40, 20)) is False assert collision.aabb(Rectangle(9, 20, 25, 25), Rectangle(-30, 0, 40, 21)) is True assert collision.aabb(Rectangle(9, 20, 25, 25), Rectangle(-30, 0, 40, 26)) is True assert collision.aabb(Rectangle(50, 50, 50, 50), Rectangle(49, 50, 50, 50)) is True assert collision.aabb(Rectangle(0, 50, 50, 50), Rectangle(49, 50, 50, 50)) is True assert collision.aabb(Rectangle(20, 30, 15, 20), Rectangle(30, 35, 10, 20)) is True
def __init__(self, x, y, w, h): super().__init__(img=TextureManager.error, x=x, y=y) self.rect = Rectangle(x, y, w, h)