Esempio n. 1
0
void ACloud10Character::bounceJump(float Value)
{
	float curJumpVelocity = Value;
	float jumpVelocity;
	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("bounceJump"));
	const FVector ForwardDir = GetActorForwardVector();
	/*bounceCount++;
	if(bounceCount > 1)
	{
		jumpVelocity = jumpVelocity * 1.3;
	}*/
	//if player has landed, reset jumpVelocity
	/*if (curJumpVelocity < baseJumpForce)
		jumpVelocity = baseJumpForce;*/

	//thresholds for jump velocity's that convert to force?
	//max jump?
	if (curJumpVelocity >= 3000)
	{
		curJumpVelocity = 3000;
	}
	//add only player's vertical speed to the last jump Velocity
	jumpVelocity = FMath().Abs(curJumpVelocity) + baseJumpForce;
	FVector AddForce = FVector(0, 0, 1) * jumpVelocity;
	//separate max walk speed from max fall speed
		//GetCharacterMovement()->MaxWalkSpeed = AddForce.Size();
	//convert float to string
	FString tempString = FString::SanitizeFloat(AddForce.Size());
	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, *tempString);
	LaunchCharacter(AddForce, false, true);
	//bPressedJump = true;
	//jumpVelocity = 600;
}
float AGGJ16_Player::TakeDamage(float DamageAmount, struct FDamageEvent const &DamageEvent, class AController* EventInstigator, AActor* DamageCauser)
{
	if (!bDamaged)
	{
		health -= DamageAmount;
	}

	if (health <= 0)
	{
		playDeathAnim = true;
	}
	else
	{
		bDamaged = true;
	}

	if (DamageCauser)
	{
		FVector curForwardVector = DamageCauser->GetActorLocation() - this->GetActorLocation();
		curForwardVector.ProjectOnTo(FVector(1, 1, 0));
		curForwardVector.Normalize();
		LaunchCharacter(curForwardVector * KnockBackAlpha, true, true);
	}

	return 0.f;
	//do the pretty things
};
Esempio n. 3
0
void APlayerCharacter::StartJump()
{
	if (GetCharacterMovement()->IsMovingOnGround() || _jumpCount == 0)
	{
		bPressedJump = true;
		_jumpCount++;
	}
	else if (_jumpCount == 1)
	{
		LaunchCharacter(FVector(0, 0, 600), false, true);
		_jumpCount++;
	}
}
/*Launchs the character in the desired direction*/
void ALivingEntity::Dodge(DodgeEnums::DodgeDirection dodgeDirection = DodgeEnums::Backwards)
{
	if (GetCharacterMovement()->IsMovingOnGround())
	{
		const FVector ForwardDir = GetActorRightVector();
		const FVector AddForce = GetForceForRoll(dodgeDirection, ForwardDir);

		GetController()->StopMovement();
		LaunchCharacter(AddForce, true, true);

		DodgeAction* tempDefenseAction = new DodgeAction();
		CurrentAction = tempDefenseAction;
	}
}
void ATotemCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	if (TimeSinceHit > 0.0f)
	{
		TimeSinceHit -= DeltaTime;
	}
	else
	{
		PreviousHit.controller = nullptr;
		PreviousHit.type = AbilityType::NONE;
		PreviousHit.name = "";
	}

	if (bThirdPersonDeathCamLerp)
	{
		if (Controller)
		{
			Controller->SetControlRotation(FRotator(-1.0f * DeathCamAngle, 0, 0));
		}
	}

	if (bThirdPersonCamLerp || bThirdPersonDeathCamLerp )
	{
		CameraBoom->TargetArmLength = FMath::Lerp<float>(CameraBoom->TargetArmLength, ThirdPersonCamDistance, DeltaTime*4.0f);
	}
	else
	{
		CameraBoom->TargetArmLength = FMath::Lerp<float>(CameraBoom->TargetArmLength, 0, DeltaTime*4.0f);
	}

	if (bIsDead && (ThirdPersonCamDistance!= ThirdPersonDeathCamDistance))
	{
		ThirdPersonCamDistance = ThirdPersonDeathCamDistance;
	}

	if ( ((FMath::Abs(CameraBoom->TargetArmLength - ThirdPersonCamDistance) < 0.5f) && bIsDead && bThirdPersonDeathCamLerp))
	{
		ATotemPlayerController *PC = Cast<ATotemPlayerController>(Controller);
		if (PC)
		{
			if (HasAuthority())
			{
				PC->HandleDead(FVector(0, 0, 0), FRotator(0, 0, 0));
			}
			bThirdPersonDeathCamLerp = false;
		}
	}

	if (bDeathEffectFired && RayCastOnGround() )
	{
		FireMaterialEffect();
		bDeathEffectFired = false;
	}

	if ((CameraBoom->TargetArmLength > 0.5f) && (!bIsShamanVisible))
	{
		if (GEngine->GetGamePlayer(GetWorld(), 0)->PlayerController == Controller)
		{
			MakeSelfVisible();
			bIsShamanVisible = true;
		}
	}
	
	if ((CameraBoom->TargetArmLength <= 0.5f) && (bIsShamanVisible))
	{
		if (GEngine->GetGamePlayer(GetWorld(), 0)->PlayerController == Controller)
		{
			MakeSelfInvisible();
			bIsShamanVisible = false;
		}
	}

	if (Controller && FirstTick)
	{
		if (GEngine->GetGamePlayer(GetWorld(), 0)->PlayerController == Controller)
		{
			MakeSelfInvisible();
			bIsShamanVisible = false;
		}
		FirstTick = false;
	}

	ATotemPlayerState *TotemPlayerState = Cast<ATotemPlayerState>(PlayerState);
	if (TotemPlayerState && bFirstSpawn)
	{
		SetActorLocation(TotemPlayerState->StartingLocation);
		SetActorRotation(TotemPlayerState->StartingRotation);
		bFirstSpawn = false;
	}

	if (bReborn && HasAuthority())
	{
		TotalRebornDuration -= DeltaTime;
		if (TotalRebornDuration < 0.0f)
		{
			bReborn = false;
			ExitReborn();
		}
	}


	if (HasAuthority())
	{
		if (bBeingKnockedBack)
		{
			TimeSinceKnockedBack -= DeltaTime;
			if (TimeSinceKnockedBack < 0.0f)
			{
				bBeingKnockedBack = false;
			}
		}
#if (WRITE_METRICS > 1)
		if (DeltaTime >= .025)
		{
			ATotemPlayerController* control = Cast<ATotemPlayerController>(Controller);
			if(control)
			{
				ATotemPlayerState* state = Cast<ATotemPlayerState>(control->PlayerState);
				if(state)
				{
					std::string team;
					switch (state->Team)
					{
					case ETeam::RED_TEAM:
						team = "Red";
						break;
					case ETeam::BLUE_TEAM:
						team = "Blue";
						break;
					default:
						team = "None";
						break;
					}
					Metrics::WriteToFile(std::string(TCHAR_TO_UTF8(*(state->MyName))), team, std::string("Frame rate hit"), std::string(std::to_string(DeltaTime) + "ms"), std::string(std::to_string(1.0f/DeltaTime) + "fps"));
				}
			}
		}
#endif
	}


	//Keep track of how long has passed since the last attack
	TimeSinceAttack += DeltaTime;
	ShotPressedDuration += DeltaTime;

	//If shot is pressed and enough time has been pressed
	if (ShotPressed && TimeSinceAttack >= TimeBetweenShots)
	{
		//And you either can rapid fire or no shot has been fired since the shot button was pressed
		if (CanRapidFire || !ShotFired)
		{
			OnFire();
			ShotFired = true;
			TimeSinceAttack = 0.0f;
		}
	}
	else if (!ShotPressed)
	{
		ShotPressedDuration = 0;
	}

	//If get hit by cyclone, then the shaman cannnot move
	if (HasAuthority())
	{
		TArray<AActor* > OverlappedActors;
		TArray<ACyclone* > OverlappedCyclones;
		GetOverlappingActors(OverlappedActors);
		for (int32 i = 0; i < OverlappedActors.Num(); i++)
		{
			ACyclone* Cyclone = Cast<ACyclone>(OverlappedActors[i]);
			if (Cyclone && !Cyclone->IsPendingKill())
			{
				//overlap myself doesn't count
				if (Cyclone->GetOwner() != GetController())
				{
					OverlappedCyclones.Add(Cyclone);
				}
			}
		}

		if (OverlappedCyclones.Num() == 0)
		{
			//Do this to prevent bCanMove be replictated every frame
			if (!bCanMove)
			{
				bCanMove = true;
			}
			AttachCyclone = nullptr;
		}
		else if (OverlappedCyclones.Num() > 0)
		{
			if (bCanMove)
			{
				bCanMove = false;
			}
			if (AttachCyclone)
			{
				FVector CycloneVelocity = AttachCyclone->ProjectileMovement->Velocity;
				ATotemPlayerController* own = Cast<ATotemPlayerController>(AttachCyclone->GetOwner());
				if (own)
				{
					ReduceHealth(AttachCyclone->Damage * DeltaTime, own, AbilityType::WIND, FName(TEXT("Cyclone"))); //every second reduce Damage amount of health
				}
				LaunchCharacter(CycloneVelocity, true, true);
			}
			//CharacterMovement->Velocity = CycloneVelocity;
		}
	}

	//temporary solution, maybe later we need more fancy stuff.
	if (bIsDead && HasAuthority())
	{
		CurrentDeadBodyDuration -= DeltaTime;
		if (CurrentDeadBodyDuration <= 0)
		{
			Destroy();
		}
	}

	if (bClickedThisFrame)
	{
		bClickedThisFrame = false;
		if (Controller)
		{
			APlayerController* control = Cast<APlayerController>(Controller);
			if (control)
			{
				if (!control->IsInputKeyDown(EKeys::LeftMouseButton))
				{
					LeftUp();
				}
			}
		}
	}

	if (bRightButtonDownThisFrame)
	{
		bRightButtonDownThisFrame = false;
		if (Controller)
		{
			APlayerController* control = Cast<APlayerController>(Controller);
			if (control)
			{
				if (!control->IsInputKeyDown(EKeys::RightMouseButton))
				{
					RightUp();
				}
			}
		}
	}

	//CheckShiftKey();

}