-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatforms.py
139 lines (73 loc) · 3.22 KB
/
platforms.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#Platforms
import pygame
import constants
from spritesheet_functions import SpriteSheet
'''Define the platform types
name = (x, y, width, height)
'''
#clouds
CLOUD = (416, 140, 38, 21)
GRASS_LEFT = (117, 94, 21, 21)
GRASS_MIDDLE = ( 71, 94, 21, 21)
GRASS_RIGHT = (117, 117, 21, 21)
ICE_LEFT = (117, 370, 21, 21)
ICE_MIDDLE = ( 71, 370, 21, 21)
ICE_RIGHT = (117, 393, 21, 21)
ICE_CENTRE = ( 48, 393, 21, 21)
PURPLE_STONE_LEFT = (117, 140, 21, 21)
PURPLE_STONE_MIDDLE = ( 71, 140, 21, 21)
PURPLE_STONE_RIGHT = (117, 163, 21, 21)
STONE_LEFT = (117, 232, 21, 21)
STONE_MIDDLE = ( 71, 232, 21, 21)
STONE_RIGHT = (117, 255, 21, 21)
#Mushrooms
MUSH_RED_LEFT = ( 25, 278, 21, 21)
MUSH_RED_MIDDLE = ( 48, 278, 21, 21)
MUSH_RED_RIGHT = ( 95, 278, 21, 21)
#EXITING LEVELS
EXIT_TOP = (232, 531, 21, 21)
EXIT_BOTTOM = (232, 554, 21, 21)
class Exit(pygame.sprite.Sprite):
#general class exit so that the player can quit and move on to the next level
def __init__(self, sprite_sheet_data):
super().__init__()
sprite_sheet = SpriteSheet("spritesheet.png")
self.image = sprite_sheet.get_image(sprite_sheet_data[0],
sprite_sheet_data[1],
sprite_sheet_data[2],
sprite_sheet_data[3])
self.image.set_colorkey(constants.SPRITE_BACK)
self.rect = self.image.get_rect()
class Platform(pygame.sprite.Sprite):
#platform for the user to jump on
def __init__(self, sprite_sheet_data):
super().__init__()
#get the specific blocks from the sprite sheet
sprite_sheet = SpriteSheet("spritesheet.png")
self.image = sprite_sheet.get_image(sprite_sheet_data[0],
sprite_sheet_data[1],
sprite_sheet_data[2],
sprite_sheet_data[3])
self.image.set_colorkey(constants.SPRITE_BACK)
self.rect = self.image.get_rect()
class MovingPlatform(Platform):
#general class for a moving platform
def __init__(self, sprite_sheet_data):
super().__init__(sprite_sheet_data)
self.change_x = 0
self.change_y = 0
self.boundary_top = 0
self.boundary_bottom = 0
self.boundary_left = 0
self.boundary_right = 0
self.level = None
self.player = None
def update(self):
#move left/right and up/down
self.rect.x += self.change_x
self.rect.y += self.change_y
#check to see if platform should reverse direction
if self.rect.bottom > self.boundary_bottom or self.rect.top < self.boundary_top:
self.change_y *= -1
if self.rect.x < self.boundary_left or self.rect.x > self.boundary_right:
self.change_x *= -1