This repository has been archived by the owner on Sep 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathw_rpg_fight_actor.py
91 lines (70 loc) · 3.06 KB
/
w_rpg_fight_actor.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
from direct.fsm.FSM import FSM
from direct.actor.Actor import Actor
import y_helpers
class FightActor(FSM):
def __init__(self, fightObj, position, lookAtPosition):
self.fightObj = fightObj
self.name = fightObj['name']
self.modelName = fightObj['model']
self.pos = position
self.lookAt = lookAtPosition
FSM.__init__(self, "FSM-FightActor-{}".format(self.name))
self.actor = Actor("{}".format(self.modelName), {"idle": "{}-battleIdle".format(self.modelName),
"strike": "{}-strike".format(self.modelName),
"defend": "{}-defend".format(self.modelName),
"blowback": "{}-blowback".format(self.modelName)})
self.actor.setPos(self.pos)
self.lookAtFix()
self.initAnimation()
def initAnimation(self):
if y_helpers.is_character_KOed(self.fightObj):
self.request('KOed')
else:
self.request('Idle')
def lookAtFix(self):
# heading to face opponent with a small hack
# ths is due to how models are best rendered in blender
self.actor.headsUp(self.lookAt)
self.actor.setH(self.actor.getH()-180)
def reparentTo(self, container):
self.actor.reparentTo(container)
# FSM ##################################################################
def enterIdle(self):
taskMgr.remove('check-{}'.format(self.modelName))
self.actor.loop('idle')
def enterAttacking(self):
self.actor.play('strike')
taskMgr.add(self.checkIfEnded, 'check-{}'.format(self.modelName))
def enterItem(self):
self.actor.play('strike')
taskMgr.add(self.checkIfEnded, 'check-{}'.format(self.modelName))
def enterMagic(self):
self.actor.play('strike')
taskMgr.add(self.checkIfEnded, 'check-{}'.format(self.modelName))
def enterPoison(self):
self.actor.play('strike')
taskMgr.add(self.checkIfEnded, 'check-{}'.format(self.modelName))
def enterAttacked(self):
self.actor.play('blowback')
taskMgr.add(self.checkIfEnded, 'check-{}'.format(self.modelName))
def enterDefending(self):
self.actor.loop('defend')
def enterQuit(self):
taskMgr.remove('check-{}'.format(self.modelName))
# FSM ##################################################################
def checkIfEnded(self, task):
animationName = self.actor.getCurrentAnim()
if animationName:
return task.cont
self.initAnimation()
return task.done
class FightActorEnemy(FightActor):
def __init__(self, fightObj, position, lookAtPosition):
FightActor.__init__(self, fightObj, position, lookAtPosition)
def enterKOed(self):
self.actor.hide()
class FightActorHero(FightActor):
def __init__(self, fightObj, position, lookAtPosition):
FightActor.__init__(self, fightObj, position, lookAtPosition)
def enterKOed(self):
self.actor.setH(180)