def getMovement(self): dx, dy, dz, rotationAngle = (0, 0, 0, 0) #move to ball/square border intersection currentPosition = self.body.getPosition() target = self.target.getPosition() if (target[0]-currentPosition[0]) * (target[0]-currentPosition[0]) + \ (target[2]-currentPosition[2]) * (target[2]-currentPosition[2]) < 2.0 and \ currentPosition[1]<1.1: dy = 2.0 if vectormath.isPointInSquare(target, self.min, self.max): targetPosition = target else: targetPosition = vectormath.getBallAndSquareIntersection( target, self.target.getLinearVel(), self.min, self.max) targetPosition = (targetPosition[0] + random() - 0.5, targetPosition[1], targetPosition[2] + random() - 0.5) vectorAB = vectormath.getVector(currentPosition, targetPosition) #to make oponents run to ball coords - self length vABAngle = atan2(vectorAB[2], vectorAB[0]) vABMagnitude = vectormath.getMagnitudeV(vectorAB) newVABMagnitude = vABMagnitude - 2.0 #malas garums/2 newVABX = [ cos(vABAngle) * newVABMagnitude, vectorAB[1], sin(vABAngle) * newVABMagnitude ] vectorAB = newVABX if vABMagnitude < 1.8: moveSpeed = 700 * self.body.getMass().mass else: moveSpeed = 4000 * self.body.getMass().mass currentRotationTuple = self.body.getRotation() currentRotation = currentRotationTuple[2], currentRotationTuple[ 5], currentRotationTuple[8] vectorAB = vectormath.normalize(vectorAB[0], 0, vectorAB[2]) rotationAngle = vectormath.getAngleBetweenVectors( currentRotation, vectorAB) currentRotation = vectormath.negate(currentRotation) dx = currentRotation[0] dz = currentRotation[2] #/------------------ return dx * moveSpeed, dy * moveSpeed, dz * moveSpeed, rotationAngle * moveSpeed
def getMovement(self): dx, dy, dz, rotationAngle = (0,0,0,0) #move to ball/square border intersection currentPosition = self.body.getPosition() target = self.target.getPosition() if (target[0]-currentPosition[0]) * (target[0]-currentPosition[0]) + \ (target[2]-currentPosition[2]) * (target[2]-currentPosition[2]) < 2.0 and \ currentPosition[1]<1.1: dy = 2.0 if vectormath.isPointInSquare(target, self.min, self.max): targetPosition = target else: targetPosition = vectormath.getBallAndSquareIntersection(target, self.target.getLinearVel(), self.min, self.max) targetPosition = (targetPosition[0] + random() - 0.5, targetPosition[1], targetPosition[2] + random() - 0.5) vectorAB = vectormath.getVector(currentPosition, targetPosition) #to make oponents run to ball coords - self length vABAngle = atan2(vectorAB[2], vectorAB[0]) vABMagnitude = vectormath.getMagnitudeV(vectorAB) newVABMagnitude = vABMagnitude - 2.0 #malas garums/2 newVABX = [cos(vABAngle) * newVABMagnitude, vectorAB[1], sin(vABAngle) * newVABMagnitude] vectorAB = newVABX if vABMagnitude<1.8: moveSpeed = 700 * self.body.getMass().mass else: moveSpeed = 4000 * self.body.getMass().mass currentRotationTuple = self.body.getRotation() currentRotation = currentRotationTuple[2], currentRotationTuple[5], currentRotationTuple[8] vectorAB = vectormath.normalize(vectorAB[0], 0, vectorAB[2]) rotationAngle = vectormath.getAngleBetweenVectors(currentRotation, vectorAB) currentRotation = vectormath.negate(currentRotation) dx = currentRotation[0] dz = currentRotation[2] #/------------------ return dx * moveSpeed, dy * moveSpeed, dz * moveSpeed, rotationAngle * moveSpeed
def resetIfAsked(self): aimedForce = (0.0, 0.0, 0.0) if abs(self.geom.resetCoords[0])\ + abs(self.geom.resetCoords[2]) > 1.0: # if we don`t drop the ball in center #we drop it in the players field with force aimVector = getVector(self.geom.resetCoords, (0.0, 0.0, 0.0)) aimedForce = multiply(aimVector, 1000) if self.geom.reset == True: self.body.setPosition(self.geom.resetCoords) self.body.setAngularVel((0.0, 0.0, 0.0)) self.body.setLinearVel((0.0, 0.0, 0.0)) self.body.setForce(aimedForce) self.geom.reset = False
def draw(self): #set listener position at camera sounds.setListenerPosition((self.x, self.y, self.z)) #target coord tx, ty, tz = self.target.body.getPosition() if self.oldTargetPos==None: self.oldTargetPos = tx, ty, tz gluLookAt(self.x, self.y, self.z, (tx+self.oldTargetPos[0])/2, (self.y+self.oldTargetPos[1])/2/3, (tz+self.oldTargetPos[2])/2, 0, 1, 0) self.oldTargetPos = tx, ty, tz v = vectormath.getVector((self.x, 0.0, self.z), (tx, 0.0, tz)) self.angleY = -(atan2(v[2], v[0]) + pi/2)*180.0/pi
def draw(self): #set listener position at camera sounds.setListenerPosition((self.x, self.y, self.z)) #target coord tx, ty, tz = self.target.body.getPosition() if self.oldTargetPos == None: self.oldTargetPos = tx, ty, tz gluLookAt(self.x, self.y, self.z, (tx + self.oldTargetPos[0]) / 2, (self.y + self.oldTargetPos[1]) / 2 / 3, (tz + self.oldTargetPos[2]) / 2, 0, 1, 0) self.oldTargetPos = tx, ty, tz v = vectormath.getVector((self.x, 0.0, self.z), (tx, 0.0, tz)) self.angleY = -(atan2(v[2], v[0]) + pi / 2) * 180.0 / pi