diff --git a/build.bat b/build.bat index 023da99..d14ae47 100644 --- a/build.bat +++ b/build.bat @@ -1 +1 @@ -pyinstaller cli.py -y -n "rise to fall" --add-data="src\levels\testlevel.json;levels" --icon="src\icon.ico" +pyinstaller cli.py --onefile -y -n "rise to fall" --add-data="src\levels\testlevel.json;levels" --icon="src\icon.ico" diff --git a/src/levels/testlevel.json b/src/levels/testlevel.json index 9cb4695..9e01fcf 100644 --- a/src/levels/testlevel.json +++ b/src/levels/testlevel.json @@ -131,7 +131,68 @@ ], "width": 4, "color": "" + }, + { + "pos1": [ + 350, + 1000 + ], + "pos2": [ + 450, + 1000 + ], + "width": 4, + "color": "" + }, + { + "pos1": [ + 750, + 1000 + ], + "pos2": [ + 650, + 1000 + ], + "width": 4, + "color": "" + }, + { + "pos1": [ + 870, + 900 + ], + "pos2": [ + 900, + 850 + ], + "width": 4, + "color": "" + }, + { + "pos1": [ + 1200, + 850 + ], + "pos2": [ + 1000, + 850 + ], + "width": 4, + "color": "" + }, + { + "pos1": [ + 1350, + 850 + ], + "pos2": [ + 1900, + 850 + ], + "width": 4, + "color": "" } + ], "obstacles": [ { @@ -143,21 +204,35 @@ "playerSpawn": [200,400], "checkpoints": [ { - "pos": [300,300], - "size":[20,20] + "pos": [20,900] } ], "switches": [ { - "pos": [300,300], - "rotation": 0 + "pos": [1150,800] } ], "text": [ { "text": "a and d to move", - "pos": [100,100], - "size": 14 + "pos": [20,420], + "color": "" + }, + { + "text" : "w to jump", + "pos" : [380,420], + "color" : "" + }, + { + "text" : "jump on box for checkpoint", + "pos" : [50,900], + "color" : "" + }, + { + "text" : "congratulations, you made it to the end", + "pos" : [1350,800], + "color" : "" } + ] } diff --git a/src/main.py b/src/main.py index 79d9bfe..d4eddd9 100644 --- a/src/main.py +++ b/src/main.py @@ -85,6 +85,27 @@ class Thing(object): """ pass +class Text(object): + def __init__(self,game,text = 'test',posList = (0,0), color = (0,0,0,1)): + self._game = game + self.text = text + self.pos = posList + self.color = color + self.img = game.font.render(text,True,color) + def draw(self): + self._game._screen.blit(self.img,self._game.camera.translate(self.pos)) + +class Checkpoint(object): + def __init__(self,game, pos = (0,0)): + self._game = game + self.pos = pos + def draw(self): + playPos = self._game.player.getPos() + if playPos[0] > self.pos[0] and playPos[0] < self.pos[0] + 25 and playPos[1] > self.pos[1] and playPos[1] < self.pos[1] + 25: + print("checkpoint") + self._game.level.level['playerSpawn'] = self.pos + pygame.draw.rect(self._game._screen,(0,255,0,.5),pygame.Rect(self._game.camera.translate(self.pos),(25,25))) + class Circle(Thing): """ This class implements a pymunk circle that can be displayed on a pygame window @@ -232,6 +253,13 @@ class Level(object): box = Platform(self._game,platform['pos1'],platform['pos2'],platform['width'] or 4,platform['color'] or (0,0,0,1)) # create platform object based on data box._poly.collision_type = 5 # specify as a platform collision type self._game._shapes.append(box) # add object to the game + for text in self.level['text']: + textObj = Text(self._game,text['text'],text['pos'],text['color'] or (0,0,0,1)) + self._game._shapes.append(textObj) + for checkpoint in self.level['checkpoints']: + check = Checkpoint(self._game,checkpoint['pos']) + self._game._shapes.append(check) + class Player(Circle): """ @@ -309,7 +337,7 @@ class RiseToFall(object): self._shapes = [] # list of objects - # font = pygame.font.SysFont("Arial",16) # font + self.font = pygame.font.SysFont("Arial.ttf",36) # font self.camera = Camera(w=self.windowSize[0],h=self.windowSize[1]) # initialize camera @@ -320,12 +348,11 @@ class RiseToFall(object): # load and start the first level - self.level = Level('levels/testlevel.json',self) + self.level = Level('levels\\testlevel.json',self) self.level.start() # create player self.player = Player(self) - self._shapes.append(self.player) self.camera.track(self.player) def _processEvents(self): @@ -361,6 +388,7 @@ class RiseToFall(object): """ for shape in self._shapes: shape.draw() + self.player.draw() def run(self): """