forked from tomalexander/h_and_b
/
evil_koi.py
146 lines (121 loc) · 4.54 KB
/
evil_koi.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
import pygame
import math
from bullet import bullet
from bullet import fireball
class evil_koi(object):
"""the final boss"""
def __init__(self, windowx):
self.images = [pygame.image.load("img/evilkoiproxy.png"), pygame.image.load("img/evildragonproxy.png")]
self.rect = self.images[0].get_rect()
self.energy = 0
#move evil koi to the middle of the screen
self.rect.x = 250
self.xvel = 35
self.yvel = 35
self.angle = 5*math.pi/4
#CONTROL LOCKS
self.shoot_cooldown = 4.0
self.bad_projectiles = []
#dragon mode activated
self.dragon = False
#animation utilities
self.frame = 0
self.windowx = windowx
#boss battle flags
self.health = 100
self.retreated = False
self.chargecooldown = 1.0
self.strafedir = False
def update(self, FrameRate):
FrameRate = FrameRate/100
#first boss stage
if self.health > 60:
self.automove(FrameRate)
self.shoot(FrameRate)
#second boss stage
elif self.health > 30:
self.dragon = True
self.xvel = 70
self.yvel = 70
self.strafe(FrameRate)
self.shoot(FrameRate)
#third boss stage
else:
if not self.retreated:
self.retreat(FrameRate)
else:
if self.chargecooldown > 0:
self.chargecooldown -= FrameRate
self.strafe(FrameRate)
self.shoot(FrameRate)
else:
self.charge(FrameRate)
#update bullets
for i, projectile in enumerate(self.bad_projectiles):
if not projectile.update(FrameRate):
self.projectiles.pop(i)
return self.bad_projectiles
def strafe(self, FrameRate):
if self.strafedir:
self.rect.move_ip(self.xvel*FrameRate, 0)
else:
self.rect.move_ip(-self.xvel*FrameRate, 0)
if self.rect.left < 100:
self.rect.left = 100
self.strafedir = True
elif self.rect.right > 500:
self.rect.right = 500
self.strafedir = False
def charge(self, FrameRate):
self.rect.move_ip(0, self.yvel*2*FrameRate)
if self.rect.bottom >= 800:
self.chargecooldown = 5.0
self.rect.bottom = 800
self.retreated = False
def retreat(self, FrameRate):
#self.angle = math.atan2(self.rect.centery - 0, self.rect.centerx - 300)
#self.rect.move_ip(self.xvel*FrameRate*math.cos(self.angle), -self.yvel*FrameRate*math.sin(self.angle))
self.rect.move_ip(0, -self.yvel*FrameRate)
if self.rect.top <= 0:
self.rect.top = 0
self.retreated = True
def automove(self, FrameRate):
self.rect.move_ip(self.xvel*FrameRate*math.cos(self.angle), -self.yvel*FrameRate*math.sin(self.angle))
#strafe
if self.rect.left < 100:
self.rect.left = 100
self.xvel = -self.xvel
elif self.rect.right > self.windowx - 180:
self.rect.right = self.windowx - 180
self.xvel = -self.xvel
if self.rect.top < 0:
self.rect.top = 0
self.yvel = -self.yvel
elif self.rect.bottom > 400:
self.rect.bottom = 400
self.yvel = -self.yvel
def take_damage(self):
self.health -= 1
def dragon_mode(self, FrameRate):
pass
def shoot(self, FrameRate):
self.shoot_cooldown -= FrameRate
if self.shoot_cooldown < 0.0:
self.shoot_cooldown = 0.0
if self.shoot_cooldown == 0.0:
if not self.dragon:
new_bullet = bullet(self.rect.left+16, self.rect.bottom, -math.pi/2)
self.bad_projectiles.append(new_bullet)
self.shoot_cooldown = 6.0
else:
new_fireball = fireball(self.rect.left+16, self.rect.bottom, -math.pi/2)
self.bad_projectiles.append(new_fireball)
self.shoot_cooldown = 4.0
def draw(self, screen):
"""draws evil koi"""
if not self.dragon:
screen.blit(self.images[0], self.rect)
else:
screen.blit(self.images[1], self.rect)
for projectile in self.bad_projectiles:
projectile.draw(screen)