Add collage object and fullscreen config option
+from Sprite import Sprite
+from OpenGL.GL import *
+
+class Collage:
+ tiles = None
+ position = (0,0)
+
+ def __init__(self, file):
+ self.parse(file)
+
+
+ def parse(self, file):
+ self.tiles = []
+ mf = (1,1)
+ f = open(file,'r')
+ for line in f:
+ args = line.split()
+ if not args:
+ continue
+ cmd = args[0]
+ args = args[1:]
+ if cmd == 'tilesize':
+ mf = (int(args[0]),int(args[1]))
+ elif cmd == 'tile':
+ s = Sprite(args[0])
+ s.position = (int(args[1]) * mf[0], int(args[2]) * mf[1])
+ self.tiles.append(s)
+
+
+ def draw(self):
+ glPushMatrix()
+ glTranslatef(self.position[0], self.position[1], 0.0)
+ for t in self.tiles:
+ t.draw()
+ glPopMatrix()
sres = [int(n * config.scalefactor) for n in resolution]
except AttributeError:
sres = resolution
- pygame.display.set_mode(sres, OPENGL|DOUBLEBUF|HWSURFACE)
+ flags = OPENGL|DOUBLEBUF|HWSURFACE
+ try:
+ if config.fullscreen:
+ flags |= FULLSCREEN
+ except AttributeError:
+ pass
+ pygame.display.set_mode(sres, flags)
# Set up the camera
glLoadIdentity()
from util import *
import TexMan
+LEFT = 0
+CENTER = 1
+RIGHT = 2
+
class Sprite:
frames = None
framerate = 0.0
uparrow = False
displaylists = None
+ gravity = (LEFT, LEFT)
+
def __init__(self, file, genlist=True):
self.frames = []
d = None
if self.displaylists == None:
n = glGenLists(len(self.frames))
self.displaylists = range(n,n+len(self.frames))
- x = -self.size[0]/2
- y = -self.size[1]/2
+ c = [0,0]
+ for i in range(0,2):
+ if self.gravity[i] == LEFT:
+ c[i] = 0
+ elif self.gravity[i] == CENTER:
+ c[i] = -self.size[0]/2
+ elif self.gravity[i] == RIGHT:
+ c[i] = -self.size[0]
+ else:
+ print "Invalid gravity:",x
+ c[i] = 0
vertexarray = array(
- ((x,y,0),(x+self.tsize[0],y,0),
- (x+self.tsize[0],y+self.tsize[1],0),
- (x,y+self.tsize[1],0))
+ ((c[0],c[1],0),(c[0]+self.tsize[0],c[1],0),
+ (c[0]+self.tsize[0],c[1]+self.tsize[1],0),
+ (c[0],c[1]+self.tsize[1],0))
,'f')
texcoordarray = array(
((1.0,0.0),(1.0,1.0),(0.0,1.0),(0.0,0.0))
def draw(self):
- now = pygame.time.get_ticks()
- dt = now - self.anim_t
- if dt > self.anim_period:
- self.frameno = (self.frameno + int(dt / self.anim_period)) % len(self.frames)
- self.anim_t = now
+ if self.framerate > 0.0:
+ now = pygame.time.get_ticks()
+ dt = now - self.anim_t
+ if dt > self.anim_period:
+ self.frameno = (self.frameno + int(dt / self.anim_period)) % len(self.frames)
+ self.anim_t = now
glPushMatrix()
glTranslatef(self.position[0], self.position[1], 0)
if self.rotation != 0:
resolution = (640,480)
#resolution = (320,240)
-spritefile = 'img/ball.png'
-try:
+if sys.argv[1:]:
spritefile = sys.argv[1:]
-except IndexError:
- pass
+else:
+ spritefile = 'img/ball.png'
class Bouncer:
def __init__(self):
Engine.init(resolution)
bouncers = []
-for i in range(0,100):
+for i in range(0,1000):
h = Bouncer()
bouncers.append(h)
# If your card has trouble with non-square textures (my TNT seems to), set this
# to true to make all textures square
-square_textures = True
+square_textures = False
#scalefactor = 2
+#fullscreen = True
+tilesize 64 64
+tile img/block.png 0 0
+tile img/block.png 1 0
+tile img/block.png 2 0
+tile img/block.png 3 0
+tile img/block.png 4 0
+tile img/block.png 5 0
+tile img/block.png 6 0
+tile img/block.png 7 0
+tile img/block.png 8 0
+tile img/block.png 9 0
+
+tile img/block.png 4 1
+tile img/block.png 4 2
+tile img/block.png 4 3
+tile img/block.png 4 4
+
+tile img/block.png 6 1
+tile img/block.png 6 2
+tilesize 64 64
+tile img/block.png 0 0
+tile img/block.png 0 1
+tile img/block.png 1 0
+tile img/block.png 1 1
+tile img/star.png 232 421
+tile img/star.png 390 193
+tile img/star.png 548 66
+tile img/star.png 311 367
+tile img/star.png 430 12
+tile img/star.png 88 64
+tile img/star.png 90 123
+tile img/star.png 286 370
+tile img/star.png 263 100
+tile img/star.png 338 84
+tile img/star.png 231 47
+tile img/star.png 132 415
+tile img/star.png 399 183
+tile img/star.png 111 470
+tile img/star.png 445 67
+tile img/star.png 427 159
+tile img/star.png 237 103
+tile img/star.png 533 223
+tile img/star.png 26 409
+tile img/star.png 382 87
+tile img/star.png 507 82
+tile img/star.png 329 380
+tile img/star.png 381 417
+tile img/star.png 518 317
+tile img/star.png 378 197
+tile img/star.png 607 463
+tile img/star.png 502 274
+tile img/star.png 406 235
+tile img/star.png 185 249
+tile img/star.png 448 412
+tile img/star.png 418 29
+tile img/star.png 248 121
+tile img/star.png 177 85
+tile img/star.png 327 352
+tile img/star.png 466 39
+tile img/star.png 591 306
+tile img/star.png 106 95
+tile img/star.png 570 209
+tile img/star.png 163 466
+tile img/star.png 100 185
+tile img/star.png 376 469
+tile img/star.png 586 33
+tile img/star.png 383 251
+tile img/star.png 178 209
+tile img/star.png 121 211
+tile img/star.png 408 289
+tile img/star.png 539 222
+tile img/star.png 476 245
+tile img/star.png 282 274
+tile img/star.png 557 90
+tile img/star.png 249 80
+tile img/star.png 563 447
+tile img/star.png 18 229
+tile img/star.png 255 244
+tile img/star.png 358 354
+tile img/star.png 563 323
+tile img/star.png 292 28
+tile img/star.png 497 241
+tile img/star.png 379 67
+tile img/star.png 260 51
+tile img/star.png 159 163
+tile img/star.png 209 304
+tile img/star.png 541 28
+tile img/star.png 635 475
+tile img/star.png 479 130
+tile img/star.png 473 45
+tile img/star.png 127 308
+tile img/star.png 281 420
+tile img/star.png 332 28
+tile img/star.png 177 478
+tile img/star.png 413 12
+tile img/star.png 265 403
+tile img/star.png 216 147
+tile img/star.png 105 117
+tile img/star.png 64 417
+tile img/star.png 164 137
+tile img/star.png 131 416
+tile img/star.png 386 67
+tile img/star.png 511 111
+tile img/star.png 239 419
+tile img/star.png 600 445
+tile img/star.png 356 369
+tile img/star.png 314 266
+tile img/star.png 153 473
+tile img/star.png 239 221
+tile img/star.png 359 135
+tile img/star.png 288 133
+tile img/star.png 511 449
+tile img/star.png 234 401
+tile img/star.png 333 71
+tile img/star.png 40 78
+tile img/star.png 426 235
+tile img/star.png 251 195
+tile img/star.png 324 432
+tile img/star.png 25 334
+tile img/star.png 205 37
+tile img/star.png 219 284
+tile img/star.png 358 414
+tile img/star.png 260 395
+tile img/star.png 202 22
+tile img/star.png 594 64
+tile img/star.png 187 39
+tile img/star.png 71 231
+tile img/star.png 428 5
+tile img/star.png 180 302
+tile img/star.png 435 93
+tile img/star.png 10 161
+tile img/star.png 45 113
+tile img/star.png 224 99
+tile img/star.png 46 401
+tile img/star.png 196 465
+tile img/star.png 432 376
+tile img/star.png 194 342
+tile img/star.png 375 76
+tile img/star.png 437 174
+tile img/star.png 197 275
+tile img/star.png 208 92
+tile img/star.png 195 118
+tile img/star.png 618 202
+tile img/star.png 554 406
+#!/usr/bin/env python
+
+import pygame
+from Sprite import *
+from Collage import *
+import Engine
+
+#resolution = (1280,1024)
+resolution = (640,480)
+#resolution = (320,240)
+
+Engine.init(resolution)
+
+pygame.display.set_caption("scrolltest")
+
+ground = Collage('data/example1')
+ground.position = [0,0]
+stars = Collage('data/stars')
+stars.position = [0,0]
+
+def update():
+ ground.position[0] -= 5
+ if ground.position[0] < 0:
+ ground.position[0] = 640
+ stars.position[0] -= 1
+ if stars.position[0] < 0:
+ stars.position[0] = 640
+
+def draw():
+ stars.draw()
+ stars.position[0] -= 640
+ stars.draw()
+ stars.position[0] += 640
+ ground.draw()
+ ground.position[0] -= 640
+ ground.draw()
+ ground.position[0] += 640
+
+n = 0
+def fpsthing():
+ global n
+ n += 1
+ if n == 100:
+ fps = "%0.1f FPS" % Engine.fpsman.get_fps()
+ pygame.display.set_caption("bouncetest [%s]" % fps)
+ print fps
+ n = 0
+
+Engine.engine([],[update,fpsthing],[draw])