예제 #1
0
파일: game.cpp 프로젝트: sig-vip/Pacman
// for easy difficulty level
inline void Ghost::UpdateAI(double call_prob)
{
	double _ProbAI = 1 - ProbAI;

	SetProbAI(_ProbAI);
	UpdateAI(call_prob, false);
	SetProbAI(1 - _ProbAI);
}
예제 #2
0
void CsShipObject::Update() {
	btVector3 vel = mRigidBody->getLinearVelocity();
	float linVel = vel.length();
	// jet sound
	mJetSound.SetPosition(mRigidBody->getWorldTransform().getOrigin());
	mJetSound.SetVelocity(vel);
	mJetSound.UpdateSound();

	float pitchf = 1 + (linVel - 150) / 300.0f;
	alSourcef(mJetSound.mSource, AL_PITCH, pitchf);

	if (mAIShip == true) {
		UpdateAI();
		return;
	}

	// perform radar upadates (target autolocking)
	if (((int)CsGame::GetSingletonPtr()->GetGameTime()) % TARGET_SCAN_DELAY == 0) FindNewTarget(this);
	if (mTarget) {
		if (!mTarget->IsActive()) ResetTarget();
	}
	//SetTarget(CsGame::GetSingletonPtr()->GetGroundEnemyManager()->at(0)->GetNode());
	
	// clear and set forces (and torques as well)
	mRigidBody->clearForces();

	btQuaternion btQuat = GetConvertedTrans().getRotation();

	Ogre::Quaternion quat(btQuat.w(), btQuat.x(), btQuat.y(), btQuat.z());
	Ogre::Vector3 ogreZ = quat.zAxis();
	btVector3 zAxis = btVector3(ogreZ.x, ogreZ.y, ogreZ.z);

	Ogre::Vector3 ogreX = quat.xAxis();
	btVector3 xAxis = btVector3(ogreX.x, ogreX.y, ogreX.z);

	btVector3 yAxis = OgretoBullet(quat.yAxis());

	mRigidBody->applyCentralForce(-zAxis * mThrottleForce);

	// tweak velocity
	//float vel = mRigidBody->getLinearVelocity().length();
	mRigidBody->setLinearVelocity( -zAxis * 0.05 * linVel + 0.95 * mRigidBody->getLinearVelocity() );


	// roll;
	if (mRollTorque != 0) {
		mRigidBody->applyTorque(zAxis * mRollTorque);
		//mRigidBody->applyTorque(yAxis * mRollTorque / 2.0);
	}
	//if (mRollTorque != 0) mRigidBody->applyTorque(zAxis * mRollTorque / 100 * mass);

	// pitch
	//if (mPitchTorque != 0) mRigidBody->applyTorque(xAxis * mPitchTorque / 100 * mass);
	if (mPitchTorque != 0) mRigidBody->applyTorque(xAxis * mPitchTorque);
}
예제 #3
0
파일: main.cpp 프로젝트: Dansken/gamedev
void Update()
{
	// Calculate delta time
	clock_t clockNow = clock();
	clock_t deltaClock = clockNow - clockLastFrame;
	float deltaTime = float(deltaClock) / CLOCKS_PER_SEC;
	clockLastFrame = clockNow;


	// Calculate FPS
	framesCounter++;
	framesTimeCounter += deltaTime;
	if( framesTimeCounter >= 1.0 )
	{
		framesTimeCounter -= 1.0;
		fps = framesCounter;
		framesCounter = 0;
	}


	// Hero control
	if( IsKeyDown(VK_UP) )
		unitsData[heroIndex].yOrder = UnitOrder_Backward;
	else
		unitsData[heroIndex].yOrder = UnitOrder_None;


	if( IsKeyDown(VK_LEFT) )
		unitsData[heroIndex].xOrder = UnitOrder_Backward;
	else
	{
		if( IsKeyDown(VK_RIGHT) )
			unitsData[heroIndex].xOrder = UnitOrder_Forward;
		else
			unitsData[heroIndex].xOrder = UnitOrder_None;
	}


	// Update all units
	for( int u = 0; u < unitsCount; u++ )
		UpdateUnit( &unitsData[u], deltaTime );

	// Update AI
	UpdateAI();

	// Hero dead
	if( unitsData[heroIndex].health <= 0 )
		Initialize();
}
예제 #4
0
파일: game.cpp 프로젝트: sig-vip/Pacman
void Ghost::Update()
{
	UpdateCoord();

	if (objType != GOT_PLAYER)
	{
		UpdateAngle();
		UpdateAI(1, true);   // in order to ghosts don't stop

		// updating AI after moving to the next cell
		if (!(i == mi && j == mj))
		{
			if (pGame->IsDifficultyHard() && pGame->GetMode() == "rl")
			{
				if (Velocity == pGame->cGhostList().cbegin()->Velocity)
					UpdateAI(0.4, false);   //0.3
				else
					UpdateAI(0.8, false);   //0.2
			}
			else if (pGame->GetCell(i, j) == 4 || pGame->GetCell(i, j) == 5)
			{
				if (pGame->GetMode() == "s")
					UpdateAI(0.8, false);
				else
				{
					double call_prob = 0.8;             //0.5   0.8
					if (pGame->GetMode() == "rl")
						call_prob = 0.3;                //0.4   0.8   0.2

					if (pGame->IsDifficultyHard())
						// for labyrinth mode
						UpdateAI(call_prob, false);
					else
					{
						if (RANDOM < 0.7)
							UpdateAI(call_prob, false);
						else
							UpdateAI(call_prob);
					}
				}
			}
		}
	}

	Update_mij();   // isn't used if (objType == GOT_PLAYER) -> for future needs
}
예제 #5
0
void Npc::Update()
{	
	mTime = SDL_GetTicks(); // Gives time in milliseconds
	if (mHealth <= 0 && State() != AnimState::Death)
	{
		SetAnimState(AnimState::Death);
	}

	Position().x += mVelocity.x * mSpeed;
	Position().y -= mVelocity.y * mSpeed;

	UpdateAI();
	SetState();

	// Update Sprite
	mpSprite->Update();
	
	// Update Collider
	UpdateCollider();
	
	mPrevTime = mTime;	// Set previous time
}
예제 #6
0
            void UpdateAI(uint32 diff) override
            {
                if (!UpdateVictim())
                    return;

                if (me->HasReactState(REACT_AGGRESSIVE) && !_gateIsOpen && !IsOnSameSide(me, me->GetVictim()))
                {
                    // NBD: this should only happen in practice if there is nobody left alive on our side (we should open gate)
                    // thus we only do a cursory check to make sure (edge cases?)
                    if (Player* newTarget = FindEligibleTarget(me, _gateIsOpen))
                    {
                        me->getThreatManager().resetAllAggro();
                        me->AddThreat(newTarget, 1.0f);
                        AttackStart(newTarget);
                    }
                    else
                        OpenGate();
                }

                events.Update(diff);

                if (!_gateIsOpen && HealthBelowPct(30) && events.IsInPhase(PHASE_TWO))
                    OpenGate();

                while (uint32 eventId = events.ExecuteEvent())
                {
                    switch (eventId)
                    {
                        case EVENT_SUMMON:
                        {
                            if (RAID_MODE(waves10,waves25).size() <= _waveCount) // bounds check
                            {
                                TC_LOG_INFO("scripts", "GothikAI: Wave count %d is out of range for difficulty %d.", _waveCount, GetDifficulty());
                                break;
                            }
                            
                            std::list<Creature*> triggers;
                            me->GetCreatureListWithEntryInGrid(triggers, NPC_TRIGGER, 150.0f);
                            for (GothikWaveEntry entry : RAID_MODE(waves10, waves25)[_waveCount].first)
                                for (uint8 i = 0; i < entry.second; ++i)
                                {
                                    // GUID layout is as follows:
                                    // CGUID+4: center (back of platform) - primary rider spawn
                                    // CGUID+5: north (back of platform) - primary knight spawn
                                    // CGUID+6: center (front of platform) - second spawn
                                    // CGUID+7: south (front of platform) - primary trainee spawn
                                    uint32 targetDBGuid;
                                    switch (entry.first)
                                    {
                                        case NPC_LIVE_RIDER: // only spawns from center (back) > north
                                            targetDBGuid = (CGUID_TRIGGER + 4) + (i % 2);
                                            break;
                                        case NPC_LIVE_KNIGHT: // spawns north > center (front) > south
                                            targetDBGuid = (CGUID_TRIGGER + 5) + (i % 3);
                                            break;
                                        case NPC_LIVE_TRAINEE: // spawns south > center (front) > north
                                            targetDBGuid = (CGUID_TRIGGER + 7) - (i % 3);
                                            break;
                                        default:
                                            targetDBGuid = 0;
                                    }
                                
                                    for (Creature* trigger : triggers)
                                        if (trigger && trigger->GetSpawnId() == targetDBGuid)
                                        {
                                            DoSummon(entry.first, trigger, 1.0f, 15 * IN_MILLISECONDS, TEMPSUMMON_CORPSE_TIMED_DESPAWN);
                                            break;
                                        }
                                }

                            if (uint8 timeToNext = RAID_MODE(waves10, waves25)[_waveCount].second)
                                events.ScheduleEvent(EVENT_SUMMON, timeToNext * IN_MILLISECONDS, 0, PHASE_ONE);

                            ++_waveCount;
                            break;
                        }
                        case EVENT_DOORS_UNLOCK:
                            _gateCanOpen = true;
                            for (ObjectGuid summonGuid : summons)
                                if (Creature* summon = ObjectAccessor::GetCreature(*me, summonGuid))
                                    if (summon->IsAlive() && (!summon->IsInCombat() || summon->IsInEvadeMode()))
                                    {
                                        OpenGate();
                                        break;
                                    }
                            break;
                        case EVENT_PHASE_TWO:
                            events.SetPhase(PHASE_TWO);
                            events.ScheduleEvent(EVENT_TELEPORT, 20 * IN_MILLISECONDS, 0, PHASE_TWO);
                            events.ScheduleEvent(EVENT_HARVEST, 15 * IN_MILLISECONDS, 0, PHASE_TWO);
                            events.ScheduleEvent(EVENT_RESUME_ATTACK, 2 * IN_MILLISECONDS, 0, PHASE_TWO);
                            Talk(SAY_PHASE_TWO);
                            Talk(EMOTE_PHASE_TWO);
                            me->SetReactState(REACT_PASSIVE);
                            me->getThreatManager().resetAllAggro();
                            DoCastAOE(SPELL_TELEPORT_LIVE);
                            break;
                        case EVENT_TELEPORT:
                            if (!HealthBelowPct(30))
                            {
                                me->CastStop();
                                me->AttackStop();
                                me->StopMoving();
                                me->SetReactState(REACT_PASSIVE);
                                me->getThreatManager().resetAllAggro();
                                DoCastAOE(_lastTeleportDead ? SPELL_TELEPORT_LIVE : SPELL_TELEPORT_DEAD);
                                _lastTeleportDead = !_lastTeleportDead;

                                events.CancelEvent(EVENT_BOLT);
                                events.ScheduleEvent(EVENT_TELEPORT, 20 * IN_MILLISECONDS, 0, PHASE_TWO);
                                events.ScheduleEvent(EVENT_RESUME_ATTACK, 2 * IN_MILLISECONDS, 0, PHASE_TWO);
                            }
                            break;

                        case EVENT_HARVEST:
                            DoCastAOE(SPELL_HARVEST_SOUL, true); // triggered allows this to go "through" shadow bolt
                            events.ScheduleEvent(EVENT_HARVEST, 15 * IN_MILLISECONDS, 0, PHASE_TWO);
                            break;
                        case EVENT_RESUME_ATTACK:
                            me->SetReactState(REACT_AGGRESSIVE);
                            events.ScheduleEvent(EVENT_BOLT, 0, 0, PHASE_TWO);
                            // return to the start of this method so victim side etc is re-evaluated
                            return UpdateAI(0u); // tail recursion for efficiency
                        case EVENT_BOLT:
                            DoCastVictim(SPELL_SHADOW_BOLT);
                            events.ScheduleEvent(EVENT_BOLT, 1 * IN_MILLISECONDS, 0, PHASE_TWO);
                            break;
                        case EVENT_INTRO_2:
                            Talk(SAY_INTRO_2);
                            break;
                        case EVENT_INTRO_3:
                            Talk(SAY_INTRO_3);
                            break;
                        case EVENT_INTRO_4:
                            Talk(SAY_INTRO_4);
                            break;
                    }
                }
            }
예제 #7
0
파일: game.cpp 프로젝트: sig-vip/Pacman
DGLE_RESULT DGLE_API Game::Update(uint uiDeltaTime)
{
	bool key_escape, pause;

	pInput->GetKey(KEY_ESCAPE, key_escape);

	if (key_escape)
		pEngineCore->QuitEngine();

	pInput->GetKey(KEY_P, pause);

	if (pause)
	{
		if (PauseChange)
		{
			Pause = !Pause;
			PauseChange = false;
		}
	}
	else
		PauseChange = true;

	if (!Pause)
	{
		bool key_right, key_left, key_down, key_up;

		pInput->GetKey(KEY_RIGHT, key_right);
		pInput->GetKey(KEY_LEFT, key_left);
		pInput->GetKey(KEY_DOWN, key_down);
		pInput->GetKey(KEY_UP, key_up);

		// update game objects
		GhostList().begin()->UpdateAngle();
		if (key_right)
		{
			GhostList().begin()->SetDirection(true, true);
			GhostList().begin()->Update();
		}
		else if (key_left)
		{
			GhostList().begin()->SetDirection(true, false);
			GhostList().begin()->Update();
		}
		else if (key_down)
		{
			GhostList().begin()->SetDirection(false, true);
			GhostList().begin()->Update();
		}
		else if (key_up)
		{
			GhostList().begin()->SetDirection(false, false);
			GhostList().begin()->Update();
		}

		for (auto it = ++GhostList().begin(); it != GhostList().end(); ++it)
			it->Update();

		// swallow score and special items
		for (auto it = cItemList().cbegin(); it != cItemList().cend();)
		{
			bool flag = false;
			if (IsBlackFlagSet())
				for (auto this_ghost = ++cGhostList().cbegin(); this_ghost != cGhostList().cend(); ++this_ghost)
					if (this_ghost->Swallow(*it))
						flag = true;

			if (cGhostList().cbegin()->Swallow(*it) || flag)
				it = ItemList().erase(it);
			else
				++it;
		}
		if (CurrentLevel > PreviousLevel)
		{
			RestartLevel(false);
			PreviousLevel = CurrentLevel;
		}

		// swallow player and ghosts
		for (auto this_ghost = ++cGhostList().cbegin(); this_ghost != cGhostList().cend(); ++this_ghost)
		{
			if (this_ghost->Swallow(*cGhostList().cbegin()))
			{
				if (Lives > 1)
				{
					RestartLevel(true);
					Lives--;
				}
				else
					NewGame();

				break;
			}
			else if (IsHelpFlagSet())
				for (auto it = ++cGhostList().cbegin(); it != cGhostList().cend();)
					if (this_ghost->Swallow(*it))
						it = GhostList().erase(it);
					else
						++it;
		}

		// additional updating AI
		if (!(Counter % 15))
			for (auto it = ++GhostList().begin(); it != GhostList().end(); ++it)
				it->UpdateAI(0.1, false);     //0.25

		++Counter;
	}

	return S_OK;
}
void CGolem_Light::Update(float fDT)
{
	CBaseGolem::Update(fDT);
	UpdateAI();
}
예제 #9
0
파일: paddle.c 프로젝트: pasoev/praxis
void RunGame()
{
  UpdatePlayer();
  UpdateAI();
  UpdateBall();
}