Skip to content
Snippets Groups Projects
Commit a22032a6 authored by Yannis ROCHE's avatar Yannis ROCHE :x:
Browse files

Merge branch 'feat/gameplay'

parents 16b41d2f 29abc9d4
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
......@@ -114,19 +114,18 @@ void ATrafficVehicle::FrontCollisionCheck()
ATrafficVehicle* TrafficVehicle = Cast<ATrafficVehicle>(Hit.GetActor());
if (CustomGameInstance != nullptr)
{
if (!LaneChangeCheck())
{
// Set the speed of this vehicle to the speed of the other vehicle
fTargetSpeed = fSpeed;
fTargetWheelSpeed = fWheelSpeed;
fSpeed = TrafficVehicle->fSpeed;
fWheelSpeed = TrafficVehicle->fWheelSpeed;
OnSpeedChanged(fSpeed, fWheelSpeed);
}
LaneChangeCheck();
}
}
}
}
bool ATrafficVehicle::LaneChangeCheck()
void ATrafficVehicle::LaneChangeCheck()
{
float fFront = fMeshLength / 2;
float fTileSize = CustomGameInstance->fTileSize;
......@@ -151,13 +150,12 @@ bool ATrafficVehicle::LaneChangeCheck()
if ((fDirection > 0 && fTargetLane < CustomGameState->iNumberOfLane) ||
(fDirection < 0 && fTargetLane >= CustomGameState->iNumberOfLane))
{
LaneChangeComponent->ChangeLane(fDirection, 300);
return true;
// call a lambda after Timerhandle of 1 second
bIsBlinking = true;
GetWorld()->GetTimerManager().SetTimer(ChangeLaneTimerHandle, [this, fDirection]() { ChangeLaneCallback(fDirection); }, 1.0f, false);
}
return false;
}
}
return false;
}
// Called every frame
......@@ -167,8 +165,30 @@ void ATrafficVehicle::Tick(float DeltaTime)
Move_Implementation(DeltaTime);
FrontCollisionCheck();
LaneChangeComponent->UpdatePosition(DeltaTime);
BlinkLeft(DeltaTime);
}
void ATrafficVehicle::Move_Implementation(float DeltaTime)
{
// Set new location based on the speed and the facing direction
FVector NewLocation = GetActorLocation() + GetActorForwardVector() * fSpeed * DeltaTime;
SetActorLocation(NewLocation);
}
void ATrafficVehicle::ChangeLaneCallback(float fDirection)
{
LaneChangeComponent->ChangeLane(fDirection, 300);
bIsBlinking = false;
fSpeed = fTargetSpeed;
fWheelSpeed = fTargetWheelSpeed;
OnSpeedChanged(fSpeed, fWheelSpeed);
RearLeftBlinker->SetVisibility(false);
}
void ATrafficVehicle::BlinkLeft(float DeltaTime)
{
// Make the vehicle blink every 0.5 second
if (bIsBlinking) {
fBlinkElapsedTime += DeltaTime;
if (fBlinkElapsedTime >= 0.5f)
{
......@@ -176,10 +196,4 @@ void ATrafficVehicle::Tick(float DeltaTime)
fBlinkElapsedTime = 0.0f;
}
}
void ATrafficVehicle::Move_Implementation(float DeltaTime)
{
// Set new location based on the speed and the facing direction
FVector NewLocation = GetActorLocation() + GetActorForwardVector() * fSpeed * DeltaTime;
SetActorLocation(NewLocation);
}
......@@ -40,6 +40,8 @@ public:
// Blinkers (Rect lights)
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Blinker")
UPointLightComponent* RearLeftBlinker;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Blinker")
float fBlinkPeriod;
// Interface variables
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Movement")
......@@ -78,7 +80,7 @@ public:
void SetOrientation(EVehicleOrientation orientation);
void FrontCollisionCheck();
bool LaneChangeCheck();
void LaneChangeCheck();
void Move_Implementation(float DeltaTime);
......@@ -86,8 +88,15 @@ private:
ACustomGameState* CustomGameState;
UCustomGameInstance* CustomGameInstance;
float fTargetSpeed;
float fTargetWheelSpeed;
float fMeshLength;
float fMeshWidth;
float fBlinkElapsedTime;
FTimerHandle ChangeLaneTimerHandle;
void ChangeLaneCallback(float fDirection);
float fBlinkElapsedTime = 0.0f;
bool bIsBlinking = false;
void BlinkLeft(float DeltaTime);
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment