def generateTilemap(): colAmount = ceil(800 / 16)*3 # (screen width / tile size) * 3 rowAmount = ceil(600 / 16) # screen height / tile size tileFile = open("levelMap.xml","w") tileFile.write('nnn') iceHeight = randint(1,10) for i in range(0,colAmount): tileFile.write('') makeHole = False if randint(0,50) == 10 and i != 0: # don't allow holes at the spawnpoint makeHole = True for j in range(0,rowAmount): if makeHole: tileFile.write('n') else: if j <= iceHeight: tileFile.write('n') else: tileFile.write('n') iceHeight = randint(iceHeight-5, iceHeight+5) if iceHeight < 0: # limit tiles from going too low iceHeight = randint(1,5) if iceHeight > rowAmount: # limit tiles from going too high iceHeight = randint(int(rowAmount/2)-5,int(rowAmount/2)+5) tileFile.write('n') tileFile.write('nn') for i in range(0,colAmount): tileFile.write('') for j in range(0,rowAmount): tileFile.write('n') tileFile.write('n') tileFile.write('nn') tileFile.close()
def startGame(): generateTilemap() # fig = Sprite('pingu.png') fig.position = (8, 500) figLayer = ScrollableLayer() figLayer.add(fig) # tileLayer = load('levelMap.xml') solidTiles = tileLayer['solid'] nsoliTiles = tileLayer['not_solid'] # scrMang = ScrollingManager() scrMang.add(nsoliTiles,z=-1) scrMang.add(solidTiles,z=0) scrMang.add(figLayer,z=1) # gameSc = Scene(scrMang) director.run(gameSc)
# "declaring" global variables keyboard = 0 scrMang = 0
def startGame(): global keyboard, scrMang generateTilemap() # fig = Sprite('pingu.png') fig.position = (8, 250) figLayer = ScrollableLayer() figLayer.add(fig) # tileLayer = load('levelMap.xml') solidTiles = tileLayer['solid'] nsoliTiles = tileLayer['not_solid'] # keyboard = key.KeyStateHandler() director.window.push_handlers(keyboard) # fig.do(PlatformerController()) mapcollider = RectMapCollider(velocity_on_bump='slide') fig.collision_handler = make_collision_handler(mapcollider, solidTiles) # scrMang = ScrollingManager() scrMang.add(nsoliTiles,z=-1) scrMang.add(solidTiles,z=0) scrMang.add(figLayer,z=1) # gameSc = Scene(scrMang) director.run(gameSc)
class PlatformerController(Action): global keyboard, scrMang on_ground = True MOVE_SPEED = 300 JUMP_SPEED = 500 GRAVITY = -1200 def start(self): self.target.velocity = (0, 0) def step(self, dt): global keyboard, scroller if dt