示例#1
0
	bool makeObs (float x, float y) {
		vec pos = {x, y, floatZero}, deg30 = {0.5f, floatZero, floatZero};
		if (hitTarget(myState, pos)) {
			setVelocity(zeroVec);
			setTargetAngVel(deg30);
			if (!startedYet) {
#if printDebug
				DEBUG(("Started obstacle\n"));
#endif
				game.startObstacle();
			}
			else {
				float curSize = game.getCurrentObstacleSize();
				if (dust < floatItsml || curSize > 0.299f || curSize - prevSize < floatItsml) {
#if printDebug
					DEBUG(("Ended obstacle\n"));
#endif
					game.stopObstacle();
					return true;
				}
				prevSize = curSize;
			}
			startedYet = true;
		}
		else {
			api.setPositionTarget(pos);
			//slowGo(pos);
			startedYet = false;
			setTargetAngVel(zeroVec);
			prevSize = floatZero;
		}
		return false;
	}
void doLineFollow()  {
	//int LightSensors[6]; 0 is far left, 4 is far right, 5 is middle
	while(!hitTarget())
	{
		if(OnLine(LightSensors[2])
		{
			if(!goingForward)
			{
				if(correcting)
				{
					StopTask(correctLine);
					correcting = false;
				}
				StartTask(MoveForward);
				goingForward = true;
			}
		}
		else
		{
			if(!correcting)
			{
				if(goingForward)
				{
					StopTask(MoveForward);
					goingForward = false;
				}
				StartTask(correctLine);
				correcting = true;
			}
		}
	}
示例#3
0
void Tower::update(){
    if (! *paused ){
        //increase the timer
        if (!shooting)  timer++;
        if (timer>rechargeTime){
            readyToShoot=true;
        }
        
        //if we are shooting, see if we hit the target
        if (shooting){
            if (bullet.pos.distance(target->p.pos)<15)
                hitTarget();
            
            //move the bullet
            //reset the particle
            bullet.resetForce();
            
            //atract the bullet to the target
            bullet.addAttractionForce(target->p.pos.x, target->p.pos.y, bullet.pos.distance(target->p.pos)*4, bulletAtraction);
            
            //dampen and update the particle
            bullet.addDampingForce();
            bullet.update();

            
        }
    }
}
示例#4
0
void oBullet::onBodyEnter( oSensor* sensor, oBody* body )
{
	if (body == _owner)
	{
		return;
	}
	bool isHitTerrain = oSharedData.isTerrain(body) && oBullet::targetAllow.isTerrainAllowed();
	bool isHitUnit = oSharedData.isPlayerUnit(body) && oBullet::targetAllow.isAllow(oSharedData.getRelation(_owner, (oUnit*)body));
	bool isRangeDamage = _bulletDef->damageRadius > 0.0f;
	bool isHit = isHitTerrain || isHitUnit;
	if (isHit && hitTarget)
	{
		if (isRangeDamage)
		{
			CCPoint pos = this->getPosition();
			CCRect rect(
				pos.x - _bulletDef->damageRadius,
				pos.y - _bulletDef->damageRadius,
				_bulletDef->damageRadius * 2,
				_bulletDef->damageRadius * 2);
			_world->query(rect, [&](oBody* body)
			{
				if (oSharedData.isPlayerUnit(body) && targetAllow.isAllow(oSharedData.getRelation(_owner, (oUnit*)body)))
				{
					hitTarget(this, (oUnit*)body);
				}
				return false;
			});
		}
		else if (isHitUnit)
		{
			/* hitTarget function may cancel this hit by returning false */
			isHit = hitTarget(this, (oUnit*)body);
		}
	}
	if (isHit)
	{
		oBullet::destroy();
	}
}
/**
 * \fn	void Projectile::onUpdate()
 *
 * \brief	Fly in direction of creep if it still exists.
 */
void Projectile::onUpdate()
{
	if(!_target->isAlive() || _target->isLeaked())
	{
		Graveyard::instance()->killChild(this);
		return;
	}

	approachToTarget();

    //FIXME is this a good condition?
	// maybe use bounding boxes for collision detection?
	if((this->getPosition()-_target->getHitPosition()).length2() < 0.1) 
	{
		hitTarget();
	}
}
示例#6
0
	void getItem (int itemNo) {
#if printDebug
		DEBUG(("getItem(%d) Info\n", itemNo));
#endif
		vec iloc;
		game.getItemLocation(itemNo, iloc);
#if printDebug
		printVec("\tItemPos (m)", iloc);
#endif
		api.setPositionTarget(iloc);
		if (hitTarget(myState, iloc)) {
			vec temp = {0.75f, floatZero, floatZero};
			setTargetAngVel(temp);
		}
		else {
			setTargetAngVel(zeroVec);
		}
	}
示例#7
0
	void getItem (int itemNo) {
#if printDebug
		DEBUG(("getItem(%d) Info\n", itemNo));
#endif
		if (game.getCurrentPhase() == 1) {
			smartGo(red ? -0.45 : 0.45, statePos(myState)[1] < -0.05f ? 0.073f : 0.0505f);
#if printDebug
			DEBUG(("\tMoving to Zone 2\n"));
#endif
			return;
		}
		vec iloc;
		game.getItemLocation(itemNo, iloc);
#if printDebug
		printVec("\tItemPos (m)", iloc);
#endif
		overshoot(iloc);
		vec degs = {floatZero, floatZero, 0.62f};
		setTargetAngVel(hitTarget(myState, iloc) ? degs : zeroVec);
	}
示例#8
0
    //END::PAGE::adef
    //BEGIN::PAGE::ctrl
	void overshoot(vec targetPos) {
		vec nPos, att;
		float dis = disBetweenPts(statePos(myState), targetPos);
		attToTarget(statePos(myState), targetPos, att);
		nPos[0] = targetPos[0] + att[0] * osMag * dis; //set target location beyond target
		nPos[1] = targetPos[1] + att[1] * osMag * dis;
		nPos[2] = targetPos[2] + att[2] * osMag * dis;
		float velComponent = mathVecInner(stateVel(myState), att, 3);
		float disLeft = dis - stillDis;
		float velDis = disToHalt(velComponent);
#if printDebug
		DEBUG(("Overshoot Info\n"));
		DEBUG(("\tOvershoot Magnitude\t%.3f\n", osMag));
		DEBUG(("\tOvershoot Threshold\t%.3f\n", lim));
		DEBUG(("\tDis to Target (m)\t%.3f\n", dis));
		DEBUG(("\tVel Component (m/s)\t%.3f\n", velComponent));
		DEBUG(("\tCur Vel Dis (m)\t%.3f\n", velDis));
		printVec("\tTarget Pos (m)", targetPos);
		printVec("\tTarget Att (unitvec)", att);
		printVec("\tNew Pos (m)", nPos);
#endif
		if (osMag <= floatZero || hitTarget(myState, targetPos)) {
#if printDebug
			DEBUG(("\tsetPositionTarget\n"));
#endif
			api.setPositionTarget(targetPos);
		}
		else if (dis < lim && velDis > disLeft + 0.001f) {
#if printDebug
			DEBUG(("\tHalting\n"));
#endif
			api.setVelocityTarget(zeroVec);
		}
		else { //overshoot
#if printDebug
			DEBUG(("\tSpeeding Up\n"));
#endif
			api.setPositionTarget(nPos);
		}
	}
示例#9
0
	void getItem (int itemNo, float x0, float x1, float y0, float y1, float z0, float z1, float acc) {
		float best = floatZero;
		int lim = 40;
		if (time < lim)
			lim = time;
	  for (float x = x0; x < x1 + floatItsml; x += acc) {
	    for (float y = y0; y < y1 + floatItsml; y += acc) {
	      for (float z = z0; z < z1 + floatItsml; z += acc) {
	        float temp = floatZero;
	        for (int i = 0; i <= lim; i ++) {
						float diff = fabs(tridis[i][itemNo] - disBetweenPts(makeVec(x, y, z), tripos[i]));
	          if (diff < 0.0101f)
							temp += floatOne - diff;
					}
	        if (temp > best) {
	          iloc[0] = x; iloc[1] = y; iloc[2] = z;
	          best = temp;
	        }
	      }
	    }
	  }
		#if printDebug
		DEBUG(("getItem(%d)\n", itemNo));
		printVec("\tItemPos (m)", iloc);
		DEBUG(("\tAccuracy Score\t%.3f\n", best / (time + 1.0f)));
		DEBUG(("\tVel Magnitude (m/s)\t%.3f\n", mathVecMagnitude(myState + 3, 3)));
		DEBUG(("\tAngvel Magnitude (deg/s)\t%.3f\n", mathVecMagnitude(myState + 9, 3) * 57.296f));
		DEBUG(("\tDis from Item (m)\t%.3f\n", disBetweenPts(myState, iloc)));
		#endif
		api.setPositionTarget(iloc);
		if (hitTarget(myState, iloc)) {
			#if printDebug
			DEBUG(("\tHit target\n"));
			#endif
			setTargetAngVel(makeVec(floatZero, floatZero, pickUpSpeed));
		}
		else {
			setTargetAngVel(zeroVec);
		}
	}
示例#10
0
	bool makeObs (vec loc) {
		#if printDebug
		DEBUG(("makeObs()\n"));
		printVec("\tAt loc (m):", loc);
		#endif
	  if (!cloudOn) {
	    targetAtt[0] = -myState[6];
	    targetAtt[1] = -myState[7];
	    targetAtt[2] = -myState[8];
	    game.startObstacle();
			cloudOn = true;
	  }
		else if (hitTarget(myState, loc)) {
	    game.stopObstacle();
			cloudOn = false;
	    return true;
	  }
		#if printDebug
		printVec("\tTarget att", targetAtt);
		#endif
	  api.setAttitudeTarget(targetAtt);
	  api.setPositionTarget(loc);
	  return false;
	}