1
Fork 0

added levels

This commit is contained in:
Andy Killorin 2021-01-13 11:20:05 -06:00
parent e005abc073
commit 3943c2610d
No known key found for this signature in database
GPG key ID: 549CE32BAC1E3D4B
2 changed files with 76 additions and 1 deletions

View file

@ -1,6 +1,6 @@
__docformat__ = "reStructuredText"
import pymunk, pymunk.pygame_util, pygame, random
import pymunk, pymunk.pygame_util, pygame, random, json
class Camera(object):
"""
@ -138,6 +138,23 @@ class Rain(object):
else:
raindrop.draw()
class Level(object):
"""
Level class
Creates and destroys a level from a JSON file.
"""
def __init__(self, levelFilePath: str, game):
self._levelFilePath = levelFilePath
self._levelFile = open(self._levelFilePath, 'r')
self.level = json.load(self._levelFile)
self._game = game
def start(self):
for platform in self.level['platforms']:
self._game._shapes.append(Platform(self._game,platform['pos1'],platform['pos2'],platform['width'] or 4,platform['color'] or (0,0,0,1)))
class RiseToFall(object):
"""
riseToFall game class
@ -168,6 +185,9 @@ class RiseToFall(object):
self.camera = Camera()
self.level = Level('testlevel.json',self)
self.level.start()
# set draw options
self._print_options = pymunk.pygame_util.DrawOptions(self._screen)

55
src/testlevel.json Normal file
View file

@ -0,0 +1,55 @@
{
"platforms": [
{
"pos1": [
200,
200
],
"pos2": [
200,
350
],
"width": 4,
"color": ""
},
{
"pos1": [
200,
350
],
"pos2": [
300,
350
],
"width": 4,
"color": ""
}
],
"obstacles": [
{
"pos": [
300,300
]
}
],
"playerSpawn": [200,400],
"checkpoints": [
{
"pos": [300,300],
"size":[20,20]
}
],
"switches": [
{
"pos": [300,300],
"rotation": 0
}
],
"text": [
{
"text": "a and d to move",
"pos": [100,100],
"size": 14
}
]
}