Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTyler B <eldrac@eldrac-laptop.(none)>2009-07-14 04:03:33 (GMT)
committer Tyler B <eldrac@eldrac-laptop.(none)>2009-07-14 04:03:33 (GMT)
commit9e59b27ededa1f4c15c93481d35ac2e602a80d9a (patch)
tree2b224e982bf391febda205a2478f73f1b558ec37
parent70a488b2e54f7b9a5e8fe2b3d9a36e412a94cd21 (diff)
Improved running efficiency in tower level
-rwxr-xr-x[-rw-r--r--]tower.py47
1 files changed, 31 insertions, 16 deletions
diff --git a/tower.py b/tower.py
index be61962..a08bbac 100644..100755
--- a/tower.py
+++ b/tower.py
@@ -344,6 +344,7 @@ def run():
dropStrings = []
updateGaps = 1 #The variable that stores if the gaps need to be updated(set to 1 whenever the heroes number changes), also need to update at start
+ updateRects = [] #The list of rectangles on the screen representing the portions of the screen that need to be updated
#Sets the movement speeds for the character, in pixels per loop increment (game runs at 40 FPS)
sideSpeed = 10
@@ -400,7 +401,6 @@ def run():
#Sees if the lists storing the gaps which are impassable need to be updated
if updateGaps != 0:
updateGaps = 0
- print "Updating Gaps"
impassableGaps = [] #The list that will store all the gaps that are not currently passable because of the heroes current number
impassableWalls = util.merge([],walls) #Combined list representing impassable gaps and all walls
@@ -453,32 +453,38 @@ def run():
gap = impassableGaps[tempHero.collidelist(impassableGaps)]
shownGap2 = pygame.Rect(gap.topleft,(gap.width,20))
+
+
#re-draws the background
- screen.blit(background, (0, 0))
+ #screen.blit(background, (0, 0))
+ for rect in updateRects:
+ screen.blit(background,rect,rect)
+
+ prevUpdateRects = updateRects
+ updateRects = []
+
pygame.draw.rect(screen, [255,50,50], hero) #draws the hero
+ updateRects.append(hero)
#Checks if any impassable gaps have been hit or stepped on and thus need to be displayed
if shownGap1 != None:
pygame.draw.rect(screen, [250,100,100,50], shownGap1)
+ updateRects.append(shownGap1)
if topHoleWait != 0:
topHoleWait = topHoleWait - 1
pygame.draw.rect(screen, [250,100,100,50], shownGap2)
+ updateRects.append(shownGap2)
#Code which spawns a drop which contains a number, only called every 100 loops
if runCounter%75 == 0:
- #for i in range(1):
newDrop = generateDropNumber(heroNumber,levelNum)
- #print "spawn bubble %d"%(runCounter),newDrop[2]
dropRects.append(pygame.Rect(random.randint(150,850),0,50,50))
dropValues.append(newDrop[0:2])
dropStrings.append(newDrop[2])
-
-
-
+
#Checks if hero has hit any drops
if hero.collidelist(dropRects) != -1:
i = hero.collidelist(dropRects)
-
if dropValues[i][0] == 0: #hit an addition drop
if heroNumber + dropValues[i][1] < 1000:
heroNumber = heroNumber + dropValues[i][1]
@@ -514,13 +520,15 @@ def run():
#Goes through every drop currently on screen (starting with most recently spawned), draws it to the screen with the appropriate number, and moves it down
dropIndexs = range(len(dropRects))
dropIndexs.reverse()
+
+ font = pygame.font.Font(None,42) #The font
for i in dropIndexs:
- #dropTextRect = dropRects[i].inflate(20,-25)
- #pygame.draw.rect(screen, [102,255,255], dropRects[i])
- font = pygame.font.Font(None,42)
dropBox = font.render(dropStrings[i], 1, (50,50,230))
textSize = font.size(dropStrings[i])
- screen.blit(dropBox, (dropRects[i].topleft[0]+(50-textSize[0])/2,dropRects[i].topleft[1]+(50-textSize[1])/2))
+ dropRect = pygame.Rect(dropRects[i].topleft[0]+(50-textSize[0])/2,dropRects[i].topleft[1]+(50-textSize[1])/2,textSize[0],textSize[1])
+ #screen.blit(dropBox, (dropRects[i].topleft[0]+(50-textSize[0])/2,dropRects[i].topleft[1]+(50-textSize[1])/2))
+ screen.blit(dropBox, dropRect)
+ updateRects.append(dropRect)
dropRects[i] = dropRects[i].move(0,2)
if dropRects[i].topleft[1]>=900: #Removes from all applicable lists if no longer on screen
dropRects.pop(i)
@@ -531,7 +539,9 @@ def run():
numBox = pygame.Rect(0,0,60,30)
hero_number_box = util.render_textrect(str(heroNumber),pygame.font.Font(None, 40),numBox,(50,50,50),[250,250,250],0,1)
screen.blit(hero_number_box, (hero.topleft[0]+5,hero.topleft[1]+35))
- pygame.display.flip() #updates screen
+ #pygame.display.flip() #updates screen
+ pygame.display.update(prevUpdateRects)
+ pygame.display.update(updateRects)
#Made it off the top of the screen, must advance to next level
if hero.topleft[1] <= -80:
@@ -563,11 +573,16 @@ def run():
#As the level has changed, gaps need to be updated again
updateGaps = 1
+ #As there is a new background, need to set to update the whole screen
+ updateRects = [pygame.Rect(0,0,1200,900)]
+ prevUpdateRects = []
+
+ #makes the botton floor of the new screen the same as the top floor of the old one
background.blit(copy, (100,850))
print "Now on level %d."%(levelNum)
- #print clock
- clock.tick(40) #limits to 40 FPS
+ print clock
+ clock.tick(30) #limits to 40 FPS
def main():
@@ -636,4 +651,4 @@ def generateDropNumber(heroNumber,level):
return (type,number,returnString)
#runs main if called via other naming convention
-if __name__ == '__main__': main() \ No newline at end of file
+if __name__ == '__main__': main()