This repository was archived by the owner on Oct 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevels.py
More file actions
154 lines (148 loc) · 6.9 KB
/
levels.py
File metadata and controls
154 lines (148 loc) · 6.9 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
try:
import simplegui
except ImportError:
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
from player import Player
from interactions import Interaction
from keyboard import Keyboard
from playerInteraction import PlayerInteraction
from walls import Wall
from interactionSet import *
from projectileCollision import ProjectileCollision
import globals
from scores import *
class Levels:
# static variable:
# this really should be moved to globals but it will be annoying to edit everything
player = Player() # the player
kbd = Keyboard() # keyboard class to check movement for player
room = None # background for level
Walls = [Wall(0), Wall(1), Wall(2), Wall(3)] # all the walls
playerInteraction = PlayerInteraction(player, kbd, Walls) # interaction to keep player within the walls
levels = [] # list of levels. levels get appended here when they load
MeleeEnemies = [] # list of melee enemies
ObjInteractions = [] # just initialising var to store interactions between melee enemies
RangedEnemies = [] # list of ranged enemies
Enemies = []
Rocks = [] # List of rocks
FriendlyProjectiles = [] # list of projectiles
EnemyProjectiles = []
wall_interactions = [] # list of wall interactions to help keep player within the walls
for wall in Walls:
wall_interactions.append(Interaction(player, wall))
Gates = [] # list of gates to move player between levels
GateInteractions = [] # list of interactions for above gates
roomText = 0 # text to represent what room the player is in
projectileCollision = ProjectileCollision(player)
# called from within level# classes
# meleeEnemiesList: the list of enemies from the level
# rangedEnemiesList: the list of enemies from the level
# gateList: list of gates from the level
def LoadLevel(self, meleeEnemiesList, rangedEnemiesList, gateList, rockList, room):
Levels.MeleeEnemies = []
Levels.RangedEnemies = []
Levels.Rocks = []
Levels.FriendlyProjectiles = []
Levels.EnemyProjectiles = []
Levels.room = None
Levels.ObjInteractions = []
Levels.allObj = []
Levels.Enemies = []
Levels.Rocks = rockList
for rock in rockList:
Levels.allObj.append(rock)
Levels.MeleeEnemies = meleeEnemiesList
for enemy in meleeEnemiesList:
Levels.allObj.append(enemy)
Levels.Enemies.append(enemy)
Levels.RangedEnemies = rangedEnemiesList
for enemy in rangedEnemiesList:
Levels.allObj.append(enemy)
Levels.Enemies.append(enemy)
Levels.Gates = []
for gate in gateList:
Levels.Gates.append(gate)
Levels.room = room
Levels.allObj.append(Levels.player)
Levels.ObjInteractions.append(InteractionSet(Levels.allObj))
@staticmethod
def update():
Levels.player.update()
Levels.playerInteraction.update()
if Levels.player.cooldown <= 0 and (
Levels.kbd.arrow_up or Levels.kbd.arrow_right or Levels.kbd.arrow_down or Levels.kbd.arrow_left):
Levels.FriendlyProjectiles.append(Levels.playerInteraction.shoot())
for interaction in Levels.wall_interactions:
interaction.update()
for melee in Levels.MeleeEnemies:
melee.daze_cycle()
if melee.currentlyTargeting:
melee.target(Levels.player.pos)
melee.update()
for interaction in Levels.ObjInteractions:
interaction.update()
for ranged in Levels.RangedEnemies:
ranged.daze_cycle()
if ranged.currentlyTargeting:
ranged.target(Levels.player.pos)
if ranged.cooldown <= 0:
Levels.EnemyProjectiles.append(ranged.shoot(Levels.player.pos))
#Levels.Projectiles.append(ranged.shoot(Levels.player.pos))
ranged.update()
for projectile in Levels.EnemyProjectiles:
projectile.update()
if projectile.frame_life <= 0:
Levels.EnemyProjectiles.remove(projectile)
for projectile in Levels.FriendlyProjectiles:
projectile.update()
if projectile.frame_life <= 0:
Levels.FriendlyProjectiles.remove(projectile)
for gate in Levels.Gates:
gate.update()
Levels.projectileCollision.update(Levels.EnemyProjectiles, Levels.FriendlyProjectiles, Levels.Rocks,
Levels.RangedEnemies, Levels.MeleeEnemies)
for enemy in Levels.MeleeEnemies:
if Levels.player.collides(enemy) and enemy.currentlyAttacking:
Levels.player.health.damaged("Player", Levels.player, Levels.RangedEnemies, Levels.MeleeEnemies)
enemy.attacked()
@staticmethod
def draw(canvas):
Levels.room.draw(canvas)
Levels.player.draw(canvas)
for rock in Levels.Rocks:
rock.draw(canvas)
for melee in Levels.MeleeEnemies:
melee.draw(canvas)
for ranged in Levels.RangedEnemies:
ranged.draw(canvas)
for projectiles in Levels.EnemyProjectiles:
projectiles.draw(canvas)
for projectiles in Levels.FriendlyProjectiles:
projectiles.draw(canvas)
for wall in Levels.Walls:
wall.draw(canvas)
for gate in Levels.Gates:
gate.draw(canvas)
canvas.draw_text("Room: " + str(Levels.roomText), (10, 9), 15, "White")
canvas.draw_text("Score: " + str(Scores.score), (930, 9), 15, "White")
@staticmethod
def restart():
Levels.player = Player() # the player
Levels.kbd = Keyboard() # keyboard class to check movement for player
Levels.room = None # background for level
Levels.Walls = [Wall(0), Wall(1), Wall(2), Wall(3)] # all the walls
Levels.playerInteraction = PlayerInteraction(Levels.player, Levels.kbd, Levels.Walls) # interaction to keep player within the walls
Levels.levels = [] # list of levels. levels get appended here when they load
Levels.MeleeEnemies = [] # list of melee enemies
Levels.ObjInteractions = [] # just initialising var to store interactions between melee enemies
Levels.RangedEnemies = [] # list of ranged enemies
Levels.Rocks = [] # List of rocks
Levels.Projectiles = [] # list of projectiles
Levels.wall_interactions = [] # list of wall interactions to help keep player within the walls
for wall in Levels.Walls:
Levels. wall_interactions.append(Interaction(Levels.player, wall))
Levels.Gates = [] # list of gates to move player between levels
Levels.GateInteractions = [] # list of interactions for above gates
Levels.roomText = 0 # text to represent what room the player is in
Scores.score = 0
Levels.projectileCollision = ProjectileCollision(Levels.player)