Skip to content

Commit

Permalink
机器人增加默认的移动测试案例
Browse files Browse the repository at this point in the history
  • Loading branch information
kbengine committed Mar 14, 2016
1 parent 197dcaf commit 23b576d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
34 changes: 27 additions & 7 deletions scripts/bots/Avatar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
import KBEngine
import KBExtra
import random, math
import Math
from KBEDebug import *
from interfaces.GameObject import GameObject
from interfaces.Dialog import Dialog
Expand Down Expand Up @@ -65,23 +67,41 @@ def onJump(self):

class PlayerAvatar(Avatar):
def __init__(self):
Avatar.__init__()

self.randomWalkRadius = 10.0
def onEnterSpace(self):
"""
KBEngine method.
这个entity进入了一个新的space
"""
DEBUG_MSG("%s::onEnterSpace: %i" % (self.__class__.__name__, self.id))
KBEngine.callback(1, self.moveUpdate)

# 注意:由于PlayerAvatar是引擎底层强制由Avatar转换过来,__init__并不会再调用
# 这里手动进行初始化一下
self.__init__()

self.spawnPosition = Math.Vector3( self.position )
KBEngine.callback(1, self.updateMove)

def onLeaveSpace(self):
"""
KBEngine method.
这个entity将要离开当前space
"""
DEBUG_MSG("%s::onLeaveSpace: %i" % (self.__class__.__name__, self.id))

def moveUpdate(self):
DEBUG_MSG("%s::moveUpdate: %i" % (self.__class__.__name__, self.id))
KBEngine.callback(1, self.moveUpdate)

def calcRandomWalkPosition( self ):
"""
计算随机移动位置
"""
center = self.spawnPosition
r = random.uniform( 1, self.randomWalkRadius ) # 最少走1米
b = 360.0 * random.random()
x = r * math.cos( b ) # 半径 * 正余玄
z = r * math.sin( b )
return Math.Vector3( center.x + x, center.y, center.z + z )

def updateMove(self):
#DEBUG_MSG("%s::updateMove: %i" % (self.__class__.__name__, self.id))
KBEngine.callback(1, self.updateMove)
self.moveToPoint( self.calcRandomWalkPosition(), self.velocity, 0.0, 0, True, True )
12 changes: 7 additions & 5 deletions scripts/bots/interfaces/Motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def onMove(self, controllerId, userarg):
KBEngine method.
使用引擎的任何移动相关接口, 在entity一次移动完成时均会调用此接口
"""
DEBUG_MSG("%s::onMove: %i controllerId =%i, userarg=%s" % \
(self.getScriptName(), self.id, controllerId, userarg))
#DEBUG_MSG("%s::onMove: %i controllerId =%i, userarg=%s" % \
# (self.getScriptName(), self.id, controllerId, userarg))
pass

def onMoveFailure(self, controllerId, userarg):
"""
Expand All @@ -28,9 +29,10 @@ def onMoveOver(self, controllerId, userarg):
KBEngine method.
使用引擎的任何移动相关接口, 在entity移动结束时均会调用此接口
"""
DEBUG_MSG("%s::onMoveOver: %i controllerId =%i, userarg=%s" % \
(self.getScriptName(), self.id, controllerId, userarg))

#DEBUG_MSG("%s::onMoveOver: %i controllerId =%i, userarg=%s" % \
# (self.getScriptName(), self.id, controllerId, userarg))
pass

def set_moveSpeed(self, oldValue):
"""
Property method.
Expand Down

0 comments on commit 23b576d

Please sign in to comment.