Exemple #1
0
 def setUp(self):
     self.w = Window(width=1, height=1, visible=False)
     self.s = Sprite(10, 10, 10, 10,
                     Image2d.from_image(SolidColorImagePattern((0, 0, 0,
                                                                0)).create_image(
                         1, 1)))
     assert (self.s.x, self.s.y) == (10, 10)
Exemple #2
0
 def setUp(self):
     self.w = Window(width=1, height=1, visible=False)
     self.s = Sprite(
         10, 10, 10, 10,
         Image2d.from_image(
             SolidColorImagePattern((0, 0, 0, 0)).create_image(1, 1)))
     assert (self.s.x, self.s.y) == (10, 10)
    def test_sprite(self):
        w = pyglet.window.Window(width=320, height=320)

        image = Image2d.load(ball_png)
        ball = Sprite(0, 0, 64, 64, image)
        view = FlatView(0, 0, 320, 320, sprites=[ball])

        w.push_handlers(view.camera)

        dx, dy = (10, 5)

        clock.set_fps_limit(30)
        while not w.has_exit:
            clock.tick()
            w.dispatch_events()

            # move, check bounds
            ball.x += dx; ball.y += dy
            if ball.left < 0: ball.left = 0; dx = -dx
            elif ball.right > w.width: ball.right = w.width; dx = -dx
            if ball.bottom < 0: ball.bottom = 0; dy = -dy
            elif ball.top > w.height: ball.top = w.height; dy = -dy

            # keep our focus in the middle of the window
            view.fx = w.width/2
            view.fy = w.height/2

            view.clear()
            view.draw()
            w.flip()

        w.close()
    def test_sprite(self):
        w = pyglet.window.Window(width=320, height=320)

        image = Image2d.load(ball_png)
        ball1 = BouncySprite(0, 0, 64, 64, image, properties=dict(dx=10, dy=5))
        ball2 = BouncySprite(288,
                             0,
                             64,
                             64,
                             image,
                             properties=dict(dx=-10, dy=5))
        view = FlatView(0, 0, 320, 320, sprites=[ball1, ball2])
        view.fx, view.fy = 160, 160

        clock.set_fps_limit(60)
        e = TintEffect((.5, 1, .5, 1))
        while not w.has_exit:
            clock.tick()
            w.dispatch_events()

            ball1.update()
            ball2.update()
            if ball1.overlaps(ball2):
                if 'overlap' not in ball2.properties:
                    ball2.properties['overlap'] = e
                    ball2.add_effect(e)
            elif 'overlap' in ball2.properties:
                ball2.remove_effect(e)
                del ball2.properties['overlap']

            view.clear()
            view.draw()
            w.flip()

        w.close()
Exemple #5
0
    def test_sprite(self):
        w = pyglet.window.Window(width=320, height=320)

        image = Image2d.load(ball_png)
        ball1 = BouncySprite(0, 0, 64, 64, image, properties=dict(dx=10, dy=5))
        ball2 = BouncySprite(288, 0, 64, 64, image, properties=dict(dx=-10, dy=5))
        view = FlatView(0, 0, 320, 320, sprites=[ball1, ball2])
        view.fx, view.fy = 160, 160

        clock.set_fps_limit(60)
        e = TintEffect((0.5, 1, 0.5, 1))
        while not w.has_exit:
            clock.tick()
            w.dispatch_events()

            ball1.update()
            ball2.update()
            if ball1.overlaps(ball2):
                if "overlap" not in ball2.properties:
                    ball2.properties["overlap"] = e
                    ball2.add_effect(e)
            elif "overlap" in ball2.properties:
                ball2.remove_effect(e)
                del ball2.properties["overlap"]

            view.clear()
            view.draw()
            w.flip()

        w.close()