Restart implemented

Added the restart level functionality binding to the R key to test the game without stopping the engine
This commit is contained in:
JKuijperM 2023-03-12 11:05:03 +01:00
parent 4dcec8140a
commit 183adf599b
8 changed files with 46 additions and 19 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:eae19cff0d1a7ec399f2bed7ddebeb12a0cd1464b7cc3aac8997e573ce9f340f oid sha256:96b498c17899f18649d1af2a84fb121464381a57d2c720e1b67754a4c459cd5a
size 35109 size 35291

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ef291271c7b8103e8cdbba9da0e9eda6b6373ff0eee807e60611f2ad9db4b52e
size 1326

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:e74d6ed0dfcdf4c8763e8adcdbba02a4ddccea77272d024f064ff50f9d288c8b oid sha256:da11530fbc1a44bde5eed884dd45e343c6a6bc6e85e5d8ef8dd4f2989067ed62
size 4382 size 5608

View File

@ -2,6 +2,7 @@
#include "EndlessZombieGameMode.h" #include "EndlessZombieGameMode.h"
#include "EndlessZombieCharacter.h" #include "EndlessZombieCharacter.h"
#include "Kismet/GameplayStatics.h"
#include "UObject/ConstructorHelpers.h" #include "UObject/ConstructorHelpers.h"
AEndlessZombieGameMode::AEndlessZombieGameMode() AEndlessZombieGameMode::AEndlessZombieGameMode()
@ -13,3 +14,9 @@ AEndlessZombieGameMode::AEndlessZombieGameMode()
DefaultPawnClass = PlayerPawnBPClass.Class; DefaultPawnClass = PlayerPawnBPClass.Class;
} }
} }
void AEndlessZombieGameMode::RestartLevel()
{
FName LevelName = FName(GetWorld()->GetCurrentLevel()->GetName());
UGameplayStatics::OpenLevel(GetWorld(), LevelName);
}

View File

@ -13,6 +13,8 @@ class AEndlessZombieGameMode : public AGameModeBase
public: public:
AEndlessZombieGameMode(); AEndlessZombieGameMode();
void RestartLevel();
}; };

View File

@ -42,9 +42,6 @@ void AObstacle::CollisionBeginOverlap(UPrimitiveComponent* OverlappedComponent,
{ {
if (OtherActor->IsA(AZombieCharacter::StaticClass())) if (OtherActor->IsA(AZombieCharacter::StaticClass()))
{ {
UE_LOG(LogTemp, Warning, TEXT("[AObstacle::CollisionBeginOverlap] Se ha chocao Paco"));
GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Red, TEXT("Se ha chocao Paco"));
AZombieCharacter* ZombieCharacter = Cast<AZombieCharacter>(OtherActor); AZombieCharacter* ZombieCharacter = Cast<AZombieCharacter>(OtherActor);
ZombieCharacter->Die(); ZombieCharacter->Die();
} }

View File

@ -2,14 +2,16 @@
#include "ZombieCharacter.h" #include "ZombieCharacter.h"
#include "EndlessZombieGameMode.h"
#include "Camera/CameraComponent.h" #include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/InputComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "GameFramework/Controller.h"
#include "GameFramework/SpringArmComponent.h"
#include "EnhancedInputComponent.h" #include "EnhancedInputComponent.h"
#include "Kismet/GameplayStatics.h"
#include "EnhancedInputSubsystems.h" #include "EnhancedInputSubsystems.h"
#include "GameFramework/Controller.h"
#include "Components/InputComponent.h"
#include "Components/CapsuleComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
// Sets default values // Sets default values
AZombieCharacter::AZombieCharacter() AZombieCharacter::AZombieCharacter()
@ -123,6 +125,9 @@ void AZombieCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom
//EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Triggered, this, &AZombieCharacter::Crouch); //EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Triggered, this, &AZombieCharacter::Crouch);
//EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Triggered, this, &ACharacter::); //EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Triggered, this, &ACharacter::);
//EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Completed, this, &ACharacter::StopCrouching); //EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Completed, this, &ACharacter::StopCrouching);
// RestartLevel
EnhancedInputComponent->BindAction(RestartAction, ETriggerEvent::Started, this, &AZombieCharacter::RestartLevel);
} }
} }
@ -148,6 +153,15 @@ void AZombieCharacter::Move(const FInputActionValue& Value)
} }
} }
void AZombieCharacter::RestartLevel()
{
AEndlessZombieGameMode* CurrentGameMode = Cast<AEndlessZombieGameMode>(UGameplayStatics::GetGameMode(GetWorld()));
if (CurrentGameMode)
{
CurrentGameMode->RestartLevel();
}
}
//void AZombieCharacter::Crouch(const FInputActionValue& Value) //void AZombieCharacter::Crouch(const FInputActionValue& Value)
//{ //{
// //

View File

@ -36,6 +36,9 @@ class ENDLESSZOMBIE_API AZombieCharacter : public ACharacter
/** Crouch Input Action */ /** Crouch Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* CrouchAction; class UInputAction* CrouchAction;
// Restart Input Action
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* RestartAction;
public: public:
// Sets default values for this character's properties // Sets default values for this character's properties
@ -50,6 +53,7 @@ protected:
void Move(const FInputActionValue& Value); void Move(const FInputActionValue& Value);
//void Crouch(const FInputActionValue& Value); //void Crouch(const FInputActionValue& Value);
void RestartLevel();
public: public:
// Called every frame // Called every frame