Пример #1
0
void AMech_RPGCharacter::Reset()
{
	if (GetCurrentWeapon() != nullptr) {
		GetCurrentWeapon()->Destroy();
		SetCurrentWeapon(nullptr);
	}

	abilities.Empty();
	armour.Empty();

	if (GetInventory() != nullptr) {
		GetInventory()->GetItems().Empty();
	}

	inventory = NewObject<UInventory>(UInventory::StaticClass());

	SetHealth(GetMaxHealth());

	channeling = false;
	inCombat = false;

	canAttack = 0;
	canMove = 0;
	canBeDamaged = 0;
}
Пример #2
0
void AMech_RPGCharacter::PostHealthChange(FHealthChange healthChange)
{
	CLAMP(health, GetMaxHealth(), 0);

	if (OnPostHealthChange.IsBound()) {
		OnPostHealthChange.Broadcast(healthChange);
	}

	UFloatingTextUI::CreateFloatingText(floatingTextClass, healthChange);

	if (health <= 0) {
		health = 0;
		SetDead(true);
		SetActorHiddenInGame(true);
		if (GetCurrentWeapon() != nullptr) GetCurrentWeapon()->SetActorHiddenInGame(true);
		OnStopFiring.Broadcast();
		healthChange.manipulator->EnemyKilled(this);

		if (GetGroup()->GetPlayer() == nullptr) {
			ItemEnumns::ItemType type = UMiscLibrary::GetRandomEnum(ItemEnumns::Resource);
			AItem* newItem = CalucluateItemDrop(healthChange.manipulator->GetGroup(), type);
			AItemPickup::CreateItemPickup(newItem)->SetActorLocation(GetActorLocation());
		}
	}

	if (GetFloatingStats() != nullptr) {
		GetFloatingStats()->UpdateHealthBar();
	}

	if (GetCharacterStats() != nullptr) {
		GetCharacterStats()->UpdateHealthBar();
	}
}
Пример #3
0
//--------------------------- TakeAimAndShoot ---------------------------------
//
//  this method aims the bots current weapon at the target (if there is a
//  target) and, if aimed correctly, fires a round
//-----------------------------------------------------------------------------
void Raven_WeaponSystem::TakeAimAndShoot()
{
	//aim the weapon only if the current target is shootable or if it has only
	//very recently gone out of view (this latter condition is to ensure the 
	//weapon is aimed at the target even if it temporarily dodges behind a wall
	//or other cover)
	if (m_pOwner->GetTargetSys()->isTargetShootable() ||
		(m_pOwner->GetTargetSys()->GetTimeTargetHasBeenOutOfView() <
		m_dAimPersistance))
	{
		//the position the weapon will be aimed at
		Vector2D AimingPos = m_pOwner->GetTargetBot()->Pos();

		//if the current weapon is not an instant hit type gun the target position
		//must be adjusted to take into account the predicted movement of the 
		//target
		if (GetCurrentWeapon()->GetType() == type_rocket_launcher ||
			GetCurrentWeapon()->GetType() == type_blaster)
		{
			AimingPos = PredictFuturePositionOfTarget();

			//if the weapon is aimed correctly, there is line of sight between the
			//bot and the aiming position and it has been in view for a period longer
			//than the bot's reaction time, shoot the weapon
			if (m_pOwner->RotateFacingTowardPosition(AimingPos) &&
				(m_pOwner->GetTargetSys()->GetTimeTargetHasBeenVisible() >
				m_dReactionTime) &&
				m_pOwner->hasLOSto(AimingPos))
			{
				AddFuzzyDeviationToAim(AimingPos);

				GetCurrentWeapon()->ShootAt(AimingPos);
			}
		}

		//no need to predict movement, aim directly at target
		else
		{
			//if the weapon is aimed correctly and it has been in view for a period
			//longer than the bot's reaction time, shoot the weapon
			if (m_pOwner->RotateFacingTowardPosition(AimingPos) &&
				(m_pOwner->GetTargetSys()->GetTimeTargetHasBeenVisible() >
				m_dReactionTime))
			{
				AddFuzzyDeviationToAim(AimingPos);

				GetCurrentWeapon()->ShootAt(AimingPos);
			}
		}

	}

	//no target to shoot at so rotate facing to be parallel with the bot's
	//heading direction
	else
	{
		m_pOwner->RotateFacingTowardPosition(m_pOwner->Pos() + m_pOwner->Heading());
	}
}
Пример #4
0
void AMech_RPGCharacter::SetActorHiddenInGame(bool bNewHidden)
{
	Super::SetActorHiddenInGame(bNewHidden);
	SetActorEnableCollision(!bNewHidden);

	if (GetCurrentWeapon() != nullptr) {
		GetCurrentWeapon()->SetActorHiddenInGame(bNewHidden);
	}
}
Пример #5
0
void AMech_RPGCharacter::RemoveFromPlay()
{
	stats->DestroyComponent();
	group->RemoveMember(this);
	//inventory->BeginDestroy();

	if (GetCurrentWeapon() != nullptr) {
		GetCurrentWeapon()->Destroy();
	}
	Destroy();
}
Пример #6
0
AMech_RPGCharacter::~AMech_RPGCharacter() {
	characters.Remove(this);
	abilities.Empty();
	armour.Empty();

	if (GetCurrentWeapon() != nullptr) {
		GetCurrentWeapon()->Destroy();
		SetCurrentWeapon(nullptr);
	}

	if (mIsChildOf(GetController(), AMech_RPGPlayerController::StaticClass())) {
		UMiscLibrary::SetPlayerController(nullptr);
	}
}
Пример #7
0
void CIVPedWeapons::SetAmmoInClip(DWORD dwAmmoInClip)
{
	CIVWeapon * pCurrentWeapon = GetCurrentWeapon();

	if(m_pPedWeapons && pCurrentWeapon)
	{
		WORD wClipSize = pCurrentWeapon->GetClipSize();

		if(dwAmmoInClip > wClipSize)
			dwAmmoInClip = wClipSize;

		DWORD dwCurrentAmmoInClip = pCurrentWeapon->GetAmmoInClip();
		pCurrentWeapon->SetAmmoInClip(dwAmmoInClip);

		DWORD dwCurrentAmmo = pCurrentWeapon->GetAmmoTotal();
		DWORD dwDifference = (dwAmmoInClip - dwCurrentAmmoInClip);

		if(dwDifference >= 25000)
			pCurrentWeapon->SetAmmoTotal(25000);

		DWORD dwNewAmmo = (dwCurrentAmmo + dwDifference);

		if(dwNewAmmo <= 25000)
			pCurrentWeapon->SetAmmoTotal(dwNewAmmo);
		else
			pCurrentWeapon->SetAmmoTotal(25000);
	}
}
Пример #8
0
bool Player::DetailInforDraw(Game_Manager* gm_, coord_def L_offset_, coord_def R_offset_)
{	
	for(list<Item*>::iterator it = gm_->item_list.begin();it != gm_->item_list.end();it++)
	{
		if((*it)->isValid() && (*it)->GetItemType() != IT_INSTANT)
		{
			if(collution((*it)->GetPos(), 10))
			{
				(*it)->DetailInforDraw(gm_->direct, L_offset_);
				break;
			}
		}
	}
	if(GetCurrentWeapon())
		GetCurrentWeapon()->DetailInforDraw(gm_->direct, R_offset_);
	return true;
}
Пример #9
0
DWORD CIVPedWeapons::GetAmmoInClip()
{
	CIVWeapon * pCurrentWeapon = GetCurrentWeapon();

	if(m_pPedWeapons && pCurrentWeapon)
		return pCurrentWeapon->GetAmmoInClip();

	return 0;
}
Пример #10
0
void AMech_RPGCharacter::SetCurrentWeapon(AWeapon* newVal) {
	if (newVal != nullptr && currentWeapon != newVal) {
		if (!GetInventory()->GetItems().Contains(newVal)) {
			AddItem(newVal);
		}

		if (GetCurrentWeapon() != nullptr) {
			GetCurrentWeapon()->Unequip();
		}

		if (OnSwappedWeapons.IsBound()) {
			OnSwappedWeapons.Broadcast(currentWeapon, newVal);
		}

		newVal->Equip();
	}

	currentWeapon = newVal;
}
Пример #11
0
void Player::SetCurrentWeaponType(WeaponTypes newType)
{
    if (firedLastFrame)
    {
        GetCurrentWeapon()->StopFire();
        firedLastFrame = false;
    }

    currentWeapon = newType;
}
Пример #12
0
void Player::Render(float elapsed, const RenderInfo& info)
{
    ActorContent::Instance.RenderPlayer(Pos, LookDir,
                                        Lvl->MatchData.TeamColors[MyTeam],
                                        Lvl->MatchData.TeamPlayerMeshIndex[MyTeam],
                                        info);

    
    //Render the weapon.
    auto posAndDir = GetWeaponPosAndDir();
    GetCurrentWeapon()->Render(posAndDir.first, posAndDir.second, info);
}
Пример #13
0
void AAgent::SelectWeapon(float Dist)
{
	// Get the currently equipped weapon
	ABaseWeapon* CurrentWeapon = GetCurrentWeapon();
	// New weapon to change to (Initialize as current weapon so it is not NULL/not initialized)
	ABaseWeapon* NewWeapon = CurrentWeapon;
	double CurrentDesirability = CurrentWeapon->CalculateDesirability(Dist);
	// The desirability of the most desirable weapon at the moment
	double TempDesirability = 0.0;
	if ((CurrentWeapon && NewWeapon) != NULL)
	{
		for (auto &it : Weapons)
		{
			if (it != NULL)
			{
				// Calculate the desirability of this weapon
				double OtherDesirability = it->CalculateDesirability(Dist);

				// If the this weapon is more desirable than the currently equipped weapon
				if (OtherDesirability > CurrentDesirability)
				{
					// Check for the first iteration of the Weapons array
					if (TempDesirability == 0.0)
					{
						// This is currently the most desirable weapon
						TempDesirability = OtherDesirability;
						// Set as new weapon to equip
						NewWeapon = it;
					}
					// Otherwise if this weapon's desirability is greater than the previous most desirable weapon
					else if (OtherDesirability > TempDesirability)
					{
						// This is the most desirable weapon
						TempDesirability = OtherDesirability;
						// Set this as the new weapon to equip
						NewWeapon = it;
					}// If a previous weapon in the array has a higher desirability score, do nothing
				}
			}
		}
		// If the current weapon isn't the same as the new weapon then
		// the weapon needs to be changed AND the currently equipped 
		// weapon's desirability is less than 30
		if ((CurrentWeapon != NewWeapon) && (CurrentDesirability < 30.0f))
			// Equip the weapon
			EquipWeapon(NewWeapon);
	}
}
Пример #14
0
DWORD CPedWeapons::GetAmmoBySlot(eWeaponSlot weaponSlot)
{
	if (m_pPedWeapons)
	{
		if(weaponSlot >= WEAPON_SLOT_MAX)
			return 0;

		CWeapon * pCurrentWeapon = GetCurrentWeapon();

		if(pCurrentWeapon && pCurrentWeapon->GetSlot() == weaponSlot)
			m_pWeaponSlots[weaponSlot]->SetAmmo(pCurrentWeapon->GetAmmoTotal());

		return m_pWeaponSlots[weaponSlot]->GetAmmo();
	}

	return 0;
}
Пример #15
0
//-------------------------- PredictFuturePositionOfTarget --------------------
//
//  predicts where the target will be located in the time it takes for a
//  projectile to reach it. This uses a similar logic to the Pursuit steering
//  behavior.
//-----------------------------------------------------------------------------
Vector2D Raven_WeaponSystem::PredictFuturePositionOfTarget()const
{
	double MaxSpeed = GetCurrentWeapon()->GetMaxProjectileSpeed();

	//if the target is ahead and facing the agent shoot at its current pos
	Vector2D ToEnemy = m_pOwner->GetTargetBot()->Pos() - m_pOwner->Pos();

	//the lookahead time is proportional to the distance between the enemy
	//and the pursuer; and is inversely proportional to the sum of the
	//agent's velocities
	double LookAheadTime = ToEnemy.Length() /
		(MaxSpeed + m_pOwner->GetTargetBot()->MaxSpeed());

	//return the predicted future position of the enemy
	return m_pOwner->GetTargetBot()->Pos() +
		m_pOwner->GetTargetBot()->Velocity() * LookAheadTime;
}
Пример #16
0
void CPlayerRotation::GetStanceAngleLimits( const SAimAccelerationParams& verticalAcceleration, IItem* pCurrentPlayerItem, float & minAngle,float & maxAngle)
{
	float fNewMinAngle = verticalAcceleration.angle_min;
	float fNewMaxAngle = verticalAcceleration.angle_max;

	CWeapon* pWeapon = GetCurrentWeapon( pCurrentPlayerItem );
	if (pWeapon)
	{
		float weaponMinAngle = fNewMinAngle;
		float weaponMaxAngle = fNewMaxAngle;
		pWeapon->GetAngleLimits(m_player.GetStance(), weaponMinAngle, weaponMaxAngle);
		fNewMinAngle = max(fNewMinAngle, weaponMinAngle);
		fNewMaxAngle = min(fNewMaxAngle, weaponMaxAngle);
	}
	
	minAngle = DEG2RAD(fNewMinAngle);
	maxAngle = DEG2RAD(fNewMaxAngle);
}
Пример #17
0
//-------------------------- RenderCurrentWeapon ------------------------------
//-----------------------------------------------------------------------------
void Raven_WeaponSystem::RenderCurrentWeapon()const
{
	GetCurrentWeapon()->Render();
}
Пример #18
0
//---------------------------- ShootAt ----------------------------------------
//
//  shoots the current weapon at the given position
//-----------------------------------------------------------------------------
void Raven_WeaponSystem::ShootAt(Vector2D pos)const
{
	GetCurrentWeapon()->ShootAt(pos);
}
Пример #19
0
bool CHUD::UpdateWeaponAccessoriesScreen()
{
	bool bWeaponHasAttachments = false;

	m_animWeaponAccessories.Invoke("clearAllSlotButtons");

	CWeapon *pCurrentWeapon = GetCurrentWeapon();
	if(pCurrentWeapon)
	{
		const CItem::THelperVector& helpers = pCurrentWeapon->GetAttachmentHelpers();
		for(int iHelper=0; iHelper<helpers.size(); iHelper++)
		{
			CItem::SAttachmentHelper helper = helpers[iHelper];
			if (helper.slot != CItem::eIGS_FirstPerson)
				continue;

			if(pCurrentWeapon->HasAttachmentAtHelper(helper.name))
			{
				// marcok: make sure the vars are correctly mapped
				SFlashVarValue args[3] = {helper.name.c_str(), "", ""};
				m_animWeaponAccessories.Invoke("addSlotButton", args, 3);
				//should really do not use dynamic strings here
				string strControl("Root.slot_");	strControl += helper.name.c_str();
				string strToken("hud.WS");	strToken += helper.name.c_str();	
				string strTokenX = strToken + "X";
				string strTokenY = strToken + "Y";
				m_animWeaponAccessories.AddVariable(strControl.c_str(),"_x",strTokenX.c_str(),1.0f,0.0f);
				m_animWeaponAccessories.AddVariable(strControl.c_str(),"_y",strTokenY.c_str(),1.0f,0.0f);

				string curAttach;
				{
					const char* szCurAttach = pCurrentWeapon->CurrentAttachment(helper.name);
					curAttach = (szCurAttach ? szCurAttach : "");
				}
				std::vector<string> attachments;
				pCurrentWeapon->GetAttachmentsAtHelper(helper.name, attachments);
				int iSelectedIndex = 0;
				int iCount = 0;
				if(attachments.size() > 0)
				{
					if(strcmp(helper.name,"magazine") && strcmp(helper.name,"attachment_front") && strcmp(helper.name,"energy_source_helper") && strcmp(helper.name,"shell_grenade"))
					{
						if(!strcmp(helper.name,"attachment_top"))
						{
							SFlashVarValue args[3] = {helper.name.c_str(), "@IronSight", "NoAttachment"};
							m_animWeaponAccessories.Invoke("addSlotButton", args, 3);
							++iCount;
						}
						else
						{
							SFlashVarValue args[3] = {helper.name.c_str(), "@NoAttachment", "NoAttachment"};
							m_animWeaponAccessories.Invoke("addSlotButton", args, 3);
							++iCount;
						}
					}
					for(int iAttachment=0; iAttachment<attachments.size(); iAttachment++)
					{
						// Ignore this item: it's a very special one!
						if(attachments[iAttachment] != "GrenadeShell")
						{
							string sName("@");
							sName.append(attachments[iAttachment]);
							SFlashVarValue args[3] = {helper.name.c_str(), sName.c_str(), attachments[iAttachment].c_str()};
							m_animWeaponAccessories.Invoke("addSlotButton", args, 3);
							if(curAttach == attachments[iAttachment])
							{
								iSelectedIndex = iCount;
							}
							bWeaponHasAttachments = bWeaponHasAttachments || iCount>0;
							++iCount;
						}
					}
				}
				if(curAttach)
				{
					SFlashVarValue args[2] = {helper.name.c_str(), iSelectedIndex};
					m_animWeaponAccessories.Invoke("selectSlotButton", args, 2);
				}
			}
			else ; // no attachment found for this helper
		}
		m_animWeaponAccessories.GetFlashPlayer()->Advance(0.25f);
	}

	return bWeaponHasAttachments;
}
Пример #20
0
void AAgent::EquipWeapon(ABaseWeapon* NewWeapon)
{
	// Get the currently equipped weapon
	if (GetCurrentWeapon() != NULL)
		// Destroy that weapon
		GetCurrentWeapon()->Destroy();

	// Spawn and equip the rifle
	FActorSpawnParameters SpawnParams;
	SpawnParams.Owner = this;
	SpawnParams.Instigator = Instigator;
	UWorld* World = GetWorld();
	if (World)
	{
		// Here we would spawn in the NewWeapon object and attach it
		// to the rootcomponent of the character. However I do have a
		// shotgun or a pistol asset (mesh, skeletal, material etc.) so
		// to visualize that they are equipped I shall merely display the 
		// shotgun or pistol animations respectively.
		if (NewWeapon == SpawnedPistol && ((NewWeapon && SpawnedPistol) != NULL))
		{
			bRifleEquipped = false;
			bShotgunEquipped = false;
			bPistolEquipped = true;

			NewWeapon = World->SpawnActor<APistol>(SpawnParams);
			if (NewWeapon != NULL)
			{
				NewWeapon->AttachRootComponentTo(ManMesh, TEXT("GunSocket"), EAttachLocation::SnapToTargetIncludingScale, true);
				SetCurrentWeapon(NewWeapon);
			}
		}
		else if (NewWeapon == SpawnedShotgun && ((NewWeapon && SpawnedShotgun) != NULL))
		{
			bRifleEquipped = false;
			bShotgunEquipped = true;
			bPistolEquipped = false;

			NewWeapon = World->SpawnActor<AShotgun>(SpawnParams);
			if (NewWeapon != NULL)
			{
				NewWeapon->AttachRootComponentTo(ManMesh, TEXT("GunSocket"), EAttachLocation::SnapToTargetIncludingScale, true);
				SetCurrentWeapon(NewWeapon);
			}
		}
		// However because the Rifle does have a mesh the spawn and attach code will need
		// to be added specifically for the instance where the rifle is equipped.
		else
		{
			bRifleEquipped = true;
			bShotgunEquipped = false;
			bPistolEquipped = false;

			NewWeapon = World->SpawnActor<ARifle>(SpawnParams);
			if (NewWeapon != NULL)
			{
				NewWeapon->AttachRootComponentTo(ManMesh, TEXT("GunSocket"), EAttachLocation::SnapToTargetIncludingScale, true);
				SetCurrentWeapon(NewWeapon);
			}
		}
	}
}
Пример #21
0
void CPlayerRotation::ProcessTargetAssistance( IItem* pCurrentPlayerItem )
{
	// aim assistance
	float targetAimAssistAngleFollowH;
	float targetAimAssistAngleFollowV;
	float targetAimAssistAngleScale;

	IPlayerInput * pIPlayerInput = m_player.GetPlayerInput();
	float absInput = 0.0f;

	float aimAssistPowerFactor = 1.0f;
	bool isUsingDedicatedInput = gEnv->IsDedicated();

#if (USE_DEDICATED_INPUT)
	isUsingDedicatedInput |= g_pGameCVars->g_playerUsesDedicatedInput ? true : false;
#endif

	if(pIPlayerInput && !isUsingDedicatedInput)
	{
		CRY_ASSERT(pIPlayerInput->GetType() == IPlayerInput::PLAYER_INPUT);
		CPlayerInput * pPlayerInput = static_cast<CPlayerInput*>(pIPlayerInput);

		const Ang3 rawDeltas = pPlayerInput->GetRawControllerInput();

		absInput = min((fabsf(rawDeltas.x) + fabsf(rawDeltas.z)) * 1.4f, 1.0f);

		aimAssistPowerFactor = 2.0f - absInput;
	}

	//Gather weapon info before processing target aim assistance
	bool playerWeaponIsRequestingSnap = false;
	CWeapon* pWeapon = GetCurrentWeapon( pCurrentPlayerItem );
	if (pWeapon)
	{
		playerWeaponIsRequestingSnap = pWeapon->ShouldSnapToTarget();
	}

	IMovementController* pMovementController = m_player.GetMovementController();
	CRY_ASSERT(pMovementController);
	SMovementState moveState;
	pMovementController->GetMovementState(moveState);

	Vec3 playerView[4] =
	{
		m_viewQuat.GetColumn0(), // Right
		m_viewQuat.GetColumn1(), // Forward
		m_viewQuat.GetColumn2(), // Up
		moveState.eyePosition    // Pos
	};

	IVehicle* pVehicle = m_player.GetLinkedVehicle();
	if (pVehicle)
	{
		Vec3 up(0.f,0.f,1.f);
		playerView[1] = moveState.eyeDirection;	// Forward
		playerView[0] = (playerView[1].cross(up)).GetNormalizedSafe(); // Right
		playerView[2] = playerView[0].cross(playerView[1]); // Up
	}

	float fZoomAmount = 0.0f;
	TargetAimAssistance(pWeapon, targetAimAssistAngleFollowH, targetAimAssistAngleFollowV, targetAimAssistAngleScale, fZoomAmount, playerView);

	targetAimAssistAngleScale = powf(targetAimAssistAngleScale, aimAssistPowerFactor);

	//TODO: Fix so it's not using auto aim unless selected

	float fFollowAssistScale = (absInput * (1.0f - fZoomAmount)) + min(absInput * fZoomAmount * __fres(g_pGameCVars->aim_assistInputForFullFollow_Ironsight), 1.0f);

	m_deltaAngles.z = (m_deltaAngles.z * targetAimAssistAngleScale) + (absInput * targetAimAssistAngleFollowH);
	m_deltaAngles.x = (m_deltaAngles.x * targetAimAssistAngleScale) + (absInput * targetAimAssistAngleFollowV);

	const bool snapToTarget = (!gEnv->bMultiplayer && playerWeaponIsRequestingSnap && !m_snap_target_dir.IsZero());
	const EntityId closeCombatSnapTargetId = g_pGame->GetAutoAimManager().GetCloseCombatSnapTarget();

	if (closeCombatSnapTargetId)
	{
		Vec3 snapDirection = GetCloseCombatSnapTargetDirection(closeCombatSnapTargetId);
		if (!snapDirection.IsZero())
		{
			const float blendSpeed = clamp_tpl( g_pGameCVars->pl_melee.melee_snap_blend_speed , 0.0f, 1.0f);
			m_deltaAngles.z = -asin_tpl(snapDirection * m_viewQuat.GetColumn0()) * blendSpeed;
			m_deltaAngles.x = asin_tpl(snapDirection * m_viewQuat.GetColumn2()) * blendSpeed;
		}
	}
	else if (snapToTarget)
	{
		const float zoomInTime = pWeapon->GetZoomInTime();
		const float blendFactor = clamp_tpl(pow_tpl((1.0f-zoomInTime),2.0f), 0.0f, 1.0f);
		m_deltaAngles.z = -asin_tpl(m_snap_target_dir * m_viewQuat.GetColumn0()) * blendFactor;
		m_deltaAngles.x = asin_tpl(m_snap_target_dir * m_viewQuat.GetColumn2()) * blendFactor;	
	}
	m_currently_snapping = playerWeaponIsRequestingSnap;

#if !defined(_RELEASE)
	if(g_pGameCVars->ctrlr_OUTPUTDEBUGINFO)
	{
		float white[] = {1,1,1,1};
		gEnv->pRenderer->Draw2dLabel( 20, 100, 1.4f, white, false, "Aim Acceleration & Assist\n  absInput: %.6f", absInput );
	}
#endif
}
Пример #22
0
u32 CAI_Stalker::GetWeaponAmmo() const
{
	if (!GetCurrentWeapon())
		return		(0);
	return			(GetCurrentWeapon()->GetSuitableAmmoTotal(true));	
}
Пример #23
0
void Player::ShootTo(const CCPoint & target)
{
	GetCurrentWeapon()->Fire(getPosition(), target);
}
Пример #24
0
void Player::Update(float elapsed)
{
    //Add friction into the acceleration.

    //If the player isn't accelerating, slow down his velocity completely.
    if (Acceleration.x == 0.0f && Acceleration.y == 0.0f)
    {
        if (Velocity.x != 0.0f || Velocity.y != 0.0f)
        {
            Acceleration = -Velocity * LevelConstants::Instance.PlayerFriction;
        }
    }
    else
    {
        //Split the acceleration and velocity into "forward" and "side" components.
        Vector2f forward = LookDir.XY().Normalized(),
                 side = Vector2f(forward.y, forward.x),
                 forwardA = forward * forward.Dot(Acceleration),
                 forwardV = forward * forward.Dot(Velocity),
                 sideA = side * side.Dot(Acceleration),
                 sideV = side * side.Dot(Velocity);

        //Add friction to any velocity components that go against the acceleration.
        if (forwardA.Dot(forwardV) < 0.0f && (abs(forwardV.x) > 0.00001f || abs(forwardV.y) > 0.00001f))
        {
            Acceleration -= forwardV.Normalized() * LevelConstants::Instance.PlayerFriction;
        }
        if (sideA.Dot(sideV) < 0.0f && (abs(sideV.x) > 0.00001f || abs(sideV.y) > 0.00001f))
        {
            Acceleration -= sideV.Normalized() * LevelConstants::Instance.PlayerFriction;
        }
    }


    //Update velocity and acceleration.
    Velocity += Acceleration * elapsed;
    Acceleration = Vector2f();

    //Constrain the velocity.
    float speedSqr = Velocity.LengthSquared();
    if (speedSqr > LevelConstants::Instance.PlayerMaxSpeed * LevelConstants::Instance.PlayerMaxSpeed)
    {
        Velocity = (Velocity / sqrtf(speedSqr)) * LevelConstants::Instance.PlayerMaxSpeed;
    }

    //Update position.
    TryMove(elapsed);


    //Handle weapons.
    if (Fire)
    {
        if (!firedLastFrame)
        {
            firedLastFrame = true;
            GetCurrentWeapon()->StartFire();
        }
        Fire = false;
    }
    else if (firedLastFrame)
    {
        GetCurrentWeapon()->StopFire();
        firedLastFrame = false;
    }
    GetCurrentWeapon()->Update(elapsed);
}