-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSean_Code_Review.py
More file actions
128 lines (105 loc) · 4.25 KB
/
Sean_Code_Review.py
File metadata and controls
128 lines (105 loc) · 4.25 KB
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
### All the stuff for Rooms
import math, sys
import pygame
from pygame.locals import *
from Spores import *
from LivingThings import *
from Terrain import *
# -- Global constants
# Colors - check out pygame.Colors. Probably does exactly what you want
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (50, 50, 255)
# Screen dimensions
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_W_MID = SCREEN_WIDTH/2
SCREEN_H_MID = SCREEN_HEIGHT/2
class Room(object):
""" This is a generic super-class used to define a level.
Create a child class for each level with level-specific
info. """
def __init__(self, player):
""" Constructor. Pass in a handle to player. Needed for when moving platforms
collide with the player. """
self.wall_list = pygame.sprite.Group()
self.enemy_list = pygame.sprite.Group()
self.sludge = pygame.sprite.Group()
self.consumeable = pygame.sprite.Group()
self.can_climb = pygame.sprite.Group()
self.player = player
self.spore_list = [Decompose_Spore, Ledge_Spore]
self.active_spore = self.spore_list[0]
# Background image
self.background = None
# Update everythign on this level
def update(self):
""" Update everything in this level."""
self.wall_list.update()
self.enemy_list.update()
self.sludge.update()
self.consumeable.update()
self.can_climb.update()
def draw(self):
""" Draw everything on this level. """
# Draw the background
self.world.fill(BLUE)
# Draw all the sprite lists that we have
self.wall_list.draw(self.world)
self.enemy_list.draw(self.world)
self.sludge.draw(self.world)
self.consumeable.draw(self.world)
self.can_climb.draw(self.world)
def draw_end(self, screen):
""" Draw the game over screen. """
screen.fill(BLACK)
game_over_pic = pygame.transform.scale(pygame.image.load('game_over_mushroom.jpg').convert(), [350, 350])
screen.blit(game_over_pic, (SCREEN_W_MID-175, SCREEN_H_MID-175))
# Create platforms for the level
class Room_01(Room):
""" Definition for level 1. """
def __init__(self, player):
""" Create level 1. """
# Call the parent constructor
Room.__init__(self, player)
self.world_size = (1000, 600)
self.world = pygame.Surface(self.world_size)
# Solid objects. Array with width, height, x, y, and class of obstacle
room = [[500, 50, 0, 550, Ground],
[180, 30, 200, 400, Ground],
[200, 30, 500, 300, Ground],
[100, 400, 900, 200, Ground],
[300, 50, 500, 550, Lava]
]
# Objects that hinder movement. Array with width, height, x, y, and class of obstacle
sludge = [[300, 100, 400, 350, Water]]
# Objects you can eat. Array with width, height, x, y, and class of obstacle
consumeable = [[50, 50, 450, 500, Edible],
[50, 50, 245, 350, Edible],
[50, 50, 160, 500, Edible],
[50, 50, 300, 500, Edible],
[50, 50, 400, 500, Edible]]
# Enemies on the level
enemy_list = [[75, 75, 425, 475, Enemy]]
# Go through the array above and add obstacles
for obstacle in room:
block = obstacle[4](obstacle[2], obstacle[3], obstacle[0], obstacle[1])
block.rect.x = obstacle[2]
block.rect.y = obstacle[3]
block.player = self.player
self.wall_list.add(block)
for obstacle in sludge:
block = obstacle[4](obstacle[2], obstacle[3], obstacle[0], obstacle[1])
block.rect.x = obstacle[2]
block.rect.y = obstacle[3]
block.player = self.player
self.sludge.add(block)
for food in consumeable:
block = food[4](food[2], food[3], food[0], food[1])
block.rect.x = food[2]
block.rect.y = food[3]
block.player = self.player
self.consumeable.add(block)
for enemy in enemy_list:
block = enemy[4](enemy[2], enemy[3], enemy[0], enemy[1])
self.enemy_list.add(block)