-
Notifications
You must be signed in to change notification settings - Fork 1
/
level.py
89 lines (67 loc) · 2.52 KB
/
level.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import pygame
class Level:
def __init__(self, imgFile, groundLevel):
self.background = imgFile
self.backgroundImage = pygame.image.load(self.background)
self.groundLevel = groundLevel
self.platformList = []
self.paintingList = []
def displayBackground(self, win):
win.blit(self.backgroundImage, (0, 0))
for platform in self.platformList:
platform.createSurface(win)
for painting in self.paintingList:
painting.createPainting(win)
def changeBackgroundImage(self, img, screen):
self.backgroundImage = pygame.image.load(img)
screen.blit(self.backgroundImage, (0,0))
def addPlatform(self, platform, win):
# win.blit(platform.surface, (platform.xCord, platform.yCord))
self.platformList.append(platform)
def clearScreen(self, win):
self.backgroundImage = pygame.image.load('WhiteScreen.png')
self.displayBackground(win)
def addPainting(self, painting, win):
self.paintingList.append(painting)
def removePlatforms(self):
self.platformList = []
def removePaintings(self):
self.paintingList = []
def findTop(self, index):
# x1, x2, y
x1 = self.platformList[index].xCord
y = self.platformList[index].yCord
x2 = x1 + self.platformList[index].xSize
return x1, x2, y
def findBottom(self, index):
# x1, x2, y
x1, x2, y = self.findTop(index)
y += self.platformList[index].ySize
return x1, x2, y
def findLeftSide(self, index):
# x, y1, y2
x = self.platformList[index].xCord
y1 = self.platformList[index].yCord
y2 = y1 + self.platformList[index].ySize
return x, y1, y2
def findRightSide(self, index):
# x, y1, y2
x, y1, y2 = self.findLeftSide(index)
x += self.platformList[index].xSize
return x, y1, y2
class Platform:
def __init__(self, x, y, xSize, ySize):
self.xCord = x
self.yCord = y
self.xSize = xSize
self.ySize = ySize
self.surface = pygame.Surface((xSize, ySize))
def createSurface(self, win):
self.surface.set_alpha(0) # make 0 for invisible
self.surface.fill((255, 255, 255))
self.displaySurface(win)
def displaySurface(self, win):
win.blit(self.surface, (self.xCord, self.yCord))
class Level2(Level):
def __init__(self, groundLevel):
super().__init__('LevelTwo.png', groundLevel)