-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
229 lines (183 loc) · 7.08 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# Import Dependences
import pygame
import os
# Import Objects
from objects.pandora import Pandora
from objects.map import Map
from objects.coin import Coin
from objects.mage import Mage
from objects.screen_choice import ScreenChoice
# Import Utilities
from scripts.constants import BLACK, LENGHT_SCREEN_HD, RED, WHITE
from scripts.colision_mod import Colision_mod
# Inicialize the Package, and a Screen Title
pygame.init()
pygame.display.set_caption('Pandora vs UFPE')
icon = pygame.image.load('media/venus_space.png')
pygame.display.set_icon(icon)
# play game music
music = pygame.mixer.music.load(os.path.join("media/music", "music.ogg"))
pygame.mixer.music.play(-1)
# Set the Screen Size
screen = pygame.display.set_mode(size=LENGHT_SCREEN_HD)
#moves every objects
def move_obj(objs,location_x,location_y):
for i in objs:
i.x += location_x
i.y += location_y
# For nobody to import this module
if __name__ == '__main__':
# Inicialize All Objects
pandora = Pandora()
background = Map()
mage = Mage()
screen_choice = ScreenChoice(name="Menu")
#======================== border controls=============
scroll = 0 #border left wall: 0 for left border and 1200 for right border
right_border = 1200
left_border = 0
speed = 5
moveble_objs = [pandora,background] #objs to be moved
#=====================================================
# Objects to the colider detector
list_objs = [pandora]
colider = Colision_mod(list_objs)
collected_golden_coins = 0
collected_red_coins = 0
coins = []
# Game-Loop
running = True
while running:
#--------------------#
#Calculate Menu Rules#
#--------------------#
if screen_choice.choice == 'Start':
# Running Game
#-------------#
# Game Over #
#-------------#
if mage.coins_dropped == 10:
if collected_red_coins >= 4:
screen_choice.name = "Lose"
# Reset
collected_golden_coins = 0
collected_red_coins = 0
mage = Mage()
coins = []
elif collected_golden_coins >= 7:
screen_choice.name = "Win"
# Reset
collected_golden_coins = 0
collected_red_coins = 0
mage = Mage()
coins = []
#--------------------#
# Drop Coin #
#--------------------#
if mage.drop_coin_gold:
coin = Coin(position_x=mage.x,
position_y=mage.y,
name='coin')
coins.append(coin)
if coin not in list_objs:
list_objs.append(coin)
if coin not in moveble_objs:
moveble_objs.append(coin)
if mage.drop_coin_red:
coin = Coin(position_x=mage.x,
position_y=mage.y,
name='coin_red')
coins.append(coin)
if coin not in list_objs:
list_objs.append(coin)
if coin not in moveble_objs:
moveble_objs.append(coin)
#--------------------#
# frame rate control #
#--------------------#
time = pygame.time.get_ticks()
pygame.time.delay(1)
#-------------------#
# Calculate Rules #
#-------------------#
pandora.calculate_rules()
background.calculate_rules()
mage.calculate_rules()
for coin in coins:
coin.calculate_rules()
#-----------------------#
# Print in the Screen #
#-----------------------#
background.draw(screen)
pandora.draw(screen)
mage.draw(screen)
for coin in coins:
coin.draw(screen)
#--------------------#
# Check all Events #
#--------------------#
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
running = False
pandora.event_processor(events)
#-------------------#
# Border #
#-------------------#
if pandora.x < (1280//2) - 40 and scroll>left_border:
scroll += -speed
move_obj(moveble_objs,speed,0)
elif pandora.x > (1280//2) - 21 and scroll<right_border:
scroll += speed
move_obj(moveble_objs,-speed,0)
#-------------------#
# Colisions #
#-------------------#
coliders_events = colider.check_colision()
clock = pygame.time.get_ticks() -time
wait = 10-clock
if wait>0:
pygame.time.delay(wait)# frame rate control
#-------------------#
# Score and Coins #
#-------------------#
if len(coliders_events) > 0:
for event in coliders_events:
for coin in coins:
if coin.name == 'coin':
if pandora ==event.go1 and coin == event.go2:
collected_golden_coins += 1
coins.remove(coin)
if coin.name == 'coin_red':
if pandora ==event.go1 and coin == event.go2:
collected_red_coins += 1
coins.remove(coin)
#-------------#
# Text update #
#-------------#
font = pygame.font.Font(None, 30)
score_golden_text = font.render('Moedas Douradas: ' + str(collected_golden_coins), 0, BLACK)
score_red_text = font.render('Moedas Vermelhas: ' + str(collected_red_coins), 0, BLACK)
screen.blit(score_golden_text, (50, 50))
screen.blit(score_red_text, (50, 80))
pygame.display.update()
#print(wait)
#if len(coliders_events)>0:
#print("fps: " + str(int(6000/(pygame.time.get_ticks() - x))))
elif screen_choice.choice == 'Exit':
break
else:
#------------------------#
# Print Menu on Screen #
#------------------------#
screen_choice.draw(screen=screen)
pygame.display.update()
#---------------------#
# Check Menu Events #
#---------------------#
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
running = False
else:
screen_choice.event_processor(event=event)