//=============snake================// HRESULT SnakeBoss::initialize(DroppedItemManager* dm, TileMap* tileMap, Player* player, float x, float y) { _tileMap = tileMap; _player = player; _dm = dm; setSize(0, 0); setCenter(x, y); setMaxSpeed(METER_TO_PIXEL * 60); _pieces[0] = new SnakePiece; _pieces[0]->initialize(this, HEAD); _pieces[0]->setCenter(getX(), getY()); for (int i = 1; i < LENGTH - 1; i++) { _pieces[i] = new SnakePiece; _pieces[i]->initialize(this, BODY); _pieces[i]->setCenter(getX(), getY()); _pieces[i]->setSpeed(METER_TO_PIXEL * 10); } _pieces[LENGTH - 1] = new SnakePiece; _pieces[LENGTH - 1]->initialize(this, TAIL); _pieces[LENGTH - 1]->setCenter(getX(), getY()); _pieces[LENGTH - 1]->setSpeed(METER_TO_PIXEL * 10); setUnitInfo(5000, 0, 20, 10); setTileCollision(false); SOUNDMANAGER->play("boss", _option.volume()); return S_OK; }
// reset state void basketballSteer::reset(Ogre::Vector3 nodePosition) { // gameState *gameS = gameState::Instance(); // sharedPtr<gameState> gameS = gameState::Instance(); conversionSharedPtr convert ; steering::reset (); // reset the vehicle setSpeed (0.0f); // speed along Forward direction. setMaxForce (3000.7f); // steering force is clipped to this magnitude setMaxSpeed (10); // velocity is clipped to this magnitude // teamStateVecSharedPtr activeTeamInstance = gameS->getActiveTeamInstance(); // basketballStateVec basketballInstance = gameS->getBasketballInstance(); // int activeBBallInstance = gameS->getActiveBBallInstance(); OpenSteer::Vec3 basketballSteerPos = convert->toOpenSteerVec3(nodePosition); // Place me on my part of the field, looking at oponnents goal // setPosition(b_ImTeamA ? OpenSteer::frandom01()*20 : -OpenSteer::frandom01()*20, 0, (OpenSteer::frandom01()-0.5f)*20); setPosition(basketballSteerPos); // setPosition(OpenSteer::Vec3(-playerSteerPos.x, playerSteerPos.y, playerSteerPos.z)); OpenSteer::Vec3 m_home = basketballSteerPos; // m_home = position(); // OpenSteer::AnnotationMixin< Super >::clearTrailHistory (); // prevent long streaks due to teleportation // OpenSteer::clearTrailHistory (); // setTrailParameters (10, 60); }
// Method to update location void Boid::update(vector<Boid*> boids, float _sep, float _ali, float _coh, float _maxSpeed, float _maxForce) { setMaxSpeed(_maxSpeed); setMaxForce(_maxForce); flock(boids, _sep, _ali, _coh); vel += acc; // Update velocity vel.x = ofClamp(vel.x, -maxspeed, maxspeed); // Limit speed vel.y = ofClamp(vel.y, -maxspeed, maxspeed); // Limit speed loc += vel; acc = 0; // Reset accelertion to 0 each cycle // if (loc.x < -r) loc.x = worldWidth+r; // if (loc.y < -r) loc.y = worldHeight+r; // if (loc.x > worldWidth+r) loc.x = -r; // if (loc.y > worldHeight+r) loc.y = -r; // not looping, bouncing if (loc.y < 0) { vel.y *= -bounce; loc.y = 0.f; } if (loc.y > worldHeight) { vel.y *= -bounce; loc.y = worldHeight; } if ((loc.x > worldWidth) || (loc.x < 0)) { vel.x *= -bounce; } }
//----------------------------------------------------------------------------- // reset all instance state void Pedestrian::reset (void) { float currRadius = radius(); // reset the vehicle // but keep the radius SteeringVehicle::reset (); setRadius( currRadius ); // max speed and max steering force (maneuverability) // setMaxSpeed (2.0); setMaxForce (8.0); setMaxSpeed (4.0f * currRadius); // setMaxForce (16.0f * currRadius); // initially stopped setSpeed (0); // // size of bounding sphere, for obstacle avoidance, etc. // setRadius (0.5); // width = 0.7, add 0.3 margin, take half // set the path for this Pedestrian to follow // path = getTestPath (); if( path != NULL ) { // set initial position // (random point on path + random horizontal offset) const float d = path->length() * frandom01(); const float r = path->radius(); const osVector3 randomOffset = randomVectorOnUnitRadiusXZDisk () * r; setPosition( path->mapPathDistanceToPoint (d) + randomOffset ); } // randomize 2D heading #if OPENSTEER_Z_ISUP randomizeHeadingOnXYPlane (); #else randomizeHeadingOnXZPlane (); #endif // pick a random direction for path following (upstream or downstream) pathDirection = (frandom01() > 0.5) ? -1 : +1; // trail parameters: 3 seconds with 60 points along the trail setTrailParameters (3, 60); // notify proximity database that our position has changed if( _proximityToken != nullptr) { _proximityToken->updateForNewPosition(position()); } #if 0 // notify the update states _steeringForceUpdate.setVehicle( this ); _eulerUpdate.setVehicle( this ); #endif }
void MeStepperMotor::begin(byte microStep,long speed,long acceleration) { MeWire::begin(0x04); // join i2c bus (address optional for master) setCurrentPosition(0); enable(); setMicroStep(microStep); setMaxSpeed(speed); setAcceleration(acceleration); }
int GLWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QGLWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: toggleWireframe((*reinterpret_cast< bool(*)>(_a[1]))); break; case 1: toggleBoidAnimation((*reinterpret_cast< bool(*)>(_a[1]))); break; case 2: toggleGoalAnimation((*reinterpret_cast< bool(*)>(_a[1]))); break; case 3: toggleRecord((*reinterpret_cast< bool(*)>(_a[1]))); break; case 4: setMass((*reinterpret_cast< double(*)>(_a[1]))); break; case 5: setMaxSpeed((*reinterpret_cast< double(*)>(_a[1]))); break; case 6: setMaxForce((*reinterpret_cast< double(*)>(_a[1]))); break; case 7: setSepDist((*reinterpret_cast< double(*)>(_a[1]))); break; case 8: setCohDist((*reinterpret_cast< double(*)>(_a[1]))); break; case 9: setAliDist((*reinterpret_cast< double(*)>(_a[1]))); break; case 10: setGoalInf((*reinterpret_cast< int(*)>(_a[1]))); break; case 11: removeBoid(); break; case 12: addBoid(); break; case 13: resetGoals(); break; default: ; } _id -= 14; } return _id; }
Laser::Laser(D3DXQUATERNION rotation, D3DXVECTOR3 position, D3DXVECTOR3 direction) : MoveableGameObject(position) , lifetimeLeft(LASER_LIFETIME_MS) , lastPosition(position) { setDirection(direction); setRotation(rotation); setMaxSpeed(LASER_MAX_SPEED); setSpeed(LASER_SPEED); }
void SteeringVehicle::initialize() { // reset LocalSpace state resetLocalSpace(); // reset SteerLibraryMixin state SimpleVehicle_2::reset(); setMaxForce(1.0f); // steering force is clipped to this magnitude setMaxSpeed(1.0f); // velocity is clipped to this magnitude }
/** \brief set block size \param block the new block size in KB \return Return true if succes */ bool WriteThread::setBlockSize(const int blockSize) { if(blockSize<1 || blockSize>16384) { this->blockSize=blockSize*1024; //set the new max speed because the timer have changed setMaxSpeed(maxSpeed); return true; } else return false; }
void Monster::onEnter() { Character::onEnter(); schedule(schedule_selector(Monster::onUpdate)); int MonsterIdx = m_iMonsterID - 1; setCurSpeed(GI.getMonsterConfig()[MonsterIdx].fMoveSpeed); setMaxSpeed(GI.getMonsterConfig()[MonsterIdx].fMoveSpeed); setMaxHealth(GI.getMonsterConfig()[MonsterIdx].iHP); setCurHealth(GI.getMonsterConfig()[MonsterIdx].iHP); setMoveVector(ccp(1, 0)); sprintf(CMonster, "spirit/monster/Monster%d", m_iMonsterID); std::string StrMonster(CMonster); // 设置动画 // 0.右 1.下 2.左 3.上 m_pWalkAnim[0] = CCAnimation::create(); m_pWalkAnim[0]->retain(); m_pWalkAnim[0]->addSpriteFrameWithFileName( (StrMonster + std::string("_R_1.png")).c_str() ); m_pWalkAnim[0]->addSpriteFrameWithFileName( (StrMonster + std::string("_R_2.png")).c_str() ); m_pWalkAnim[0]->setDelayPerUnit(0.5f / getCurSpeed()); m_pWalkAnim[1] = CCAnimation::create(); m_pWalkAnim[1]->retain(); m_pWalkAnim[1]->addSpriteFrameWithFileName( (StrMonster + std::string("_D_1.png")).c_str() ); m_pWalkAnim[1]->addSpriteFrameWithFileName( (StrMonster + std::string("_D_2.png")).c_str() ); m_pWalkAnim[1]->setDelayPerUnit(0.5f / getCurSpeed()); m_pWalkAnim[2] = CCAnimation::create(); m_pWalkAnim[2]->retain(); m_pWalkAnim[2]->addSpriteFrameWithFileName( (StrMonster + std::string("_L_1.png")).c_str() ); m_pWalkAnim[2]->addSpriteFrameWithFileName( (StrMonster + std::string("_L_2.png")).c_str() ); m_pWalkAnim[2]->setDelayPerUnit(0.5f / getCurSpeed()); m_pWalkAnim[3] = CCAnimation::create(); m_pWalkAnim[3]->retain(); m_pWalkAnim[3]->addSpriteFrameWithFileName( (StrMonster + std::string("_U_1.png")).c_str() ); m_pWalkAnim[3]->addSpriteFrameWithFileName( (StrMonster + std::string("_U_2.png")).c_str() ); m_pWalkAnim[3]->setDelayPerUnit(0.5f / getCurSpeed()); // 设置技能 m_pSkill = Skill::create(GI.getMonsterConfig()[MonsterIdx].iSkillID); addChild(m_pSkill); // 冰冻 m_bIsFrozen = false; m_bForceToStop = false; m_bDropItemAfterDeath = true; }
//=================== water ===================// HRESULT MBall::initialize(float lifeTime, float effectTime) { _effectTime = effectTime; _time = 0; _lifeTime = lifeTime; setMaxSpeed(METER_TO_PIXEL * 100); setSize(5, 5); _effectName = "magic effect bagic"; return S_OK; }
void Hero::onEnter() { Character::onEnter(); schedule(schedule_selector(Hero::onUpdate)); // 设置速度 setCurSpeed(GI.HeroInitSpeed); setMaxSpeed(GI.HeroMaxSpeed); // 设置动画 // 0.下 1.左 2.上 3.右 m_pWalkAnim[0] = CCAnimation::create(); m_pWalkAnim[0]->retain(); m_pWalkAnim[0]->addSpriteFrameWithFileName("Hero1_1.png"); m_pWalkAnim[0]->addSpriteFrameWithFileName("Hero1_2.png"); m_pWalkAnim[0]->setDelayPerUnit(0.5 / getCurSpeed()); }
bool ArmPlat::setPort( uint16_t newport ) { LOGF_DEBUG("Port set to %d", newport ); if ( port != newport ) { port = newport; if ( halfstep != -1 ) setHalfStep( (bool)halfstep ); if ( wiring != -1 ) setWiring( (uint16_t)wiring ); if ( speed != -1 ) setMaxSpeed( (uint16_t)speed ); if ( motortype != -1 ) setMotorType( (uint16_t)motortype ); LOG_INFO("Applying motor config, as port is active now" ); //loadConfig(); } return true; }
Ghost::Ghost(Math::Point pos, Pointer<Entity> parent, QString name) : Actor(parent, name), mKillCount(0) { subclass(); setPos(pos); setMaxSpeed(9.0); mPursue = new Pursue(pointer()); mWander = new Wander(pointer()); addSteeringBehavior(mPursue); addSteeringBehavior(mWander); PersonView* view = new PersonView(pointer(), Qt::green); //view->setColor(Qt::green); // HULK SMASH! -- 20070108 iank setView(view); setVisible(true); newTarget(); }
//============piece============// HRESULT SnakePiece::initialize(SnakeBoss* self, PIECE p) { if (p == HEAD) { _image = IMAGEMANAGER->findImage("boss snake head"); } else if (p == BODY) { _image = IMAGEMANAGER->findImage("boss snake body"); } else if (p == TAIL) { _image = IMAGEMANAGER->findImage("boss snake tail"); } _self = self; setSize(50, 50); setUnitInfo(1, 1, 20, 10); setTileCollision(false); setMaxSpeed(METER_TO_PIXEL * 35); return S_OK; }
bool ArmPlat::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) { //IDLog( "NewNumber: %s %s %lf %s %d\n", dev, name, values[ 0 ], names[ 0 ], n ); if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { ///////////////////////////////////////////// // Backlash ///////////////////////////////////////////// if (strcmp(name, BacklashNP.name) == 0) { IUUpdateNumber(&BacklashNP, values, names, n); // Only update backlash value if compensation is enabled if (BacklashCompensationS[BACKLASH_ENABLED].s == ISS_ON) { bool rc = setBacklash(BacklashN[0].value); BacklashNP.s = rc ? IPS_OK : IPS_ALERT; } else { backlash = 0; BacklashNP.s = IPS_OK; } IDSetNumber(&BacklashNP, nullptr); return true; } // if (strcmp(name, SyncNP.name) == 0) // { // bool rc = sync(static_cast<uint32_t>(values[0])); // SyncNP.s = rc ? IPS_OK : IPS_ALERT; // if (rc) // SyncN[0].value = values[0]; // IDSetNumber(&SyncNP, nullptr); // return true; // } ///////////////////////////////////////////// // Relative goto ///////////////////////////////////////////// else if (strcmp(name, FocusRelPosNP.name) == 0) { IUUpdateNumber(&FocusRelPosNP, values, names, n); IDSetNumber(&FocusRelPosNP, nullptr); MoveRelFocuser( FocusMotionS[ 0 ].s == ISS_ON ? FOCUS_INWARD : FOCUS_OUTWARD, (uint32_t)values[ 0 ] ); return true; } ///////////////////////////////////////////// // MaxSpeed ///////////////////////////////////////////// else if (strcmp(name, MaxSpeedNP.name) == 0) { IUUpdateNumber(&MaxSpeedNP, values, names, n); bool rc = setMaxSpeed(MaxSpeedN[0].value); MaxSpeedNP.s = rc ? IPS_OK : IPS_ALERT; IDSetNumber(&MaxSpeedNP, nullptr); return true; } } return INDI::Focuser::ISNewNumber(dev, name, values, names, n); }
bool NStep::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { // Compensation Settings if (!strcmp(name, CompensationSettingsNP.name)) { // Extract values int change = 0, step = 0, backlash = 0, timer = 0; for (int i = 0; i < n; i++) { if (!strcmp(names[i], CompensationSettingsN[COMPENSATION_SETTING_CHANGE].name)) { change = values[i]; } else if (!strcmp(names[i], CompensationSettingsN[COMPENSATION_SETTING_STEP].name)) { step = values[i]; } else if (!strcmp(names[i], CompensationSettingsN[COMPENSATION_SETTING_BACKLASH].name)) { backlash = values[i]; } else if (!strcmp(names[i], CompensationSettingsN[COMPENSATION_SETTING_TIMER].name)) { timer = values[i]; } } // Try to update settings if (setCompensationSettings(change, step, backlash, timer)) { IUUpdateNumber(&CompensationSettingsNP, values, names, n); CompensationSettingsNP.s = IPS_OK; } else { CompensationSettingsNP.s = IPS_ALERT; } IDSetNumber(&CompensationSettingsNP, nullptr); return true; } // Stepping Phase if (!strcmp(name, SteppingPhaseNP.name)) { if (setSteppingPhase(static_cast<uint8_t>(values[0]))) { IUUpdateNumber(&SteppingPhaseNP, values, names, n); SteppingPhaseNP.s = IPS_OK; } else SteppingPhaseNP.s = IPS_ALERT; IDSetNumber(&SteppingPhaseNP, nullptr); return true; } // Max Speed if (!strcmp(name, MaxSpeedNP.name)) { if (setMaxSpeed(static_cast<uint8_t>(values[0]))) { IUUpdateNumber(&MaxSpeedNP, values, names, n); MaxSpeedNP.s = IPS_OK; // We must update the Min/Max of focus speed FocusSpeedN[0].max = values[0]; IUUpdateMinMax(&FocusSpeedNP); } else { MaxSpeedNP.s = IPS_ALERT; } IDSetNumber(&MaxSpeedNP, nullptr); return true; } } return INDI::Focuser::ISNewNumber(dev, name, values, names, n); }
void BadAgent::getReadyToFight(int type, int dif, int speed){ switch (type) { case BA_TYPE_BACTERIA: img = IMG_BACTERIA; hitPoints = 100 + 50 * dif; setDefs(50, 10); setSizes(25, 25, 1); dmgToDo = 2 + 1 * dif; dnaToGive = 25 + 5 * dif; pointsToGice = 50; break; case BA_TYPE_VIRUS: img = IMG_VIRUS; hitPoints = 75 + 30 * dif; setDefs(10, 70); setSizes(25, 25, 1); dmgToDo = 1 + 2 * dif; dnaToGive = 15 + 10 * dif; pointsToGice = 60; break; case BA_TYPE_BOSS_BACTERIA: img = IMG_BACTERIA; hitPoints = 1000 + 200 * dif; setDefs(90, 25); setSizes(50, 50, 1); dmgToDo = 20 + 5 * dif; dnaToGive = 400 + 20 * dif; pointsToGice = 150; break; case BA_TYPE_BOSS_VIRUS: img = IMG_VIRUS; hitPoints = 1000 + 100 * dif; setDefs(10, 100); setSizes(50, 50, 1); dmgToDo = 20 + 3 *dif; dnaToGive = 300 + 25 * dif; pointsToGice = 180; break; default: std::cout << "Error not valid type: " << type << " deleting...\n"; destroying = true; readyToDestroy = true; break; } switch (speed) { case BA_MOV_SLOW: setMaxSpeed(80 + 10 * dif); break; case BA_MOV_NORMAL: setMaxSpeed(120 + 15 * dif); break; case BA_MOV_FAST: setMaxSpeed(160 + 20 * dif); break; default: setMaxSpeed(800); std::cout << "ERROR" << std::endl; break; } maxHitPoints = hitPoints; setPositions(-2000, -2000, 1); }
//---------------------------------------------------------------------------------------------------------------------- void SMCAgent::init() { m_radius = 0.02; if (SETTINGS->hasChild("Config/GA/Evolvable")) { const ci::XmlTree& xml = SETTINGS->getChild("Config/GA/Evolvable"); // Todo: move to respective sensor class!!! // Distance sensor if (xml.getChild("DistanceSensor").getValue<bool>(0)) { m_distanceSensor = new DistanceSensor(); m_distanceSensor->fromXml(xml.getChild("DistanceSensor")); setSensorMode(xml.getChild("DistanceSensor").getAttributeValue<std::string>("Mode", "Absolute")); } else { m_distanceSensor = NULL; } // Gradient sensor if (xml.getChild("GradientSensor").getValue<bool>(0)) { m_gradientSensor = new GradientSensor(); m_gradientSensor->fromXml(xml.getChild("GradientSensor")); } else { m_gradientSensor = NULL; } // Torus sensor if (xml.getChild("TorusSensor").getValue<bool>(0)) { m_torusSensor = new TorusSensor(); m_torusSensor->fromXml(xml.getChild("TorusSensor")); } else { m_torusSensor = NULL; } setMaxSpeed(xml.getChild("MaxSpeed").getValue<double>(1.0)); setMaxAngularSpeed(degreesToRadians(xml.getChild("MaxAngularSpeed").getValue<double>(180))); setMaxAngle(degreesToRadians(xml.getChild("MaxAngle").getValue<double>(90))); setMaxPosition(xml.getChild("MaxPosition").getValue<double>(0.5)); setAngleWraps(xml.getChild("AngleWraps").getValue<bool>(1)); setPositionWraps(xml.getChild("PositionWraps").getValue<bool>(1)); m_energyInitial = xml.getChild("Energy").getAttributeValue<float>("initial", 30.0); m_energySpeedTresh = xml.getChild("Energy").getAttributeValue<float>("threshForSpeed", -1); m_evMin = xml.getChild("Energy").getAttributeValue<float>("evMin", 0); m_evMax = xml.getChild("Energy").getAttributeValue<float>("evMax", 10); m_engReplFoodSens = xml.getChild("Energy").getAttributeValue<bool>("engReplFoodSens", false); getEnvironment().fromXml(xml.getChild("Environment")); } reset(); }
CMotor::CMotor() { setStillThreshold(10); setMaxSpeed(0xFF); }
Boid::Boid( float aMaxSpeed, float aMaxSteeringForce ) { reset(); setMaxSpeed( aMaxSpeed ); setMaxSteeringForce( aMaxSteeringForce ); }