Skip to content

Commit

Permalink
Improved the Background class.
Browse files Browse the repository at this point in the history
  • Loading branch information
asweigart committed Aug 11, 2012
1 parent 442cfc1 commit 42a6bf0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions DemonKingdom/demonkingdom_makeover.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
import sys import sys


class Background(pygame.sprite.Sprite): class Background(pygame.sprite.Sprite):
def __init__(self, image): def __init__(self, imageList):
self.image = image self.imageList = []
self.rect = image.get_rect() for image in imageList:
self.imageList.append(pygame.image.load("images/" + image).convert())
self.image = self.imageList[0]
self.rect = self.image.get_rect()
self.rect.top = 0 self.rect.top = 0
self.rect.left = 0 self.rect.left = 0
def changeBackground(self, image):
self.image = image def changeBackground(self, imageNum):
self.image = self.imageList[imageNum]
self.rect = self.image.get_rect()

def draw(self): def draw(self):
screen.blit(self.image, self.rect) screen.blit(self.image, self.rect)


Expand Down Expand Up @@ -265,13 +271,13 @@ def castGhost():
getGem = pygame.mixer.Sound("sounds/pickupGem.wav") getGem = pygame.mixer.Sound("sounds/pickupGem.wav")


#background #background
background = Background(pygame.image.load("images/background.png").convert()) background = Background(('background1.png',
'background2.png',
'background3.png',
'background4.png',
'background5.png',
'background6.png'))
sidebar = Sidebar() sidebar = Sidebar()
back2 = pygame.image.load("images/background2.png").convert()
back3 = pygame.image.load("images/background3.png").convert()
back4 = pygame.image.load("images/background4.png").convert()
back5 = pygame.image.load("images/background5.png").convert()
back6 = pygame.image.load("images/background6.png").convert()


#monsters #monsters
gems = pygame.sprite.Group() gems = pygame.sprite.Group()
Expand Down Expand Up @@ -671,7 +677,7 @@ def draw():
finalWaveDone = False finalWaveDone = False
level += 1 level += 1
gems = pygame.sprite.Group() gems = pygame.sprite.Group()
background.changeBackground(back2) background.changeBackground(1)
draw() draw()
screen.blit(level2Text, [10, 10]) screen.blit(level2Text, [10, 10])
pygame.display.flip() pygame.display.flip()
Expand All @@ -689,7 +695,7 @@ def draw():
finalWaveDone = False finalWaveDone = False
level += 1 level += 1
gems = pygame.sprite.Group() gems = pygame.sprite.Group()
background.changeBackground(back3) background.changeBackground(2)
draw() draw()
screen.blit(level3Text, [10, 10]) screen.blit(level3Text, [10, 10])
pygame.display.flip() pygame.display.flip()
Expand All @@ -707,7 +713,7 @@ def draw():
finalWaveDone = False finalWaveDone = False
level += 1 level += 1
gems = pygame.sprite.Group() gems = pygame.sprite.Group()
background.changeBackground(back4) background.changeBackground(3)
draw() draw()
screen.blit(level4Text, [10, 10]) screen.blit(level4Text, [10, 10])
pygame.display.flip() pygame.display.flip()
Expand Down Expand Up @@ -747,7 +753,7 @@ def draw():
finalWaveDone = False finalWaveDone = False
level += 1 level += 1
gems = pygame.sprite.Group() gems = pygame.sprite.Group()
background.changeBackground(back5) background.changeBackground(4)
draw() draw()
screen.blit(level5Text, [10, 10]) screen.blit(level5Text, [10, 10])
pygame.display.flip() pygame.display.flip()
Expand All @@ -765,7 +771,7 @@ def draw():
finalWaveDone = False finalWaveDone = False
level += 1 level += 1
gems = pygame.sprite.Group() gems = pygame.sprite.Group()
background.changeBackground(back6) background.changeBackground(5)
draw() draw()
screen.blit(level6Text, [10, 10]) screen.blit(level6Text, [10, 10])
pygame.display.flip() pygame.display.flip()
Expand Down
File renamed without changes

0 comments on commit 42a6bf0

Please sign in to comment.