Skip to content

Commit

Permalink
Updating interact logic, Started creation of WindowPuzzle
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Warnock committed Jul 17, 2019
1 parent aee1cdc commit d93500a
Show file tree
Hide file tree
Showing 18 changed files with 296 additions and 28 deletions.
Binary file added Content/Curve.uasset
Binary file not shown.
Binary file removed Content/DoorCurve.uasset
Binary file not shown.
Binary file modified Content/Maps/BackgroundLevel.umap
Binary file not shown.
Binary file modified Content/Maps/BackgroundLevel_BuiltData.uasset
Binary file not shown.
Binary file modified Content/StarterContent/Architecture/Floor_400x400.uasset
Binary file not shown.
Binary file not shown.
Binary file added Content/StaticMeshes/Window/WindowMain.uasset
Binary file not shown.
10 changes: 5 additions & 5 deletions HouseEscape.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28315.86
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Engine", "Engine", "{E433A6F4-1263-4E82-BE90-5EFFCBC89097}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Engine", "Engine", "{04ED2554-904D-4F0E-86D7-C7D3949FDEC5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Games", "Games", "{D41278EB-4AB0-4848-B2F9-9616498E0DF4}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Games", "Games", "{C7880518-90A0-47FE-BADD-72AC9F105A06}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UE4", "Intermediate\ProjectFiles\UE4.vcxproj", "{EDC5F083-6B6A-4B23-8664-42A8B24F77BA}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HouseEscape", "Intermediate\ProjectFiles\HouseEscape.vcxproj", "{23C9CCDC-6722-41D9-906B-EF4409C5D4ED}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Visualizers", "Visualizers", "{01677F62-2F22-4BA3-96DC-907EE161554F}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Visualizers", "Visualizers", "{7D594CD1-DAA6-4C3E-88A7-55126C96B769}"
ProjectSection(SolutionItems) = preProject
C:\Program Files\Epic Games\UE_4.22\Engine\Extras\VisualStudioDebugging\UE4.natvis = C:\Program Files\Epic Games\UE_4.22\Engine\Extras\VisualStudioDebugging\UE4.natvis
EndProjectSection
Expand Down Expand Up @@ -99,7 +99,7 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{EDC5F083-6B6A-4B23-8664-42A8B24F77BA} = {E433A6F4-1263-4E82-BE90-5EFFCBC89097}
{23C9CCDC-6722-41D9-906B-EF4409C5D4ED} = {D41278EB-4AB0-4848-B2F9-9616498E0DF4}
{EDC5F083-6B6A-4B23-8664-42A8B24F77BA} = {04ED2554-904D-4F0E-86D7-C7D3949FDEC5}
{23C9CCDC-6722-41D9-906B-EF4409C5D4ED} = {C7880518-90A0-47FE-BADD-72AC9F105A06}
EndGlobalSection
EndGlobal
2 changes: 0 additions & 2 deletions Source/HouseEscape/Character/HouseEscapeCharacter.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ class AHouseEscapeCharacter : public ACharacter

TArray<AInteractable*> currentTargets;



UFUNCTION()
void AddInteractTarget(FMessage message);

Expand Down
10 changes: 8 additions & 2 deletions Source/HouseEscape/Interactables/Door.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ ADoor::ADoor()
BoxComponent->SetRelativeLocation(FVector(0, 0, 100));
BoxComponent->SetRelativeScale3D(FVector(1.5f, 1.75f, 3.0f));

static ConstructorHelpers::FObjectFinder<UCurveFloat> Curve(TEXT("/Game/DoorCurve.DoorCurve"));
static ConstructorHelpers::FObjectFinder<UCurveFloat> Curve(TEXT("/Game/Curve.Curve"));
check(Curve.Succeeded());

FloatCurve = Curve.Object;

doorState = DoorStates::NoKey;

interactType = Interacts::Door;

meshToRender = DoorComponent;
}

void ADoor::BeginPlay()
Expand Down Expand Up @@ -110,6 +111,11 @@ void ADoor::BeginPlay()
}

messenger->OnKeyPickedUp.AddDynamic(this, &ADoor::HandleKeyPickedUp);

if (saveGameUtil->DoesPlayerHaveKey(neededKey))
{
doorState = DoorStates::Closed;
}
}

void ADoor::Tick(float DeltaSeconds)
Expand Down
28 changes: 14 additions & 14 deletions Source/HouseEscape/Interactables/Door.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ class HOUSEESCAPE_API ADoor : public AInteractable
void OnInteract();
void OnInteract_Implementation() override;

void BeginPlay() override;

void Tick(float DeltaSeconds) override;

UPROPERTY(BlueprintReadOnly)
TEnumAsByte<DoorStates> doorState;

private:
UPROPERTY(EditAnywhere)
TEnumAsByte<Rooms> neededKey;

UFUNCTION()
void HandleKeyPickedUp(FMessage message);

UPROPERTY()
UTimelineComponent* MyTimeline;

Expand All @@ -42,20 +56,6 @@ class HOUSEESCAPE_API ADoor : public AInteractable
UPROPERTY()
TEnumAsByte<ETimelineDirection::Type> TimelineDirection;

void BeginPlay() override;

void Tick(float DeltaSeconds) override;

UPROPERTY(BlueprintReadOnly)
TEnumAsByte<DoorStates> doorState;

private:
UPROPERTY(EditAnywhere)
TEnumAsByte<Rooms> neededKey;

UFUNCTION()
void HandleKeyPickedUp(FMessage message);

public:
TEnumAsByte<DoorStates> GetDoorState();
};
16 changes: 14 additions & 2 deletions Source/HouseEscape/Interactables/Interactable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ AInteractable::AInteractable()
uniqueId = FGuid::NewGuid();

IsValidInteract = true;

meshToRender = StaticMeshComponent;
}

// Called when the game starts or when spawned
Expand Down Expand Up @@ -83,7 +85,17 @@ void AInteractable::OnUseItem_Implementation(FMessage message)

bool AInteractable::IsPlayerOverlapping()
{
return BoxComponent->IsOverlappingActor(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
TArray<UBoxComponent*> components;
AInteractable::GetComponents<UBoxComponent>(components);
for (UBoxComponent* box : components)
{
if (box->IsOverlappingActor(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)))
{
return true;
}
}

return false;
}

AInteractable* AInteractable::FindMostDesirableTarget(TArray<AInteractable*> interactables, AHouseEscapeCharacter* player)
Expand Down Expand Up @@ -119,7 +131,7 @@ AInteractable* AInteractable::FindMostDesirableTarget(TArray<AInteractable*> int

void AInteractable::SetRenderDepth(bool renderSet)
{
Cast<UStaticMeshComponent>(RootComponent)->SetRenderCustomDepth(renderSet);
meshToRender->SetRenderCustomDepth(renderSet);
}

TEnumAsByte<Interacts> AInteractable::GetInteractType()
Expand Down
4 changes: 2 additions & 2 deletions Source/HouseEscape/Interactables/Interactable.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class HOUSEESCAPE_API AInteractable : public AActor, public IInteractInterface

TEnumAsByte<Interacts> GetInteractType();

bool GetIsValidInteract();

protected:

UFUNCTION()
Expand All @@ -72,6 +70,8 @@ class HOUSEESCAPE_API AInteractable : public AActor, public IInteractInterface

bool IsPlayerOverlapping();

UStaticMeshComponent* meshToRender;

FGuid uniqueId;

bool IsValidInteract;
Expand Down
176 changes: 176 additions & 0 deletions Source/HouseEscape/Interactables/Puzzles/WindowPuzzle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
// Fill out your copyright notice in the Description page of Project Settings.

#include "WindowPuzzle.h"

AWindowPuzzle::AWindowPuzzle()
{
puzzleType = Puzzles::WindowPuzzle;
roomPuzzleUnlocks = Rooms::BasementFrontCenterRoom;
interactType = Interacts::Puzzle;

static ConstructorHelpers::FObjectFinder<UStaticMesh> MainWindow(TEXT("/Game/StaticMeshes/Window/WindowMain.WindowMain"));
static ConstructorHelpers::FObjectFinder<UStaticMesh> BottomWindow(TEXT("/Game/StaticMeshes/Window/BottomWindowPane.BottomWindowPane"));

StaticMeshComponent->SetStaticMesh(MainWindow.Object);

CenterWindowTop = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("CenterWindowTop"));
CenterWindowTop->SetStaticMesh(MainWindow.Object);
CenterWindowTop->SetupAttachment(RootComponent);
CenterWindowTop->SetRelativeLocation(FVector(200, 0, 0));

RightWindowTop = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("RightWindowTop"));
RightWindowTop->SetStaticMesh(MainWindow.Object);
RightWindowTop->SetupAttachment(RootComponent);
RightWindowTop->SetRelativeLocation(FVector(400, 0, 0));

LeftWindowBottom = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("LeftWindowBottom"));
LeftWindowBottom->SetStaticMesh(BottomWindow.Object);
LeftWindowBottom->SetupAttachment(RootComponent);
LeftWindowBottom->SetRelativeLocation(FVector::ZeroVector);

CenterWindowBottom = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("CenterWindowBottom"));
CenterWindowBottom->SetStaticMesh(BottomWindow.Object);
CenterWindowBottom->SetupAttachment(CenterWindowTop);
CenterWindowBottom->SetRelativeLocation(FVector::ZeroVector);

RightWindowBottom = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("RightWindowBottom"));
RightWindowBottom->SetStaticMesh(BottomWindow.Object);
RightWindowBottom->SetupAttachment(RightWindowTop);
RightWindowBottom->SetRelativeLocation(FVector::ZeroVector);

CenterBox = CreateDefaultSubobject<UBoxComponent>(TEXT("CenterBox"));
CenterBox->SetupAttachment(CenterWindowTop);
CenterBox->SetRelativeLocation(FVector(0, -40, 75));

RightBox = CreateDefaultSubobject<UBoxComponent>(TEXT("RightBox"));
RightBox->SetupAttachment(RightWindowTop);
RightBox->SetRelativeLocation(FVector(0, -45, 75));

BoxComponent->SetRelativeLocation(FVector(0, -40, 75));

static ConstructorHelpers::FObjectFinder<UCurveFloat> Curve(TEXT("/Game/Curve.Curve"));
check(Curve.Succeeded());

FloatCurve = Curve.Object;
}

void AWindowPuzzle::OnInteract_Implementation()
{
switch (CurrentInteraction)
{
case Windows::LEFT:
Timeline->SetPropertySetObject(LeftWindowBottom);
LeftWindowBottom->GetRelativeTransform().GetLocation() == FVector::ZeroVector
? Timeline->PlayFromStart()
: Timeline->ReverseFromEnd();
break;
case Windows::RIGHT:
Timeline->SetPropertySetObject(RightWindowBottom);
RightWindowBottom->GetRelativeTransform().GetLocation() == FVector::ZeroVector
? Timeline->PlayFromStart()
: Timeline->ReverseFromEnd();
break;
case Windows::CENTER:
Timeline->SetPropertySetObject(CenterWindowBottom);
CenterWindowBottom->GetRelativeTransform().GetLocation() == FVector::ZeroVector
? Timeline->PlayFromStart()
: Timeline->ReverseFromEnd();
break;
}
}

void AWindowPuzzle::HandleBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (IsPlayerOverlapping() && !isSolved)
{
FMessage message;

if (OverlappedComp == BoxComponent)
{
CurrentInteraction = Windows::LEFT;
meshToRender = StaticMeshComponent;
}
else if (OverlappedComp == CenterBox)
{
CurrentInteraction = Windows::CENTER;
meshToRender = CenterWindowTop;
}
else
{
CurrentInteraction = Windows::RIGHT;
meshToRender = RightWindowTop;
}

message.interact = this;
message.interactableType = interactType;
message.uniqueId = uniqueId;
messenger->AddInteractTarget(message);
}
}

void AWindowPuzzle::BeginPlay()
{
Super::BeginPlay();

CenterBox->OnComponentBeginOverlap.AddDynamic(this, &AWindowPuzzle::HandleBeginOverlap);
RightBox->OnComponentBeginOverlap.AddDynamic(this, &AWindowPuzzle::HandleBeginOverlap);

CenterBox->OnComponentEndOverlap.AddDynamic(this, &AWindowPuzzle::HandleEndOverlap);
RightBox->OnComponentEndOverlap.AddDynamic(this, &AWindowPuzzle::HandleEndOverlap);

FOnTimelineFloat onTimelineCallback;
FOnTimelineEventStatic onTimelineFinishedCallback;

if (FloatCurve != NULL)
{
Timeline = NewObject<UTimelineComponent>(this, FName("TimelineAnimation"));
Timeline->SetDirectionPropertyName(FName("TimelineDirection"));
Timeline->SetLooping(false);
Timeline->SetTimelineLength(1.0f);
Timeline->SetTimelineLengthMode(ETimelineLengthMode::TL_LastKeyFrame);
Timeline->SetPlaybackPosition(0.0f, false);
//Add the float curve to the timeline and connect it to your timelines's interpolation function
onTimelineCallback.BindUFunction(this, FName{ TEXT("TimelineCallback") });
onTimelineFinishedCallback.BindUFunction(this, FName{ TEXT("TimelineFinishedCallback") });
Timeline->AddInterpFloat(FloatCurve, onTimelineCallback);
Timeline->SetTimelineFinishedFunc(onTimelineFinishedCallback);
Timeline->RegisterComponent();
}
}

void AWindowPuzzle::HandleEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
APuzzle::HandleEndOverlap(OverlappedComp, OtherActor, OtherComp, OtherBodyIndex);
}

void AWindowPuzzle::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);

if (Timeline != NULL)
{
Timeline->TickComponent(DeltaSeconds, ELevelTick::LEVELTICK_TimeOnly, NULL);
}
}

void AWindowPuzzle::TimelineCallback(float interpolatedVal)
{
float newZ = 50 * interpolatedVal;
switch (CurrentInteraction)
{
case Windows::CENTER:
CenterWindowBottom->SetRelativeLocation(FVector(0, 0, newZ));
break;
case Windows::LEFT:
LeftWindowBottom->SetRelativeLocation(FVector(0, 0, newZ));
break;
case Windows::RIGHT:
RightWindowBottom->SetRelativeLocation(FVector(0, 0, newZ));
break;
}
}

void AWindowPuzzle::TimelineFinishedCallback()
{
// This function is called when the timeline finishes playing.
}
Loading

0 comments on commit d93500a

Please sign in to comment.