-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.py
123 lines (108 loc) · 4.05 KB
/
Player.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
import os
from uuid import uuid4
import math
import pygame
from pygame import sprite
from Misc import roll_damage
class Player(sprite.Sprite):
"""
Player Class
"""
def __init__(self, name, job):
"""
Constructor
"""
pygame.sprite.Sprite.__init__(self)
self.image_name = "dorf.png"
self.image = pygame.image.load(os.path.join("images", self.image_name))
self.rect = self.image.get_rect()
self.portrait_name = "portrait_player.png"
self.portrait = pygame.image.load(os.path.join("images", self.portrait_name))
self.portrait_rect = self.portrait.get_rect()
self.pathlines = None
self.fov = set()
self.selected = False
self.name = name
self.job = job
self.x = 0
self.y = 0
self.z = 0
self.color = (255, 255, 255)
self.alive = True
self.uuid = uuid4()
self.view_range = 5
self.experience = 0
self.max_hp = self.get_level() * job.hit_dice
self.hp = self.max_hp
self.type = "player"
self.backpack = []
def re_init_images(self):
# this has to be done to reload the sprite after loading a 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()
def get_level(self):
level = int(math.floor((1 + math.sqrt(self.experience / 125 + 1)) / 2))
""" return the level based on the xp recieved so far """
return level
def get_attack_bonus(self):
"""return the job attack bonus + the str bonus that's not implemented yet :)"""
# would add effects from items here.
attack_bonus = int(self.job.attack_bonus) + int(self.get_level() * 0.5) + 1
for item in self.backpack:
if item.equipped and "attack" in item.effects:
attack_bonus = attack_bonus + int(item.effects["attack"])
return attack_bonus
def get_defense_bonus(self):
"""return the job defense bonus and the level bonus till I get the stats bonus's worked out"""
defense_bonus = (
10 + int(self.job.defense_bonus) + int(self.get_level() * 0.5) + 1
)
for item in self.backpack:
if item.equipped and "defense" in item.effects:
defense_bonus = defense_bonus + int(item.effects["defense"])
return defense_bonus
def get_view_range(self):
"""return the view range with bonuses"""
view_range_bonus = self.view_range + int(self.job.view_range_bonus)
for item in self.backpack:
if item.equipped and "view_range" in item.effects:
view_range_bonus = view_range_bonus + int(item.effects["view_range"])
return view_range_bonus
def gain_xp(self, num):
"""Gain some Xp"""
self.max_hp = self.get_level() * self.job.hit_dice
self.experience = self.experience + num
def take_damage(self, damage):
"""Ouch"""
if damage <= 0:
pass
# print "Damage absorbed"
else:
self.hp = self.hp - damage
if self.hp <= 0:
# print "Monster is dead"
return False
return True
def heal(self, num):
"""heals the player for num"""
if self.hp + num >= self.max_hp:
self.hp = self.max_hp
else:
self.hp = self.hp + num
def pressed_portrait(self, mx, my):
"""portrait was 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