char CZombie::RecalculateIA(Vect3f hisPosition) { Vect3f myPosition( GetInstance()->GetPosition() ); switch(GetState()) { case (char)IDLE: GoIdle(hisPosition,myPosition); break; case (char)OLIENDO: GoOliendo(hisPosition,myPosition); break; case (char)MIRANDO: GoMirando(hisPosition,myPosition); break; case (char)ANDANDO: // m_pRenderableAnimatedInstanceModel->GetAnimatedInstanceModel()->BlendCycle(MIRANDO,elapsedTime); GoAndando(hisPosition,myPosition); break; case (char)ATACANDO: GoAtacando(hisPosition,myPosition); break; case (char)RECIBIENDOGOLPE: GoRecibiendoGolpe(hisPosition,myPosition); break; case (char)VOLVIENDOINICIO: GoVolviendoInicio(hisPosition,myPosition); break; case (char)MURIENDO: GoMuriendo(); break; } return GetState(); }
// calculate intercept point from ship's current position and velocity Vector3 NounShip::intercept( Noun * pIntercept, float fVelocity ) { Vector3 target( pIntercept->worldPosition() ); if ( fVelocity < 1.0f ) return target; Vector3 velocity( pIntercept->worldVelocity() ); Vector3 myPosition( worldPosition() ); // calculate the distance to the target float distance = (target - myPosition).magnitude(); // caluclate the projectile time to the target float t = distance / fVelocity; // calculate the intercept point Vector3 intercept( target + (velocity * t) ); // refine the intercept position int recurseCount = INTERCEPT_RECURSE_COUNT; while( recurseCount > 0 ) { recurseCount--; // recalculate the intercept point again distance = (intercept - myPosition).magnitude(); t = distance / fVelocity; intercept = target + (velocity * t); } return intercept; }
void ASSOscReceiver::buildCursorEvent(const std::string& theType, int theId, const asl::Vector3f& thePosition, float theIntensity) { if(!_myDidOverflow) { if(_myBounded) { asl::Vector2f myPosition(thePosition[0], thePosition[1]); if(!_myRegion.contains(myPosition)) { return; } } _myEmpty = false; std::string myAddress("/"); myAddress += theType; try { _myStream << osc::BeginMessage(myAddress.c_str()) << theId << thePosition[0] << thePosition[1] << thePosition[2] << theIntensity << osc::EndMessage; } catch (osc::OutOfBufferMemoryException) { _myDidOverflow = true; } } }
void Enemy::moveEnemy(sf::Vector2f playerPosition){ sf::Vector2f myPosition(getSpritePosition()); if(playerIsInRadious(myPosition, playerPosition)){ if(this->movement.x == 0.f && playerPosition.y < myPosition.y - 1){ jump(); } if(playerPosition.x < myPosition.x - 1){ facingRight = false; movingLeft = true; movingRight = false; if(this->movement.x > -(speed)){ this->movement.x -= 0.2; } else { this->movement.x = -(speed); } } else if(playerPosition.x > myPosition.x + 1){ facingRight = true; movingLeft = false; movingRight = true; if(this->movement.x < speed){ this->movement.x += 0.2; } else{ this->movement.x = speed; } } else { stopEnemy(); } } else { stopEnemy(); } }
vector<y60::EventPtr> DSADriver::poll() { vector<y60::EventPtr> myEvents; for (SensorServerList::iterator ssli = _mySensorServers.begin(); ssli != _mySensorServers.end(); ++ssli) { SensorServer::SensorData mySensorData; ssli->second->poll(mySensorData); for (SensorArrayList::iterator sali = _mySensorArray.begin(); sali != _mySensorArray.end(); ++sali) { std::vector<asl::Vector2i> myRawEvents; for(SensorServer::SensorData::iterator sdi = mySensorData.begin(); sdi != mySensorData.end(); ++sdi) { if (sali->second->getGridSize()[0] == 0 && sali->second->getGridSize()[1] == 0) { // TODO: Raw Events for multiple Ports sali->second->createRawEvents(myRawEvents, ssli->first, // thePortId sdi->first, // theControllerId sdi->second // theBitMask ); } else { sali->second->createCookedEvents(myRawEvents, ssli->first, // thePortId sdi->first, // theControllerId sdi->second // theBitMask ); } } for (unsigned int i = 0; i < myRawEvents.size(); ++i) { asl::Vector2f myPosition((float)myRawEvents[i][0], (float)myRawEvents[i][1]); unsigned int myCount = 1; // interpolate neighboring events if (_myInterpolateFlag) { for (unsigned int j = 0; j < myRawEvents.size(); ++j) { if (i == j) { continue; } asl::Vector2i myDelta = asl::difference(myRawEvents[j], myRawEvents[i]); if (magnitude(myDelta) <= 1) { myPosition += asl::Vector2f((float)myRawEvents[j][0], (float)myRawEvents[j][1]); myCount++; } } if (myCount > 1) { myPosition = product(myPosition, 1.0f / float(myCount)); AC_TRACE << "DSADriver: interpolated distance " << myPosition << "," << myCount; } } y60::EventPtr myEvent(new y60::TouchEvent(sali->second->getName(), myPosition, sali->second->getGridSize(), float(myCount))); myEvents.push_back(myEvent); } } } return myEvents; }
int GadgetELF::useEnergy( dword nTick, int energy ) { if ( active() ) { Vector3 myPosition( worldPosition() ); m_nUpdateAffected++; if ( m_nUpdateAffected >= ELF_UPDATE_RATE ) { m_nUpdateAffected -= ELF_UPDATE_RATE; m_Affect.release(); // update list of ship list Array< GameContext::NounCollision > nouns; if ( context()->proximityCheck( worldPosition(), range(), nouns, CLASS_KEY(NounShip) ) ) { for(int i=0;i<nouns.size();i++) { NounShip * pAffect = (NounShip *)nouns[i].pNoun; if ( pAffect != NULL && pAffect != parentBody() ) m_Affect.push( pAffect ); } } } // drain energy from the affected ships... based on range for(int i=0;i<m_Affect.size();i++) { NounShip * pAffect = m_Affect[ i ]; float fDistance = (pAffect->worldPosition() - myPosition).magnitude(); if ( fDistance < range() ) { int leech = damageRatioInv() * ((fDistance * pAffect->energy()) / range()); if ( leech > MAX_ENERGY_LEECH ) leech = MAX_ENERGY_LEECH; pAffect->setEnergy( pAffect->energy() - leech ); energy += leech; } } } return energy; }
/** * Changes currentTarget to be the closest alive tank. * @param otherTanks */ void DefendBehavior::selectTarget(vector<otank_t>* otherTanks, tank_t me) { Point myPosition(me.pos[0], me.pos[1]); Point enemyPosition; int minDistance = 1000000; for(int i = 0; i < otherTanks->size(); i++) { enemyPosition.x = otherTanks->at(i).pos[0]; enemyPosition.y = otherTanks->at(i).pos[1]; if(SearchTools::distance(myPosition, enemyPosition) < minDistance && !(DEADSTRING.compare(otherTanks->at(i).status) == 0)) { currentTarget = &enemies->at(i); minDistance = SearchTools::distance(myPosition, enemyPosition); } } }