diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f4334a5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +Binaries +DerivedDataCache +Intermediate +Saved +.vscode +.vs +*.VC.db +*.opensdf +*.opendb +*.sdf +*.sln +*.suo +*.xcodeproj +*.xcworkspace \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..306e1e3 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# CodRemake + +Developed with Unreal Engine 5 diff --git a/Source/CodRemake.Target.cs b/Source/CodRemake.Target.cs new file mode 100644 index 0000000..6796651 --- /dev/null +++ b/Source/CodRemake.Target.cs @@ -0,0 +1,15 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +using UnrealBuildTool; +using System.Collections.Generic; + +public class CodRemakeTarget : TargetRules +{ + public CodRemakeTarget(TargetInfo Target) : base(Target) + { + Type = TargetType.Game; + DefaultBuildSettings = BuildSettingsVersion.V4; + IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_3; + ExtraModuleNames.Add("CodRemake"); + } +} diff --git a/Source/CodRemake/CodRemake.Build.cs b/Source/CodRemake/CodRemake.Build.cs new file mode 100644 index 0000000..7180fcd --- /dev/null +++ b/Source/CodRemake/CodRemake.Build.cs @@ -0,0 +1,23 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +using UnrealBuildTool; + +public class CodRemake : ModuleRules +{ + public CodRemake(ReadOnlyTargetRules Target) : base(Target) + { + PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; + + PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput" }); + + PrivateDependencyModuleNames.AddRange(new string[] { }); + + // Uncomment if you are using Slate UI + // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" }); + + // Uncomment if you are using online features + // PrivateDependencyModuleNames.Add("OnlineSubsystem"); + + // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true + } +} diff --git a/Source/CodRemake/CodRemake.cpp b/Source/CodRemake/CodRemake.cpp new file mode 100644 index 0000000..34e19cc --- /dev/null +++ b/Source/CodRemake/CodRemake.cpp @@ -0,0 +1,6 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "CodRemake.h" +#include "Modules/ModuleManager.h" + +IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, CodRemake, "CodRemake" ); diff --git a/Source/CodRemake/CodRemake.h b/Source/CodRemake/CodRemake.h new file mode 100644 index 0000000..677c8e2 --- /dev/null +++ b/Source/CodRemake/CodRemake.h @@ -0,0 +1,6 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include "CoreMinimal.h" + diff --git a/Source/CodRemake/GameMode/SinglePlayerGameModeBase.cpp b/Source/CodRemake/GameMode/SinglePlayerGameModeBase.cpp new file mode 100644 index 0000000..62d9a60 --- /dev/null +++ b/Source/CodRemake/GameMode/SinglePlayerGameModeBase.cpp @@ -0,0 +1,15 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "SinglePlayerGameModeBase.h" + +#include "UObject/ConstructorHelpers.h" + +ASinglePlayerGameModeBase::ASinglePlayerGameModeBase(): Super() +{ + static ConstructorHelpers::FClassFinder PlayerPawnClassFinder(TEXT("/Script/Engine.Blueprint'/Game/Player/Blueprints/BP_PlayerCharacter.BP_PlayerCharacter_C'")); + if (PlayerPawnClassFinder.Succeeded()) + { + DefaultPawnClass = PlayerPawnClassFinder.Class; + } +} \ No newline at end of file diff --git a/Source/CodRemake/GameMode/SinglePlayerGameModeBase.h b/Source/CodRemake/GameMode/SinglePlayerGameModeBase.h new file mode 100644 index 0000000..324b6cf --- /dev/null +++ b/Source/CodRemake/GameMode/SinglePlayerGameModeBase.h @@ -0,0 +1,21 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/GameModeBase.h" +#include "SinglePlayerGameModeBase.generated.h" + +/** + * + */ +UCLASS() +class CODREMAKE_API ASinglePlayerGameModeBase : public AGameModeBase +{ + GENERATED_BODY() + + ASinglePlayerGameModeBase(); + +}; + + diff --git a/Source/CodRemake/Player/PlayerCharacter.cpp b/Source/CodRemake/Player/PlayerCharacter.cpp new file mode 100644 index 0000000..da1498f --- /dev/null +++ b/Source/CodRemake/Player/PlayerCharacter.cpp @@ -0,0 +1,169 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "PlayerCharacter.h" + +#include "EnhancedInputSubsystems.h" +#include "EnhancedInputComponent.h" +#include "DrawDebugHelpers.h" +#include "InputAction.h" +#include "Components/CapsuleComponent.h" + + +// Sets default values +APlayerCharacter::APlayerCharacter() +{ + // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. + PrimaryActorTick.bCanEverTick = true; + + CameraComponent = CreateDefaultSubobject(TEXT("FirstPersonCamera")); + CameraComponent->SetupAttachment(GetCapsuleComponent()); + CameraComponent->SetRelativeLocation(FVector(-10.f, 0.f, 80.f)); // Position the camera + CameraComponent->bUsePawnControlRotation = true; + + + GetCapsuleComponent()->InitCapsuleSize(40.0f, 90.0f); + + USkeletalMeshComponent* MeshComp = GetMesh(); + check(MeshComp); + MeshComp->SetRelativeRotation(FRotator(0.0f, -90.0f, 0.0f)); + // Rotate mesh to be X forward since it is exported as Y forward. + MeshComp->SetRelativeLocation(FVector(0.0f, 0.0f, -90.0f)); + MeshComp->SetupAttachment(GetCapsuleComponent()); + MeshComp->SetCollisionProfileName(TEXT("Mesh")); + MeshComp->bCastDynamicShadow = false; + MeshComp->CastShadow = false; + + BaseEyeHeight = 80.0f; + CrouchedEyeHeight = 50.0f; +} + +// Called when the game starts or when spawned +void APlayerCharacter::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +void APlayerCharacter::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + + TObjectPtr world = GetWorld(); + if (world != nullptr) + { + + FHitResult HitResult; + const FVector Start = GetActorLocation(); + const FVector End = GetActorForwardVector() * 100 + Start; + const FCollisionObjectQueryParams QueryParams(FCollisionObjectQueryParams::AllStaticObjects); + + DrawDebugLine(world, Start, End, FColor::Green, false, 1, 0, 1); + world->LineTraceSingleByObjectType(HitResult, Start, End, QueryParams); + + if (HitResult.bBlockingHit) + { + if (GEngine != nullptr) + { + GEngine->AddOnScreenDebugMessage( + -1, + 1.f, + FColor::Red, + FString::Printf(TEXT("You are hitting: %s"), + *HitResult.GetActor()->GetName() + )); + } + } + } +} + +#pragma region Inputs + + +// Called to bind functionality to input +void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) +{ + Super::SetupPlayerInputComponent(PlayerInputComponent); + // Get the player controller + APlayerController* PC = Cast(GetController()); + + // Get the local player subsystem + UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(PC->GetLocalPlayer()); + // Clear out existing mapping, and add our mapping + Subsystem->ClearAllMappings(); + Subsystem->AddMappingContext(InputMapping, 0); + + // Get the EnhancedInputComponent + UEnhancedInputComponent* PEI = Cast(PlayerInputComponent); + + // Bind the actions + PEI->BindAction(IA_Move, ETriggerEvent::Triggered, this, &APlayerCharacter::Move); + PEI->BindAction(IA_Look, ETriggerEvent::Triggered, this, &APlayerCharacter::Look); + PEI->BindAction(IA_Jump, ETriggerEvent::Triggered, this, &APlayerCharacter::ActivateJump); + +} + +void APlayerCharacter::Move(const FInputActionValue& Value) +{ + if (Controller != nullptr) + { + const FVector2D MoveValue = Value.Get(); + const FRotator MovementRotation(0, Controller->GetControlRotation().Yaw, 0); + + // Forward/Backward direction + if (MoveValue.Y != 0.f) + { + // Get forward vector + const FVector Direction = MovementRotation.RotateVector(FVector::ForwardVector); + + AddMovementInput(Direction, MoveValue.Y); + } + + // Right/Left direction + if (MoveValue.X != 0.f) + { + // Get right vector + const FVector Direction = MovementRotation.RotateVector(FVector::RightVector); + + AddMovementInput(Direction, MoveValue.X); + } + } +} + +void APlayerCharacter::Look(const FInputActionValue& Value) +{ + if (Controller != nullptr) + { + const FVector2D LookValue = Value.Get(); + + if (LookValue.X != 0.f) + { + AddControllerYawInput(LookValue.X); + } + + if (LookValue.Y != 0.f) + { + AddControllerPitchInput(LookValue.Y); + } + } +} + +void APlayerCharacter::ActivateJump(const FInputActionValue& Value) +{ + if (Controller != nullptr) + { + const bool JumpValue = Value.Get(); + if (JumpValue) + { + Jump(); + } + else + { + StopJumping(); + } + } +} + +#pragma endregion + diff --git a/Source/CodRemake/Player/PlayerCharacter.h b/Source/CodRemake/Player/PlayerCharacter.h new file mode 100644 index 0000000..bb3701d --- /dev/null +++ b/Source/CodRemake/Player/PlayerCharacter.h @@ -0,0 +1,56 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Camera/CameraComponent.h" +#include "GameFramework/Character.h" +#include "InputAction.h" +#include "PlayerCharacter.generated.h" + +UCLASS() +class CODREMAKE_API APlayerCharacter : public ACharacter +{ + GENERATED_BODY() + +public: + // Sets default values for this character's properties + APlayerCharacter(); + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Player|Character", Meta = (AllowPrivateAccess = "true")) + TObjectPtr CameraComponent; + +#pragma region Inputs + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Player|Enhanced Input") + class UInputMappingContext* InputMapping; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Player|Enhanced Input") + UInputAction* IA_Move; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Player|Enhanced Input") + UInputAction* IA_Look; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Player|Enhanced Input") + UInputAction* IA_Jump; + + // Handle move input + void Move(const FInputActionValue& Value); + + // Handle look input + void Look(const FInputActionValue& Value); + + void ActivateJump(const FInputActionValue& Value); +#pragma endregion + +public: + // Called every frame + virtual void Tick(float DeltaTime) override; + + // Called to bind functionality to input + virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; +}; diff --git a/Source/CodRemake/Weapon/BaseWeapon.cpp b/Source/CodRemake/Weapon/BaseWeapon.cpp new file mode 100644 index 0000000..387c424 --- /dev/null +++ b/Source/CodRemake/Weapon/BaseWeapon.cpp @@ -0,0 +1,31 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "BaseWeapon.h" + + +// Sets default values +ABaseWeapon::ABaseWeapon() +{ + PrimaryActorTick.bCanEverTick = false; + + Root = CreateDefaultSubobject(TEXT("Root")); + RootComponent = Root; + + WeaponMeshComponent = CreateDefaultSubobject(TEXT("Weapon")); + WeaponMeshComponent->SetupAttachment(Root); +} + +// Called when the game starts or when spawned +void ABaseWeapon::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +// void ABaseWeapon::Tick(float DeltaTime) +// { +// Super::Tick(DeltaTime); +// } + diff --git a/Source/CodRemake/Weapon/BaseWeapon.h b/Source/CodRemake/Weapon/BaseWeapon.h new file mode 100644 index 0000000..e616a6a --- /dev/null +++ b/Source/CodRemake/Weapon/BaseWeapon.h @@ -0,0 +1,35 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Actor.h" +#include "BaseWeapon.generated.h" + +UCLASS(Abstract) +class CODREMAKE_API ABaseWeapon : public AActor +{ + GENERATED_BODY() + +public: + // Sets default values for this actor's properties + ABaseWeapon(); + + UPROPERTY(VisibleAnywhere, BlueprintReadWrite) + float Damage; + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + // Called every frame + // virtual void Tick(float DeltaTime) override; + + + UPROPERTY(VisibleAnywhere, BlueprintReadWrite) + TObjectPtr Root; + + UPROPERTY(VisibleAnywhere, BlueprintReadWrite) + TObjectPtr WeaponMeshComponent; +}; diff --git a/Source/CodRemakeEditor.Target.cs b/Source/CodRemakeEditor.Target.cs new file mode 100644 index 0000000..6e76c99 --- /dev/null +++ b/Source/CodRemakeEditor.Target.cs @@ -0,0 +1,15 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +using UnrealBuildTool; +using System.Collections.Generic; + +public class CodRemakeEditorTarget : TargetRules +{ + public CodRemakeEditorTarget( TargetInfo Target) : base(Target) + { + Type = TargetType.Editor; + DefaultBuildSettings = BuildSettingsVersion.V4; + IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_3; + ExtraModuleNames.Add("CodRemake"); + } +}