-
Notifications
You must be signed in to change notification settings - Fork 0
/
boss_stage.py
109 lines (91 loc) · 3.04 KB
/
boss_stage.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
import game_framework
from pico2d import *
import game_world
import start_state
import dead_state
from chasha import Chasha
from map import Map
boss = []
hit_sound = None
def collide(a, b):
# fill here
left_a, bottom_a, right_a, top_a = a.get_bb()
left_b, bottom_b, right_b, top_b = b.get_bb()
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
def enter():
global boss, hit_sound
boss.append(Chasha(3))
game_world.add_object(Map('map1.txt'), 0)
hit_sound = load_wav('sound_resources\\hit sound.ogg')
hit_sound.set_volume(40)
pass
def exit():
global boss, hit_sound
while len(boss) > 0:
boss.pop()
while len(game_framework.player.arrow_list):
game_framework.player.arrow_list.pop()
game_world.clear()
del hit_sound
pass
def handle_events():
events = get_events()
for event in events:
if event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
game_framework.pop_state()
elif event.type == SDL_MOUSEBUTTONDOWN and event.button == SDL_BUTTON_LEFT:
game_framework.player.attack(event)
elif event.type == SDL_KEYDOWN and event.key == SDLK_F1:
game_framework.change_state(dead_state)
else:
game_framework.player.handle_event(event)
pass
def update():
global boss, hit_sound
for game_object in game_world.all_objects():
game_object.update()
for bosses in boss:
bosses.update()
if not game_framework.player.Isinvincible:
if collide(bosses, game_framework.player):
game_framework.player.life -= bosses.atk
game_framework.player.invincible_time = get_time()
game_framework.player.Isinvincible = True
for arrow in game_framework.player.arrow_list:
if collide(arrow, bosses):
bosses.life -= game_framework.player.atk
game_framework.player.arrow_list.remove(arrow)
hit_sound.play()
if bosses.life <= 0:
if bosses.level > 1:
boss.append(Chasha(bosses.level - 1, bosses.x, bosses.y))
boss.append(Chasha(bosses.level - 1, bosses.x, bosses.y))
game_framework.player.money += bosses.money
boss.remove(bosses)
else:
game_framework.player.money += bosses.money
boss.remove(bosses)
if len(boss) <= 0:
game_framework.change_state(start_state)
if game_framework.player.life <= 0:
game_framework.change_state(dead_state)
game_framework.player.update()
delay(0.05)
pass
def draw():
global boss
clear_canvas()
for game_object in game_world.all_objects():
game_object.draw()
game_framework.player.draw()
for bosses in boss:
bosses.draw()
update_canvas()
def pause():
pass
def resume():
pass