squirrel-battle/dungeonbattle/entities/player.py

33 lines
799 B
Python
Raw Normal View History

from ..interfaces import FightingEntity
2020-11-06 14:33:26 +00:00
class Player(FightingEntity):
2020-11-10 20:47:36 +00:00
name = "player"
2020-11-06 20:23:17 +00:00
maxhealth: int = 20
strength: int = 5
2020-11-08 22:48:26 +00:00
intelligence: int = 1
charisma: int = 1
dexterity: int = 1
constitution: int = 1
2020-11-06 20:23:17 +00:00
level: int = 1
current_xp: int = 0
max_xp: int = 10
2020-11-06 17:12:17 +00:00
2020-11-10 21:02:41 +00:00
def move(self, y: int, x: int) -> None:
"""
When the player moves, move the camera of the map.
"""
super().move(y, x)
self.map.currenty = y
self.map.currentx = x
2020-11-06 20:15:09 +00:00
def level_up(self) -> None:
2020-11-06 20:23:17 +00:00
while self.current_xp > self.max_xp:
2020-11-06 20:15:09 +00:00
self.level += 1
2020-11-06 20:23:17 +00:00
self.current_xp -= self.max_xp
2020-11-06 20:15:09 +00:00
self.max_xp = self.level * 10
def add_xp(self, xp: int) -> None:
self.current_xp += xp
2020-11-06 17:12:17 +00:00
self.level_up()