Compare commits
3 Commits
3f089caa33
...
d9dba81c7e
Author | SHA1 | Date |
---|---|---|
baz | d9dba81c7e | |
baz | b8f08e83cc | |
baz | b054db1478 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -79,11 +79,11 @@ UGoldComponent* APlayerCharacter::GetGoldComponent()
|
|||
|
||||
void APlayerCharacter::MovementCallback(const FInputActionInstance& Instance)
|
||||
{
|
||||
FVector2D vec2 = Instance.GetValue().Get<FVector2D>();
|
||||
PreviousMovementDirection = Instance.GetValue().Get<FVector2D>();
|
||||
|
||||
if (vec2.Size() != 0.0f)
|
||||
if (PreviousMovementDirection.Size() != 0.0f)
|
||||
{
|
||||
AddMovementInput({0.0f, 1.0f, 0.0f}, vec2.Y);
|
||||
AddMovementInput({1.0f, 0.0f, 0.0f}, vec2.X);
|
||||
AddMovementInput({0.0f, 1.0f, 0.0f}, PreviousMovementDirection.Y);
|
||||
AddMovementInput({1.0f, 0.0f, 0.0f}, PreviousMovementDirection.X);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ public:
|
|||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
UWeaponInventoryComponent* WeaponInventoryComponent;
|
||||
|
||||
FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f);
|
||||
|
||||
private:
|
||||
FTimerHandle GarlicTimerHandle;
|
||||
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
|
||||
#include "Projectile.h"
|
||||
|
||||
#include "EnemyCharacter.h"
|
||||
#include "Weapons/MagicWandWeapon.h"
|
||||
#include "Weapons/ProjectileWeapon.h"
|
||||
|
||||
// Sets default values
|
||||
AProjectile::AProjectile()
|
||||
|
@ -13,7 +12,7 @@ AProjectile::AProjectile()
|
|||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
|
||||
SphereComponent->SetupAttachment(RootComponent);
|
||||
SetRootComponent(SphereComponent);
|
||||
SphereComponent->SetSphereRadius(50.0f);
|
||||
}
|
||||
|
||||
|
@ -21,8 +20,8 @@ AProjectile::AProjectile()
|
|||
void AProjectile::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
AMagicWandWeapon* OwnerWeapon = Cast<AMagicWandWeapon>(GetOwner());
|
||||
SphereComponent->OnComponentBeginOverlap.AddDynamic(OwnerWeapon, &AMagicWandWeapon::OnProjectileBeginOverlap);
|
||||
AProjectileWeapon* OwnerWeapon = Cast<AProjectileWeapon>(GetOwner());
|
||||
SphereComponent->OnComponentBeginOverlap.AddDynamic(OwnerWeapon, &AProjectileWeapon::OnProjectileBeginOverlap);
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "FireWandWeapon.h"
|
||||
|
||||
#include "Kismet/KismetMathLibrary.h"
|
||||
|
||||
AFireWandWeapon::AFireWandWeapon()
|
||||
{
|
||||
}
|
||||
|
||||
void AFireWandWeapon::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
void AFireWandWeapon::FireWeaponAction_Implementation()
|
||||
{
|
||||
Super::FireWeaponAction_Implementation();
|
||||
|
||||
if (IsValid(ProjectileTemplate) && OverlappedEnemies.Num() > 0)
|
||||
{
|
||||
FActorSpawnParameters actorSpawnParameters;
|
||||
actorSpawnParameters.Owner = this;
|
||||
actorSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
actorSpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot;
|
||||
|
||||
AProjectile* projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(),
|
||||
actorSpawnParameters);
|
||||
|
||||
AActor* target = OverlappedEnemies[FMath::RandRange(0, OverlappedEnemies.Num() - 1)];
|
||||
FVector direction = UKismetMathLibrary::GetDirectionUnitVector(
|
||||
GetActorLocation(), target->GetActorLocation());
|
||||
direction.Z = 0.0;
|
||||
direction.Normalize();
|
||||
|
||||
projectile->TargetDirection = direction;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "ProjectileWeapon.h"
|
||||
#include "FireWandWeapon.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class VAMPIRES_API AFireWandWeapon : public AProjectileWeapon
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
AFireWandWeapon();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
virtual void FireWeaponAction_Implementation() override;
|
||||
};
|
|
@ -0,0 +1,37 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "KnifeWeapon.h"
|
||||
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "vampires/PlayerCharacter.h"
|
||||
|
||||
AKnifeWeapon::AKnifeWeapon()
|
||||
{
|
||||
}
|
||||
|
||||
void AKnifeWeapon::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
void AKnifeWeapon::FireWeaponAction_Implementation()
|
||||
{
|
||||
Super::FireWeaponAction_Implementation();
|
||||
|
||||
APlayerCharacter* playerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
||||
if (IsValid(ProjectileTemplate) && playerCharacter)
|
||||
{
|
||||
FActorSpawnParameters actorSpawnParameters;
|
||||
actorSpawnParameters.Owner = this;
|
||||
actorSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
actorSpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot;
|
||||
|
||||
AProjectile* projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(),
|
||||
actorSpawnParameters);
|
||||
|
||||
FVector direction = FVector(playerCharacter->PreviousMovementDirection, 0.0);
|
||||
direction.Normalize();
|
||||
projectile->TargetDirection = direction;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "ProjectileWeapon.h"
|
||||
#include "KnifeWeapon.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class VAMPIRES_API AKnifeWeapon : public AProjectileWeapon
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
AKnifeWeapon();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
virtual void FireWeaponAction_Implementation() override;
|
||||
};
|
|
@ -5,20 +5,14 @@
|
|||
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Kismet/KismetMathLibrary.h"
|
||||
#include "vampires/EnemyCharacter.h"
|
||||
|
||||
AMagicWandWeapon::AMagicWandWeapon()
|
||||
{
|
||||
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
|
||||
SphereComponent->SetupAttachment(RootComponent);
|
||||
SphereComponent->SetSphereRadius(1000.0f);
|
||||
}
|
||||
|
||||
void AMagicWandWeapon::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &AMagicWandWeapon::OnWeaponBeginOverlap);
|
||||
SphereComponent->OnComponentEndOverlap.AddDynamic(this, &AMagicWandWeapon::OnWeaponEndOverlap);
|
||||
}
|
||||
|
||||
void AMagicWandWeapon::FireWeaponAction_Implementation()
|
||||
|
@ -37,7 +31,7 @@ void AMagicWandWeapon::FireWeaponAction_Implementation()
|
|||
actorSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
actorSpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot;
|
||||
|
||||
AProjectile* projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetTransform(),
|
||||
AProjectile* projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(),
|
||||
actorSpawnParameters);
|
||||
FVector direction = UKismetMathLibrary::GetDirectionUnitVector(
|
||||
GetActorLocation(), nearestActor->GetActorLocation());
|
||||
|
@ -47,45 +41,3 @@ void AMagicWandWeapon::FireWeaponAction_Implementation()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AMagicWandWeapon::OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult)
|
||||
{
|
||||
if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor))
|
||||
{
|
||||
OverlappedEnemies.Add(Enemy);
|
||||
}
|
||||
}
|
||||
|
||||
void AMagicWandWeapon::OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
|
||||
{
|
||||
if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor))
|
||||
{
|
||||
OverlappedEnemies.Remove(Enemy);
|
||||
}
|
||||
}
|
||||
|
||||
void AMagicWandWeapon::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult)
|
||||
{
|
||||
if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor))
|
||||
{
|
||||
UHealthComponent* EnemyHealthComponent = Enemy->GetHealthComponent();
|
||||
|
||||
if (!EnemyHealthComponent->GetIsDead())
|
||||
{
|
||||
AController* ownerController = nullptr;
|
||||
if (AVampireCharacter* character = Cast<AVampireCharacter>(GetOwner()))
|
||||
{
|
||||
ownerController = character->GetController();
|
||||
}
|
||||
|
||||
EnemyHealthComponent->TakeDamage(Enemy, Damage, nullptr, ownerController, this);
|
||||
|
||||
OverlappedComponent->GetAttachmentRootActor()->Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,29 +3,17 @@
|
|||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "../Weapon.h"
|
||||
#include "Components/SphereComponent.h"
|
||||
#include "vampires/Projectile.h"
|
||||
#include "ProjectileWeapon.h"
|
||||
#include "MagicWandWeapon.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class VAMPIRES_API AMagicWandWeapon : public AWeapon
|
||||
class VAMPIRES_API AMagicWandWeapon : public AProjectileWeapon
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
USphereComponent* SphereComponent = nullptr;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Weapon Properties")
|
||||
TSubclassOf<AProjectile> ProjectileTemplate = nullptr;
|
||||
|
||||
private:
|
||||
TArray<AActor*> OverlappedEnemies = TArray<AActor*>();
|
||||
|
||||
public:
|
||||
AMagicWandWeapon();
|
||||
|
||||
|
@ -34,17 +22,4 @@ protected:
|
|||
|
||||
public:
|
||||
virtual void FireWeaponAction_Implementation() override;
|
||||
|
||||
UFUNCTION()
|
||||
void OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult);
|
||||
|
||||
UFUNCTION()
|
||||
void OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
|
||||
int32 OtherBodyIndex);
|
||||
|
||||
UFUNCTION()
|
||||
void OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "ProjectileWeapon.h"
|
||||
|
||||
#include "vampires/EnemyCharacter.h"
|
||||
|
||||
AProjectileWeapon::AProjectileWeapon()
|
||||
{
|
||||
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
|
||||
SphereComponent->SetupAttachment(RootComponent);
|
||||
SphereComponent->SetSphereRadius(1000.0f);
|
||||
}
|
||||
|
||||
void AProjectileWeapon::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &AProjectileWeapon::OnWeaponBeginOverlap);
|
||||
SphereComponent->OnComponentEndOverlap.AddDynamic(this, &AProjectileWeapon::OnWeaponEndOverlap);
|
||||
}
|
||||
|
||||
void AProjectileWeapon::OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
||||
{
|
||||
if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor))
|
||||
{
|
||||
OverlappedEnemies.Add(Enemy);
|
||||
}
|
||||
}
|
||||
|
||||
void AProjectileWeapon::OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
|
||||
{
|
||||
if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor))
|
||||
{
|
||||
OverlappedEnemies.Remove(Enemy);
|
||||
}
|
||||
}
|
||||
|
||||
void AProjectileWeapon::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
||||
{
|
||||
if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor))
|
||||
{
|
||||
UHealthComponent* EnemyHealthComponent = Enemy->GetHealthComponent();
|
||||
|
||||
if (!EnemyHealthComponent->GetIsDead())
|
||||
{
|
||||
AController* ownerController = nullptr;
|
||||
if (AVampireCharacter* character = Cast<AVampireCharacter>(GetOwner()))
|
||||
{
|
||||
ownerController = character->GetController();
|
||||
}
|
||||
|
||||
EnemyHealthComponent->TakeDamage(Enemy, Damage, nullptr, ownerController, this);
|
||||
|
||||
OverlappedComponent->GetAttachmentRootActor()->Destroy();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "../Weapon.h"
|
||||
#include "vampires/Projectile.h"
|
||||
#include "ProjectileWeapon.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class VAMPIRES_API AProjectileWeapon : public AWeapon
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
USphereComponent* SphereComponent = nullptr;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Weapon Properties")
|
||||
TSubclassOf<AProjectile> ProjectileTemplate = nullptr;
|
||||
|
||||
protected:
|
||||
TArray<AActor*> OverlappedEnemies = TArray<AActor*>();
|
||||
|
||||
public:
|
||||
AProjectileWeapon();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
UFUNCTION()
|
||||
void OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult);
|
||||
|
||||
UFUNCTION()
|
||||
void OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
|
||||
int32 OtherBodyIndex);
|
||||
|
||||
UFUNCTION()
|
||||
void OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
|
||||
};
|
Loading…
Reference in New Issue