Compare commits

..

2 Commits

Author SHA1 Message Date
adfe961cef highlight enemies 2025-08-30 15:10:56 -05:00
16eddc8849 added the enemy interface 2025-08-30 14:07:09 -05:00
12 changed files with 120 additions and 4 deletions

View File

@ -2,7 +2,7 @@
bEnabled=False
Startup=AutomaticButHidden
bEnableReinstancing=True
bAutomaticallyCompileNewClasses=True
bAutomaticallyCompileNewClasses=False
bPreloadEngineModules=False
bPreloadEnginePluginModules=False
bPreloadProjectModules=True

Binary file not shown.

View File

@ -1,4 +1,4 @@
// Fill out your copyright notice in the Description page of Project Settings.
// Copyright; GhostPacket Games
#pragma once

View File

@ -3,3 +3,12 @@
#include "Character/AuraEnemy.h"
void AAuraEnemy::HighlightActor()
{
bHighlighted = true;
}
void AAuraEnemy::UnHighlightActor()
{
bHighlighted = false;
}

View File

@ -0,0 +1,6 @@
// Copyright; GhostPacket Games
#include "Interaction/EnemyInterface.h"
// Add default functionality here for any IEnemyInterface functions that are not pure virtual.

View File

@ -5,12 +5,75 @@
#include "EnhancedInputSubsystems.h"
#include "EnhancedInputComponent.h"
#include "Interaction/EnemyInterface.h"
AAuraPlayerController::AAuraPlayerController()
{
bReplicates = true;
}
void AAuraPlayerController::PlayerTick(float DeltaTime)
{
Super::PlayerTick(DeltaTime);
CursorTrace();
}
void AAuraPlayerController::CursorTrace()
{
FHitResult CursorHit;
GetHitResultUnderCursor(ECC_Visibility, false, CursorHit);
if (!CursorHit.bBlockingHit)
return;
LastActor = ThisActor;
ThisActor = CursorHit.GetActor();
/*
* Line tracer from cursor. There are several scenarios:
* A. LastActor is null && ThisActor is null
* - Do nothing.
* B. LastActor is null && ThisActor is valid
* - Highlight ThisActor.
* C. LastActor is valid && ThisActor is null
* - UnHighlight LastActor
* D. Both actors are valid, but LastActor != ThisActor
* - UnHighlight LastActor.
* - Highlight ThisActor.
* E. Both actors are valid, and are the same actor
* - Do nothing.
*/
if (!LastActor)
{
if (ThisActor)
{
// Case B
ThisActor->HighlightActor();
}
// else Case A
}
else // LastActor is valid
{
if (!ThisActor)
{
// Case C
LastActor->UnHighlightActor();
}
else
{
// Both Actors are valid
if (LastActor != ThisActor)
{
// Case D
LastActor->UnHighlightActor();
ThisActor->HighlightActor();
}
// else do nothing
}
}
}
void AAuraPlayerController::BeginPlay()
{
Super::BeginPlay();
@ -52,4 +115,4 @@ void AAuraPlayerController::Move(const FInputActionValue& InputActionValue)
ControlledPawn->AddMovementInput(ForwardDirection, InputAxisVector.Y);
ControlledPawn->AddMovementInput(RightDirection, InputAxisVector.X);
}
}

View File

@ -4,14 +4,21 @@
#include "CoreMinimal.h"
#include "Character/AuraCharacterBase.h"
#include "Interaction/EnemyInterface.h"
#include "AuraEnemy.generated.h"
/**
*
*/
UCLASS()
class AURA_API AAuraEnemy : public AAuraCharacterBase
class AURA_API AAuraEnemy : public AAuraCharacterBase, public IEnemyInterface
{
GENERATED_BODY()
public:
virtual void HighlightActor() override;
virtual void UnHighlightActor() override;
UPROPERTY (BlueprintReadOnly)
bool bHighlighted = false;
};

View File

@ -0,0 +1,22 @@
// Copyright; GhostPacket Games
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "EnemyInterface.generated.h"
UINTERFACE(MinimalAPI)
class UEnemyInterface : public UInterface
{
GENERATED_BODY()
};
class AURA_API IEnemyInterface
{
GENERATED_BODY()
public:
virtual void HighlightActor () = 0; // pure virtual function
virtual void UnHighlightActor () = 0;
};

View File

@ -9,6 +9,8 @@
class UInputMappingContext;
class UInputAction;
class IEnemyInterface;
struct FInputActionValue;
UCLASS()
@ -18,6 +20,7 @@ class AURA_API AAuraPlayerController : public APlayerController
public:
AAuraPlayerController ();
virtual void PlayerTick(float DeltaTime) override;
protected:
virtual void BeginPlay() override;
@ -31,4 +34,10 @@ private:
TObjectPtr<UInputAction> MoveAction;
void Move (const FInputActionValue &InputActionValue);
void CursorTrace ();
// for highlighting
TScriptInterface<IEnemyInterface> LastActor; // TScriptInterface must be used to hold interfaces
TScriptInterface<IEnemyInterface> ThisActor;
};