add code
This commit is contained in:
14
.gitignore
vendored
Normal file
14
.gitignore
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
Binaries
|
||||||
|
DerivedDataCache
|
||||||
|
Intermediate
|
||||||
|
Saved
|
||||||
|
.vscode
|
||||||
|
.vs
|
||||||
|
*.VC.db
|
||||||
|
*.opensdf
|
||||||
|
*.opendb
|
||||||
|
*.sdf
|
||||||
|
*.sln
|
||||||
|
*.suo
|
||||||
|
*.xcodeproj
|
||||||
|
*.xcworkspace
|
||||||
15
Source/CodRemake.Target.cs
Normal file
15
Source/CodRemake.Target.cs
Normal file
@@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
23
Source/CodRemake/CodRemake.Build.cs
Normal file
23
Source/CodRemake/CodRemake.Build.cs
Normal file
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
6
Source/CodRemake/CodRemake.cpp
Normal file
6
Source/CodRemake/CodRemake.cpp
Normal file
@@ -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" );
|
||||||
6
Source/CodRemake/CodRemake.h
Normal file
6
Source/CodRemake/CodRemake.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
|
||||||
15
Source/CodRemake/GameMode/SinglePlayerGameModeBase.cpp
Normal file
15
Source/CodRemake/GameMode/SinglePlayerGameModeBase.cpp
Normal file
@@ -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<APawn> PlayerPawnClassFinder(TEXT("/Script/Engine.Blueprint'/Game/Player/Blueprints/BP_PlayerCharacter.BP_PlayerCharacter_C'"));
|
||||||
|
if (PlayerPawnClassFinder.Succeeded())
|
||||||
|
{
|
||||||
|
DefaultPawnClass = PlayerPawnClassFinder.Class;
|
||||||
|
}
|
||||||
|
}
|
||||||
21
Source/CodRemake/GameMode/SinglePlayerGameModeBase.h
Normal file
21
Source/CodRemake/GameMode/SinglePlayerGameModeBase.h
Normal file
@@ -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();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
169
Source/CodRemake/Player/PlayerCharacter.cpp
Normal file
169
Source/CodRemake/Player/PlayerCharacter.cpp
Normal file
@@ -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<UCameraComponent>(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<UWorld> 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<APlayerController>(GetController());
|
||||||
|
|
||||||
|
// Get the local player subsystem
|
||||||
|
UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer());
|
||||||
|
// Clear out existing mapping, and add our mapping
|
||||||
|
Subsystem->ClearAllMappings();
|
||||||
|
Subsystem->AddMappingContext(InputMapping, 0);
|
||||||
|
|
||||||
|
// Get the EnhancedInputComponent
|
||||||
|
UEnhancedInputComponent* PEI = Cast<UEnhancedInputComponent>(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<FVector2D>();
|
||||||
|
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<FVector2D>();
|
||||||
|
|
||||||
|
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<bool>();
|
||||||
|
if (JumpValue)
|
||||||
|
{
|
||||||
|
Jump();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
StopJumping();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
56
Source/CodRemake/Player/PlayerCharacter.h
Normal file
56
Source/CodRemake/Player/PlayerCharacter.h
Normal file
@@ -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<UCameraComponent> 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;
|
||||||
|
};
|
||||||
31
Source/CodRemake/Weapon/BaseWeapon.cpp
Normal file
31
Source/CodRemake/Weapon/BaseWeapon.cpp
Normal file
@@ -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<USceneComponent>(TEXT("Root"));
|
||||||
|
RootComponent = Root;
|
||||||
|
|
||||||
|
WeaponMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(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);
|
||||||
|
// }
|
||||||
|
|
||||||
35
Source/CodRemake/Weapon/BaseWeapon.h
Normal file
35
Source/CodRemake/Weapon/BaseWeapon.h
Normal file
@@ -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<USceneComponent> Root;
|
||||||
|
|
||||||
|
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
|
||||||
|
TObjectPtr<USkeletalMeshComponent> WeaponMeshComponent;
|
||||||
|
};
|
||||||
15
Source/CodRemakeEditor.Target.cs
Normal file
15
Source/CodRemakeEditor.Target.cs
Normal file
@@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user