import yaml
from Collage import Collage
from Surface import SurfaceSet
-from Stage import Stage, Layer
+from OpenGL.GL import *
classpath = ['classes']
for path in classpath:
mod[0].close()
+class Layer:
+ """Container for layer data.
+
+ collage - A Collage object defining the visuals of the layer
+ scale - A float value for the size of the background layer
+ parallax - A float value specifying the relative scroll speed (where
+ 1.0 is typically the playfield scroll speed, >1.0 is faster,
+ and <1.0 is slower)"""
+
+ def __init__(self, collage=None, surfaces=None, scale=1.0, parallax=1.0):
+ self.collage = collage
+ self.surfaces = surfaces
+ self.scale = scale
+ self.parallax = parallax
+ self.position = (0, 0)
+ self.things = []
+
+
+ def add(self, thing):
+ self.things.append(thing)
+
+
+ def moveTo(self, x, y):
+ self.position = (x * self.parallax, y * self.parallax)
+
+
+ def draw(self):
+ glPushMatrix()
+ if self.scale != 1.0:
+ glScalef(self.scale, self.scale, self.scale)
+ glTranslatef(-self.position[0], -self.position[1], 0)
+ self.collage.draw()
+ for t in self.things:
+ t.draw()
+ glPopMatrix()
+
+
class Level:
def __init__(self, dir):
+ self.layers = []
+ self.position = (0, 0)
+ self.drawsurfaces = False
self.env = {}
+
self.load(dir)
layers = yaml.safe_load(f)
f.close()
- self.stage = Stage()
-
for layer in layers:
collage = None
surfaces = None
parallax = layer['properties']['parallax']
new_layer = Layer(collage, surfaces, scale, parallax)
- self.stage.addLayerBack(new_layer)
+ self.addLayerBack(new_layer)
if layer.has_key('things'):
self.compileThings(new_layer, layer['things'])
properties['surfaces'] = layer.surfaces
self.env[name] = c(**properties)
layer.add(self.env[name])
+
+
+ def addLayerBack(self, layer):
+ self.layers.insert(0, layer)
+
+
+ def addLayerFront(self, layer):
+ self.layers.append(layer)
+
+
+ def setSurfaces(self, datafile):
+ self.surfaces = SurfaceSet(datafile)
+
+
+ def drawSurfaces(self):
+ self.drawsurfaces = True
+
+
+ def hideSurfaces(self):
+ self.drawsurfaces = False
+
+
+ def toggleDrawSurfaces(self):
+ self.drawsurfaces = not self.drawsurfaces
+
+
+ def moveTo(self, x, y):
+ self.position = [x,y]
+ for l in self.layers:
+ l.moveTo(x, y)
+
+
+ def draw(self):
+ for l in self.layers:
+ l.draw()
+ if self.drawsurfaces:
+ glPushMatrix()
+ glTranslate(-self.position[0], -self.position[1], 0)
+ self.surfaces.draw()
+ glPopMatrix()
-from Collage import *
-from Surface import *
-
-class Layer:
- """Container for layer data.
-
- collage - A Collage object defining the visuals of the layer
- scale - A float value for the size of the background layer
- parallax - A float value specifying the relative scroll speed (where
- 1.0 is typically the playfield scroll speed, >1.0 is faster,
- and <1.0 is slower)"""
-
- def __init__(self, collage=None, surfaces=None, scale=1.0, parallax=1.0):
- self.collage = collage
- self.surfaces = surfaces
- self.scale = scale
- self.parallax = parallax
- self.position = (0, 0)
- self.things = []
-
-
- def add(self, thing):
- self.things.append(thing)
-
-
- def moveTo(self, x, y):
- self.position = (x * self.parallax, y * self.parallax)
-
-
- def draw(self):
- glPushMatrix()
- if self.scale != 1.0:
- glScalef(self.scale, self.scale, self.scale)
- glTranslatef(-self.position[0], -self.position[1], 0)
- self.collage.draw()
- for t in self.things:
- t.draw()
- glPopMatrix()
-
-
-class Stage:
- layers = None
- surfaces = None
- drawsurfaces = False
- position = None
-
- def __init__(self):
- self.layers = []
- self.position = (0, 0)
- self.env = {}
-
-
- def addLayerBack(self, layer):
- self.layers.insert(0, layer)
-
-
- def addLayerFront(self, layer):
- self.layers.append(layer)
-
-
- def setSurfaces(self, datafile):
- self.surfaces = SurfaceSet(datafile)
-
-
- def drawSurfaces(self):
- self.drawsurfaces = True
-
-
- def hideSurfaces(self):
- self.drawsurfaces = False
-
-
- def toggleDrawSurfaces(self):
- self.drawsurfaces = not self.drawsurfaces
-
-
- def moveTo(self, x, y):
- self.position = [x,y]
- for l in self.layers:
- l.moveTo(x, y)
-
-
- def draw(self):
- for l in self.layers:
- l.draw()
- if self.drawsurfaces:
- glPushMatrix()
- glTranslate(-self.position[0], -self.position[1], 0)
- self.surfaces.draw()
- glPopMatrix()