pyTransform Example

This example implements a simple bouncing transform in Python. The script generates a "bounce" event every time it bounces (when the height goes below 0). A wand trigger in the scene changes the value of the gravity variable within the object in response to button presses.

These files are included in the pyg.tgz tar file.


The scene file - bouncer.scene:

light (position(0 0 1))
light (position(0.2 -1 1))

environment (skyColor(.2 .5 1))

pyTransform bounce (script(bouncer.py), when(bounce, boing.play), autoreset)
    {
    staticObject (file(banana.pfb))
    sound boing (file(boing.aiff))
    }

wandTrigger aTrigger (when(button1, bounce.call(gravity=1)),
            when(button2, bounce.call(gravity=8)),
            when(button3, bounce.call(gravity=20)))

The Python script - bouncer.py:

class bouncer(ygTransform):
    def __init__(self):
        self.height = 8
        self.speed = 0
        self.gravity = 2
    def app(self):
        self.speed -= self.gravity * ygdrasil.frameDeltaTime()
        self.height += self.speed * ygdrasil.frameDeltaTime()
        if (self.height < 0):
            self.height = -self.height
            self.speed = -self.speed
            self.eventOccurred('bounce')
        self.setPosition(0,0,self.height)




Last updated 13 September 2002.
home page