Skip to content
This repository has been archived by the owner on Dec 26, 2019. It is now read-only.

Commit

Permalink
Travel-Bug Fix Part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-bansal committed Jan 13, 2019
1 parent 1762d28 commit c9cfc6d
Show file tree
Hide file tree
Showing 16 changed files with 248 additions and 44 deletions.
6 changes: 6 additions & 0 deletions AppEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ def hide(self):
def show(self):
self.visible = True

def moveToFront(self):
sprites.remove(self)
sprites.append(self)

def update(self):
self.edgeLeft = self.x
self.edgeRight = self.x + self.width
Expand Down Expand Up @@ -207,6 +211,8 @@ def collide(self, otherSprite):

def destroy(self):
self.HPtext.destroy()
self.main = None
self.rect = None
sprites.remove(self)
del(self)

Expand Down
4 changes: 4 additions & 0 deletions Consumable.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def __init__(self, name, x, y, standalone = None, standaloneDesc = None):
def assignInvSlot(self, slot):
self.invSlot = slot

def destroy(self):
self.spriteImage.destroy()
del(self)

def use(self):
pass

Expand Down
40 changes: 28 additions & 12 deletions GameConfig/levels.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,33 @@
###############

// Level Two
###############
##### #####
# #
# #
# #
# #
#
#
#
#
# #
##### #######
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# #
# #
# #
###############

// Level Three
###############
# #
# #
# #
# #
#
#
#
#
# #
# #
# #
# #
##### #####
28 changes: 21 additions & 7 deletions LevelOne.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def __init__(self):
self.lvl1 = LevelParser.Parser("Level One")
self.lvl1.parse()

self.itemInfo = [
["Cherry Juice", 600, 700],
["Blackberry", 500, 700],
["Book", 400, 700],
["Blue Potion", 300, 700]
]

self.items = []

def generateGround(self):
Expand All @@ -32,19 +39,26 @@ def destroy(self):
# c.sprite.destroy()
for f in self.groundTiles:
f.destroy()
#for q in self.items:
# q.spriteImage.destroy()
self.obstacleTiles.clear()
self.hazards.clear()
self.groundTiles.clear()
self.items.clear()
self.stopMusic()

def spawnTreasure(self):
self.items.append(co.Consumable("Cherry Juice", 600, 700))
self.items.append(co.Consumable("Blackberry", 500, 700))
self.items.append(co.Consumable("Book", 400, 700))
self.items.append(co.Consumable("Blue Potion", 300, 700))
if len(self.items) > 0:
temp = []
for item in self.items:
if item.spriteImage.y != 905:
item.spriteImage.destroy()
item.spriteImage = None
del item
else:
temp.append(item)
self.items = temp

else:
for x in range(len(self.itemInfo)):
self.items.append(co.Consumable(self.itemInfo[x][0], self.itemInfo[x][1], self.itemInfo[x][2]))

return self.items

Expand Down
10 changes: 7 additions & 3 deletions LevelParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ def parse(self):
self.lines = f.read().splitlines()

self.lines = self.lines[self.lines.index("// %s" % self.level):]
self.lines.pop(0)

done = False
for line in self.lines:
if line == "":
self.lines = self.lines[:self.lines.index(line)]
if line == '':
if done == False:
self.lines = self.lines[:self.lines.index(line)]
done = True


self.lines.pop(0)
self.hasParsed = True

def checkForParse(self):
Expand Down
87 changes: 87 additions & 0 deletions LevelThree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import AppEngine
from AppEngine import *

import Consumable as co
import LevelParser
import Spritesheet

import random


class StageThree():
def __init__(self):
self.groundTiles = []
self.obstacleTiles = []
self.hazards = []

self.lvl3 = LevelParser.Parser("Level Three")
self.lvl3.parse()

self.itemInfo = []

self.items = []

def generateGround(self):
self.lvl3.generate_ground(self.groundTiles)

def generateObstacles(self):
self.lvl3.generate_obstacles(self.obstacleTiles)

def destroy(self):
for i in self.obstacleTiles:
i.sprite.destroy()
#for c in self.hazards:
# c.sprite.destroy()
for f in self.groundTiles:
f.destroy()
self.obstacleTiles.clear()
self.hazards.clear()
self.groundTiles.clear()
self.items.clear()
self.stopMusic()

def spawnTreasure(self):
if len(self.items) > 0:
temp = []
for item in self.items:
if item.spriteImage.y != 905:
item.spriteImage.destroy()
item.spriteImage = None
del item
else:
temp.append(item)
self.items = temp

else:
for x in range(len(self.itemInfo)):
self.items.append(co.Consumable(self.itemInfo[x][0], self.itemInfo[x][1], self.itemInfo[x][2]))

return self.items

def startMusic(self):
au.playMusic("Music/Level1.ogg", -1)

def stopMusic(self):
au.stopMusic()

def checkCollision(self, hero):
heroRect = hero.main.get_rect(topleft=(hero.x, hero.y))
heroRect.inflate_ip(10, 10)
for f in self.obstacleTiles:
fRect = f.sprite.main.get_rect(topleft=(f.sprite.x, f.sprite.y))
if f.id_ == "stationary":
if fRect.colliderect(heroRect):
if fRect.collidepoint(heroRect.midleft):
return "west"
if fRect.collidepoint(heroRect.midright):
return "east"
if fRect.collidepoint(heroRect.midtop):
return "north"
if fRect.collidepoint(heroRect.midbottom):
return "south"
return ""





32 changes: 27 additions & 5 deletions LevelTwo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def __init__(self):
self.lvl2 = LevelParser.Parser("Level Two")
self.lvl2.parse()

self.itemInfo = [
["Yellow Potion", 600, 700],
["Small Sword", 500, 700],
["Red Apple", 400, 700],
["Orange Potion", 300, 700]
]

self.items = []

def generateGround(self):
Expand All @@ -26,17 +33,32 @@ def generateObstacles(self):
self.lvl2.generate_obstacles(self.obstacleTiles)

def destroy(self):
for i in self.obstacleTiles:
i.sprite.destroy()
#for c in self.hazards:
# c.sprite.destroy()
for f in self.groundTiles:
f.destroy()
self.obstacleTiles.clear()
self.hazards.clear()
self.groundTiles.clear()
self.items.clear()
self.stopMusic()

def spawnTreasure(self):
self.items.append(co.Consumable("Yellow Potion", 600, 700))
self.items.append(co.Consumable("Small Sword", 500, 700))
self.items.append(co.Consumable("Red Apple", 400, 700))
self.items.append(co.Consumable("Orange Potion", 300, 700))
if len(self.items) > 0:
temp = []
for item in self.items:
if item.spriteImage.y != 905:
item.spriteImage.destroy()
item.spriteImage = None
del item
else:
temp.append(item)
self.items = temp

else:
for x in range(len(self.itemInfo)):
self.items.append(co.Consumable(self.itemInfo[x][0], self.itemInfo[x][1], self.itemInfo[x][2]))

return self.items

Expand Down
Loading

0 comments on commit c9cfc6d

Please sign in to comment.