-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
201 lines (163 loc) · 7 KB
/
main.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import pygame
import os
import random
import asset
import functions
from asset import Block
from player import Player
from enemy import Portal, Imp, FatImp
from bullet import Bullet
# SCENE LOGIC ###
class SceneBase:
'''
Centralized Scene framework
ProcessInput - This method will receive all the events that happened since the last frame.
Update - Put your game logic in here for the scene.
Render - Put your render code here. It will receive the main screen Surface as input.
'''
def __init__(self):
self.next = self
self.shoot_loop = 0
self.attack_loop = 0
def ProcessInput(self, events, key, player):
print("uh-oh, you didn't override this in the child class")
def Update(self, player):
#self.player = player
print("uh-oh, you didn't override this in the child class")
def Render(self, screen):
print("uh-oh, you didn't override this in the child class")
def SwitchToScene(self, next_scene):
self.next = next_scene
def Terminate(self):
self.SwitchToScene(None)
class TitleScene(SceneBase):
def __init__(self):
SceneBase.__init__(self)
def ProcessInput(self, events, key, player):
for event in events:
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
# Move to the next scene when the user pressed Enter
self.SwitchToScene(GameScene1())
def Update(self, player):
pass
def Render(self, screen, font, smallfont):
screen.fill((0, 0, 0))
text1 = font.render("IMPS & ASSASIN", 1, (250, 250, 250), )
screen.blit(text1, (320, 250))
class GameScene1(SceneBase):
def __init__(self):
SceneBase.__init__(self)
self.imp_cap = 1
self.fat_cap = 1
self.acid_cap = 0
self.mama_cap = 0
self.full = False
self.transition = False
self.game_over = False
def ProcessInput(self, events, key, player):
if self.transition == True:
for event in events:
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
# Move to the next scene when the user pressed Enter
self.SwitchToScene(GameScene2())
if self.game_over == True:
for event in events:
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
# Move to the first scene when the user pressed Enter
self.SwitchToScene(TitleScene())
player.health = player.health_cap
if self.full == False:
functions.enemy_generator(2, 1, 0, 0, self.imp_cap, self.fat_cap, self.acid_cap, self.mama_cap)
self.full = True
if player.health > 0:
functions.movement_manager(player)
functions.jump_manager(player)
if self.attack_loop == 0:
functions.attack_manager(player)
self.attack_loop += 1
if self.attack_loop == 3:
self.attack_loop = 0
if self.shoot_loop == 0:
functions.shooting_manager(player)
self.shoot_loop += 1
if self.shoot_loop == 5:
self.shoot_loop = 0
def Update(self, player):
functions.collision_manager(asset.PLAYER_GROUP, asset.BULLET_GROUP, asset.ENEMY_GROUP, asset.BLOCK_GROUP)
functions.death_manager(asset.ENEMY_GROUP)
def Render(self, screen, font, smallfont):
# The game scene is just a blank blue screen
functions.redraw_manager(screen, asset.BG[0], font, asset.PLAYER_GROUP, asset.BULLET_GROUP, asset.ENEMY_GROUP)
for player in asset.PLAYER_GROUP:
if player.health <= 0:
functions.game_over_message(screen, font, smallfont)
self.game_over = True
if len(asset.ENEMY_GROUP) == 0:
functions.transition_message(screen, font, smallfont)
self.transition = True
class GameScene2(SceneBase):
def __init__(self):
SceneBase.__init__(self)
self.imp_cap = 2
self.fat_cap = 2
self.acid_cap = 0
self.mama_cap = 0
self.full = False
self.transition = False
self.game_over = False
def ProcessInput(self, events, key, player):
if self.transition == True:
for event in events:
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
# Move to the next scene when the user pressed Enter
self.SwitchToScene(CreditsScene())
if self.game_over == True:
for event in events:
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
# Move to the first scene when the user pressed Enter
self.SwitchToScene(TitleScene())
player.health = player.health_cap
if self.full == False:
functions.enemy_generator(2, 1, 0, 0, self.imp_cap, self.fat_cap, self.acid_cap, self.mama_cap)
self.full = True
if player.health > 0:
functions.movement_manager(player)
functions.jump_manager(player)
if self.attack_loop == 0:
functions.attack_manager(player)
self.attack_loop += 1
if self.attack_loop == 3:
self.attack_loop = 0
if self.shoot_loop == 0:
functions.shooting_manager(player)
self.shoot_loop += 1
if self.shoot_loop == 5:
self.shoot_loop = 0
def Update(self, player):
functions.collision_manager(asset.PLAYER_GROUP, asset.BULLET_GROUP, asset.ENEMY_GROUP, asset.BLOCK_GROUP)
functions.death_manager(asset.ENEMY_GROUP)
def Render(self, screen, font, smallfont):
# The game scene is just a blank blue screen
functions.redraw_manager(screen, asset.BG[1], font, asset.PLAYER_GROUP, asset.BULLET_GROUP, asset.ENEMY_GROUP)
for player in asset.PLAYER_GROUP:
if player.health <= 0:
functions.game_over_message(screen, font, smallfont)
self.game_over = True
if len(asset.ENEMY_GROUP) == 0:
functions.transition_message(screen, font, smallfont)
self.transition = True
class CreditsScene(SceneBase):
def __init__(self):
SceneBase.__init__(self)
def ProcessInput(self, events, key, player):
for event in events:
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
# Move to the next scene when the user pressed Enter
self.SwitchToScene(GameScene1())
def Update(self, player):
player.health = player.health_cap
def Render(self, screen, font, smallfont):
screen.fill((0, 0, 0))
text = font.render("IMPS & ASSASIN", 1, (250, 250, 250), )
screen.blit(text, (320, 250))
functions.run_game(800, 600, 27, TitleScene())