From 410dd9caf768688605fe4377c21e0ca1a98eb5b0 Mon Sep 17 00:00:00 2001 From: baz Date: Wed, 31 Jul 2024 17:05:54 +0100 Subject: [PATCH] Add Pentagram Weapon --- .../Pentagram/BP_PentagramWeapon.uasset | 3 + Source/vampires/Weapons/PentagramWeapon.cpp | 84 +++++++++++++++++++ Source/vampires/Weapons/PentagramWeapon.h | 47 +++++++++++ 3 files changed, 134 insertions(+) create mode 100644 Content/Weapons/Pentagram/BP_PentagramWeapon.uasset create mode 100644 Source/vampires/Weapons/PentagramWeapon.cpp create mode 100644 Source/vampires/Weapons/PentagramWeapon.h diff --git a/Content/Weapons/Pentagram/BP_PentagramWeapon.uasset b/Content/Weapons/Pentagram/BP_PentagramWeapon.uasset new file mode 100644 index 0000000..dfb5fa8 --- /dev/null +++ b/Content/Weapons/Pentagram/BP_PentagramWeapon.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2ef5a15c8a243ddadce18effdfb741c3b03c0abc1cd07faa8c1fdc780bb8d71d +size 23836 diff --git a/Source/vampires/Weapons/PentagramWeapon.cpp b/Source/vampires/Weapons/PentagramWeapon.cpp new file mode 100644 index 0000000..04ee8df --- /dev/null +++ b/Source/vampires/Weapons/PentagramWeapon.cpp @@ -0,0 +1,84 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "PentagramWeapon.h" + +#include "Kismet/GameplayStatics.h" +#include "vampires/VampirePlayerController.h" +#include "../PlayerCharacter.h" + +APentagramWeapon::APentagramWeapon() +{ + BoxComponent = CreateDefaultSubobject(TEXT("Sphere Component")); + BoxComponent->SetupAttachment(RootComponent); + WeaponCooldown = 90.0f; +} + +void APentagramWeapon::BeginPlay() +{ + Super::BeginPlay(); + BoxComponent->OnComponentBeginOverlap.AddDynamic(this, &APentagramWeapon::OnBeginOverlap); + BoxComponent->OnComponentEndOverlap.AddDynamic(this, &APentagramWeapon::OnEndOverlap); + + FVector TopLeft, TopLeftDir; + FVector TopRight, TopRightDir; + FVector BottomLeft, BottomLeftDir; + FVector BottomRight, BottomRightDir; + + FVector2d ViewportSize; + GEngine->GameViewport->GetViewportSize(ViewportSize); + + APlayerCharacter* PlayerCharacter = Cast(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)); + AVampirePlayerController* PlayerController = Cast( + UGameplayStatics::GetPlayerController(PlayerCharacter, 0)); + PlayerController->DeprojectScreenPositionToWorld(0, 0, TopLeft, TopLeftDir); + PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X, 0, TopRight, TopRightDir); + PlayerController->DeprojectScreenPositionToWorld(0, ViewportSize.Y, BottomLeft, BottomLeftDir); + PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X, ViewportSize.Y, BottomRight, BottomRightDir); + + float width = FVector::Dist(TopLeft, TopRight) * 60; + float height = FVector::Dist(TopLeft, BottomLeft) * 60; + BoxComponent->SetBoxExtent(FVector(height, width, 200.0f)); +} + +void APentagramWeapon::FireWeaponAction_Implementation() +{ + Super::FireWeaponAction_Implementation(); + + for (int i = OverlappedPickups.Num() - 1; i >= 0; i--) + { + OverlappedPickups[i]->Destroy(); + } + + for (int i = OverlappedEnemies.Num() - 1; i >= 0; i--) + { + OverlappedEnemies[i]->Destroy(); + } +} + +void APentagramWeapon::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, + const FHitResult& SweepResult) +{ + if (AEnemyCharacter* Enemy = Cast(OtherActor)) + { + OverlappedEnemies.Add(Enemy); + } + else if (APickup* Pickup = Cast(OtherActor)) + { + OverlappedPickups.Add(Pickup); + } +} + +void APentagramWeapon::OnEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) +{ + if (AEnemyCharacter* Enemy = Cast(OtherActor)) + { + OverlappedEnemies.Remove(Enemy); + } + else if (APickup* Pickup = Cast(OtherActor)) + { + OverlappedPickups.Remove(Pickup); + } +} diff --git a/Source/vampires/Weapons/PentagramWeapon.h b/Source/vampires/Weapons/PentagramWeapon.h new file mode 100644 index 0000000..d46235a --- /dev/null +++ b/Source/vampires/Weapons/PentagramWeapon.h @@ -0,0 +1,47 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "../Weapon.h" +#include "Components/BoxComponent.h" +#include "vampires/EnemyCharacter.h" +#include "vampires/Pickup.h" +#include "PentagramWeapon.generated.h" + +/** + * + */ +UCLASS() +class VAMPIRES_API APentagramWeapon : public AWeapon +{ + GENERATED_BODY() + +public: + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + UBoxComponent* BoxComponent = nullptr; + +private: + TArray OverlappedEnemies = TArray(); + + TArray OverlappedPickups = TArray(); + +public: + APentagramWeapon(); + +protected: + virtual void BeginPlay() override; + +public: + virtual void FireWeaponAction_Implementation() override; + +protected: + UFUNCTION() + void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, + const FHitResult& SweepResult); + + UFUNCTION() + void OnEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, + int32 OtherBodyIndex); +};