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_field_actor.py
72 lines (60 loc) · 2.38 KB
/
w_rpg_field_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
from panda3d.core import (
CollisionHandlerQueue,
CollisionRay,
CollideMask,
CollisionHandlerPusher,
CollisionNode,
CollisionSphere,
CollisionBox)
from direct.fsm.FSM import FSM
from direct.actor.Actor import Actor
from panda3d.ai import AICharacter
class FieldActor(FSM):
def __init__(self, name, indexNumber, modelName, stage, actorsList, hero):
self.indexNumber = indexNumber
self.modelName = modelName
self.stage = stage
self.name = name
self.actorsList = actorsList
self.hero = hero
FSM.__init__(
self, "FSM-FieldActor-{}_{}".format(self.name, self.indexNumber))
self.initActor()
def initActor(self):
faEmpty = self.stage.find(
"**/{}_{}".format(self.name, self.indexNumber))
faPos = faEmpty.getPos()
self.actor = Actor("{}".format(self.modelName), {"idle": "{}-idle".format(self.modelName),
"walk": "{}-walk".format(self.modelName)})
self.actor.reparentTo(self.stage)
self.actor.setPos(faPos)
cNode = CollisionNode("{}_{}".format(self.name, self.indexNumber))
cNode.addSolid(CollisionBox(0, 1.5, 1.5, 1))
faCollision = self.actor.attachNewNode(cNode)
#####################################################
# faCollision.show()
#####################################################
base.pusher.addCollider(
faCollision, self.actor, base.drive.node())
base.cTrav.addCollider(faCollision, base.pusher)
self.actorsList.append(self)
AIchar = AICharacter("{}_{}".format(
self.name, self.indexNumber), self.actor, 100, 0.05, 5)
base.AIworld.addAiChar(AIchar)
self.AIbehaviors = AIchar.getAiBehaviors()
# FSM ##################################################################
def enterIdle(self):
self.actor.loop('idle')
def enterWander(self):
self.actor.loop('walk')
self.AIbehaviors.wander(5, 0, 10, 1.0)
def enterPursue(self):
self.actor.loop('walk')
self.AIbehaviors.pursue(self.hero)
def enterHide(self):
self.actor.hide()
def enterShow(self):
self.actor.show()
def enterDeleteActor(self):
self.actor.delete()
# FSM ##################################################################