本文整理汇总了C++中setVelocity函数的典型用法代码示例。如果您正苦于以下问题:C++ setVelocity函数的具体用法?C++ setVelocity怎么用?C++ setVelocity使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setVelocity函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setVelocity
void Simulation::setVelocity(const Vec3f& v1) {
setVelocity(v1, Vec3f(0,0,0));
}
示例2: getPhysicsBody
void Ball::increaseVelocity() {
auto body = getPhysicsBody();
body->setVelocity(body->getVelocity() * VELOCITY_INCREASE);
}
示例3: rand
void GiantSlimeEntity::animate(float delay)
{
slimeTimer -= delay;
if (slimeTimer <= 0.0f)
{
slimeTypeEnum slimeType = SlimeTypeStandard;
if (game().isAdvancedLevel())
{
slimeType = (slimeTypeEnum)(slimeType + rand() % 3);
}
switch (slimeCounter)
{
case 0:
new SlimeEntity(TILE_WIDTH * 1.5f, TILE_HEIGHT * 1.5f, slimeType, true);
break;
case 1:
new SlimeEntity(TILE_WIDTH * (MAP_WIDTH - 2) + TILE_WIDTH * 0.5f, TILE_HEIGHT * 1.5f, slimeType, true);
break;
case 2:
new SlimeEntity(TILE_WIDTH * (MAP_WIDTH - 2) + TILE_WIDTH * 0.5f, TILE_HEIGHT * (MAP_HEIGHT - 2) + TILE_HEIGHT * 0.5f, slimeType, true);
break;
case 3:
new SlimeEntity(TILE_WIDTH * 1.5f, TILE_HEIGHT * (MAP_HEIGHT - 2) + TILE_HEIGHT * 0.5f, slimeType, true);
break;
}
slimeTimer = 7.0f;
slimeCounter ++;
if (slimeCounter == 4) slimeCounter = 0;
}
if (age <= 0.0f)
{
age += delay;
return;
}
EnemyEntity::animate(delay);
if (specialState[SpecialStateIce].active) delay *= specialState[SpecialStateIce].param1;
timer -= delay;
if (timer <= 0.0f)
{
if (state == 0) // walking
{
counter--;
if (counter >= 0)
{
timer = 0.5f;
if (hp <= hpMax / 4)
creatureSpeed = GIANT_SLIME_SPEED * 1.4f;
if (hp <= hpMax / 2)
creatureSpeed = GIANT_SLIME_SPEED * 1.2f;
else
creatureSpeed = GIANT_SLIME_SPEED;
setVelocity(Vector2D(x, y).vectorTo(game().getPlayerPosition(), GIANT_SLIME_SPEED ));
}
else
{
int r = rand() % 3;
if (r == 0) changeToState(1);
else if (r == 1) changeToState(3);
else changeToState(5);
}
}
else if (state == 1) // waiting for jumping
{
changeToState(2);
}
else if (state == 2) // jumping
{
changeToState(8);
}
else if (state == 3)
{
changeToState(4);
}
else if (state == 4) // walking
{
counter--;
if (counter >= 0)
{
if (hp <= hpMax / 4)
timer = missileDelay * 0.6f;
if (hp <= hpMax / 2)
timer = missileDelay * 0.8f;
else
timer = missileDelay;
fire();
}
else
{
changeToState(8);
}
}
else if (state == 5)
{
changeToState(6);
}
else if (state == 6) // jump
{
//.........这里部分代码省略.........
示例4: rand
void Robot::setRandDirection()
{
int randAngle = rand() % 360;
setVelocity(Vector3(1, 0, 0).GetRotatedY(randAngle));
setRotation(Vector3(0, -randAngle+90.f, 0));
}
示例5: switch
void SimpleWalkingMonster::update()
{
switch(mState)
{
case State_Walking:
{
mVelocity.y += 6.0f;
mVelocity.x = 20.0f * ((mFacing==Facing_Left)?-1:1);
setVelocity(mVelocity);
int bumps = moveWithCollision();
if ((bumps & (Direction_Up | Direction_Down)) != 0)
{
mVelocity.y = 0;
}
if ((bumps & (Direction_Left)) != 0)
{
mFacing = Facing_Right;
}
if ((bumps & (Direction_Right)) != 0)
{
mFacing = Facing_Left;
}
int offsetX = (mState==Facing_Right)?-getHalfSize().x-2:getHalfSize().x+2;
int offsetY = getHalfSize().y+2;
float2 position = getPosition();
int x = (position.x+offsetX) / (float)mRoom->getTileWidth();
int y = (position.y+offsetY) / (float)mRoom->getTileHeight();
if (!mRoom->isCollidable(x, y))
{
if (mFacing == Facing_Left)
{
mFacing = Facing_Right;
}
else
{
mFacing = Facing_Left;
}
}
if (mRand.getFloat(1.0f) < WALK_TO_IDLE_CHANCE)
{
mState = State_Idling;
}
}
break;
case State_Idling:
if (mRand.getFloat(1.0f) < IDLE_TO_WALK_CHANCE)
{
if (mRand.getFloat(1.0f) > 0.5)
{
mFacing = Facing_Left;
}
else
{
mFacing = Facing_Right;
}
mState = State_Walking;
}
break;
}
Hero* hero = mRoom->getHero();
if (Collides(hero->getCollisionRect(), getCollisionRect()))
{
hero->kill();
}
mFrame++;
}
示例6: to_string
bool HelloWorld::init()
{
if ( !Layer::init() )
{
return false;
}
this->isGameOver = false;
visibleSize = Director::getInstance()->getVisibleSize();
// Ground setup
groundSprite0 = Sprite::create("ground.png");
this->addChild(groundSprite0);
groundSprite0->setPosition(Vec2(groundSprite0->getContentSize().width/2.0 , groundSprite0->getContentSize().height/2));
groundSprite1 = Sprite::create("ground.png");
this->addChild(groundSprite1);
groundSprite1->setPosition(Vec2(visibleSize.width + groundSprite1->getContentSize().width/2.0 -10, groundSprite1->getContentSize().height/2));
auto groundbody0 = PhysicsBody::createBox(groundSprite0->getContentSize());
groundbody0->setDynamic(false);
groundbody0->setContactTestBitmask(true);
groundSprite0->setPhysicsBody(groundbody0);
auto groundbody1 = PhysicsBody::createBox(groundSprite1->getContentSize());
groundbody1->setDynamic(false);
groundbody1->setContactTestBitmask(true);
groundSprite1->setPhysicsBody(groundbody1);
// SkyGround setup
Sprite *skySprite0 = Sprite::create("flappy_background.png");
Sprite *skySprite1 = Sprite::create("flappy_background.png");
Sprite *skySprite2 = Sprite::create("flappy_background.png");
this->addChild(skySprite0);
this->addChild(skySprite1);
this->addChild(skySprite2);
skySprite0->setPosition(visibleSize.width/2, 168 + 200);
skySprite1->setPosition(visibleSize.width/2 - skySprite1->getContentSize().width, 168 + 200);
skySprite2->setPosition(visibleSize.width/2 + skySprite1->getContentSize().width, 168 + 200);
// bird setup
/*
Sprite *birdSprite = Sprite::create("flappybird1.png");
this->addChild(birdSprite);
birdSprite->setPosition(visibleSize.width/2, visibleSize.height/2 + 120);
*/
SpriteFrameCache* cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("bird.plist");
auto flyAnim = Animation::create();
for (int i = 1; i < 4; i++) {
SpriteFrame * frame = cache->getSpriteFrameByName("flappybird" + to_string(i) + ".png");
flyAnim->addSpriteFrame(frame);
}
auto birdSprite = Sprite::createWithSpriteFrameName("flappybird1.png");
flyAnim->setDelayPerUnit(0.2f);
auto action = Animate::create(flyAnim);
auto animation = RepeatForever::create(action);
birdSprite->runAction(animation);
birdSprite->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2 + 80));
this->addChild(birdSprite);
auto birdBody = PhysicsBody::createCircle(17.0);
birdBody->setDynamic(true);
birdBody->setMass(1.0f);
birdBody->setVelocity(Vec2(4.0f, 2.0f));
birdBody->setVelocityLimit(50);
birdBody->setContactTestBitmask(true);
birdSprite->setPhysicsBody(birdBody);
//pipe setup
topPipeSprite = Sprite::create("top_pipe.png");
bottomPipeSprite = Sprite::create("bottom_pipe.png");
topPipeSprite->setPosition(visibleSize.width + topPipeSprite->getContentSize().width/2, 600);
auto pipebody0 = PhysicsBody::createBox(topPipeSprite->getContentSize());
pipebody0->setDynamic(false);
topPipeSprite->setPhysicsBody(pipebody0);
pipebody0->setContactTestBitmask(true);
auto pipebody1 = PhysicsBody::createBox(bottomPipeSprite->getContentSize());
pipebody1->setDynamic(false);
pipebody1->setContactTestBitmask(true);
bottomPipeSprite->setPhysicsBody(pipebody1);
this->positionBottomPipe();
this->addChild(topPipeSprite);
this->addChild(bottomPipeSprite);
//setup touch listener
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = [=](Touch *touch, Event *event){
if (!this->isGameOver) {
birdBody->applyImpulse(Vec2(0, 90.0f));
}
log("touch detected!");
//.........这里部分代码省略.........
示例7: setVelocity
void BouncyLogo::initSpeed()
{
const double speed = 4.0;
double d = (double)(rand()%1024) / 1024.0;
setVelocity( d*speed*2-speed, (1-d)*speed*2-speed );
}
示例8: setVelocity
void Listener::setVelocity(const Ogre::Vector3& vec)
{
setVelocity(vec.x, vec.y, vec.z);
}
示例9: AssertFatal
bool SFXSound::_allocVoice( SFXDevice* device )
{
// We shouldn't have any existing voice!
AssertFatal( !mVoice, "SFXSound::_allocVoice() - Already had a voice!" );
// Must not assign voice to source that isn't playing.
AssertFatal( getLastStatus() == SFXStatusPlaying,
"SFXSound::_allocVoice() - Source is not playing!" );
// The buffer can be lost when the device is reset
// or changed, so initialize it if we have to. If
// that fails then we cannot create the voice.
if( mBuffer.isNull() )
{
SFXProfile* profile = getProfile();
if( profile != NULL )
{
SFXBuffer* buffer = profile->getBuffer();
if( buffer )
_setBuffer( buffer );
}
if( mBuffer.isNull() )
return false;
}
// Ask the device for a voice based on this buffer.
mVoice = device->createVoice( is3d(), mBuffer );
if( !mVoice )
return false;
// Set initial properties.
mVoice->setVolume( mPreAttenuatedVolume );
mVoice->setPitch( mEffectivePitch );
mVoice->setPriority( mEffectivePriority );
if( mDescription->mRolloffFactor != -1.f )
mVoice->setRolloffFactor( mDescription->mRolloffFactor );
// Set 3D parameters.
if( is3d() )
{
// Scatter the position, if requested. Do this only once so
// we don't change position when resuming from virtualized
// playback.
if( !mTransformScattered )
_scatterTransform();
// Set the 3D attributes.
setTransform( mTransform );
setVelocity( mVelocity );
_setMinMaxDistance( mMinDistance, mMaxDistance );
_setCone( mConeInsideAngle, mConeOutsideAngle, mConeOutsideVolume );
}
// Set reverb, if enabled.
if( mDescription->mUseReverb )
mVoice->setReverb( mDescription->mReverb );
// Update the duration... it shouldn't have changed, but
// its probably better that we're accurate if it did.
mDuration = mBuffer->getDuration();
// If virtualized playback has been started, we transfer its position to the
// voice and stop virtualization.
const U32 playTime = mPlayTimer.getPosition();
if( playTime > 0 )
{
const U32 pos = mBuffer->getFormat().getSampleCount( playTime );
mVoice->setPosition( pos);
}
mVoice->play( isLooping() );
#ifdef DEBUG_SPEW
Platform::outputDebugString( "[SFXSound] allocated voice for source '%i' (pos=%i, 3d=%i, vol=%f)",
getId(), playTime, is3d(), mPreAttenuatedVolume );
#endif
return true;
}
示例10: setVelocity
void Player::setVelocity(float dx, float dy)
{
setVelocity(Vector(dx, dy));
}
示例11: updateHead
void Player::update(float dt)
{
if(mStunnedCounter > 0.0f)
mStunnedCounter -= dt;
else
mStunned = false;
// Update the animation
mAnimation->animate(dt);
// Update the head rotation
updateHead();
// Update the weapon
if(mWeapon != NULL) {
mWeapon->updatePosition(getPosition());
mWeapon->incrementCooldownCounter(dt);
}
/* Update the velocity */
// Strafing sideways
if(gDInput->keyDown(DIK_A) && !mStunned && getVelocity().x > -mMaxVelocity) { // Left
getBody()->ApplyForce(Vector(-mAcceleration, 0), getPosition());
setFacingDirection(LEFT);
if(mWeapon != NULL)
mWeapon->setFlipped(true);
// If the player is on the ground, continue the animation
if(!mInAir)
mAnimation->resume();
}
else if(gDInput->keyDown(DIK_D) && !mStunned && getVelocity().x < mMaxVelocity) { // Right
getBody()->ApplyForce(Vector(mAcceleration, 0), getPosition());
setFacingDirection(RIGHT);
if(mWeapon != NULL)
mWeapon->setFlipped(false);
// If the player is on the ground, continue the animation
if(!mInAir)
mAnimation->resume();
}
// If A or D is released set the frame to 0 if the player not is in the air
if(gDInput->keyReleased(DIK_A) || gDInput->keyReleased(DIK_D)) {
mAnimation->pause();
if(!mInAir)
mAnimation->setFrame(0);
}
// Jump if the player is on the ground
if(gDInput->keyDown(DIK_SPACE) && !mInAir) {
setVelocity(getVelocity() + Vector(0, -500));
getBody()->Move(0, -1); // Move it out of collision (:HACK:)
mAnimation->setFrame(7); // Set the jumping frame
mAnimation->pause(); // Pause the animation
mInAir = true; // The player is now in the air
}
// Shooting with the left mouse button
if(gDInput->mouseButtonDown(0)) {
if(mWeapon != NULL) {
if(mWeapon->isReady()) {
mWeapon->attack();
mWeapon->setCooldownCounter(0.0f);
mWeapon->setAttacking(true);
}
}
}
// Drop the equipped weapon if the drop button was pressed
if(gDInput->keyPressed(DIK_G))
dropWeapon();
// Loot
if(gDInput->keyPressed(DIK_E))
checkLoot();
}
示例12: loop
void loop() {
//Variable Initialization
time ++;
api.getMyZRState(myState);
api.getOtherZRState(otherState);
phase = game.getCurrentPhase();
fuel = game.getFuelRemaining();
myScore = game.getScore();
otherScore = game.getOtherScore();
dust = game.getRemainingMaterial();
chg = game.getCharge();
if (time < 2) {
red = statePos(myState)[0] < floatZero;
}
//Debug Console
DEBUG(("\nDevilTech Message Screen: Fall 2012\n"));
#if printDebug
DEBUG(("Debug Info\n"));
DEBUG(("\tTime (s)\t%d\tPhase\t%d\tPlayer\t%s\n", time, phase, (red ? "Red" : "Blue")));
DEBUG(("\tFuel\t%.3f\tDust\t%.3f\tChg\t%d\n", fuel, dust, chg));
DEBUG(("\tScore\t%.2f\tOther Score\t%.2f\n", myScore, otherScore));
DEBUG(("\tOther Message\t%u\n", otherMessage));
printVec("\tMy Pos (m)", statePos(myState));
printVec("\tMy Vel (m/s)", stateVel(myState));
printVec("\tMy Att (unitvec)", stateAtt(myState));
printVec("\tMy AngVel (rad/s)", stateAngVel(myState));
printVec("\tOther Pos (m)", statePos(otherState));
printVec("\tOther Vel (m/s)", stateVel(otherState));
printVec("\tOther Att (unitvec)", stateAtt(otherState));
printVec("\tOther AngVel (rad/s)", stateAngVel(otherState));
#endif
vec att = {floatZero, -1.0f, floatZero};
if (!obsCreated) {
if (makeObs(red ? -0.17f : 0.17f, -0.63f)) obsCreated ++;
}
else if (obsCreated == 1) {
if (makeObs(red ? -0.47f : 0.47f, -0.03f)) obsCreated ++;
}
else if (phase == 1) {
vec temp = {norm((red ? -0.45f : 0.45f) - myState[0], 0.015f), 0.05f, floatZero};
setVelocity(temp);
//api.setAttitudeTarget(att);
}
else {
if (!game.haveObject(0)) getItem(0);
else if (!game.haveObject(1) && !game.otherHasObject(1)) getItem(1);
else if (!game.haveObject(2) && !game.otherHasObject(2) && !game.haveObject(1)) getItem(2);
else {
if (game.haveObject(1) || game.haveObject(2)) {
api.setAttitudeTarget(att);
}
vec temp = {floatZero, floatZero, floatZero};
if (phase == 2) {
vec temp2 = {(red ? 0.04f : -0.04f), 0.09f, floatZero};
attToTarget(myState, temp2, temp);
vecScale(temp, 0.057f);
temp[2] = maintainZ();
setVelocity(temp);
}
else {
if (!alreadySet) {
alreadySet = true;
top = myState[2] > floatZero;
}
if (myState[1] > -0.4f) {
remDust();
temp[0] = norm((red ? 0.045f : -0.045f) - myState[0], 0.015f);
temp[1] = -0.051f;
temp[2] = maintainZ();
}
else if (myState[1] > -0.6f) {
temp[0] = norm((red ? 0.045f : -0.045f) - myState[0], 0.015f);
temp[1] = -0.022f;
temp[2] = maintainZ();
}
else {
temp[0] = norm((red ? 0.045f : -0.045f) - myState[0], 0.015f);
temp[1] = floatZero;
temp[2] = (top ? -0.055f : 0.055f);
DEBUG(("Top:\t%d\t%.3f\n", top, temp[2]));
}
setVelocity(temp);
}
}
}
}
示例13: length
void Physics::shock(cg::Vector2d collisionPoint, double Force) {
cg::Vector2d collisionVector = cg::Vector2d(_position[0] - collisionPoint[0], _position[1] - collisionPoint[1]);
collisionVector /= length(collisionVector);
setVelocity(Force*collisionVector[0]/_mass + _velocity[0],Force*collisionVector[1]/_mass + _velocity[1]);
}
示例14: setVelocity
void Physics::decelerate(double step, double limit) {
_velocity = _velocity - _velocity/step;
if (length(_velocity) < limit)
setVelocity(0,0);
}
示例15: down
//.........这里部分代码省略.........
else { // phase 1
if (isDead() || dying()) {
explode(); // shatters the ship into spinning fragments.
delete this;
return;
}
if (rotateSlow_)
rotateSlow_--;
if (rotateLeft_) {
angleIndex_ -= rotateSlow_ ? 1 : rotationRate_;
if (angleIndex_ < 0)
angleIndex_ = SHIP_STEPS-1;
angle_ = angleIndex_ * PI_X_2 / SHIP_STEPS;
cosangle_ = cos(angle_);
sinangle_ = sin(angle_);
}
if (rotateRight_) {
angleIndex_ += rotateSlow_ ? 1 : rotationRate_;
if (angleIndex_ >= SHIP_STEPS)
angleIndex_ = 0;
angle_ = angleIndex_ * PI_X_2 / SHIP_STEPS;
cosangle_ = cos(angle_);
sinangle_ = sin(angle_);
}
if (isBraking()) {
stopEngine();
stopRotation();
if ((fabs(dx_) < 2.5) && (fabs(dy_) < 2.5)) {
dx_ = 0.0;
dy_ = 0.0;
setVelocity(dx_,dy_);
releaseBrakes();
}
else {
double motionAngle = atan2(-dy_,-dx_);
if (angle_ > M_PI)
angle_ -= PI_X_2;
double angleDiff = angle_ - motionAngle;
if (angleDiff > M_PI)
angleDiff = PI_X_2 - angleDiff;
else if (angleDiff < -M_PI)
angleDiff = PI_X_2 + angleDiff;
double fdiff = fabs(angleDiff);
if (fdiff > 0.08) {
if (angleDiff > 0)
rotateLeft_ = true;
else if (angleDiff < 0)
rotateRight_ = true;
if (fdiff > 0.6)
rotationRate_ = brakeForce() + 1;
else if (fdiff > 0.4)
rotationRate_ = 2;
else
rotationRate_ = 1;
if (rotationRate_ > 5)
rotationRate_ = 5;
}
else if ((fabs(dx_)>1) || (fabs(dy_)>1)) {
startEngine();
// we'll make braking a bit faster
dx_ += cosangle_/6 * (brakeForce() - 1);
dy_ += sinangle_/6 * (brakeForce() - 1);