Example #1
0
 def getInput(self):
     self.mousemoveX=None; self.mouseMoveY = None
     self.mouseX, self.mouseY = pygame.mouse.get_pos()
     self.mouseMoveX, self.mouseMoveY = pygame.mouse.get_rel()
     self.events.update()
     if self.events.quit or K_ESCAPE in self.events.keyboard.hit: 
        pyggel.quit() 
        sys.exit(0)
     if K_DELETE in self.events.keyboard.hit:
         self.killbox()
     #if 1 mouse button is held down
     if len(self.events.mouse.held)==2:
         self.mousebutton = self.events.mouse.held[0]
         self.mousedown = True
     else:
         self.mousebutton = None
         self.mousedown = False
     #if 2 mouse buttons are held down
     if len(self.events.mouse.held)==4:
         self.twomousebuttons = True
     else:
         self.twomousebuttons = False
     #if 1 mouse button is pressed
     if len(self.events.mouse.hit)==2 and self.mouse_over_object:
         if self.events.mouse.hit[0] == 1: #if left mouse button
             self.object_selected = self.mouse_over_object
         else:
             self.object_selected = None            
Example #2
0
def main():

    os.environ["SDL_VIDEO_CENTERED"] = "1"
    pyggel.view.init([1024, 768])
    g = game.Game()
    g.run()
    pyggel.quit()
Example #3
0
def main():
    """pyggel.view.init can take several args that handle how the view is set up.
       screen_size is the 2d size of the screen to create
       screen_size_2d is the 2d size of the screen that the 2d uses,
           the 2d elements are handled as if this is the real screen size,
           and then scaled to fit the real screen size at render time,
           this allows multiple screen resolutions without resorting to hacking the 2d or,
           like some 3d engines do, make the 2d elements really 3d that are projected funny.
       use_psyco indicates whether to try and use psyco if it is available, for a speed boost.
       icon_image must be a string indicating the image to load from disk, or a pygame Surface to use for the window icon.
       full_screen indicates whether the render screen is fullscreen or not
       hwrender indicates whether hwrendering should be used for pygame operations
       decorated indicates whether the display window should have a border and top bar or not"""
    pyggel.init(screen_size=(640,480)) #initialize everything
    #for now, pyggel.init just calls pyggel.view.init...

    event_handler = pyggel.event.Handler()

    clock = pygame.time.Clock() #pyggel automatically imports OpenGL/Pygame
                                #for a full list of everything included,
                                #look in pyggel/include.py

    while 1:
        clock.tick(60) #limit FPS
        pyggel.view.set_title("FPS: %s"%int(clock.get_fps()))

        event_handler.update() #get the events!

        if event_handler.quit or K_ESCAPE in event_handler.keyboard.hit: #were the quit 'X' box on the window or teh ESCAPE key hit?
           pyggel.quit() #close the window and clean up everything
           return None #close the loop

        pyggel.view.clear_screen() #clear screen for new drawing...
        pyggel.view.refresh_screen() #flip the display buffer so anything drawn now appears
Example #4
0
def main():
    
    os.environ["SDL_VIDEO_CENTERED"] = "1"
    pyggel.view.init([800, 600])
    g = game.Game()
    g.run()
    pyggel.quit()
Example #5
0
    def getInput(self):
        """Get user input"""
        self.mousemoveX = None
        self.mouseMoveY = None
        self.mouseX, self.mouseY = pygame.mouse.get_pos()
        self.mouseMoveX, self.mouseMoveY = pygame.mouse.get_rel()
        self.events.update()

        if K_PERIOD in self.events.keyboard.hit:  #period ">"
            self.testnumber += 1
            self.do_once = False
            self.delta = 0
        if K_COMMA in self.events.keyboard.hit:  #comma "<"
            self.testnumber -= 1
            self.do_once = False
            self.delta = 0
            if self.testnumber < 1:
                self.testnumber = 1
        if K_DOWN in self.events.keyboard.hit:
            self.currentkey = "down"
        if K_UP in self.events.keyboard.hit:
            self.currentkey = "up"
        if K_LEFT in self.events.keyboard.hit:
            self.currentkey = "left"
        if K_RIGHT in self.events.keyboard.hit:
            self.currentkey = "right"
        if K_SPACE in self.events.keyboard.hit:
            self.currentkey = "space"
        if self.events.quit or K_ESCAPE in self.events.keyboard.hit:
            pyggel.quit()
            sys.exit(0)

        #if 1 mouse button is held down
        if len(self.events.mouse.held) == 2:
            #if right mouse button is held down
            self.mousebutton = self.events.mouse.held[0]
            self.mousedown = True
        else:
            self.mousebutton = None
            self.mousedown = False
        #if 2 mouse buttons are held down
        if len(self.events.mouse.held) == 4:
            self.twomousebuttons = True
        else:
            self.twomousebuttons = False

        #if 1 mouse button is pressed
        if len(self.events.mouse.hit) == 2 and self.mouse_over_object:
            if self.events.mouse.hit[0] == 1:  #if left mouse button
                self.object_selected = self.mouse_over_object
            else:
                self.object_selected = None
Example #6
0
 def getInput(self):
     self.mousemoveX=None; self.mouseMoveY = None
     self.mouseX, self.mouseY = pygame.mouse.get_pos()
     self.mouseMoveX, self.mouseMoveY = pygame.mouse.get_rel()
     self.events.update()
     if self.events.quit or K_ESCAPE in self.events.keyboard.hit: 
        pyggel.quit() 
        sys.exit(0)
     #1 boton apretado
     if len(self.events.mouse.held)==2:
         self.mousebutton = self.events.mouse.held[0]
         self.mousedown = True
     else:
         self.mousebutton = None
         self.mousedown = False
     #2 botones apretados
     if len(self.events.mouse.held)==4:
         self.twomousebuttons = True
     else:
         self.twomousebuttons = False
Example #7
0
def main():
    pyggel.init()

    pyggel.view.set_lighting(False)
    pyggel.view.set_background_color((1,1,1))

    camera = pyggel.camera.LookAtCamera((0,0,0), distance=10)

    emitter = particle.Emitter3D(particle.Fire3D)
    emitter.behavior.image = image.Image3D("data/fire1.png")
    emitter.behavior.image.scale = .5

    emitter2 = particle.EmitterPoint(particle.FirePoint)
    emitter2.visible = False

    scene = pyggel.scene.Scene()
    scene.camera = camera
    scene.add_3d_blend(emitter)
    scene.add_3d_blend(emitter2)

    eh = event.Handler()

    clock = pygame.time.Clock()

    while 1:
        clock.tick(999)
        pyggel.view.set_title("FPS: %s"%clock.get_fps())

        eh.update()
        if eh.quit:
            pyggel.quit()
            return None
        if " " in eh.keyboard.hit:
            emitter.visible = not emitter.visible
            emitter2.visible = not emitter2.visible

        view.clear_screen()
        scene.render()#camera)
        view.refresh_screen()
def main():
    pyggel.init(screen_size=(640,480)) #initialize everything
    #for now, pyggel.init just calls pyggel.view init...

    event_handler = pyggel.event.Handler()

    scene = pyggel.scene.Scene()
    scene.pick = True #let's make sure we are picking here, eh?

    """Alrighty, so when we left off in the last tutorial, we had a few 3d elements in,
       but they looked bad because there were no lights!
       Also, each and every object had to be positioned so that it could be seen, ie 20 units in,
       that really is the job of a camera to position for view, not the objects.
       Another thing, that black background is getting annoying, don't you think? Let's change that as well."""

    """So first thing is first, a camera.
       When creating cameras, you can use either of the two builtin camera's
       (LookFromCamera and LookAtCamera, basically first/third person camera)
       or, you can make your own by subclassing camera.Base - if you want something else entirely.
       camera.LookAtCamera(pos, rotation, distance) - this creates a "third-person" camera, it will
           always face pos, and rotate around it, instead of around it's own position.
           distance is how many units back the camera is from pos
       camera.LookFromCamera(pos, rotation) - this creates a "first-person" camera, it will
           always be at pos, any rotation is like turning your head, not like orbitting a planet."""

    #So, for our needs I think a LookAtCamera is best
    scene.camera = pyggel.camera.LookAtCamera((0,0,0), distance=20)


    """Now we need some light in our scene!
       Remember that scenes may each have up to 8 lights, any more are ignored.
       light.Light(pos, ambient, diffuse, specular, spot_direction, directional)
           pos is the 3d position of the light
           ambient, diffuse are the colors of the light
           specular controls how shiny objects are when lit
           spot_direction is the (x,y,z) direction of the light if it is a spot light
           directional (True/False) controls whether this light is a directional or a spot light - defaults to True"""

    #OK, so let's make one, simple light...
    light = pyggel.light.Light((0,100,0),#so this is aobve most the elements
                               (0.5,0.5,0.5,1),#ambient color
                               (1,1,1,1),#diffuse color
                               (50,50,50,10),#specular
                               (0,0,0),#spot position - not used
                               True) #directional, not a spot light

    scene.add_light(light)


    img = pyggel.image.Image3D("data/ar.png")
    img.pos = (3,5,0)

    img4 = pyggel.image.SpriteSheet3D("data/ar.png", [(0,0,16,16), (16,0,16,16), (32,0,16,16), (16,0,16,16)], 100)
    img4.pos = (-3,5,0)

    #now the fonts
    font = pyggel.font.Font(font_char_height3d=1)
    text1 = font.make_text_image3D("test?", italic=True)
    text1.pos = (0, 5, 0)

    scene.add_3d((img, img4)) #these images don't have perpixel alpha, so they are ok to go in base 3d class
    scene.add_3d_blend(text1) #unfortunately, this one does have perpixel alpha,
                              #you can either put it in 3d and deal with the funny blending,
                              #or stick it in 3d_blend!

    #OK, let's make some stuff!
    a = pyggel.geometry.Cube(1, pos=(-5, 0, 0)) #this one is untextured
    a.rotation = (45, 45, 0)
    #first, a texture to use...
    tex = pyggel.data.Texture("data/ar.png")
    b = pyggel.geometry.Cube(1, pos=(-3, 0, 0), texture=tex, mirror=False) #this one is textured as a cubemap
    b.rotation = (0,45,45)
    c = pyggel.geometry.Cube(1, pos=(-1, 0, 0), texture=tex) #this one copies the texture for each face

    d = pyggel.geometry.Quad(1, pos=(1, 0, 0), texture=tex) #this will look exactly like the cubes, because it is facing us...
    e = pyggel.geometry.Plane(10, pos=(0, -7.5, 0), texture=tex, tile=10)
    f = pyggel.geometry.Sphere(1, pos=(3, 0, 0), texture=tex, show_inside=True)

    #Hey, those positions for the elements looks a lot nicer now, eh?

    scene.add_3d((a,b,c,d,e,f))

    #lets make a mesh!
    mesh = pyggel.mesh.OBJ("data/bird_plane.obj", pos=(5, 0, 0))
    scene.add_3d(mesh)

    root = mesh.get_obj_by_name("cylinder1")
    tail = mesh.get_obj_by_name("sphere2")
    head = mesh.get_obj_by_name("sphere2_copy3")
    wings = mesh.get_obj_by_name("cube4")

    skel = pyggel.mesh.Skeleton()
    skel.add_bone(root.name,
                  (0,0,root.side("back")),
                  (0,0,root.side("front")))
    skel.add_bone(tail.name,
                  (0,0,tail.side("front")),
                  (0,0,tail.side("back")),
                  root.name)
    skel.add_bone(head.name,
                  (0,0,head.side("back")),
                  (0,0,head.side("front")),
                  root.name,
                  0.25)
    skel.add_bone(wings.name,
                  (wings.side("left"),0,0),
                  (wings.side("right"),0,0),
                  root.name,
                  0.5)

    action = pyggel.mesh.Action(2, [pyggel.mesh.RotateTo(wings.name, (0,0,45),0,.5),
                        pyggel.mesh.RotateTo(wings.name, (0,0,-45),.5,1.5),
                        pyggel.mesh.RotateTo(wings.name, (0,0,0),1.5,2),
                        pyggel.mesh.ScaleTo(tail.name, (1.25,1.25,1.25), 0, 1),
                        pyggel.mesh.ScaleTo(tail.name, (1,1,1), 1, 2),
                        pyggel.mesh.RotateTo(head.name, (0,15,0),0,.25),
                        pyggel.mesh.RotateTo(head.name, (0,-15,0),.25,.75),
                        pyggel.mesh.RotateTo(head.name, (0,0,0),.75,1),

                        #you can also define animations for non-existing mesh parts,
                        #so you can later add those parts
                        pyggel.mesh.RotateTo("weapon_right", (0,0,-45),0,.5), 
                        pyggel.mesh.RotateTo("weapon_right", (0,0,45),.5,1.5),
                        pyggel.mesh.RotateTo("weapon_right", (0,0,0),1.5,2),
                        pyggel.mesh.RotateTo("weapon_left", (0,0,-45),0,.5),
                        pyggel.mesh.RotateTo("weapon_left", (0,0,45),.5,1.5),
                        pyggel.mesh.RotateTo("weapon_left", (0,0,0),1.5,2)])

    ani = pyggel.mesh.Animation(mesh, skel, {"move":action})
    ani.pos=(0,0,8)
    ani.rotation = (0,180,0) #so it faces us!
    ani.do("move")
    scene.add_3d(ani)

    """Alright, now that our 3d scene is lit and looks decent,
       let's add a skybox so we don't have that pesky blackness everywhere...

       Skyboxes/Skyballs functional pretty much identically to Cubes/Spheres,
           they just appear in only one place and are infinitely large.
           geometry.Skybox(texture, colorize)
               both args are exactly the same as for a Cube
           geometry.Skyball(texture, colorize, detail)
               again, exactly the same as a Sphere"""

    skybox = pyggel.geometry.Skybox("data/skybox.png")
    skyball = pyggel.geometry.Skyball("data/skyball.png")
    scene.add_skybox(skybox)

    clock = pygame.time.Clock() #pyggel automatically imports OpenGL/Pygame
                                #for a full list of everything included,
                                #look in pyggel/include.py

    last_obj = None #here we store which object was "picked" in the scene

    while 1:
        clock.tick(60) #limit FPS
        pyggel.view.set_title("FPS: %s"%int(clock.get_fps()))

        event_handler.update() #get the events!

        if event_handler.quit or K_ESCAPE in event_handler.keyboard.hit: #were the quit 'X' box on the window or teh ESCAPE key hit?
           pyggel.quit() #close the window and clean up everything
           return None #close the loop

        """Alrighty, so now that we have everything set up, camera, lights and a skybox,
           lets actually do something!"""

        if K_LEFT in event_handler.keyboard.active: #rotate view!
            scene.camera.roty -= .5
        if K_RIGHT in event_handler.keyboard.active:
            scene.camera.roty += .5
        if K_UP in event_handler.keyboard.active:
            scene.camera.rotx -= .5
        if K_DOWN in event_handler.keyboard.active:
            scene.camera.rotx += .5
        if K_1 in event_handler.keyboard.active:
            scene.camera.rotz -= .5
        if "2" in event_handler.keyboard.active: #just to throw you off ;)
            scene.camera.rotz += .5

        if "=" in event_handler.keyboard.active: #move closer/farther out
            scene.camera.distance -= .1
        if "-" in event_handler.keyboard.active:
            scene.camera.distance += .1

        if "a" in event_handler.keyboard.active: #move the camera!
            scene.camera.posx -= .1
        if K_d in event_handler.keyboard.active:
            scene.camera.posx += .1
        if K_s in event_handler.keyboard.active:
            scene.camera.posz -= .1
        if K_w in event_handler.keyboard.active:
            scene.camera.posz += .1

        if " " in event_handler.keyboard.hit: #swap the skybox so we can see the different ones in action!
            if scene.graph.skybox == skybox:
                scene.add_skybox(skyball)
            elif scene.graph.skybox == skyball:
                scene.add_skybox()
            else:
                scene.add_skybox(skybox)

        pyggel.view.clear_screen() #clear screen for new drawing...
        """Now, you need to make sure the scene actually uses your camera.
           PYGGEL scenes are very flexible, and allow you to swap cameras on demand,
           just pass whatever camera you want right now to the render call."""

        #all right, let's check if any objects are picked, and work with them here
        #then, if there is a pick, let's make the object turn red...

        #first, we render the scene, this also returns our object
        obj = scene.render() #render the scene
        #Now, since we want to highlight the object the mouse is over, we gotta undo it too
        if last_obj:
            last_obj.colorize = (1,1,1,1)
        last_obj = obj
        if obj: #now we colorize the correct object
            obj.colorize = (1,0,0,1)
        pyggel.view.refresh_screen() #flip the display buffer so anything drawn now appears

        """And there you have all the basics to building a game with PYGGEL. Good luck!"""
Example #9
0
dt = 1.0/fps
loopFlag = True
clock = pygame.time.Clock()

#main loop

while 1:

    #update window title
    pyggel.view.set_title("FPS: %s"%int(clock.get_fps()))

    #get events!
    event_handler.update() 

    if event_handler.quit or K_ESCAPE in event_handler.keyboard.hit: #were the quit 'X' box on the window or teh ESCAPE key hit?
        pyggel.quit()
        sys.exit(0)
        

    #clear screen for new drawing...
    pyggel.view.clear_screen()

    # get pyode body positions
    x1,y1,z1 = body1.getPosition()
    x2,y2,z2 = body2.getPosition()

    #update pygel object co-ords with pyode body values
    s1.pos = (x1,y1,z1)
    s2.pos = (x2,y2,z2)

    #manually update the pendulum chain
Example #10
0
def main():
    #Alright, the first thing you can do, is tell pyggel to use psyco
    #doing this will make the init try and locate psyco and then run it
    #if it doesn't find it psyco it will ignore this
    #By default, pyggel.init/pyggel.view.init will set use_psyco to True
    #but, this can be a bit of a mermoy hog, so if you don't need it to get decent framerates
    #then it is suggested that you disable it...
    pyggel.init(screen_size=(640,480))

    #Now, OpenGL does a ton of debug testing, which can really slow things down, so you can disable that for a speed boost
    #NOTE, tracebacks won't be as complete anymore ;)
    pyggel.view.set_debug(False)

    event_handler = pyggel.event.Handler()

    scene = pyggel.scene.Scene()

    scene.camera = pyggel.camera.LookAtCamera((0,0,0), distance=20)

    light = pyggel.light.Light((0,100,0), (0.5,0.5,0.5,1), (1,1,1,1),
                               (50,50,50,10), (0,0,0), True)

    scene.add_light(light)

    #OK, let's make some stuff!
    a = pyggel.geometry.Cube(1, pos=(-5, 0, 0))
    a.rotation = (45, 45, 0)

    tex = pyggel.data.Texture("data/ar.png")
    b = pyggel.geometry.Cube(1, pos=(-3, 0, 0), texture=tex, mirror=False)
    b.rotation = (0,45,45)
    c = pyggel.geometry.Cube(1, pos=(-1, 0, 0), texture="data/ar.png")

    d = pyggel.geometry.Quad(1, pos=(1, 0, 0), texture=tex)
    e = pyggel.geometry.Plane(10, pos=(0, -7.5, 0), texture=tex, tile=10)
    f = pyggel.geometry.Sphere(1, pos=(3, 0, 0), texture=tex)

    mesh = pyggel.mesh.OBJ("data/bird_plane.obj", pos=(5, 0, 0))

    #Now look at this.
    #suppose we never wanted to modify these objects again? Their position, color, rotation, etc are all exactly where they need to be
    #and they won't ever need to change.
    #IE, we have scenery, they just need to render fast, we don't need to be constantly changing them.
    #So instead of adding them each to the scene and rendering them slowly (more or less), let's stick them into one big object
    #that compiles them up to runs fast, but be cemented, ie you can't change anything.

    #Introducing the StaticObjectGroup
    #This object takes a whole bunch of 3d objects and pre-renders them into a display list, so we don't have to do so
    #much to render them.
    #NOTE: nothing even semi-dynamic will work with this, ie Images (which are billboarded and need to updated to the
    #camera every render.
    #Another note - objects in here are considered one big object,
    #so picking will return the group, not any individual object.
    sog = pyggel.misc.StaticObjectGroup((a, b, c, d, e, f, mesh))
    scene.add_3d(sog)

    skybox = pyggel.geometry.Skybox("data/skybox.png")
    scene.add_skybox(skybox)

    clock = pygame.time.Clock() #pyggel automatically imports OpenGL/Pygame
                                #for a full list of everything included,
                                #look in pyggel/include.py

    #Those are the primary ways to boost speed in pyggel.
    #Another way is not to use one big scene, but instead several smaller, and swap between them for the active one...

    while 1:
        clock.tick(60) #limit FPS
        pyggel.view.set_title("FPS: %s"%int(clock.get_fps()))

        event_handler.update() #get the events!

        if event_handler.quit or K_ESCAPE in event_handler.keyboard.hit: #were the quit 'X' box on the window or teh ESCAPE key hit?
           pyggel.quit() #close the window and clean up everything
           return None #close the loop

        if K_LEFT in event_handler.keyboard.active: #rotate view!
            scene.camera.roty -= .5
        if K_RIGHT in event_handler.keyboard.active:
            scene.camera.roty += .5
        if K_UP in event_handler.keyboard.active:
            scene.camera.rotx -= .5
        if K_DOWN in event_handler.keyboard.active:
            scene.camera.rotx += .5
        if K_1 in event_handler.keyboard.active:
            scene.camera.rotz -= .5
        if "2" in event_handler.keyboard.active: #just to throw you off ;)
            scene.camera.rotz += .5

        if "=" in event_handler.keyboard.active: #move closer/farther out
            scene.camera.distance -= .1
        if "-" in event_handler.keyboard.active:
            scene.camera.distance += .1

        if "a" in event_handler.keyboard.active: #move the camera!
            scene.camera.posx -= .1
        if K_d in event_handler.keyboard.active:
            scene.camera.posx += .1
        if K_s in event_handler.keyboard.active:
            scene.camera.posz -= .1
        if K_w in event_handler.keyboard.active:
            scene.camera.posz += .1

        pyggel.view.clear_screen()
        scene.render()
        pyggel.view.refresh_screen()
Example #11
0
def main():
    pyggel.view.init()

    camera = pyggel.camera.LookAtCamera(rotation=(-15,0,0), distance=15)
    my_light = pyggel.light.Light((50,100,50), (0.5,0.5,0.5,1),
                                  (1,1,1,1), (50,50,50,10),
                                  (0,0,0), True)

    verts, norms, colors = get_points((130,130))
    how_many = len(verts)

    vert_vbo = data.get_best_array_type(GL_TRIANGLES, len(verts), 5)
    if pyggel.VBO_AVAILABLE and isinstance(vert_vbo, pyggel.data.VBOArray):
        have_vbo = True
    else:
        have_vbo = False
    vert_vbo.reset_verts(verts)
    vert_vbo.reset_colors(colors)
    vert_vbo.reset_norms(norms)

    meh = pyggel.event.Handler()

    last_index = 0

    clock = pygame.time.Clock()

    view_angle = 45
    view_add = 0.2

    while 1:
        view_angle += view_add
        if view_angle >= 180:
            view_angle = 179
            view_add = -0.2
        elif view_angle <= 45:
            view_angle = 45
            view_add = 0.2
        pyggel.view.set_view_angle(view_angle)
        clock.tick(999)
        if have_vbo:
            pyggel.view.set_title("FPS with %s verts (using VBO): "%how_many+str(clock.get_fps()))
        else:
            pyggel.view.set_title("FPS with %s verts (not using VBO): "%how_many+str(clock.get_fps()))
        meh.update()
        if meh.quit:
            pyggel.quit()
            return None

        if K_UP in meh.keyboard.active:
            camera.posz += 0.1
        if K_DOWN in meh.keyboard.active:
            camera.posz -= 0.1
        if K_LEFT in meh.keyboard.active:
            camera.posx -= 0.1
        if K_RIGHT in meh.keyboard.active:
            camera.posx += 0.1

        view.set3d()

        colors = [(1,0,0,1), (0,1,0,1),
                  (0,0,1,1), (1,1,0,1),
                  (1,0,1,1), (0,1,1,1),
                  (.5,.5,.5,1)]

        view.clear_screen()
        my_light.shine()
        camera.push()
        vert_vbo.render()
        camera.pop()
        view.refresh_screen()
Example #12
0
def main():
    pyggel.view.init(screen_size=(800,600), screen_size_2d=(640, 480))
    pyggel.view.set_debug(False)

    my_light = pyggel.light.Light((0,100,0), (0.5,0.5,0.5,1),
                                  (1,1,1,1), (50,50,50,10),
                                  (0,0,0), True)

    camera = pyggel.camera.LookAtCamera((0,0,0), distance=10)
    camera.roty = 180

    obj = pyggel.mesh.OBJ("data/bird_plane.obj")
    root = obj.get_obj_by_name("cylinder1")
    tail = obj.get_obj_by_name("sphere2")
    head = obj.get_obj_by_name("sphere2_copy3")
    wings = obj.get_obj_by_name("cube4")

    skel = pyggel.mesh.Skeleton()
    skel.add_bone(root.name, (0,0,root.side("back")), (0,0,root.side("front")))
    skel.add_bone(tail.name, (0,0,tail.side("front")), (0,0,tail.side("back")), root.name)
    skel.add_bone(head.name, (0,0,head.side("back")), (0,0,head.side("front")), root.name, 0.25)
    skel.add_bone(wings.name, (wings.side("left"),0,0), (wings.side("right"),0,0), root.name, 0.5)

    action = pyggel.mesh.Action(2, [pyggel.mesh.RotateTo(wings.name, (0,0,45),0,.5),
                        pyggel.mesh.RotateTo(wings.name, (0,0,-45),.5,1.5),
                        pyggel.mesh.RotateTo(wings.name, (0,0,0),1.5,2),
                        pyggel.mesh.ScaleTo(tail.name, (1.25,1.25,1.25), 0, 1),
                        pyggel.mesh.ScaleTo(tail.name, (1,1,1), 1, 2),
                        pyggel.mesh.RotateTo(head.name, (0,15,0),0,.25),
                        pyggel.mesh.RotateTo(head.name, (0,-15,0),.25,.75),
                        pyggel.mesh.RotateTo(head.name, (0,0,0),.75,1),

                        pyggel.mesh.RotateTo("weapon_right", (0,0,-45),0,.5),
                        pyggel.mesh.RotateTo("weapon_right", (0,0,45),.5,1.5),
                        pyggel.mesh.RotateTo("weapon_right", (0,0,0),1.5,2),
                        pyggel.mesh.RotateTo("weapon_left", (0,0,-45),0,.5),
                        pyggel.mesh.RotateTo("weapon_left", (0,0,45),.5,1.5),
                        pyggel.mesh.RotateTo("weapon_left", (0,0,0),1.5,2)])
    head_left = pyggel.mesh.Action(1, [pyggel.mesh.RotateTo(head.name, (0,45,0),0,1)])
    head_right = pyggel.mesh.Action(1, [pyggel.mesh.RotateTo(head.name, (0,-45,0), 0,1)])
    head_up = pyggel.mesh.Action(1, [pyggel.mesh.RotateTo(head.name, (45,0,0),0,1)])
    head_down = pyggel.mesh.Action(1, [pyggel.mesh.RotateTo(head.name, (-45,0,0),0,1)])
    head_test = pyggel.mesh.Action(5, [pyggel.mesh.RotateTo(head.name, (0,0,45),0,1),
                           pyggel.mesh.RotateTo(head.name, (0,-45,0),2,3),
                           pyggel.mesh.RotateTo(head.name, (0,0,0),4,5),
                           pyggel.mesh.RotateTo(tail.name, (0,0,360), 0,5),
                           pyggel.mesh.RotateTo(wings.name, (0,0,720),0,5)])
    ani = pyggel.mesh.Animation(obj, skel, {"1":head_left,
                                "2":head_right,
                                "3":head_up,
                                "4":head_down,
                                "5":action,
                                "6":head_test})

    #Let's make some connections here:
    new_obj = wings.copy()
    new_obj.name = "weapon_right"
    skel.add_bone(new_obj.name, (wings.side("right"),0,0), (wings.side("right")+new_obj.side("width"),0,0), wings.name)
    ani.mesh.objs.append(new_obj)
    new_obj2 = wings.copy()
    new_obj2.name = "weapon_left"
    skel.add_bone(new_obj2.name, (wings.side("left"),0,0), (wings.side("left")-new_obj2.side("width"),0,0), wings.name)
    ani.mesh.objs.append(new_obj2)

    ani2 = ani.copy()
    ani2.do("5", True)
    ani2.pos = (0,0,-10)

    exp = pyggel.mesh.Exploder(obj.copy(), frame_duration=100,
                               kill_when_finished=False)

    my_scene = pyggel.scene.Scene()
    my_scene.camera = camera
    my_scene.add_3d(ani)
    my_scene.add_3d(ani2)
    my_scene.add_light(my_light)
    my_scene.add_3d(exp)

    clock = pygame.time.Clock()

    meh = pyggel.event.Handler()
    meh.bind_to_event(" ", lambda a,b: pyggel.misc.save_screenshot("Test.png"))

    last = None

    while 1:
        clock.tick(60)
        pyggel.view.set_title("FPS: %s"%clock.get_fps())

        meh.update()

        if meh.quit:
            pyggel.quit()
            return None

        if K_LEFT in meh.keyboard.active:
            camera.roty -= .5
        if K_RIGHT in meh.keyboard.active:
            camera.roty += .5
        if K_DOWN in meh.keyboard.active:
            camera.rotx -= .5
        if K_UP in meh.keyboard.active:
            camera.rotx += .5

        if "=" in meh.keyboard.active:
            camera.distance -= .1
        if "-" in meh.keyboard.active:
            camera.distance += .1

        if "a" in meh.keyboard.active:
            camera.posx -= .1
        if K_d in meh.keyboard.active:
            camera.posx += .1
        if K_s in meh.keyboard.active:
            camera.posz -= .1
        if K_w in meh.keyboard.active:
            camera.posz += .1

        nums = ("1", "2", "3", "4", "5", "6")
        for i in nums:
            if i in meh.keyboard.hit:
                ani.do(i, False)

        if exp.dead:
            exp.reset()

        pyggel.view.clear_screen()

##        pyggel.view.set3d()

        my_scene.render()#camera)

        pyggel.view.refresh_screen()
Example #13
0
def main():
    #First, the standard pyggel init stuff
    pyggel.init()

    scene = pyggel.scene.Scene()
    event_handler = pyggel.event.Handler()

    #Now for the gui
    """The PYGGEL gui is quite complex and powerful, but most of it's features can generally be ignored.
       This tutorial will teach the basics, and what args for widgets generally do - you will need to reference
       the doc strings for individual widgets to find their exact usage, in some places.

       At the root of any gui is the app. Apps are integrated into the event handler, and you may have multiple,
       though only one may be active at any one time. The app will catch events from the handler before the user can,
       and block any it uses.
       Creating an app is simple:
           app = gui.App(handler) - this creates the app, handler must be the event handler it is attached to.
       There are a few attributes and methods you should pay attention to with App's:
           theme - this is a gui.Theme object that allows you to load a theme style for your gui.
                    Anywhere that a specific value (that isn't mandatory) is not set by the user (ie, set to gui.tdef),
                    the theme will insert the value needed.
                    Theme's are highly extensible, you will find a basic one in data/gui/theme.py
                    If you create your own widgets, you can add theme components for them to a theme file
                    with no modification to the gui code. Simply put "widget_name" instead of, say "Label",
                    and then any attributes you want. You can see how it is done with any of the widgets in the gui.
                    The theme file is basically a glorified Python dictionary.
                    values are placed like this:
                        "Name":{
                            "variable name":"value"
                            },
                    Now, you will want to pay attention to the Fonts section of the theme.
                    This is not a widget style as the others are, instead this is where you define the fonts for your theme.
                    You then reference those fonts in your widgets later in the theme.
                    look at data/gui/theme.py to see the specific values you can use for each widget.
                    NOTE: all widgets can take a special_name arg that will force them to change their widget name to use a different them value...
            packer - this is a gui.Packer object that is used to position widgets in the scene.
                     This object is used by various widgets besides the App, the only ones you need worry about are frames and windows.
                     Anytime a widget's position is set to None, it uses the packer, otherwise it will use the pos specified.
                     Packer has one attribute you need to pay attention to, packtype.
                     packtype can be:
                     "wrap" - simply pushes widgets one after another, creating a new line when they hit the edge of the screen/widget
                     "center" - centers widgets on their line and from the center of the screen/widget
                     None/"None" - just sticks the widgets one after another - only a NewLine widget can force a new line.

        Now, each individual widget can either use the theme default for their args, or they can be overwritten.
        Some widgets have values you *must* supply, ie, all widgets need app to be set,
        which is the root app or frame/window object they are attached to.
        Check the doc-strings for the args you must supply.
        Now, everything that is not a must, has a default in the theme.
        To overwrite a value, just send a different value than gui.tdef.
        Args for widgets match the names for them in the theme,
        except that "-" are converted into "_" so Python can handle them.

        So now that you know the overall general idea of widgets in the gui, let's make some widgets..."""

    #first the App
    app = pyggel.gui.App(event_handler)
    app.theme.load("data/gui/theme.py") #here we load a theme
    newapp = pyggel.gui.App(event_handler) #why not make another?
    newapp.theme = app.theme #and of course it uses the same theme
    app.activate() #gotta make sure the first app is the active one - since only one can be active, it will be rendered and get input...
    regfont = app.get_regfont("default") #A default font is always created - but our theme also specifies this
                                         #When the gui loads a font, it loads both a font.Font and font.MEFont version
                                         #Here we get the font.Font object
    mefont = app.get_mefont("default") #and here we get the font.MEFont for the "default" font
    #you can also do: regfont, mefont = app.get_font("default")

    #Now let's add a few embeddable images to the fonts
    #NOTE: regular images or GIF's can be specified in theme font declarations, but not SpriteSheet type ones
    regfont.add_image(":P", pyggel.image.GridSpriteSheet("data/ar.png", (3,3)))
    mefont.add_image(":P", pyggel.image.GridSpriteSheet("data/ar.png", (3,3)))

    #let's center our widgets...
    app.packer.packtype="center"

    #The App is a PYGGEL object like any other, and as such needs to be added to the scene for rendering...
    scene.add_2d(app)
    scene.add_2d(newapp)

    #OK, let's make a frame in our gui to add other widgets to
    #Creating a Frame is a lot like an App, except you have to give it the root app (or another frame/window), a pos and size
    #both pos and size are optional though, they have defaults in the theme...
    #But for now we want a widget with an absolute position, not a relative one...
    frame = pyggel.gui.Frame(app, (500, 0), (140, 300))
    frame.packer.packtype = "wrap" #and this frame's packer wraps, instead of center, widgets

    #Now, let's make some widgets to put in the frame!
    #the Button requires an app to add to (such as an App, Frame or Window)
    #here we are also setting the text to "click!:P" - since we have an embedded image bound to ":P" that is converted into it
    #also, we attach a callback to the button click event.
    #All widgets will fire this event when clicked, but unlike buttons you have to specifically find it
    #simply do this: widget.dispatch.bind("click", function) to attach a callback when one is not allowed in args.
    #we are also overwriting the theme for text underlining
    pyggel.gui.Button(frame, "click!:P", callbacks=[test_callback],
                         font_underline=True)
    #Another button - long text O.o this time we overwrite the background-image-click and set to None,
    #so while we are holding mouse down on the button the background is gone...
    pyggel.gui.Button(frame, "click!124675326745327645762354",
                         callbacks=[test_callback],
                         background_image_click=None)

    #Labels take a lot of what Buttons do, excepting anything having to do with hover/clicking
    #here we attach it to the frame, with text "test:" and underline it
    pyggel.gui.Label(frame, "test:", font_underline=True)
    #And now we want a checkbox next to the previous Label
    #checkbox simply requires the frame, here, since we are content with the theme images for it.
    #the checkboxes state (1=on or 0=off) is stored in checkbox.state
    #unfortunately we aren't checking that here because we just add it to the frame and then forget about it
    #you could, however, assign it to a variable and keep track of it later...
    #You can also attach a function to the dispatch event "change" to get called every time the state changes
    #this function must take one arg, which is the state of the checkbox
    pyggel.gui.Checkbox(frame)

    #Now let's create 10 more labels for this frame
    for i in xrange(10):
        pyggel.gui.Label(frame, "testing456")


    #Now we are done with that frame, and we are adding widget directly to the App...
    #A few Buttons, the first uses the same callback as the previous ones have, but the second
    #contains a callback to swap the active App...
    pyggel.gui.Button(app, "Click me!:PXD", callbacks=[test_callback],
                         background_image_click=None)
    pyggel.gui.Button(app, "Swap Apps!", callbacks=[lambda: swap_apps(newapp)],
                         background_image_click=None)
    #And here is the NewLine widget we talked about before, it simply forces text to a new line in a packer.
    #it can take an optional height arg to specify the minimum height of the line it ends, ie
    #the minimum amount of space between the top of the current line and the top of the new line
    pyggel.gui.NewLine(app)

    #Now let's fill the App with a few lines of Labels
    for i in xrange(2):
        for i in xrange(random.randint(1, 2)):
            pyggel.gui.Label(app, "testing! 123")
        pyggel.gui.NewLine(app, random.choice([0, 15]))

    #Alright, now that you know how to make Labels, Buttons, NewLines and Checkboxes
    #let's make some more complex widgets

    #the Radio widget takes a group of options and makes a checkbox and a label for each, allowing you to click and select one option.
    #the widget requires the standard App arg, but also should be given the options arg
    #here we give it 3 options you can pick.
    #the radio keeps a dict of option:state objects for the state fo each option,
    #just check for which one has a state of 1 for the actual state.
    #like the Checkbox you can attach a function to the dispatch event "change",
    #the function must take one arg, which is a dict of all options and their states - either 1, selected or 0, not
    pyggel.gui.Radio(app, options=["test", "34", "56"])

    #The MultiChoiceRadio is exactly the same as the radio, except it allows multiple options to be clicked
    pyggel.gui.MultiChoiceRadio(app, options=["mc1", "mc2"])
    pyggel.gui.NewLine(app)

    #The Input widget simply converts keyboard events into text
    #it only catches when active though - so it has to be clicked, like a button, first.
    #to catch you can give a function in args, ie callback=function or attach one manually to the "submit" event
    pyggel.gui.Input(app, "test me...")

    #The MoveBar widget is an interesting widget.
    #Basically, it is a widget that, when clicked and held will follow the mouse around.
    #You can attach any other widget to it as it's child, and it will also move.
    #The move bar will relocate the child widget to be right under it.
    #unique, optional, args are width and child
    pyggel.gui.MoveBar(app, "TestWindow", child=frame)

    #A Window is a widget that basicaly wraps a MoveBar and a Frame, and attaches the Frame to the MoveBar.
    #As such it takes args for both the Frame and the MoveBar
    #Here, the size arg is used for both the Frame, and the x value is the width of the MoveBar
    window = pyggel.gui.Window(app, "P Window-take2!!!", pos=(100,100), size=(100,100))

    #Let's just stick some Label into the window so it isn't lonely...
    pyggel.gui.Label(window, "Woot!:P")

    #Now we are done with the first App
    #So let's add something to the other app, newapp.

    #So, let's make a Menu widget.
    #The menu will take args for a whole host of different things, but basically,
    #it has a button, that when clicked activates a frame with a bunch of options
    #Now, options must be a list of string options, or nested lists of their own options.
    #allows unlimited nesting.
    #when a list option is encountered, a sub menu is created,
    #with a button in the previous option screen that swaps, when clicked, to the new menu
    #the option name for the sub menu is the first option in the list, the options for it are the rest of the strings (or lists) in the list
    #only rule is that first option shouldn't be a list, as it needs a name...
    #you can tell when an option is clicked by attaching a function to the callback arg when creating,
    #or directly to the dispatch event menu-click
    #this function must take one arg, which is the option clicked.
    #If it is a sub-menu option, the name will be <submenu-name>.<option-name>,
    #   where submenu-name is the name of the option for the submenu (or the first option in the list)
    #   and option-name is the option clicked.
    #This applies to sub-sub-widgets as well, ie, hitting one of the numbers in the last widget will submit:
    #   "please work!.subagain!.1 or whatever it was that was clicked.
    pyggel.gui.Menu(newapp, "Menu", options=["help", "test", "quit","2","3","4","Snazzlemegapoof!!!!",
                                             ["please work!", "1", "2", "3", "asfkjhsakfh",
                                              ["subagain!", "1", "2", "3"*10]]],
                       callback=test_menu)

    #now a button to swap the current App back to the first...
    pyggel.gui.Button(newapp, "Swap Back!", callbacks=[lambda: swap_apps(app)],
                         background_image_click=None)
    #Finally, let's add an Icon widget to the newapp, so it isn't so lonely...
    #And Icon does nothing, just shows an image.
    pyggel.gui.Icon(newapp, image="data/gui/smiley.gif")


    #And there you have it, a simple gui is set up, and running.
    #Good luck! :)

    clock = pygame.time.Clock()

    while 1:
        clock.tick(999)
        pyggel.view.set_title("FPS: %s"%clock.get_fps())
        event_handler.update()
        if event_handler.quit:
            pyggel.quit()
            return None

        pyggel.view.clear_screen()
        scene.render()
        pyggel.view.refresh_screen()
Example #14
0
def main():
    pyggel.view.init(screen_size=(800,600), screen_size_2d=(640, 480))
    pyggel.view.set_debug(False)

    my_light = pyggel.light.Light((0,100,0), (0.5,0.5,0.5,1),
                                  (1,1,1,1), (50,50,50,10),
                                  (0,0,0), True)

    camera = pyggel.camera.LookAtCamera((0,0,0), distance=10)

    img = pyggel.image.Image("data/tile_example.png", pos=(50, 50))
    img.colorize=(1,0,0,1)
    img2 = pyggel.image.Image("data/ar.png", pos=(50,0))
    img2.colorize=(1,1,1,0.5)
    img3d = []
    for x in xrange(10):
        img3d.append(pyggel.image.Image3D("data/tile_example.png",
                                          pos=(random.randint(-10, 10),
                                               random.randint(-10, 10),
                                               10)))

    font = pyggel.font.MEFont()
    font3d = pyggel.font.Font(font_char_height3d=0.3)
    img4 = font.make_text_image("Hello World: 2D", (1, 1, 0, 1), underline=True, italic=True, bold=True)
    img4.pos = (50,50)
    img5 = font3d.make_text_image3D("Hello World: 3D", (0, 1, 1, 1))
    img5.scale = 2

    img6 = pyggel.image.GIFImage("data/smiley.gif", pos=(150, 150))
    img7 = pyggel.image.GIFImage3D("data/smiley.gif", pos=(0,0,1))

    pyggel.view.set_cursor(pyggel.image.SpriteSheet("data/ar.png",
                                    [(0,0,16,16), (16,0,16,16), (32,0,16,16), (16,0,16,16)],
                                    100),
                           True)

    obj = pyggel.mesh.OBJ("data/bird_plane.obj")
    obj.scale = .5
    obj2 = obj.copy()
    obj2.pos = (0,0,5)

    box = pyggel.geometry.Cube(5, texture=data.Texture("data/stickdude.png"))
    box.pos = (-5, 0, 0)

    box2 = pyggel.geometry.Cube(5, texture=data.Texture("data/skybox.png"), mirror=False)
    box2.pos = (5, 0, 0)

    verts = [(0,0,0),
             (0,1,0),
             (1,0,0)]
    batch = pyggel.misc.BatchVertObject(verts)

    my_scene = pyggel.scene.Scene()
    my_scene.pick = True
    my_scene.add_2d(img)
    my_scene.add_2d(img2)
    my_scene.add_2d(img4)
    my_scene.add_2d(img6)

    my_scene.add_3d(obj)
    my_scene.add_3d(obj2)
    my_scene.add_3d((box, box2, batch))
    for i in img3d:
        my_scene.add_3d(i)
    my_scene.add_3d(img5)
    my_scene.add_3d(img7)

    my_scene.add_light(my_light)
    my_scene.camera = camera

    clock = pygame.time.Clock()

    rot = 0

    last_hit = None

    meh = pyggel.event.Handler()
    meh.bind_to_event(" ", lambda a,b: pyggel.misc.save_screenshot("Test.png"))

    while 1:
        clock.tick(999)
        pyggel.view.set_title("FPS: %s"%clock.get_fps())

        meh.update()

        if meh.quit:
            pyggel.quit()
            return None
        if "left" in meh.mouse.hit:
            if img.get_rect().collidepoint(pyggel.view.screen.get_mouse_pos2d()):
                print 32
        if "right" in meh.mouse.hit:
            cur = view.screen.cursor
            if cur.running:
                cur.pause()
            else:
                cur.play()

        if K_LEFT in meh.keyboard.active:
            camera.roty -= .5
        if K_RIGHT in meh.keyboard.active:
            camera.roty += .5
        if K_DOWN in meh.keyboard.active:
            camera.rotx -= .5
        if K_UP in meh.keyboard.active:
            camera.rotx += .5
        if K_1 in meh.keyboard.active:
            camera.rotz -= .5
        if "2" in meh.keyboard.active: #just to throw you off ;)
            camera.rotz += .5

        if "=" in meh.keyboard.active:
            camera.distance -= .1
        if "-" in meh.keyboard.active:
            camera.distance += .1

        if "a" in meh.keyboard.active:
            camera.posx -= .1
        if K_d in meh.keyboard.active:
            camera.posx += .1
        if K_s in meh.keyboard.active:
            camera.posz -= .1
        if K_w in meh.keyboard.active:
            camera.posz += .1

        rot += 1
        a,b,c = img.rotation
        c += 1
        img.rotation = a,b,c

        a,b,c = img2.rotation
        c -= 1
        img2.rotation = a,b,c

        img5.visible = not img5.visible

        pyggel.view.clear_screen(my_scene)

        hit = my_scene.render()#camera)
        if last_hit:
            last_hit.outline = False
        if hit:
            hit.outline = True
        last_hit = hit

        mpx, mpy = pyggel.view.screen.get_mouse_pos()

        pyggel.view.refresh_screen()
Example #15
0
def main():
    pyggel.init(screen_size=(640,480))

    event_handler = pyggel.event.Handler()

    scene = pyggel.scene.Scene()

    scene.camera = pyggel.camera.LookAtCamera((0,0,0), distance=10)

    light = pyggel.light.Light((0,100,0), (0.5,0.5,0.5,1), (1,1,1,1),
                               (50,50,50,10), (0,0,0), True)

    scene.add_light(light)

    skybox = pyggel.geometry.Skybox("data/skybox.png")
    scene.add_skybox(skybox)

    #So, you know how to make particle behaviors and emitters now, so lets make a couple:
    emitter1 = pyggel.particle.Emitter3D(Fire3D, pos=(-2.5, 0, 0))
    emitter2 = pyggel.particle.EmitterPoint(FirePoint, pos=(2.5, 0, 0))

    scene.add_3d_blend((emitter1, emitter2))

    clock = pygame.time.Clock()

    while 1:
        clock.tick(60) #limit FPS
        pyggel.view.set_title("FPS: %s"%int(clock.get_fps()))

        event_handler.update() #get the events!

        if event_handler.quit or K_ESCAPE in event_handler.keyboard.hit: #were the quit 'X' box on the window or teh ESCAPE key hit?
           pyggel.quit() #close the window and clean up everything
           return None #close the loop

        if K_LEFT in event_handler.keyboard.active: #rotate view!
            camera.roty -= .5
        if K_RIGHT in event_handler.keyboard.active:
            camera.roty += .5
        if K_UP in event_handler.keyboard.active:
            camera.rotx -= .5
        if K_DOWN in event_handler.keyboard.active:
            camera.rotx += .5
        if K_1 in event_handler.keyboard.active:
            camera.rotz -= .5
        if "2" in event_handler.keyboard.active: #just to throw you off ;)
            camera.rotz += .5

        if "=" in event_handler.keyboard.active: #move closer/farther out
            camera.distance -= .1
        if "-" in event_handler.keyboard.active:
            camera.distance += .1

        if "a" in event_handler.keyboard.active: #move the camera!
            camera.posx -= .1
        if K_d in event_handler.keyboard.active:
            camera.posx += .1
        if K_s in event_handler.keyboard.active:
            camera.posz -= .1
        if K_w in event_handler.keyboard.active:
            camera.posz += .1

        pyggel.view.clear_screen()
        scene.render()
        pyggel.view.refresh_screen()
Example #16
0
def main():
    pyggel.view.init(screen_size=(800,600), screen_size_2d=(640, 480))
    pyggel.view.set_debug(False)

    my_light = pyggel.light.Light((0,100,0), (0.5,0.5,0.5,1),
                                  (1,1,1,1), (50,50,50,10),
                                  (0,0,0), True)

    camera = pyggel.camera.LookAtCamera((0,0,0), distance=10)

    img = pyggel.image.Image("data/tile_example.png", pos=(50, 50))
    img.colorize=(1,0,0,1)
    img2 = pyggel.image.Image("data/ar.png", pos=(50,0))
    img2.colorize=(1,1,1,0.5)
    img2sub = img2.sub_image((0,0), (15, 15))
    img2sub.colorize=(1, 0, 0, 1)
    img2sub.pos = (600, 400)
    img3d = []
    for x in xrange(10):
        img3d.append(pyggel.image.Image3D("data/tile_example.png",
                                          pos=(random.randint(-10, 10),
                                               random.randint(-10, 10),
                                               10)))

    font = pyggel.font.MEFont()
    font3d = pyggel.font.Font(font_char_height3d=0.3)
    img4 = font.make_text_image("Hello World: 2D", (1, 1, 0), underline=True, italic=True, bold=True)
    img4.pos = (50,50)
    img5 = font3d.make_text_image3D("Hello World: 3D", (0, 1, 1))
    img5.scale = 2

    img6 = pyggel.image.GIFImage("data/smiley.gif", pos=(150, 150))
    img7 = pyggel.image.GIFImage3D("data/smiley.gif", pos=(0,0,1))

    pyggel.view.set_cursor(pyggel.image.SpriteSheet("data/ar.png",
                                    [(0,0,16,16), (16,0,16,16), (32,0,16,16), (16,0,16,16)],
                                    100),
                           True)

    img.blit(img2, (0, 0))

    obj = pyggel.mesh.OBJ("data/bird_plane.obj")
    obj.scale = .5
    obj2 = obj.copy()
    obj2.pos = (0,0,5)

    box = pyggel.geometry.Cube(5, texture=data.Texture("data/stickdude.png"))
    box.pos = (-5, 0, 0)

    my_scene = pyggel.scene.Scene()
    my_scene.camera = camera
    my_scene.pick = True
    my_scene.add_2d(img)
    my_scene.add_2d(img2)
    my_scene.add_2d(img2sub)
    my_scene.add_2d(img4)
    my_scene.add_2d(img6)

    my_scene.add_3d(obj)
    my_scene.add_3d(obj2)
    my_scene.add_3d(box)
    my_scene.add_3d(img3d)
    my_scene.add_3d(img5)
    my_scene.add_3d(img7)

    my_scene.add_light(my_light)

    clock = pygame.time.Clock()

    rot = 0

    last_hit = None

    meh = pyggel.event.Handler()
    meh.bind_to_event(" ", lambda a,b: pyggel.misc.save_screenshot("Test.png"))

    to_swap = [obj, box, img5]+img3d

    swap_to_image = pyggel.data.BlankTexture(color=(0,1,0,.75))
    swap_material = pyggel.data.Material("blank")
    swap_material.set_color((0,1,0,.75))
    for i in to_swap: #here are our objects we want to change around...
        if isinstance(i, pyggel.mesh.BasicMesh):
            #needs a little different from others!
            new = []
            for x in i.objs:
                a = x.copy()
                a.material = swap_material
                new.append(a)
            i.swap_texs = [i.objs, new] #this value can be whatever you want!
        else:
            i.swap_texs = [i.texture, swap_to_image]
        i.current_swap_tex = 0 #because it is!
        #now the rest will be handled in teh main loop!

    last_time = time.time()
    while 1:
        clock.tick(999)
        pyggel.view.set_title("FPS: %s"%clock.get_fps())

        meh.update()

        if meh.quit:
            pyggel.quit()
            return None
        if "left" in meh.mouse.hit:
            if img.get_rect().collidepoint(pyggel.view.screen.get_mouse_pos2d()):
                if img.to_be_blitted:
                    img.clear_blits()
                else:
                    img.blit(img2, (0,0))
        if "right" in meh.mouse.hit:
            cur = view.screen.cursor
            if cur.running:
                cur.pause()
            else:
                cur.play()

        if K_LEFT in meh.keyboard.active:
            camera.roty -= .5
        if K_RIGHT in meh.keyboard.active:
            camera.roty += .5
        if K_DOWN in meh.keyboard.active:
            camera.rotx -= .5
        if K_UP in meh.keyboard.active:
            camera.rotx += .5
        if K_1 in meh.keyboard.active:
            camera.rotz -= .5
        if "2" in meh.keyboard.active: #just to throw you off ;)
            camera.rotz += .5

        if "=" in meh.keyboard.active:
            camera.distance -= .1
        if "-" in meh.keyboard.active:
            camera.distance += .1

        if "a" in meh.keyboard.active:
            camera.posx -= .1
        if K_d in meh.keyboard.active:
            camera.posx += .1
        if K_s in meh.keyboard.active:
            camera.posz -= .1
        if K_w in meh.keyboard.active:
            camera.posz += .1

        rot += 1
        a,b,c = img.rotation
        c += 1
        img.rotation = a,b,c

        a,b,c = img2.rotation
        c -= 1
        img2.rotation = a,b,c

        if time.time() - last_time >= 1: #limit to every second
            last_time = time.time()
            for i in to_swap: #time to apply those texture swaps!
                i.current_swap_tex = abs(i.current_swap_tex - 1)
                if isinstance(i, pyggel.mesh.BasicMesh):
                    i.objs = i.swap_texs[i.current_swap_tex]
                else:
                    i.texture = i.swap_texs[i.current_swap_tex]

        pyggel.view.clear_screen()

        hit = my_scene.render()#camera)
        if last_hit:
            last_hit.colorize = (1,1,1,1)
        if hit:
            hit.colorize = (1, 0, 0, 1)
        last_hit = hit

        mpx, mpy = pyggel.view.screen.get_mouse_pos()

        pyggel.view.refresh_screen()
Example #17
0
def main():
    pyggel.init(icon_image="data/ar.png")

    light = pyggel.light.Light((0,0,-5), (0,0,0,0),
                                  (1,1,1,1), (1,1,1,1),
                                  (0,0,0), True)

    camera1 = pyggel.camera.LookFromCamera((0,0,-10))
    camera2 = pyggel.camera.LookAtCamera((0,0,5), distance=10)

    font = pyggel.font.Font(None, 32)
    font2d = pyggel.font.RFont(None, 32)
    img = font.make_text_image3D("Hello\nWorld: 3D", (1, 1, 0, 1))
    img.scale = 5
    img2 = font.make_text_image3D("Hello World: 3D X2!!!", (0, 1, 1, 1))
    img2.pos = (0, .7, 0)
    img3 = img2.copy()
    img3.pos = (0, 0, 0)
    img4 = font.make_text_image3D("Testy...123...", (0, 1, 0, 1))
    img4.pos = (0, -1, 0)
    img5 = img4.copy()

    del img5
    img5 = img4.copy()
    img5.colorize = (1, 0, 0, .5)
    img5.pos = (0, .1, 0)

    text = font2d.make_text_image("ARG!!!!", (1, 0, 0, 1))
    text2 = text.copy()
    text2.pos = (0,75)

    font2 = pyggel.font.MEFont(None, 32)
    text3 = font2.make_text_image("Testing -\n1, 2, 3", (0, 0, 1, 1))

    box = pyggel.geometry.Cube(5, texture=data.Texture("data/ar.png"))
    box.pos = (0,0,5)
    box.rotation = list(box.rotation)
    sphere = pyggel.geometry.Sphere(5, texture=data.Texture("data/ar.png"),
                                    show_inside=True)
    sphere.pos = (10, 0, 0)

    emitter = particle.Emitter3D(particle.Fire3D, (0, 0, -2))
    emitter.behavior.image = image.Image3D("data/fire1.png")
    emitter.behavior.image.scale = .5

    emitter2 = particle.EmitterPoint(particle.FirePoint, (2, 0, -2))

    mscene = pyggel.scene.Scene()
    mscene.camera = camera1
    mscene.add_3d(img)
    mscene.add_3d(img2)
    mscene.add_3d(box)
    mscene.add_3d(sphere)
    mscene.add_3d_blend(img3)
    mscene.add_3d_blend(img5)
    mscene.add_3d_always(img4)
    mscene.add_2d(text)
    mscene.add_2d(text2)
    mscene.add_2d(text3)
    mscene.add_3d_blend(emitter)
    mscene.add_3d(emitter2)

    skybox = pyggel.geometry.Skybox(data.Texture("data/skybox.png"))
    skyball = pyggel.geometry.Skyball(data.Texture("data/skyball.png"))
    mscene.add_skybox(skybox)

    mscene.add_light(light)

    quad = pyggel.geometry.Plane(50, (0,5,0),
                                 texture=data.Texture("data/tile_example.png"),
                                 tile=10)
    quad.rotation=(90,0,0)
    mscene.add_3d(quad)

    eh = pyggel.event.Handler()

    clock = pygame.time.Clock()

    while 1:
        clock.tick(999)
        pyggel.view.set_title("FPS: %s"%clock.get_fps())

        eh.update()

        if eh.quit:
            pyggel.quit()
            return None
        if K_RETURN in eh.keyboard.hit:
            if mscene.camera == camera1:
                mscene.camera = camera2
            else:
                mscene.camera = camera1

        if "s" in eh.keyboard.hit:
            if mscene.graph.skybox == skybox:
                mscene.graph.skybox = skyball
            elif mscene.graph.skybox == skyball:
                mscene.graph.skybox = None
            else:
                mscene.graph.skybox = skybox

        if " " in eh.keyboard.hit:
            misc.save_screenshot("test.png")

        if "m" in eh.keyboard.active:
            if K_LEFT in eh.keyboard.active:
                mscene.camera.posx -= .1
            if K_RIGHT in eh.keyboard.active:
                mscene.camera.posx += .1
            if K_DOWN in eh.keyboard.active:
                mscene.camera.posy -= .1
            if K_UP in eh.keyboard.active:
                mscene.camera.posy += .1
            if "-" in eh.keyboard.active:
                mscene.camera.posz -= .1
            if "=" in eh.keyboard.active:
                mscene.camera.posz += .1
        if "r" in eh.keyboard.active:
            if K_LEFT in eh.keyboard.active:
                mscene.camera.roty -= .5
            if K_RIGHT in eh.keyboard.active:
                mscene.camera.roty += .5
            if K_DOWN in eh.keyboard.active:
                mscene.camera.rotx += .5
            if K_UP in eh.keyboard.active:
                mscene.camera.rotx -= .5
            if "-" in eh.keyboard.active:
                mscene.camera.rotz -= .5
            if "=" in eh.keyboard.active:
                mscene.camera.rotz += .5

        box.rotation[1] += 1

        pyggel.view.clear_screen(mscene)
        mscene.render()
        pyggel.view.refresh_screen()
Example #18
0
def main():
    pyggel.init(screen_size=(640,480)) #initialize everything
    #for now, pyggel.init just calls pyggel.view init...

    event_handler = pyggel.event.Handler()

    scene = pyggel.scene.Scene()

    """Now, handling 3d elements is a lot like handling 2d ones, in fact there are 3d fonts and images,
           with exactly the same api just having a 3d position instead of 2d!
       For 3d, you basically have Meshes, geometric shapes and 3d images/fonts.

       So, let's make all those same 2d elements from the last tutorial into 3d!"""

    #first, let's load an image!
    img = pyggel.image.Image3D("data/ar.png")
    img2 = img.copy() #let's make another! copying is cheaper than loading the image again, because textures don't have to be recompiled or loaded.
    #You can also copy by doing img2 = pyggel.image.Image(img) - but that is just long ;)
    #let's change some attributes here...
    img2.pos = (10, 3, 20) # new slot here, for "z" position
    img2.rotation = (0,0,45)

    #Woot, animations too!
    img3 = pyggel.image.GIFImage3D("data/smiley.gif")
    img3.pos = (2, 3, 20)

    img4 = pyggel.image.SpriteSheet3D("data/ar.png", [(0,0,16,16), (16,0,16,16), (32,0,16,16), (16,0,16,16)], 100)
    img4.pos = (4,3,20)

    img5 = pyggel.image.GridSpriteSheet3D("data/ar.png", (3, 3), 100)
    img5.pos = (6, 3, 20)

    #now the fonts
    font = pyggel.font.Font(font_char_height3d=1) #see tut5-scene_2d.py for 3d fonts...
    text1 = font.make_text_image3D("test?", italic=True)
    text1.pos = (-2, 3, 20)

    scene.add_3d((img, img2, img3, img4, img5)) #these images don't have perpixel alpha, so they are ok to go in base 3d class
    scene.add_3d_blend(text1) #unfortunately, this one does have perpixel alpha,
                              #you can either put it in 3d and deal with the funny blending,
                              #or stick it in 3d_blend!


    """Alright, so now that we know that most 2d elements have a sister element to render in 3d, let's extend into 3d only territory.
       So let's start with some geometry. Now, regardless of 2d or 3d, PYGGEL allows the user to call any OpenGL stuff they want,
       Either by putting it into a class that scene can handle, or just calling gl render code between screen clear and refresh.
       But we've written a few classes to help with basic geometry so you don't have to reinvent the wheel all the time.
       These objects support all the features of other 3d objects (textures, colorize, pos, rotation, etc.):
           geometry.Cube(size, pos, rotation, colorize, texture)
               size is the length of each side of the cube
               pos is the (x,y,z) position of the object - defaults to (0,0,0)
               rotation is the (x,y,z) rotation of the object - defaults to (0,0,0)
               colorize is the (r,g,b,a) color, bound to range 0-1, of the object
               texture can be None, a single data.Texture object which will be mapped as cube map,
                   or a list of 6 data.Texture objects - each for it's own face
               mirror indicates whether the texture is the same for each face (like [tex]*6, if mirror is True)
                   or if it is used as a cube map (if False)
                   defaults to True

           geometry.Quad(size, pos, rotation, colorize, texture, facing)
               A Quad is a simple 3d square
               All the args are the same as for Cube, except:
                   texture can be None or a single data.Texture for the face
           geometry.Plane(size, pos, rotation, colorize, texture, facing, tile)
               A Plane is exactly the same as a Quad, except that you can tile the texture so that it repeats,
               which is much faster than having a ton of quads...
               Args are the same as for Quad with one addition:
                   tile is the number of times to repeat the image in the (x,y) surface of the plane
           geometry.Sphere(size, pos, rotation, colorize, texture, detail)
               The Args for a Sphere are virtually identacle to a Cube, only differences are:
                   texture can be None or a single texture mapped to the Sphere
                   size is the radius of the sphere
                   detail is smoothness of the sphere - higher is more smooth - defaults to 30

       Alrighty, so now you know how to add 4 kinds of geometry into your scene.
       The interface for each of these is pretty simple - there aren't really any methods you need to use,
       all you do is change the position/rotation/scale/colorize of the object..."""

    #OK, let's make some stuff!
    a = pyggel.geometry.Cube(1, pos=(-10, 6, 20)) #this one is untextured
    #first, a texture to use...
    tex = pyggel.data.Texture("data/ar.png")
    b = pyggel.geometry.Cube(1, pos=(-8, 6, 20), texture=tex, mirror=False) #this one is textured as a cubemap
    c = pyggel.geometry.Cube(1, pos=(-6, 6, 20), texture=tex) #this one copies the texture for each face

    d = pyggel.geometry.Quad(1, pos=(-4, 6, 20), texture=tex) #this will look exactly like the cubes, because it is facing us...
    e = pyggel.geometry.Plane(10, pos=(-6, -6, 20), texture=tex, tile=10)
    f = pyggel.geometry.Sphere(1, pos=(2, 6, 20), texture=tex)

    scene.add_3d((a,b,c,d,e,f))

    #Woah, so why are all these new 3d elements so dark and bland and everything?
    #Because we have no light in the scene.
    #The 3d image types are pseudo - they don't use lights, and they always face the camera (unless specifically rotated away)
    #we will get to lights in the next lesson - for now, let's add a mesh and then we're done here :)

    """Ok, so you want more than just blocks and balls?
       Good, now we'll show you how you can import 3d models into PYGGEL.
       NOTE: for now there is only a loader for OBJ files, but more loaders are planned for the next release(s)...

       Loading a mesh is quite simple:
           mesh = mesh.OBJ(filename, pos, rotation, colorize)
               the pos, rotation and colorize args are the same as for geometry
               filename is the filename of the .obj object to load
       mesh.OBJ returns a mesh.BasicMesh object, which has the exact same usage as geometry objects do."""

    #lets make a mesh!
    mesh = pyggel.mesh.OBJ("data/bird_plane.obj", pos=(4, 6, 20))
    #this OBJ file is actually in PYGGEL coords, so no swapping is needed
    scene.add_3d(mesh)

    """Alright, so a static mesh isn't gonna do you a lot of good now is it?
       So, let's animate it!
       NOTE: the animation uses the named objects in an OBJ file.
       Creating an animation is fairly straight forward:
           First, you have to create the skeleton representing the mesh parts
           Second you need to defeine the animation
           Lastly you create the animation object itself."""

    #ok, so let's define the names of our mesh parts:
    root = mesh.get_obj_by_name("cylinder1")
    tail = mesh.get_obj_by_name("sphere2")
    head = mesh.get_obj_by_name("sphere2_copy3")
    wings = mesh.get_obj_by_name("cube4")
    #Normally you will want to name the parts something more generic, like root, head, etc.

    #Now create the skeleton:
    skel = pyggel.mesh.Skeleton()
    #let's add some the bones to it then!
    #add_bone requires at least 3 arguments:
    #   name - the name of the mesh objext this bone represents
    #   start - the xyz start position of the bone
    #   end - the xyz end position of the bone
    #Also, the add_bone can take two optional arguments:
    #   root_name - any bone other than root must be attached to another bone,
    #               this can be the root bone or another child
    #   anchor - a value ranging from 0 to 1,
    #            indicating where the rotate point between the start/end of the bone is
    #            0 equals the start point, 1 equals the end point and 0.5 equals the center
    skel.add_bone(root.name,
                  (0,0,root.side("back")),
                  (0,0,root.side("front")))
    skel.add_bone(tail.name,
                  (0,0,tail.side("front")),
                  (0,0,tail.side("back")),
                  root.name)
    skel.add_bone(head.name,
                  (0,0,head.side("back")),
                  (0,0,head.side("front")),
                  root.name,
                  0.25)
    skel.add_bone(wings.name,
                  (wings.side("left"),0,0),
                  (wings.side("right"),0,0),
                  root.name,
                  0.5)

    #Alrighty, now for our action!
    #actions are incredibly simple to understand
    #the first argument is the duration (in seconds) the entire action takes
    #the second is a list of command objects
    #There are three kinds of action commands:
    #   RotateTo, MoveTo and ScaleTo
    #each one works on an interpolation scheme, by the end of the commands run-time,
    #the bone values will match the command.
    #Each takes 3 arguments:
    #   name - the name of the bone and mesh object this action affects
    #   val - the ending value of the action - ie, rotation for RotateTo, movement for MoveTo, etc.
    #   start_time - how many seconds into the action this command starts
    #   end_time - how many seconds into the action this command ends
    action = pyggel.mesh.Action(2, [pyggel.mesh.RotateTo(wings.name, (0,0,45),0,.5),
                        pyggel.mesh.RotateTo(wings.name, (0,0,-45),.5,1.5),
                        pyggel.mesh.RotateTo(wings.name, (0,0,0),1.5,2),
                        pyggel.mesh.ScaleTo(tail.name, (1.25,1.25,1.25), 0, 1),
                        pyggel.mesh.ScaleTo(tail.name, (1,1,1), 1, 2),
                        pyggel.mesh.RotateTo(head.name, (0,15,0),0,.25),
                        pyggel.mesh.RotateTo(head.name, (0,-15,0),.25,.75),
                        pyggel.mesh.RotateTo(head.name, (0,0,0),.75,1),

                        #you can also define animations for non-existing mesh parts,
                        #so you can later add those parts
                        pyggel.mesh.RotateTo("weapon_right", (0,0,-45),0,.5), 
                        pyggel.mesh.RotateTo("weapon_right", (0,0,45),.5,1.5),
                        pyggel.mesh.RotateTo("weapon_right", (0,0,0),1.5,2),
                        pyggel.mesh.RotateTo("weapon_left", (0,0,-45),0,.5),
                        pyggel.mesh.RotateTo("weapon_left", (0,0,45),.5,1.5),
                        pyggel.mesh.RotateTo("weapon_left", (0,0,0),1.5,2)])

    #Alright, now for the animation object
    ani = pyggel.mesh.Animation(mesh, skel, {"move":action})
    ani.pos=(1,-2,10)
    ani.rotation = (0,180,0) #so it faces us!
    ani.do("move") #do takes two args: name of action, and loop = True/False
    scene.add_3d(ani)

    """And there we go, you have some geometry, a mesh, some 3d images/text and that is the basis for almost every scene in PYGGEL!"""

    clock = pygame.time.Clock() #pyggel automatically imports OpenGL/Pygame
                                #for a full list of everything included,
                                #look in pyggel/include.py

    while 1:
        clock.tick(60) #limit FPS
        pyggel.view.set_title("FPS: %s"%int(clock.get_fps()))

        event_handler.update() #get the events!

        if event_handler.quit or K_ESCAPE in event_handler.keyboard.hit: #were the quit 'X' box on the window or teh ESCAPE key hit?
           pyggel.quit() #close the window and clean up everything
           return None #close the loop

        pyggel.view.clear_screen() #clear screen for new drawing...
        scene.render() #render the scene
        pyggel.view.refresh_screen() #flip the display buffer so anything drawn now appears
def main():
    pyggel.init(screen_size=(640,480))

    pyggel.view.set_debug(False)

    event_handler = pyggel.event.Handler()

    scene = pyggel.scene.Scene()

    scene.camera = pyggel.camera.LookAtCamera((0,0,0), distance=35)

    light = pyggel.light.Light((0,100,0), (0.5,0.5,0.5,1), (1,1,1,1),
                               (50,50,50,10), (0,0,0), True)

    scene.add_light(light)

    #let's load a mesh
    #NOTE: this does not work for animations!
    obj = pyggel.mesh.OBJ("data/bird_plane.obj")

    #now let's make the exploder object
    #The object takes 4 arguments:
    #mesh - the mesh object to explode,
    #       generally you will use a copy as it modifies the values of the object directly!
    #speed - how fast the pieces move each frame
    #frame_duration - how many frames this animation lasts...
    #kill_when_finished - if True will remove from scene when finished
    exp = pyggel.mesh.Exploder(obj.copy(), .05, 125, False)
    scene.add_3d(exp)

    skybox = pyggel.geometry.Skybox("data/skybox.png")
    scene.add_skybox(skybox)

    clock = pygame.time.Clock()

    while 1:
        clock.tick(60)
        pyggel.view.set_title("FPS: %s"%int(clock.get_fps()))

        event_handler.update()

        if event_handler.quit or K_ESCAPE in event_handler.keyboard.hit: #were the quit 'X' box on the window or teh ESCAPE key hit?
           pyggel.quit()
           return None

        if K_LEFT in event_handler.keyboard.active: #rotate view!
            camera.roty -= .5
        if K_RIGHT in event_handler.keyboard.active:
            camera.roty += .5
        if K_UP in event_handler.keyboard.active:
            camera.rotx -= .5
        if K_DOWN in event_handler.keyboard.active:
            camera.rotx += .5
        if K_1 in event_handler.keyboard.active:
            camera.rotz -= .5
        if "2" in event_handler.keyboard.active: #just to throw you off ;)
            camera.rotz += .5

        if "=" in event_handler.keyboard.active: #move closer/farther out
            camera.distance -= .1
        if "-" in event_handler.keyboard.active:
            camera.distance += .1

        if "a" in event_handler.keyboard.active: #move the camera!
            camera.posx -= .1
        if K_d in event_handler.keyboard.active:
            camera.posx += .1
        if K_s in event_handler.keyboard.active:
            camera.posz -= .1
        if K_w in event_handler.keyboard.active:
            camera.posz += .1

        if exp.dead:
            exp.reset()

        pyggel.view.clear_screen()
        scene.render()
        pyggel.view.refresh_screen()
Example #20
0
def main():
    pyggel.init(screen_size=(640,480)) #initialize everything
    #for now, pyggel.init just calls pyggel.view init...

    event_handler = pyggel.event.Handler()

    clock = pygame.time.Clock() #pyggel automatically imports OpenGL/Pygame
                                #for a full list of everything included,
                                #look in pyggel/include.py

    while 1:
        clock.tick(60) #limit FPS
        pyggel.view.set_title("FPS: %s"%int(clock.get_fps()))

        event_handler.update() #get the events!

        if event_handler.quit or K_ESCAPE in event_handler.keyboard.hit: #were the quit 'X' box on the window or teh ESCAPE key hit?
           pyggel.quit() #close the window and clean up everything
           return None #close the loop

        """In PYGGEL, events are registered and handled automatically, you simply have to look up the current state of keys or the mouse.
           You can use Pygame to get events instead, if you prefer that - but note, the GUI will only work with PYGGEL's event handler.

           The event handler currently handles these kinds of events:
           KEY press, release, hold
           MOUSE button press, release, hold
           MOUSE motion
           QUIT

           Anything not caught by the event handler is stuffed is stuffed into an uncaught_events list.

           There are two ways to handle input with PYGGEL's event handler.
           You can quarry for the status of the keyboard, mouse, quit or uncaught_events,
           or you can attach a function callback to events.

           In this tutorial, we will show you how to use the direct quarry method, the next tut will explain the callback binding.


           Now, you already know how to create and event handler, update it, and get a couple of events from it.
           The event handler has 4 attributes you should pay attention to - the others handle internal functionality of the handler,
           and you will never need to touch them (generally).
           The attributes are:
               keyboard, mouse, quit and uncaught_events

           NOTE: when a gui is present, it will supress events, so they will not appear in the event handler as you might guess.
                 If you want to get events regardless of if the gui used them,
                 the gui events are stored in the same place as the regular ones, except the access names are preceeded with gui_*:
                     gui_keyboard, gui_mouse and gui_uncaught_events
                 The only exception is quit - which is only held by regular events, the GUI won't catch it.
                 
           keyboard is where all key states are stored, it has 3 attributes you should watch:
               active, hit and held

               active is a list of all keys that were either hit or held
               hit is a list of all keys that were hit just this last check
               held is a list of all keys that were hit but not this last check, ie they have been held

               To check if a key is in any of the storage areas, you do:
                   if <key> in keyboard.active #or whatever you are checking, replace <key> with the key you are looking for.
               Keys you can check for are listed here:
                   Any Pygame key constants:
                       K_ESCAPE, K_a, K_1, K_LEFT, etc.
                   And, if the key is printable, a string representing it:
                       " " - for space, "a" - for a, "A" for a if shift and/or caps lock are on

           mouse is where all mouse states are stored, it has 4 atributes you should watch:
               active, hit, held and motion

               active, hit and held are identacle to keyboard, except for mouse buttons, instead of keys
               mouse is a list of the [x,y] movement of the mouse since last update

               You check for mouse states the same way as with the keyboard, except you use these constants:
                   Pygame events buttons - 1=left, 2=middle, 3=right, 4=wheelup, 5=wheeldown, rest are extra...

                   or with these string names:
                       "left", "middle", "right", "wheel-up", "wheel-down" and "extra-#" - replacing # with whatever pygame event button it was

           quit you already know about, it simply is a boolean that is true if QUIT (or the X button on the window) was clicked or not

           uncaught_events is a list of pygame events that the handler didn't catch.
           You should use these the same way you would handle pygame.event.get() events:

           for event in event_handler.uncaught_events:
               etc..."""

        #Alrighty, so now that you know what to do, let's handle some input:

        if " " in event_handler.keyboard.hit: #was space bar hit?
            print "space bar!"
        for i in xrange(10): #get all numbers from 0-9
            if str(i) in event_handler.keyboard.hit: #a number was hit...
                print "number", i

        for i in event_handler.mouse.hit: #get all mouse press events
            if not type(i) is type(1): #only get the button names, not the button numbers
                print "mouse", i

        pyggel.view.clear_screen() #clear screen for new drawing...
        pyggel.view.refresh_screen() #flip the display buffer so anything drawn now appears
Example #21
0
def main():
    pyggel.init(screen_size=(640,480)) #initialize everything
    #for now, pyggel.init just calls pyggel.view init...

    event_handler = pyggel.event.Handler()
    """Now that you understand how to handle keys by directly quarring their state,
       now we'll show you how to bind callbacks for events.

       You attach a callback to an event like this:
           event_handler.bind_to_event("event-name", function) #where event-name is the constant event name used to fire events,
                                                               #and function is the function to be called when this event is fired
                                                               #NOTE: you can bind multiple events to each event
                                                               #if you want to ensure function is the only one bound, you can use:
                                                               #event_handler.replace_event("event-name", function) instead
       There are several events you can bind callbacks for, listed here:
           "keydown" - fired for any events put in keyboard.hit
               #takes two args, key_constant and key_name
           "keyup" - fired for any key that is released
               #takes two args, key_constant and key_name
           "keyhold" - fired for any events put in keyboard.held
               #takes two args, key_constant and key_name
           "keyactive" - fired for any events put in keyboard.active
               #takes two args, key_constant and key_name

           "mousedown" - fired for any events put in mouse.hit
               #takes two args, button_number and button_name
           "mouseup" - fired for any mouse button that is released
               #takes two args, button_number and button_name
           "mousehold" - fired for any events put in mouse.held
               #takes two args, button_number and button_name
           "mouseactive" - fired for any events put in mouse.active
               #takes two args, button_number and button_name

           "quit" - fired for any QUIT events

           "uncaught-event" - fired for any uncaught events
               #takes one arg, pygame_event

           "update" - fired at end of event_handler.update() when all events are processed and fired."""

    #Now that you know how to attach callbacks to events, let's add our new mouse and keyboard handlers:
    event_handler.bind_to_event("mousedown", handle_mouse_press)
    event_handler.bind_to_event("keydown", handle_keyboard_press)
    event_handler.bind_to_event("quit", handle_quit)

    clock = pygame.time.Clock() #pyggel automatically imports OpenGL/Pygame
                                #for a full list of everything included,
                                #look in pyggel/include.py

    while 1:
        clock.tick(60) #limit FPS
        pyggel.view.set_title("FPS: %s"%int(clock.get_fps()))

        event_handler.update() #get the events!

        if event_handler.quit or K_ESCAPE in event_handler.keyboard.hit: #were the quit 'X' box on the window or teh ESCAPE key hit?
           pyggel.quit() #close the window and clean up everything
           return None #close the loop

        pyggel.view.clear_screen() #clear screen for new drawing...
        pyggel.view.refresh_screen() #flip the display buffer so anything drawn now appears
Example #22
0
def main():
    pyggel.init(screen_size_2d=(600, 400))

    pyggel.view.set_debug(False)

    scene = pyggel.scene.Scene()

    eh = pyggel.event.Handler()
    app = pyggel.gui.App(eh)
    app.theme.load("data/gui/theme.py")
    newapp = pyggel.gui.App(eh)
    newapp.theme = app.theme
    app.activate() #first one ;)
    app.packer.packtype="center"
    scene.add_2d(app)
    scene.add_2d(newapp)

    frame = pyggel.gui.Frame(app, (500, 0), (140, 300), image_border=9)
    frame.packer.packtype = "wrap"

    pyggel.gui.Button(frame, "click!:P", callbacks=[test_callback],
                         font_underline=True)
    pyggel.gui.Button(frame, "click!124675326745327645762354",
                         callbacks=[test_callback],
                         background_image_click=None)
    pyggel.gui.Label(frame, "test:", font_underline=True)
    pyggel.gui.Checkbox(frame)

    for i in xrange(10):
        pyggel.gui.Label(frame, "testing456")

    pyggel.gui.Button(app, "Click me!:PXD", callbacks=[test_callback],
                         background_image_click=None)
    pyggel.gui.Button(app, "Swap Apps!", callbacks=[lambda: swap_apps(newapp)],
                         background_image_click=None)
    pyggel.gui.NewLine(app)

    for i in xrange(2):
        for i in xrange(random.randint(1, 2)):
            pyggel.gui.Label(app, "testing! 123")
        pyggel.gui.NewLine(app, random.choice([0, 15]))

    pyggel.gui.Label(app, "Hey!", (0, 0))
    pyggel.gui.Radio(app, options=["test", "34", "56"])
    pyggel.gui.MultiChoiceRadio(app, options=["mc1", "mc2"])
    pyggel.gui.NewLine(app)
    pyggel.gui.Input(app, "test me...")

    pyggel.gui.MoveBar(app, "TestWindow", child=frame)
    window = pyggel.gui.Window(app, "P Window-take2!!!", (100,100), (100,100))
    pyggel.gui.Label(window, "Woot!:P")
    pyggel.gui.Menu(window, "testing?", options=["1"*6]*5, callback=test_menu)
    pyggel.gui.Menu(newapp, "Menu", options=["help", "test", "quit","2","3","4","Snazzlemegapoof!!!!",
                                             ["please work!", "1", "2", "3", "asfkjhsakfh",
                                              ["subagain!", "1", "2", "3"*10]]],
                       callback=test_menu)
    pyggel.gui.Button(newapp, "Swap Back!", callbacks=[lambda: swap_apps(app)],
                         background_image_click=None)
    pyggel.gui.Icon(newapp, image="data/gui/smiley.gif")

    clock = pygame.time.Clock()

    while 1:
        clock.tick(999)
        pyggel.view.set_title("FPS: %s"%clock.get_fps())
        eh.update()
        if eh.quit:
            pyggel.quit()
            return None

        pyggel.view.clear_screen()
        scene.render()
        pyggel.view.refresh_screen()
Example #23
0
def main():
    pyggel.init(screen_size=(640,480)) #initialize everything
    #for now, pyggel.init just calls pyggel.view init...

    event_handler = pyggel.event.Handler()

    """Scenes, in PYGGEL control the rendering, updating and picking of 2d and 3d objects in an application.
       There are numerous things you need to pay attention with in the scene object, because it controls so many things,
       many of these things can't be addressed in a single tutorial, so they will be spread over a few,
       but for now here is a reference to them:
           objects:
               objects are added to the scene based on their type, which determines the OpenGL settings when rendered.
               Each type of object has an associated add_type/remove_type method, to add/remove objects from the scene.
               The types of objects are:
                   2d - renders last, on top of any 3d elements, no lighting/depth testing etc. blending on
                   3d - basic 3d object, no blending (but alpha testing is allowed), depth testing on
                   3d_blend - same as plain 3d, except blending is on
                   3d_always - same as 3d_blend, except depth testing is turned off
               Generally any object can be added to any of these groups - but they won't always look right.
               A general rule is that any object followed with a 3D should *always* go in one of the 3d containers,
               anything with 2D should always go into 2d, and anything else depends on the object - but it should be pretty obvious,
               ie, mesh.OBJ/BasicMesh should always go in 3d simply becaus you don't need 3d meshes in 2d
               (generally speaking, you'd have to hack a bit to make it work...)
           skyboxes:
               skyboxes are "background" objects that are rendered before everything else, to gives the appearance of an infinite world.
               to add a skybox simply call scene.add_skybox(skybox) - if skybox is None it removes the skybox.
               Objects that you can use for the sckybox are geometry.Skybox, geometry.Skyball and None
           lights:
               Almost every scene needs them. Scenes may have up to 8 lights attached to them at any time.
               To add/remove a light simply call scene.add_light(light)/scene.remove_light(light).
               Acceptable light objects are pyggel.light.Light objects, only.

           rendering:
               Ok, here is the main point of the scene - to efficiently and accurately render all your objects.
               To render you simply call scene.render() - render takes an optional argument to pass a camera to use to render.
           picking:
               Now here is the other main function of the scene - to pick objects, ie, to figure out which object the mouse is hitting.
               picking is integrated into the rendering loop, so setting it up is quite simple:
                   scene.pick = True #this tells the render method to also pick while it runs
                   picked_object = scene.render() #when you call render, the return object will be None or the picked object.
               And that is all there is to it.

       Alright. Now that you know what a scene is and what it does, let's make one!"""
    scene = pyggel.scene.Scene()

    clock = pygame.time.Clock() #pyggel automatically imports OpenGL/Pygame
                                #for a full list of everything included,
                                #look in pyggel/include.py

    while 1:
        clock.tick(60) #limit FPS
        pyggel.view.set_title("FPS: %s"%int(clock.get_fps()))

        event_handler.update() #get the events!

        if event_handler.quit or K_ESCAPE in event_handler.keyboard.hit: #were the quit 'X' box on the window or teh ESCAPE key hit?
           pyggel.quit() #close the window and clean up everything
           return None #close the loop

        pyggel.view.clear_screen() #clear screen for new drawing...
        item = scene.render() #render the scene, also, see if anything was picked
        if item and item.hit: #see if anything was picked
            print "something hit! But since we have nothing in the scene this will never be called O.o"
        pyggel.view.refresh_screen() #flip the display buffer so anything drawn now appears
 def processInput(self):
     """Get user input"""
     change = False
     keyboard = self.events.keyboard
     mousemoveX=None; mouseMoveY = None
     mouseX, mouseY = pygame.mouse.get_pos()
     mouseMoveX, mouseMoveY = pygame.mouse.get_rel()
     self.events.update()
     # check max mouseMove
     if norm(array([mouseMoveX, mouseMoveY])) > MAX_MOUSE_DIFF-150:
         mouseMoveX = mouseMoveY = 0
     # chck for quit
     if self.events.quit or K_ESCAPE in keyboard.hit:
         pyggel.view.clear_screen()
         pyggel.view.refresh_screen()
         pyggel.quit()
         sys.exit(0)
     # if 1 mouse button is held down
     if len(self.events.mouse.held)==2:
         # if right mouse button is held down
         mousebutton = self.events.mouse.held[0]
         mousedown = True
     else:
         mousebutton = None
         mousedown = False
     # if 2 mouse buttons are held down
     if len(self.events.mouse.held)==4:
         twomousebuttons = True
     else:
         twomousebuttons = False
     # mousehit
     mousehit = self.events.mouse.hit[0] if len(self.events.mouse.hit) else 0
     # tab
     tabhit = K_TAB in keyboard.hit
     # arrow keys
     movex = movey = 0
     if K_LEFT in keyboard.active or K_q in keyboard.active:
         movex = -1
     if K_RIGHT in keyboard.active or K_d in keyboard.active:
         movex = 1
     if K_UP in keyboard.active or K_z in keyboard.active:
         movey = 1
     if K_DOWN in keyboard.active or K_s in keyboard.active:
         movey = -1
     
     """ Process user input """
     # rotate third person camera
     rotx=0; roty=0; rotz=0
     if (mousebutton == LEFTMOUSEBUTTON and mousedown) or (not mousedown and self.camera is self.cameraFPS):
         if mouseMoveX:
             roty = -0.5*mouseMoveX
             change = True
         if mouseMoveY:
             rotx = -0.5*mouseMoveY
             change = True
     self.rotateCamera((rotx,roty,rotz))
     # move third person camera
     dx = dy = 0
     if mousebutton == MIDDLEMOUSEBUTTON and mousedown and mouseMoveX:
         dx = -0.5*mouseMoveX
         change = True
     if mousebutton == MIDDLEMOUSEBUTTON and mousedown and mouseMoveY:
         dy = -0.5*mouseMoveY
         change = True
     self.moveCamera((dx,dy))
     # move camera distance
     if mousebutton == RIGHTMOUSEBUTTON and mouseMoveY:
         self.changeCameraDistance(0.05*mouseMoveY)
         change = True
     # move camera distance
     if mousehit == MOUSEWHEELUP:
         self.changeCameraDistance(-3)
         change = True
     if mousehit == MOUSEWHEELDOWN:
         self.changeCameraDistance(3)
         change = True
     # switch camera view
     if tabhit:
         self.switchCamera()
         change = True
     # move around
     if movex or movey:
         change = True
     self.moveCamera(WALL_SCALE_PARAM * 4 * array([movex, -movey]))
     
     return change
Example #25
0
def main():
    pyggel.init(screen_size=(640,480), screen_size_2d=(640,480)) #initialize everything
    #for now, pyggel.init just calls pyggel.view init...

    event_handler = pyggel.event.Handler()

    scene = pyggel.scene.Scene()

    """Now that you know *how* to make a scene and what to do with them, let's put it to work!
       In this tutorial we will explain how to load, create, mess with and render 2d things, mainly images,
       but also font text, animations, sprite sheets and such."""

    """So, how exactly do we load and mess with images?
       In PYGGEL the image.Image class handles the vast majority or image things, from loading to handling (pos, rotation) to rendering.
       image.Image takes a few args at initiation:
           filename must be a string representing the file to load, a pygame Surface or another image.Image to copy.
           pos is the (x,y) position of the image
           rotation is the (x,y,z) rotation of the image
           scale is either the X or the (x,y,z) scale factor for the image
           colorize is the coloring for the image
       Beyond that there are only a few things you should know about images to use them:
           image.blit(other, pos) - this visually acts like pygame surface blitting,
               but in actuality it merely renders image first, then clips the view to itself and renders other at offset pos
               this method removes any previous blits of other image to this image
           image.blit_again(other, pos) - this is the same as blit, except it allows you to blit the same image multiple times
           get_width/height/size return the dimensions of the image
           get_rect returns a pygame.Rect with the images pos and size
           remove_blit(other) removes any blits of other image to this image
           sub_image(topleft, size) returns a new image that uses the pixels of this image's data from topleft to topleft+size"""

    #so, let's load an image!
    img = pyggel.image.Image("data/ar.png")
    img2 = img.copy() #let's make another! copying is cheaper than loading the image again, because textures don't have to be recompiled or loaded.
    #You can also copy by doing img2 = pyggel.image.Image(img) - but that is just long ;)
    #let's change some attributes here...
    img2.pos = (100,0)
    img2.rotation = (0,0,45)

    #alright, so now let's move on to animated images!
    """Animated images are quite similar to regular Images, there are just a few more/different methods.
       All Image methods are allowed - but they act differently - setting thigns occurs to all frames, getting returns current frame only.
       Creating an Animation is exactly the same as creating an image, except instead of filename a frames arg is supplied.
           frames must be a list of (Image, duration) objects, duration is in seconds
       Rendering an animation will automatically handle flipping frames unless paused or not looping and on last frame.
       The new methods are:
           seek(num) - change current frame of animation to frame[num]
           set_bounds(start, end) - this sets the start/end boundaries for playback - playback will only play inside these bounds
           pause - stops flipping of frames
           rewind - seeks to first frames
           fastforward - seeks to last frame
           length - number of frames
           reverse - reverses order of flipping frames
           reset - rewinds and undoes any reversal
           loop(boolean) - turns on/off looping - if off it will stop at last frame
           current - returns the current frame Image"""

    #loading animations can be doen manually, specifying an image/duration for each frame, but there are some automated tools for that.
    #First, you can load a GIF into an animation:
    img3 = pyggel.image.GIFImage("data/smiley.gif")
    img3.pos = (10,150)
    #or you can load a spritesheet!
    img4 = pyggel.image.SpriteSheet("data/ar.png", [(0,0,16,16), (16,0,16,16), (32,0,16,16), (16,0,16,16)], 100)
    img4.pos = (10,200)
    #the second argument are the boundaries of each frame in the image, and the third is the duration for each frame.
    #You can also automate this so you don't have to specify the bounds as well:
    img5 = pyggel.image.GridSpriteSheet("data/ar.png", (3, 3), 100)
    img5.pos = (10, 250)
    #with these you simply tell it how many frames in the (x,y) direction there are, and it figures out the rest.

    #ok, so now that we have some images, lets do some text!
    """With text you have 3 different options in PYGGEL, which you choose will depend on the situation.
       Regular Font objects (RFont) create text that is very fast to render, but changing the text is very slow.
       MEFont objects create text that is quite a bit slower to render, but changing text takes almost no time at all.
       And you have the Font class - it is very fast for both rendering and modifying - and supports 3d text output as well,
           but they do not support embedded images, and are slower than the other fonts in some circumstances.
       The usage for the first two fonts is identical:
           font = pyggel.font.RFont/MEFont creates the font. It takes two optional arguments, filename and size.
               filename must be None or the filename of the font to load,
               size is the, well, size of the font :)
           font.add_image(name, img) - adds an embedded image for the text to use, like a smiley,
               anytime a text has name in it it is replaced with the image, instead of the text glyph.
               name must be the string used to reference this image, can be any text
               img must be an image.Image, image.Animation or the filename of an image to load.
           font.make_text_image(text) creates a new text image for rendering the text, args are:
               text - a string of text to render - all 'n characters are converted to newlines,
                   and any names of embedded images found are converted into the images
               color - the (r,g,b,a) color of the text, with values bound to 0-1
               linewrap - None or the pixel width for each line of text (text only broken at newlines and spaces, so might overrun
               underline, italic and bold - the attributes of the text, True or False for each
       The usage for the Font object is as follows:
           font = pyggel.font.Font(filename, font_char_height=32, font_char_height=0.1, internal_font_size=64)
               filename can be None or the filename of the font to load
               font_char_height is the max height of each character in text
               font_char_height3d is the max height of each character in 3d text
               internal_font_size controls how big the absolute font size, for rendering on the texture map
                   if it is too large an Exception will be thrown, indicating you need to decrease size
           font.make_text_image2D(text, color=(1,1,1,1), underline=False, italic=False, bold=False,
                                  linewrap=None, break_words=False, override_char_height=None)
               #Creates/returns a 2d font image
               text is the text to render
               color can be 1 single color, or a list of colors for each character in the text
                   NOTE: if underlining, the underlines color is the first color in the list!
               underline, italic, bold control the view of the text
               linewrap can be None or the width for each line of text
               break_words - if True will not care about breaking words for line wrap
                             if False will try and break the lines up intelligently,
                             keeping words together where possible.
               override_char_height can be None or the new font_char_height for this text to use
           font.make_text_image3D - same as make_text_image except for 3d rendering"""
    font = pyggel.font.RFont(None, 32)
    mefont = pyggel.font.MEFont(None, 32)
    #but wait - do we want some embedded images?
    font.add_image(":)", img4.copy())
    mefont.add_image(":)", img4.copy())
    text1 = font.make_text_image("test?:)", italic=True)
    text1.pos = (10, 350)
    text2 = mefont.make_text_image("test!:)", color=(1,0,0,1), underline=True)
    text2.pos = (10, 400)

    #Now that we have all our images and fonts, lets add them to the scene and enjoy!
    scene.add_2d(img)
    scene.add_2d(img2)
    scene.add_2d(img3)

    #ok, so you can dump each and every object into the scene one at a time, or...
    #you can dump them all at once...
    scene.add_2d((img4, img5, text1, text2))

    clock = pygame.time.Clock() #pyggel automatically imports OpenGL/Pygame
                                #for a full list of everything included,
                                #look in pyggel/include.py

    while 1:
        clock.tick(60) #limit FPS
        pyggel.view.set_title("FPS: %s"%int(clock.get_fps()))

        event_handler.update() #get the events!

        if event_handler.quit or K_ESCAPE in event_handler.keyboard.hit: #were the quit 'X' box on the window or teh ESCAPE key hit?
           pyggel.quit() #close the window and clean up everything
           return None #close the loop

        #let's do some mouse input handling, and flip and image when it is clicked:
        #we use view.screen.get_mouse_pos2d to get the mouse pos in relation to the 2d screen size, which may be different
        #view.screen.get_mouse_pos returns the mouse pos in relation to the real screen size
        if "left" in event_handler.mouse.hit:
            if img.get_rect().collidepoint(pyggel.view.screen.get_mouse_pos2d()): #check for a collision
                img.scale = -img.scale

        pyggel.view.clear_screen() #clear screen for new drawing...
        scene.render() #render the scene
        pyggel.view.refresh_screen() #flip the display buffer so anything drawn now appears
Example #26
0
def main():
    pyggel.view.init(screen_size=(800,600), screen_size_2d=(640, 480))
    pyggel.view.set_debug(False)

    my_light = pyggel.light.Light((0,100,0), (0.5,0.5,0.5,1),
                                  (1,1,1,1), (50,50,50,10),
                                  (0,0,0), True)

    camera = pyggel.camera.LookAtCamera((0,0,0), distance=10)
    fbo_camera = pyggel.camera.LookAtCamera((0,0,0), distance=5)
    fbo_camera.rotx = -90

    obj = pyggel.mesh.OBJ("data/bird_plane.obj")
    obj.scale = .25

    box = pyggel.geometry.Cube(2.5, texture=None)
    box.pos=(-3, 0, 0)

    box2 = pyggel.geometry.Cube(2.5, texture=None)
    box2.pos=(3, 0, 0)

    my_scene = pyggel.scene.Scene()
    fbo_scene = pyggel.scene.Scene()
    fbo_scene.render_buffer = pyggel.data.FrameBuffer(clear_color=(1,0,0))

    tbo_scene = pyggel.scene.Scene()
    tbo_scene.render_buffer = pyggel.data.TextureBuffer(clear_color=(1,1,0))

    print fbo_scene.render_buffer.worked, tbo_scene.render_buffer.worked

    fbo_scene.add_3d(obj)
    tbo_scene.add_3d(obj)
    my_scene.add_3d((box, box2, obj))

    my_scene.add_light(my_light)
    my_scene.camera = camera
    fbo_scene.add_light(my_light)
    fbo_scene.camera = fbo_camera
    tbo_scene.add_light(my_light)
    tbo_scene.camera = fbo_camera

    clock = pygame.time.Clock()

    meh = pyggel.event.Handler()
    meh.bind_to_event(" ", lambda a,b: pyggel.misc.save_screenshot("Test.png"))

    while 1:
        clock.tick(999)
        pyggel.view.set_title("FPS: %s"%clock.get_fps())

        meh.update()

        if meh.quit:
            pyggel.quit()
            return None

        if K_LEFT in meh.keyboard.active:
            camera.roty -= .5
        if K_RIGHT in meh.keyboard.active:
            camera.roty += .5
        if K_DOWN in meh.keyboard.active:
            camera.rotx -= .5
        if K_UP in meh.keyboard.active:
            camera.rotx += .5
        if K_1 in meh.keyboard.active:
            camera.rotz -= .5
        if "2" in meh.keyboard.active: #just to throw you off ;)
            camera.rotz += .5

        if "=" in meh.keyboard.active:
            camera.distance -= .1
        if "-" in meh.keyboard.active:
            camera.distance += .1

        if "a" in meh.keyboard.active:
            camera.posx -= .1
        if K_d in meh.keyboard.active:
            camera.posx += .1
        if K_s in meh.keyboard.active:
            camera.posz -= .1
        if K_w in meh.keyboard.active:
            camera.posz += .1

        fbo_camera.rotz += 1

        pyggel.view.clear_screen()

        fbo_scene.render()#fbo_camera)

        tbo_scene.render()#fbo_camera)

        box.texture = fbo_scene.render_buffer.texture
        box2.texture = tbo_scene.render_buffer.texture

        my_scene.render()#camera)

        pyggel.view.refresh_screen()
Example #27
0
def main():
    try:
        pygame.mixer.pre_init(22050,-16,4,1024)
    except:
        pass
    pyggel.init()
    try:
        i = pygame.image.load(data.image_path("chickenstein_logo_small.png"))
        i.set_colorkey(i.get_at((0,0)), RLEACCEL)
        pygame.display.set_icon(i)
    except:
        pass
    try:
        pyggel.view.set_debug(False)
    except:
        print "Cannot disable debug, speed may be slower..."

    pData = PlayerData(hud.Hud())

    level = 1
    mode = "menu"
    pData.game_hud.sfx.set_track("menu")

    core_menu = Menu()
    core_story_menu = StoryMenu()
    core_death_menu = DeathMenu()
    core_win_menu = WinMenu()
    core_LP_menu = LevelPickMenu()

    while 1:
        pyggel.view.set_title("Chickenstein - Team [insert name] - Pyweek #9")
        if mode == "menu":
            level = 1
            pData.reset()
            retval = core_menu.run()
            command = retval[0]
        elif mode == "game":
            retval = play_level(level, pData)
            command = retval[0]
        elif mode == "story":
            retval = core_story_menu.run()
            command = retval[0]
        elif mode == "death":
            pData.reset()
            retval = core_death_menu.run()
            command = retval[0]
        elif mode == "win":
            pData.reset()
            retval = core_win_menu.run()
            command = retval[0]
        elif mode == "level_pick":
            pData.reset()
            retval = core_LP_menu.run()
            command = retval[0]

        if command == "play warp":
            level = int(retval[1])
            mode = "game"
            pick = Weapon((0,0,0), "handgun")
            pData.reset()
            pData.add_weapon(None, pick.name, pick.obj)
            pData.game_hud.sfx.set_track("play")
            continue

        if command == "menu":
            mode = "menu"
            pData.game_hud.sfx.set_track("menu")
        if command == "level_pick":
            mode = "level_pick"
        if command == "story":
            mode = "story"
            pData.game_hud.sfx.set_track("menu")
        if command == "quit":
            pyggel.quit()
            return None
        if command == "play":
            mode = "game"
            level = 1
            pData.game_hud.sfx.set_track("play")
        if command == "next":
            mode = "game"
            do_transition(retval[1], pData)
            level += 1
            pData.game_hud.sfx.set_track("play")
            continue
        if command == "win":
            mode = "win"
            pData.game_hud.sfx.play_win()
            level = 1
            pData.game_hud.sfx.set_track("menu")
        if command == "death":
            mode = "death"
            pData.game_hud.sfx.play_loss()
            level = 1
            pData.game_hud.sfx.set_track("menu")
        if len(retval) == 2:
            do_transition(retval[1], pData, mute=True)