/
Npc.py
50 lines (44 loc) · 1.13 KB
/
Npc.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
from live import Live
import iniFile as ini
import sfml as sf
from object import Position
from walker import Walker
FRIEND = 1
ENEMY = -1
NEUTRAL = 0
ALARM_TIME = 10 # alarm time in seconds
iniReader=ini.IniFile("configs\\relations_test.ini")
def GetRelation(group1,group2):
value=iniReader.ReadInt(group1,group2)
if(value>999):
return FRIEND
elif(value<999):
return ENEMY
else:
return NEUTRAL
def SetRelation(group1,group2,value):
if value<=-5000:
value=-5000
elif value>=5000:
value=5000
iniReader.Write(group1,group2,value)
class Npc(Live, Walker):
def __init__(self, objectLogicPath, object):
Live.__init__(self,objectLogicPath, object)
Walker.__init__(self, objectLogicPath, object)
logicFileName = object.GetLogicFileName()
configFile=ini.IniFile(objectLogicPath)
configFile.ReadString("npc", "group")
self.SetHealth(configFile.ReadInt("npc", "health"))
self._clock = sf.Clock()
self._alarm = False
def IsAlarm(self):
if self._alarm:
if self._clock.elapsed_time.seconds < ALARM_TIME:
return True
else:
self._alarm = False
return False
_group = None
_clock = None
_alarm = None