Fixed texture alignment and added sprite scaling
# Set up the camera
glLoadIdentity()
glMatrixMode(GL_PROJECTION)
- gluOrtho2D(0,resolution[0],0,resolution[1])
+ #gluOrtho2D(0,resolution[0],0,resolution[1])
+ # calculate Z-depth from average resolution
+ zdepth = sum(resolution) / 2
+ glFrustum(0,resolution[0],0,resolution[1],zdepth,zdepth * 10)
+ glTranslate(0,0,-zdepth)
+
+ #glTranslate(resolution[0]/2, resolution[1]/2, 0)
+ #glTranslate(0,0,-zdepth)
+ #glRotate(30, 0, 1, 0)
+ #glTranslate(-resolution[0]/2, -resolution[1]/2, 0)
# And initialize things how we like in GL
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
from util import *
import TexMan
-LEFT = 0
-CENTER = 1
-RIGHT = 2
-TOP = 2
-BOTTOM = 0
+LEFT = -1
+BOTTOM = -1
+CENTER = 0
+RIGHT = 1
+TOP = 1
class Sprite:
frames = None
framerate = 0.0
frameno = 0
+ animating = False
+ anim_t = 0
color = (1.0,1.0,1.0,1.0)
position = (0,0)
size = (0,0)
+ scale = 1.0
rotation = 0
+ gravity = (LEFT, BOTTOM)
uparrow = False
displaylists = None
- gravity = (LEFT, LEFT)
-
def __init__(self, file, genlist=True):
self.frames = []
d = None
self.frames.append(d['texture'])
self.size = d['size']
self.tsize = d['tsize']
+ print "size:",self.size
+ print "tsize:",self.tsize
if genlist:
self.gen_displaylist()
glDrawArrays(GL_QUADS, 0, 4)
glEndList()
+ def setColor(self, r, g, b, a = 1.0):
+ self.color = (r,g,b,a)
+ self.gen_displaylist()
+
+ def setScale(self, scale):
+ self.scale = scale
+
+
+ def setGravity(self, xg, yg):
+ if self.gravity != (xg,yg):
+ self.gravity = (xg,yg)
+ self.gen_displaylist()
+
+
+ def setFramerate(self, rate):
+ self.framerate = rate
+ if self.framerate != 0.0:
+ self.anim_period = int(1000/rate)
+ if self.anim_t == 0:
+ self.reset()
+ else:
+ self.stop()
- def anim_start(self):
+
+ def reset(self):
self.anim_t = pygame.time.get_ticks()
- self.anim_period = int(1000/self.framerate)
+
+
+ def play(self):
+ self.animating = True
+
+
+ def stop(self):
+ self.animating = False
def draw(self):
- if self.framerate > 0.0:
+ if self.animating:
now = pygame.time.get_ticks()
dt = now - self.anim_t
if dt > self.anim_period:
glTranslatef(self.position[0], self.position[1], 0)
if self.rotation != 0:
glRotatef(self.rotation, 0, 0, -1)
+ if self.scale != 1.0:
+ glScalef(self.scale, self.scale, 1.0)
glCallList(self.displaylists[self.frameno])
if self.uparrow:
glDisable(GL_TEXTURE_2D)
th = n2ceil(h)
if config.square_textures:
tw = th = max(tw,th)
- newImage = pygame.Surface((tw,th), SRCALPHA, 32);
+ newImage = pygame.Surface((tw,th), SRCALPHA, 32)
newImage.fill((255,255,255,0))
- newImage.blit(image, (0,0));
+ newImage.blit(image, (0, th - h)) # We want this in the lower corner
# Freaking pygame making us do this by hand...
colors = pygame.surfarray.pixels3d(newImage)
tilesize 1 1
texture img/ByteIco.png
-tile 263 249
+tile 263 263
ground.position = [0,0]
stars = Collage('data/stars')
stars.position = [0,0]
-candelabra = Sprite(['Sprites/candelabra_short/cand_s_1.png','Sprites/candelabra_short/cand_s_2.png','Sprites/candelabra_short/cand_s_3.png','Sprites/candelabra_short/cand_s_4.png'],False)
-candelabra.position = [64, 50]
-candelabra.gravity = (CENTER, BOTTOM)
-candelabra.framerate = 10.0
-candelabra.anim_start()
-candelabra.gen_displaylist()
+candelabra = Sprite(['Sprites/candelabra_short/cand_s_1.png','Sprites/candelabra_short/cand_s_2.png','Sprites/candelabra_short/cand_s_3.png','Sprites/candelabra_short/cand_s_4.png'])
+candelabra.position = [64, 64]
+candelabra.setScale(4.0)
+candelabra.setGravity(CENTER, BOTTOM)
+candelabra.setFramerate(10.0)
+candelabra.play()
def update():
ground.position[0] -= 5