-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_game.py
250 lines (180 loc) · 5.74 KB
/
main_game.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import game_framework
import Character
import MAP
import GAUGE
import MONSTER
import TRAP
import ITEM
import stop_state
from SKILL import Skill
from ATTACK import Stage2_Attack, Stage3_Attack
from pico2d import *
name = "main_game"
#SPEED
MAX_SPEED_PPS = 1000
#난이도
Level = 0
#점수
score = 0
def collide(a, b):
left_a, bottom_a, right_a, top_a = a.collision()
left_b, bottom_b, right_b, top_b = b.collision()
if left_a > right_b : return False
if right_a < left_b : return False
if top_a < bottom_b : return False
if bottom_a > top_b : return False
return True
#시간================================
current_time = 0.0
frame_time = 0
def get_frame_time():
global current_time, frame_time
frame_time = get_time() - current_time
current_time += frame_time
return frame_time
#====================================
girl = None
stage1_monster = None
stage2_monster = None
stage3_monster = None
stage4_monster = None
stage2_monster_attack = None
stage3_monster_attack = None
stage2_trap = None
stage1_map = None
stage2_map = None
stage3_map = None
stage4_map = None
hp_gauge = None
skill = None
protected = None
def enter():
global girl, stage1_monster, stage2_monster, stage3_monster, stage4_monster, stage2_trap, stage1_map, stage2_map, stage3_map
global hp_gauge, stage2_monster_attack, stage3_monster_attack, skill, current_time, Level, protected, stage4_map, score
#다시시작 할때를 위한 객체 위치 초기화
MONSTER.monster_positionX = 0
MONSTER.monster_positionY = 0
TRAP.trap_positionX = 0
TRAP.trap_positionY = 0
ITEM.protected_positionX = 0
ITEM.protected_positionY = 0
ITEM.protect_State = 0
Level = 0
score = 0
girl = Character.Character()
stage1_monster = [MONSTER.Stage1_Monster() for i in range(20)]
stage2_monster = [MONSTER.Stage2_Monster() for i in range(20)]
stage3_monster = [MONSTER.Stage3_Monster() for i in range(20)]
stage4_monster = [MONSTER.Stage4_Monster() for i in range(40)]
stage2_monster_attack = [Stage2_Attack() for i in range(10)]
stage3_monster_attack = [Stage3_Attack() for i in range(15)]
stage2_trap = [TRAP.Trap() for i in range(13)]
stage4_map = MAP.Map('image\MAP\MAP(STAGE4)_450x1200.png', 'music\stage4BGM.mp3', 225, 25425)
stage3_map = MAP.Map('image\MAP\MAP(STAGE3)_450x750.png', 'music\stage3BGM.mp3', 225, 18000)
stage2_map = MAP.Map('image\MAP\MAP(STAGE2)_450x750.png', 'music\stage2BGM.mp3', 225, 10800)
stage1_map = MAP.Map('image\MAP\MAP(STAGE1)_450x750.png', 'music\stage1BGM.mp3', 225, 3600)
hp_gauge = GAUGE.Gauge()
skill = Skill()
protected = [ITEM.Protected() for i in range(5)]
current_time = get_time()
def exit():
pass
def pause():
pass
def resume():
pass
def handle_events():
global Level, frame_time, score, hp_gauge, skill
events = get_events()
for event in events:
if event.type == SDL_QUIT:
game_framework.quit()
elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
game_framework.push_state(stop_state)
elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_LEFT):
if girl.way == 2:
pass
else:
girl.way = 1
Level += 1
score += 60
if Level > 144:
hp_gauge.frame -= 6
elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_RIGHT):
if girl.way == 1:
pass
else:
girl.way = 2
Level += 1
score += 60
if Level > 144:
hp_gauge.frame -= 6
elif (event.type, event.key) == (SDL_KEYDOWN, SDLK_x):
skill.handle_skill()
def update():
global stage1_monster, stage2_monster, stage3_monster, stage4_monster, stage2_trap, stage1_map
global stage2_monster_attack, stage3_monster_attack, frame_time, protected
frame_time = get_frame_time()
# Update =============================
girl.update(frame_time)
stage1_map.update()
for Mon in stage1_monster:
Mon.update()
for Mon in stage2_monster:
Mon.update()
for Mon in stage3_monster:
Mon.update()
for Mon in stage4_monster:
Mon.update()
for ATK in stage2_monster_attack:
ATK.update(frame_time)
for ATK in stage3_monster_attack:
ATK.update(frame_time)
for Trp in stage2_trap:
Trp.update()
hp_gauge.update()
skill.update(frame_time)
for PROTECT in protected:
PROTECT.update()
# ====================================
def draw_main_scene():
global stage1_monster, stage2_monster, stage3_monster, stage4_monster, stage2_trap, stage2_monster_attack
global stage3_monster_attack, protected
# Draw ===============================
stage1_map.draw()
stage2_map.draw()
stage3_map.draw()
stage4_map.draw()
girl.draw()
for ATK in stage2_monster_attack:
ATK.draw()
for ATK in stage3_monster_attack:
ATK.draw()
for Mon in stage1_monster:
Mon.draw()
for Mon in stage2_monster:
Mon.draw()
for Mon in stage3_monster:
Mon.draw()
for Mon in stage4_monster:
Mon.draw()
for Trp in stage2_trap:
Trp.draw()
hp_gauge.draw()
skill.draw()
for PROTECT in protected:
PROTECT.draw()
#girl.collision_box()
#for Mon in Monster:
# Mon.collision_box()
#for Mon in Monster2:
# Mon.collision_box()
#for Mon in stage3_monster:
# Mon.collision_box()
#for ATK in stage3_monster_attack:
# ATK.collision_box()
# ====================================
def draw():
clear_canvas()
draw_main_scene()
update_canvas()