-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mob.py
97 lines (87 loc) · 3 KB
/
Mob.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
""" Basic Mob class """
import os
from uuid import uuid4
import pygame
from pygame import sprite
class Mob(sprite.Sprite):
"""
Mob Class
"""
def __init__(self, name, job, image, portrait, dead_image):
"""
Constructor
"""
pygame.sprite.Sprite.__init__(self)
self.image_name = image
self.image = pygame.image.load(os.path.join("images", self.image_name))
self.rect = self.image.get_rect()
self.portrait_name = portrait
self.portrait = pygame.image.load(os.path.join("images", self.portrait_name))
self.portrait_rect = self.portrait.get_rect()
self.dead_image_name = dead_image
self.dead_image = pygame.image.load(
os.path.join("images", self.dead_image_name)
)
self.pathlines = None
self.selected = False
self.fov = set()
self.name = name
self.job = job
self.x = None
self.y = None
self.z = None
self.alive = True
self.uuid = uuid4()
self.view_range = 5
self.experience = 250
self.type = "monster"
self.level = 1
self.max_hp = self.job.hit_dice * self.level
self.hp = self.max_hp
def re_init_images(self):
# required after loading the game
self.image = pygame.image.load(os.path.join("images", self.image_name))
self.rect = self.image.get_rect()
self.portrait = pygame.image.load(os.path.join("images", self.portrait_name))
self.portrait_rect = self.portrait.get_rect()
self.dead_image = pygame.image.load(
os.path.join("images", self.dead_image_name)
)
def get_level(self):
"""Levels for monsters are hard coded as they don't have xp to base it off"""
return self.level
def get_attack_bonus(self):
"""get the attack bonus"""
return int(self.job.attack_bonus) + int(self.level * 0.5) + 1
def get_defense_bonus(self):
"""get the defense bonus"""
return 10 + int(self.job.defense_bonus) + int(self.level * 0.5) + 1
def get_view_range(self):
"""get the view range"""
return self.view_range + int(self.job.view_range_bonus)
def take_damage(self, damage):
"""ouch"""
if damage <= 0:
# print "Damage absorbed"
pass
else:
self.hp = self.hp - damage
if self.hp <= 0:
# print "Monster is dead"
return False
return True
def pressed_portrait(self, mx, my):
"""Was my picture clicked"""
if mx > self.portrait_rect.topleft[0]:
if my > self.portrait_rect.topleft[1]:
if mx < self.portrait_rect.bottomright[0]:
if my < self.portrait_rect.bottomright[1]:
return True
else:
return False
else:
return False
else:
return False
else:
return False