-
Notifications
You must be signed in to change notification settings - Fork 0
/
character.py
67 lines (59 loc) · 2.04 KB
/
character.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
import yaml
import pygame
from constants import *
from location import Location
class Character:
def __init__(self):
self.loc = None
self.dest = None
self.path = None
self.completion = None
self.action = None
@staticmethod
def load_from_file(path, name):
f = open('%s/%s.yaml' % (path, name))
data = yaml.load(f)
f.close()
return Character.load_from_data(data)
@staticmethod
def load_from_data(data):
char = Character()
if data.has_key('unit'):
#FIXME: load unit from file and be done with it
pass
else:
char.char_class = data['class']
char.race = data['race']
# FIXME: probably pass area info too and have a general level for
# creatures roaming the area instead of defaulting to one
if data.has_key('level'):
char.level = data['level']
else:
char.level = 1
char.image = pygame.image.load('images/units/%s.png' % data['class'])
return char
def location(self):
return self.loc
def set_location(self, loc):
self.loc = loc
def move(self, path):
self.path = path[1:]
self.completion = 0
self.action = 'move'
def update(self, area, proportion):
factor = proportion * step
if self.action == 'move':
# FIXME: check if the path is still free and that kind of things
if self.path and not self.dest:
self.dest = self.path.pop(0)
if len(self.path) == 0:
self.path = None
self.completion = self.completion + factor * 5
# FIXME: it would be cool to move the completion over 100 go to the
# next movement
if self.completion > 100:
area.move_character(self, self.dest, self.path)
self.dest = None
self.completion = 0
if not self.path:
self.action = None