-
Notifications
You must be signed in to change notification settings - Fork 1
/
npc.py
87 lines (53 loc) · 1.8 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
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
# -*- coding: utf-8 -*-
# Authors: ep0s TurBoss
# Models: ep0s TurBoss
# Just sandboxing
from direct.task import Task
from panda3d.core import Vec3,Vec4,BitMask32, VBase4
from panda3d.core import Point3, TransparencyAttrib,TextNode
from panda3d.core import CollisionTraverser, CollisionNode
from panda3d.core import CollisionHandlerQueue, CollisionRay
from panda3d.core import CollideMask
from direct.actor.Actor import Actor
from direct.interval.IntervalGlobal import Sequence
from panda3d.ai import *
class Npc():
def __init__(self, game, hp, mana, speed, attackSpeed, name):
self.game = game
self.hp = hp
self.mana = mana
self.speed = speed
self.attackSpeed = attackSpeed
self.name = name
self.model = "models/%s" % self.name
self.modelWalk = "models/%s-walk" % self.name
self.npcActor = Actor({ "body":self.model,},
{"body":{"walk":self.modelWalk},
})
self.npcActor.setHpr(0,0,0)
self.npcActor.setPos(0,0,5)
self.npcActor.setScale(0.5)
self.npcActor.reparentTo(render)
self.setupAI()
def getName(self):
return self.name
def setupAI(self):
#Creating AI World
self.AIworld = AIWorld(render)
self.AIchar = AICharacter("npc", self.npcActor, 100, 0.05, 5)
self.game.AIworld.addAiChar(self.AIchar)
self.AIbehaviors = self.AIchar.getAiBehaviors()
self.AIbehaviors.wander(10, 0, 15, 1.0)
#Path follow (note the order is reveresed)
"""
self.AIbehaviors.pathFollow(1)
self.AIbehaviors.addToPath((0,-20,0))
self.AIbehaviors.addToPath((0,20,0))
self.AIbehaviors.addToPath((20,-10,0))
self.AIbehaviors.addToPath((15,-20,0))
self.AIbehaviors.startFollow()
"""
self.npcActor.loop("walk")
def update(self, Task):
self.AIworld.update()
return Task.cont