def on_init(self, ev):
        self.world = PhysicsWorld()
        self.add(self.world)
 
        self.ground = Sprite("ground.png")
        self.ground.top = 500
        self.ground.left = 20
        self.ground.scale(1.5, 0.5)
        self.ground.add(Body(BodyType.static))
        
        self.tuqui = Sprite("tuqui.png")
        self.tuqui.top = -300
        self.tuqui.left = 300
        self.tuqui.scale(0.5, 0.5)
        self.tuqui_body = Body()
        self.tuqui.add(self.tuqui_body)
        
        self.add(self.ground)
        print('added ground to scene')
        self.add(self.tuqui)
        print('added tuqui to scene')
    
        self.dragging = False
        
        self.tuqui.listen({"pointer_up": self.on_tuqui_up})
        self.tuqui.listen({"pointer_down": self.on_tuqui_down})
 def setUp(self):
     self.drag = Drag()
     scene = Scene()
     self.sprite = Sprite("tuqui.png")
     self.sprite.scene = scene
     self.sprite.add(self.drag)
     self.scene = scene
Beispiel #3
0
    def on_init(self, ev):
        sprite = Sprite("grey.png")
        self.add(sprite)

        c = sprite.add(Collector())

        self.collector = c
        self.sprite = sprite
Beispiel #4
0
 def on_init(self, event):
     print("Init called!")
     s = Sprite("tuqui.png")
     print("Sprite initialized.")
     self.add(s)
     print("Sprite added.")
     s.top = 0
     s.left = 0
     d = s.add(Drag())
    def on_init(self, ev):
        self.sprite = Sprite("tuqui.png")
        self.world = PhysicsWorld()

        self.add(self.world)
        self.add(self.sprite)

        self.sprite_body = Body(BodyType.kinematic)
        self.sprite.add(self.sprite_body)

        self.body_drag = BodyDrag(self.sprite_body)
        self.sprite.add(self.body_drag)
class KillPedoBear1(Scene):
    def on_init(self, ev):
        self.counter = 0
        self.background = Sprite("bedroom.png")
        self.pedobear = Sprite("pedoBear.png")
        self.add(self.background)
        self.background.scale(1.33, 1.50)
        self.background.left = 0
        self.background.top = 0
        self.add(self.pedobear)
        self.pedobear.scale(0.5, 0.5)
        self.pedobear.left = 0
        self.pedobear.top = 230
        self.pedobear.listen({"pointer_down": self.on_pedobear_click})
        self.background.listen({"pointer_down": self.on_background_click})

        self.start_animation()

    def on_pedobear_click(self, ev):
        print("pedo bear has exploded")
        self.pedobear.image = Image("boom-hi.png")

    def on_background_click(self, ev):
        print("background clicked")

    def start_animation(self):
        anim = SideToSide()
        anim.loop = True
        anim.setup(self.pedobear)
        self.add(anim)
        anim.start()
    def on_init(self, ev):
        self.counter = 0
        self.background = Sprite("bedroom.png")
        self.pedobear = Sprite("pedoBear.png")
        self.add(self.background)
        self.background.scale(1.33, 1.50)
        self.background.left = 0
        self.background.top = 0
        self.add(self.pedobear)
        self.pedobear.scale(0.5, 0.5)
        self.pedobear.left = 0
        self.pedobear.top = 230
        self.pedobear.listen({"pointer_down": self.on_pedobear_click})
        self.background.listen({"pointer_down": self.on_background_click})

        self.start_animation()
    def setUp(self):
        self.sprite = Sprite("pedoBear.png")

        self.frame1 = Frame()
        self.frame2 = Frame()

        self.frame1.width = 100
        self.frame1.height = 200

        self.frame2.width = 50
        self.frame2.height = 60

        self.sheet = SpriteSheet()
        self.sheet.add(self.frame1)
        self.sheet.add(self.frame2)
        self.sprite.add(self.sheet)
Beispiel #9
0
    def on_init(self, ev):
        self.world = PhysicsWorld()
        self.add(self.world)

        self.tuqui = Sprite("tuqui.png")
        self.tuqui.top = 0
        self.tuqui.left = 300
        self.tuqui.scale(0.5, 0.5)
        self.tuqui_body = Body()
        self.tuqui_body.type = BodyType.kinematic

        self.tuqui.add(self.tuqui_body)
        self.add(self.tuqui)
        bd = BodyDrag(self.tuqui_body)
        bd.always_drag = False
        self.tuqui.add(bd)
        print('added tuqui to scene')
Beispiel #10
0
    def make_explosion(self):
        explosion = Sprite("explosion.png")
        sheet = SpriteSheet("explosion.xml")
        explosion.add(sheet)
        sheet.loop = True
        self.add(explosion)

        explosion.width = 60
        explosion.height = 60
        explosion.left = 20
        explosion.top = 20

        sheet.start()
        sheet.loop = True
        explosion.sheet = sheet

        return explosion
Beispiel #11
0
    def make_sonic(self):
        sonic = Sprite("sonic.png")
        sheet = SpriteSheet("sonic.xml")
        sonic.add(sheet)

        jump_set = sheet.find_by("name", "idle")
        jump_set.loop = True
        jump_set.frame_duration = 15
        jump_set.start()
        sonic.left = 150
        sonic.top = 20
        self.add(sonic)
Beispiel #12
0
 def __init__(self):
     Sprite.__init__(self)
     
     self.listen({"add": self.on_add})
class TestDrag(unittest.TestCase):
    def setUp(self):
        self.drag = Drag()
        scene = Scene()
        self.sprite = Sprite("tuqui.png")
        self.sprite.scene = scene
        self.sprite.add(self.drag)
        self.scene = scene

    def tearDown(self):
        pass

    def testInit(self):
        self.assertEqual(True, self.drag.enabled, "Whether drag is enabled")
        self.assertEqual(0, self.drag.delta.x, "Amount of position")

    def testEvents(self):
        self.drag.dragging = False
        self.sprite.notify(Event("pointer_down"))
        self.assertTrue(self.drag.dragging,
                        "Drag not fired after pointer down")

    def testRender(self):
        p = Point()
        p.x = 0
        p.y = 0
        self.scene.window.pointer = p
        self.sprite.left = 0
        self.sprite.top = 0
        self.drag.on_render(self.scene)

        self.sprite.notify(Event("pointer_down"))
        p.x = 10
        self.scene.window.pointer = p
        self.drag.on_render(self.scene)
        self.assertEqual(10, self.sprite.left, "Sprite not moved on x")
        self.assertEqual(0, self.sprite.top,
                         "Sprite moved on Y when its not supposed to")
        self.sprite.notify(Event("pointer_up"))

        self.sprite.notify(Event("pointer_down"))
        p.y = 10
        self.scene.window.pointer = p
        self.drag.on_render(self.scene)
        self.assertEqual(10, self.sprite.left,
                         "Sprite moved on X when its not supposed to")
        self.assertEqual(10, self.sprite.top, "Sprite not moved on Y")
        self.sprite.notify(Event("pointer_up"))

        p.y = 20
        self.scene.window.pointer = p
        self.drag.on_render(self.scene)
        self.assertEqual(10, self.sprite.left,
                         "Sprite moved when not dragging")
        self.assertEqual(10, self.sprite.top, "Sprite moved when not dragging")

        # tests the last position
        self.sprite.notify(Event("pointer_down"))
        p.y = 15
        self.scene.window.pointer = p
        self.drag.on_render(self.scene)
        p.y = 30
        self.scene.window.pointer = p
        self.drag.on_render(self.scene)
        self.assertEqual(30, self.drag.last_pos.y,
                         "last position not being updated")
class TestSpriteSheet(unittest.TestCase):
    def setUp(self):
        self.sprite = Sprite("pedoBear.png")

        self.frame1 = Frame()
        self.frame2 = Frame()

        self.frame1.width = 100
        self.frame1.height = 200

        self.frame2.width = 50
        self.frame2.height = 60

        self.sheet = SpriteSheet()
        self.sheet.add(self.frame1)
        self.sheet.add(self.frame2)
        self.sprite.add(self.sheet)

    def tearDown(self):
        pass

    def testAddAndRemove(self):
        sheet = SpriteSheet()
        frame = Frame()
        sheet.add(frame)

        self.assertEqual(sheet.frames[0], frame)

        element = Element()
        sheet.add(element)
        self.assertEqual(len(sheet.frames), 1)
        self.assertEqual(len(sheet.children), 2)

        sheet.remove(frame)
        self.assertEqual(len(sheet.frames), 0)
        self.assertEqual(len(sheet.children), 1)

    def testResize(self):
        self.sheet.resize(0)
        self.assertEqual(self.sprite.width, 100)
        self.assertEqual(self.sprite.height, 200)

        self.sheet.resize(1)
        self.assertEqual(self.sprite.width, 50)
        self.assertEqual(self.sprite.height, 60)

    def testRenderSingle(self):

        self.sheet.render_single(0)
        self.assertEqual(self.sprite.width, 100)
        self.assertEqual(self.sprite.height, 200)

        self.sheet.lock_width = True
        self.sprite.width = 200
        self.sheet.render_single(0)
        self.assertEqual(self.sprite.width, 200)
        self.assertEqual(self.sprite.height, 400)

        self.sheet.lock_height = True
        self.sheet.lock_width = False
        self.sprite.height = 500
        self.sheet.render_single(0)
        self.assertEqual(self.sprite.width, 250)
        self.assertEqual(self.sprite.height, 500)
Beispiel #15
0
 def testImageUrl(self):
     sprite = Sprite()
     sprite.image_url = "orange.png"
     self.assertEqual(48, sprite.width)
     self.assertEqual(48, sprite.height)
class PhysicsJointScene(Scene):
    def on_init(self, ev):
        self.world = PhysicsWorld()
        self.add(self.world)
 
        self.ground = Sprite("ground.png")
        self.ground.top = 500
        self.ground.left = 20
        self.ground.scale(1.5, 0.5)
        self.ground.add(Body(BodyType.static))
        
        self.tuqui = Sprite("tuqui.png")
        self.tuqui.top = -300
        self.tuqui.left = 300
        self.tuqui.scale(0.5, 0.5)
        self.tuqui_body = Body()
        self.tuqui.add(self.tuqui_body)
        
        self.add(self.ground)
        print('added ground to scene')
        self.add(self.tuqui)
        print('added tuqui to scene')
    
        self.dragging = False
        
        self.tuqui.listen({"pointer_up": self.on_tuqui_up})
        self.tuqui.listen({"pointer_down": self.on_tuqui_down})
        
    def on_tuqui_up(self, e):
        self.world.remove(self.mj)
        self.dragging = False
        print("up")
    
    def on_tuqui_down(self, e):
        # construct this bitch and add to the world
        self.mj = MouseJoint(self.ground, self.tuqui)
        self.world.add(self.mj)
        self.dragging = True
        print("down")
        
    def on_render(self, e):
        if not self.dragging:
            return
        
        self.mj.update(self.scene.pointer)
Beispiel #17
0
 def on_init(self, e):
     #pydevd.settrace()
     
     world = PhysicsWorld()
     world.pixel_size = 20
     self.add(world)
     
     ground = Sprite("ground.png")
     ground.top = 400
     ground.left = 0
     ground.name = "GROUND";
     self.add(ground)
     ground.add(Body(BodyType.static))
     
     ipod = Sprite("orange.png")
     ipod.top = 300
     ipod.left = 100
     ipod.name = "ORANGE"
     self.ipod_body = Body()
     self.add(ipod)
     ipod.add(self.ipod_body)
     
     target = Sprite("blue.png")
     target.top = 100
     target.left = 0
     target.name = "BLUE"
     self.target_body = Body(BodyType.kinematic)
     self.target = self.add(target)
     target.add(self.target_body)
     
     self.text = Text("Try to hit the blue ipod")
     self.add(self.text)
     self.text.left = 60.0
     self.text.top = 0.0
     self.text.font.color = Color(0x00FFCCFF)
     
     ipod.listen({"pointer_up": self.on_ipod_click})
     
     world.listen({"pre_solve": self.on_collide})
 def on_init(self, ev):
     self.background = Sprite("background-winter.png")
     self.add(self.background)
     self.background.left = 0
     self.background.top = 0
Beispiel #19
0
    def on_init(self, ev):
        world = PhysicsWorld()
        self.add(world)
 
        pedoA = Sprite("tuqui.png")
        pedoA.top = -100
        pedoA.left = 0
        pedoA.scale(0.5, 0.5)
        pedoA.add(Body(BodyType.static))
        
        pedoB = Sprite("tuqui.png")
        pedoB.top = -300
        pedoB.left = 300
        pedoB.scale(0.5, 0.5)
        pedoB_body = Body()
        pedoB.add(pedoB_body)
        pedoB_body.linear_damping = .02
        
        dj = DistanceJoint(pedoA, pedoB)
        print("created distance Joint")
        
        self.add(pedoA)
        print('added pedoA to scene')
        self.add(pedoB)
        print('added pedoB to scene')
        world.add(dj)