/
zombie.py
66 lines (56 loc) · 2.66 KB
/
zombie.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
import random, math, const
import pygame as pg
from treasure import Treasure
class Zombie(pg.sprite.Sprite):
def __init__(self, px, py, game):
super().__init__()
self.game = game
self.hp = random.randint(40,50)
self.hp_copy = self.hp
self.damage = random.randint(5, 10)
spawn_x = [0, 1000]
spawn_y = [0, 500, 1000]
self.x = random.sample(spawn_x, 2)[0]
self.y = random.sample(spawn_y, 3)[0]
self.rise = py - self.y
self.run = px - self.x
self.angle = math.atan2(self.rise, self.run)
self.rect = pg.Rect(self.x+12, self.y, 50, 70)
self.speed = random.randint(2, 4)
self.dmg_cooldown = 0
self.image = self.game.zom_enemy
self.aid = False
self.level = self.damage*self.speed*self.hp // 100
self.drop_treasure = random.randint(0,1)
print(self.drop_treasure)
def draw(self, px, py):
if self.hp <= 0:
if self.drop_treasure:
t = Treasure(self.x+10, self.y+10)
self.game.treasures.add(t)
self.game.player.zombies.remove(self)
self.game.zombies.remove(self)
self.kill()
self.rise = py - self.y
self.run = px - self.x
self.angle = math.atan2(self.rise, self.run)
self.rot_ang = int(360-self.angle*180/math.pi) - 180
rotated_knife = self.game.knife
if self.rot_ang > 270 or self.rot_ang < 90:
rotated_knife = pg.transform.flip(self.game.knife, False, True)
rotated_knife = pg.transform.rotate(rotated_knife, self.rot_ang)
self.rect = pg.Surface.get_rect(self.game.zom_enemy, topleft=(self.x, self.y))
self.rect = self.rect.inflate(-25, -20)
self.game.screen.blit(self.image, (self.x, self.y))
self.game.screen.blit(rotated_knife, (self.x-20, self.y-15))
g = 2.55*(self.hp * 100/self.hp_copy)
r = 2.55*(self.hp_copy-self.hp)
if 0 < r < 255 and 0 < g < 255:
pg.draw.rect(self.game.screen, const.black, pg.Rect(self.x-2 + self.hp_copy//3, self.y-16, self.hp_copy+3, 10), 2)
pg.draw.rect(self.game.screen, (r, g, 0), pg.Rect(self.x + self.hp_copy//3, self.y-13, self.hp, 6))
else:
pg.draw.rect(self.game.screen, const.black, pg.Rect(self.x - 2 + self.hp_copy//3, self.y-16, self.hp_copy+3, 10), 2)
pg.draw.rect(self.game.screen, const.green, pg.Rect(self.x + self.hp_copy//3, self.y-13, self.hp, 6))
text = pg.font.SysFont('SysFont', 30)
self.lvl_text = text.render(f"Lvl. {self.level}", False, const.red)
self.game.screen.blit(self.lvl_text, (self.x+10, self.y-35))