__init__.py :  » Game-2D-3D » Pyzzle » pyzzle-0.9 » pyzzle » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Game 2D 3D » Pyzzle 
Pyzzle » pyzzle 0.9 » pyzzle » __init__.py
import pygame, sys, sqlite3

import pyzzle
import DB
from Slide import Slide
from Hotspot import Hotspot
from Switch import Switch
from Item import Item
from Panel import Panel
from Text import Text
from standard import *
import os

panel=Panel()
cursor=pygame.sprite.Sprite()
cursor.rect=Rect(0,0,0,0)
cursor.image=pygame.Surface((0,0))
screen=None
framerate=30
datafile=None
globals=DB.Table('globals', (object,), {})
stages=DB.Table('stages', (object,), {})
design=False
menu=sys.exit
history=[]

def init(screensize=(800,600), name='Pyzzle', iconfile=None, fullscreen=False):
    """Initializes the screen. Must call before anything else.
    @type screensize: (int,int)
    @param screensize: Dimensions of the screen.
    @type name: string
    @param name: Text to display in the window's title bar
    @param iconfile: name of the image file to display as the window's icon
    """
    pygame.init()
    pyzzle.screen=pygame.display.set_mode(screensize, 
                                          pygame.FULLSCREEN if fullscreen else 0)
    pyzzle.panel.rect=pyzzle.screen.get_rect()
    if iconfile:
        icon=pygame.image.load(iconfile).convert_alpha()
        pygame.display.set_icon(icon)
    pygame.mouse.set_visible(False)
    pygame.display.set_caption(name)
def load(datafilename):
    """Loads game data from a SQLite database file.
    @param datafilename: name of the SQLite database file to load
    """
    pyzzle.datafile=DB.DB(datafilename)
    
    stages.rows.update(**datafile.select('Stage',value=lambda row: row,key=lambda row: row.id))
    datafile.select('Slide', value=lambda row:Slide._load(row))
    for slide in Slide:  slide._loadRefs()
    datafile.select('Hotspot', value=lambda row:Hotspot._load(row))
    datafile.select('Item',value=lambda row:Item._load(row))
    datafile.select('Switch',value=lambda row:Switch._load(row))

def cleanup():
    """Corrects capitalization of any image files mentioned in 
    the loaded SQLite database file. 
    Useful to prepare for distribution using dynamically downloaded content,
    but takes a while to run."""
    for stage in stages:
        directory=os.path.join('pictures',stage.folder)
        print directory
        for file in os.listdir(directory):
            print file
            datafile.query('update Slide set image = ? where lower(image)=lower(?)', 
                           (file,file))
def play():
    """The main game loop. Call this function only after you have finished 
    scripting and other initialization."""
    clock = pygame.time.Clock()
    while True:
        #update/draw the game
        clock.tick(150)
        pyzzle.framerate=clock.get_fps()
        
        pyzzle.beginDraw()
        pyzzle.drawCursor(pyzzle.panel.highlight())
        pyzzle.endDraw()
        
        #process user input - MUST COME AFTER DRAW
        #(cursor pos needs to be set when calling pyzzle.panel.click())
        for event in pygame.event.get():
            if event.type == QUIT:
                pyzzle.datafile.close()
                sys.exit()
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    pyzzle.menu()
                if  pyzzle.design and pygame.key.get_mods() & KMOD_CTRL:
                    if event.key == K_z:
                        if pyzzle.history:
                            oldslide, newslide=pyzzle.history.pop(-1)
                            if oldslide:
                                pyzzle.transition(newslide, oldslide, 0)
                                pyzzle.history=pyzzle.history[0:-1]
                    elif event.key==K_g:
                        slidename = pyzzle.promptText('Enter slide to jump to:')
                        if slidename in Slide.rows:
                            pyzzle.panel.sprites.empty()
                            pyzzle.panel.add(Slide[slidename])
            if event.type == MOUSEBUTTONDOWN:
                pyzzle.panel.click(design=(pygame.mouse.get_pressed()[2] and pyzzle.design))
                
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.