diff --git a/Content/Blueprints/BP_ZombieCharacter.uasset b/Content/Blueprints/BP_ZombieCharacter.uasset index d46e062..ff2164e 100644 --- a/Content/Blueprints/BP_ZombieCharacter.uasset +++ b/Content/Blueprints/BP_ZombieCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:eae19cff0d1a7ec399f2bed7ddebeb12a0cd1464b7cc3aac8997e573ce9f340f -size 35109 +oid sha256:96b498c17899f18649d1af2a84fb121464381a57d2c720e1b67754a4c459cd5a +size 35291 diff --git a/Content/Input/Actions/Restart.uasset b/Content/Input/Actions/Restart.uasset new file mode 100644 index 0000000..4a5fd37 --- /dev/null +++ b/Content/Input/Actions/Restart.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ef291271c7b8103e8cdbba9da0e9eda6b6373ff0eee807e60611f2ad9db4b52e +size 1326 diff --git a/Content/Input/InputMapping.uasset b/Content/Input/InputMapping.uasset index 5c9a5b6..0c46972 100644 --- a/Content/Input/InputMapping.uasset +++ b/Content/Input/InputMapping.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e74d6ed0dfcdf4c8763e8adcdbba02a4ddccea77272d024f064ff50f9d288c8b -size 4382 +oid sha256:da11530fbc1a44bde5eed884dd45e343c6a6bc6e85e5d8ef8dd4f2989067ed62 +size 5608 diff --git a/Source/EndlessZombie/EndlessZombieGameMode.cpp b/Source/EndlessZombie/EndlessZombieGameMode.cpp index 90ab1c2..5fc98f7 100644 --- a/Source/EndlessZombie/EndlessZombieGameMode.cpp +++ b/Source/EndlessZombie/EndlessZombieGameMode.cpp @@ -2,6 +2,7 @@ #include "EndlessZombieGameMode.h" #include "EndlessZombieCharacter.h" +#include "Kismet/GameplayStatics.h" #include "UObject/ConstructorHelpers.h" AEndlessZombieGameMode::AEndlessZombieGameMode() @@ -13,3 +14,9 @@ AEndlessZombieGameMode::AEndlessZombieGameMode() DefaultPawnClass = PlayerPawnBPClass.Class; } } + +void AEndlessZombieGameMode::RestartLevel() +{ + FName LevelName = FName(GetWorld()->GetCurrentLevel()->GetName()); + UGameplayStatics::OpenLevel(GetWorld(), LevelName); +} diff --git a/Source/EndlessZombie/EndlessZombieGameMode.h b/Source/EndlessZombie/EndlessZombieGameMode.h index 042ba4f..3297eb4 100644 --- a/Source/EndlessZombie/EndlessZombieGameMode.h +++ b/Source/EndlessZombie/EndlessZombieGameMode.h @@ -13,6 +13,8 @@ class AEndlessZombieGameMode : public AGameModeBase public: AEndlessZombieGameMode(); + + void RestartLevel(); }; diff --git a/Source/EndlessZombie/Obstacle.cpp b/Source/EndlessZombie/Obstacle.cpp index ab72661..637c091 100644 --- a/Source/EndlessZombie/Obstacle.cpp +++ b/Source/EndlessZombie/Obstacle.cpp @@ -42,9 +42,6 @@ void AObstacle::CollisionBeginOverlap(UPrimitiveComponent* OverlappedComponent, { 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(OtherActor); ZombieCharacter->Die(); } diff --git a/Source/EndlessZombie/ZombieCharacter.cpp b/Source/EndlessZombie/ZombieCharacter.cpp index e8d603f..c16f011 100644 --- a/Source/EndlessZombie/ZombieCharacter.cpp +++ b/Source/EndlessZombie/ZombieCharacter.cpp @@ -2,14 +2,16 @@ #include "ZombieCharacter.h" +#include "EndlessZombieGameMode.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 "Kismet/GameplayStatics.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 AZombieCharacter::AZombieCharacter() @@ -96,12 +98,12 @@ void AZombieCharacter::Tick(float DeltaTime) if (!bDied) { - TurnTimeline.TickTimeline(DeltaTime); + TurnTimeline.TickTimeline(DeltaTime); - if (!bTurning) - { - MoveForwardConstant(DeltaTime); - } + if (!bTurning) + { + MoveForwardConstant(DeltaTime); + } } } @@ -123,6 +125,9 @@ void AZombieCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom //EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Triggered, this, &AZombieCharacter::Crouch); //EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Triggered, this, &ACharacter::); //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(UGameplayStatics::GetGameMode(GetWorld())); + if (CurrentGameMode) + { + CurrentGameMode->RestartLevel(); + } +} + //void AZombieCharacter::Crouch(const FInputActionValue& Value) //{ // @@ -179,7 +193,7 @@ void AZombieCharacter::MoveForwardConstant(float DeltaTime) { if (bStraight) { - FVector vLocation = GetActorLocation(); + FVector vLocation = GetActorLocation(); fBaseSpeed += fAcceleration * DeltaTime; vLocation += GetActorForwardVector() * fBaseSpeed; SetActorLocation(vLocation); @@ -226,7 +240,7 @@ void AZombieCharacter::ControlTurning() { FRotator CurrentRotation = Controller->GetControlRotation(); CurrentRotation.Yaw += fVal * iSideTurn; - Controller->SetControlRotation(CurrentRotation); + Controller->SetControlRotation(CurrentRotation); } } diff --git a/Source/EndlessZombie/ZombieCharacter.h b/Source/EndlessZombie/ZombieCharacter.h index 3688a63..81ca22c 100644 --- a/Source/EndlessZombie/ZombieCharacter.h +++ b/Source/EndlessZombie/ZombieCharacter.h @@ -36,6 +36,9 @@ class ENDLESSZOMBIE_API AZombieCharacter : public ACharacter /** Crouch Input Action */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) class UInputAction* CrouchAction; + // Restart Input Action + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) + class UInputAction* RestartAction; public: // Sets default values for this character's properties @@ -50,6 +53,7 @@ protected: void Move(const FInputActionValue& Value); //void Crouch(const FInputActionValue& Value); + void RestartLevel(); public: // Called every frame