DWORD GObjectBulletPmp::Update(long idx) { this->Animations[State].ProcAnimation(Game::AnimationTicker::Tick); if(this->Animations[State].CurrentFrame == 1 ) { //do the dmg and destroy obj for(size_t i = 0; i < Game::ObjectBuffer::Buffer.size() ; i++) { GObject* Obj = Game::ObjectBuffer::Buffer[i]; if(IsPlayer(Obj->ObjectType) || IsBullet(Obj->ObjectType)) continue; float Distance = Vec3Distance(&this->Position , &Obj->Position); if(Distance < this->Radius + Obj->Radius ) { Obj->Health -= Power; Game::LastDamage = Power; } } } if(this->Animations[State].Ended) { this->Animations[State].ResetAnimation(); return OBJECT_DESTROY; } return OBJECT_IDLE; }
DWORD GObjectBonusAid::Update(long idx) { Animations[State].ProcAnimation(Game::AnimationTicker::Tick); float Distance = Vec3Distance(&this->Position , &Game::Player->Position);//distance between aid and player if(Distance < Radius) { //Add health ,adjust health , destroy object Game::Player->Health += 45.5f; if(Game::Player->Health > 255.0f) Game::Player->Health = 255.0f ; return OBJECT_DESTROY; } return OBJECT_IDLE; }
DWORD GObjectBonusPmp::Update(long idx) { this->Animations[State].ProcAnimation(Game::AnimationTicker::Tick); float Distance = Vec3Distance(&this->Position , &Game::Player->Position); if(Distance < this->Radius + Game::Player->Radius) { //give bullets Game::PmpAmmo += 5; ((GObjectPlayer*)Game::Player)->FireFunc = Gun::Pmp::Shoot; return OBJECT_DESTROY; } return OBJECT_IDLE; }
DWORD GObjectDecoreRock::Update(long idx) { for(int i = 0 ; i < Game::ObjectBuffer::Buffer.size() ; i++) { if(IsBullet(Game::ObjectBuffer::Buffer[i]->ObjectType)) { float Delta = Vec3Distance(&Position , &Game::ObjectBuffer::Buffer[i]->Position); if(Delta < Radius + Game::ObjectBuffer::Buffer[i]->Radius) { Game::ObjectBuffer::DestroyObject(i); i--; } } } return OBJECT_IDLE; }
DWORD GObjectBonusCrate::Update(long idx) { this->Animations[State].ProcAnimation(Game::AnimationTicker::Tick); float Distance = Vec3Distance(&this->Position , &Game::Player->Position); if(Distance < this->Radius + Game::Player->Radius) { Game::PmpAmmo += 2; Game::Grenades += 2; Game::Player->Health += 16.f; if(Game::Player->Health > 255.f)Game::Player->Health = 255.f; return OBJECT_DESTROY; } return OBJECT_IDLE; }
DWORD GObjectBulletSniper::Update(long idx) { float Distance = Vec3Distance(&Game::Player->Position , &this->Position); Position.x += Facing*BaseSpeed; if(fabsf(Position.x - Game::Player->Position.x) > 480.0f) { return OBJECT_DESTROY; } else if(Game::Player->Radius + this->Radius >= Distance) { Game::Player->Health -= this->Power; return OBJECT_DESTROY; } return OBJECT_IDLE; }
DWORD GObjectBonusCoin::Update(long idx) { Animations[State].ProcAnimation(Game::AnimationTicker::Tick); float Distance = Vec3Distance(&this->Position , &Game::Player->Position);//distance between coin and player if(Distance < Radius) { //Add points and destroy object Game::Points += 1.0f; Game::Player->Health += 1.23f; if(Game::Player->Health > 255.f)Game::Player->Health = 255.f; if(Game::Points > 99) { Game::Player->Health = 255.f; Game::Grenades += 3; Game::Points = 0; } return OBJECT_DESTROY; } return OBJECT_IDLE; }
/** Update the enemy's position. @param timeElapsed The time that has elapsed since the last clock tick. @see PrecisionTimer */ void Enemy::update(float time_elapsed) { Vector3 steering_force; Vector3 acceleration; if (mAlive && mHP > 0) { setHeight(mPosition); render(); steering_force = mSteering->calculate(); //calculate the combined force from each steering behavior in the vehicle's list acceleration = steering_force / mMass; //Acceleration = Force/Mass mVelocity += acceleration * time_elapsed; //update velocity mVelocity.truncate(mMaxSpeed); //make sure vehicle does not exceed maximum velocity mPosition += mVelocity * time_elapsed; //update the position //update the heading if the vehicle has a non zero velocity if (mVelocity.lengthSq() > 0.00000001) { mHeading = Vec3Normalize(mVelocity); mSide = Cross(mHeading, getRotation()); } float player_to_enemy = Vec3Distance(mGameWorld.mPlayer->mPosition, this->getPosition()); // If player is within n units of enemy. if (player_to_enemy <= 40) { this->mSteering->setTarget(mGameWorld.mPlayer->getPosition()); this->mSteering->followPathOff(); this->mSteering->seekOn(); float dx = mGameWorld.mPlayer->getPosition().x - this->getPosition().x; float dz = mGameWorld.mPlayer->getPosition().z - this->getPosition().z; setRotation(Vector3(0, RAD2DEG(atan2(dx,dz)), 0)); } else { float dx = mSteering->GetPath()->CurrentWaypoint().x - this->getPosition().x; float dz = mSteering->GetPath()->CurrentWaypoint().z - this->getPosition().z; setRotation(Vector3(0, RAD2DEG(atan2(dx,dz)), 0)); this->mSteering->followPathOn(); this->mSteering->seekOff(); } if (player_to_enemy <= 10) { playerCloseCounter++; if (playerCloseCounter > 30) { mGameWorld.mPlayer->hurt(5); // damage the player playerCloseCounter = 0; } mMesh.initAnim(2); } else { mMesh.initAnim(1); if (playerCloseCounter > 0) { playerCloseCounter--; } } if (player_to_enemy <= 15) { int mx, my, mb; CML_GetMouse(&mx,&my,&mb); if (hurtCounter == 0 && (mb & CML_INPUT_MOUSEBUTTON_LEFT)) { mMesh.initAnim(3); this->hurt(10); hurtCounter++; } else if (hurtCounter > 0 && hurtCounter <= 30) hurtCounter++; else if (hurtCounter > 30) hurtCounter = 0; } else { if (hurtCounter > 0) { hurtCounter--; } } } else if (mAlive && mHP <= 0) { mAlive = false; mGameWorld.mEnemyCounter--; } }
//////////////////////////////////////////////////// //Update DWORD GObjectEnemySniper::Update(long idx) { if(Health <= 0) { State = 2; } BOOL IsAttacking = State == 1; BOOL IsDieing = State == 2; if(IsDieing) { Animations[2].ProcAnimation(Game::AnimationTicker::Tick); if(Animations[2].Ended) { Game::ObjectBuffer::SpawnObject(OBJECT_MISC_COIN , this->Position , 0); int i = rand()% 100 + 1 ; if(i > 95) { Game::ObjectBuffer::SpawnObject(OBJECT_MISC_AID , this->Position , 0); } return OBJECT_DESTROY; } return OBJECT_IDLE; } if(IsAttacking) { Animations[1].ProcAnimation(Game::AnimationTicker::Tick); if(Animations[1].CurrentFrame == 2) { D3DXVECTOR3 BulletPosition = Position; BulletPosition.x += Facing*10.f; BulletPosition.y += sinf( float(rand()%6280)/1000.f - 6.28f)*7.f - 3.5f; Game::ObjectBuffer::SpawnObject(OBJECT_BULLET_SNIPER , BulletPosition , &Facing); } if(Animations[1].Ended) { Animations[1].ResetAnimation(); D3DXVECTOR3 BulletPosition = Position; BulletPosition.x += Facing*10.f; Game::ObjectBuffer::SpawnObject(OBJECT_BULLET_SNIPER , BulletPosition , &Facing); RandDir = D3DXVECTOR3(0,0,0); State = 0; } return OBJECT_IDLE; } if(State == 0) { if(RandDir == D3DXVECTOR3(0,0,0)) { this->RandDir.x = (float) (rand()% 100); this->RandDir.y = (float) (rand()% 100); float xdir = (float) (rand()% 100) - 50.f; xdir /= fabsf(xdir); float ydir = (float) (rand()% 100) - 50.f; ydir /= fabsf(ydir); this->RandDir.x *= xdir; this->RandDir.y *= ydir; this->RandDir.z = 0; D3DXVec3Normalize(&this->RandDir , &this->RandDir); } if(timeGetTime() - Time > 3000) { State = 1; Time = timeGetTime(); return OBJECT_IDLE; } D3DXVECTOR3 NewPos = Position + RandDir*CurrentSpeed; this->AdjustPositionToWorld(NewPos); bool IsPositionAcceptable = 1; for(size_t i = 0 ; i < Game::ObjectBuffer::Buffer.size() ; i++) { if(i == idx)continue; if(IsMisc(Game::ObjectBuffer::Buffer[i]->ObjectType))continue; IsPositionAcceptable = IsPositionAcceptable && !this->Collision(NewPos , i) ; } if(IsPositionAcceptable) { if(Position.x < NewPos.x)Facing = 1.f; else Facing = -1.f; float PosDelta = Vec3Distance(&Position , &NewPos); Position = NewPos; Animations[0].ProcAnimation(Game::AnimationTicker::Tick); if(PosDelta < BaseSpeed*0.8f) { RandDir.x *= -1.f; RandDir.y *= -1.f; } } else RandDir = D3DXVECTOR3(0,0,0); }//end if(State == 0) return OBJECT_IDLE; }