added levels
This commit is contained in:
parent
e005abc073
commit
3943c2610d
2 changed files with 76 additions and 1 deletions
22
src/main.py
22
src/main.py
|
@ -1,6 +1,6 @@
|
||||||
__docformat__ = "reStructuredText"
|
__docformat__ = "reStructuredText"
|
||||||
|
|
||||||
import pymunk, pymunk.pygame_util, pygame, random
|
import pymunk, pymunk.pygame_util, pygame, random, json
|
||||||
|
|
||||||
class Camera(object):
|
class Camera(object):
|
||||||
"""
|
"""
|
||||||
|
@ -138,6 +138,23 @@ class Rain(object):
|
||||||
else:
|
else:
|
||||||
raindrop.draw()
|
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):
|
class RiseToFall(object):
|
||||||
"""
|
"""
|
||||||
riseToFall game class
|
riseToFall game class
|
||||||
|
@ -168,6 +185,9 @@ class RiseToFall(object):
|
||||||
|
|
||||||
self.camera = Camera()
|
self.camera = Camera()
|
||||||
|
|
||||||
|
self.level = Level('testlevel.json',self)
|
||||||
|
self.level.start()
|
||||||
|
|
||||||
# set draw options
|
# set draw options
|
||||||
self._print_options = pymunk.pygame_util.DrawOptions(self._screen)
|
self._print_options = pymunk.pygame_util.DrawOptions(self._screen)
|
||||||
|
|
||||||
|
|
55
src/testlevel.json
Normal file
55
src/testlevel.json
Normal 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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in a new issue