Compare commits

..

2 Commits

Author SHA1 Message Date
baz 2e59bb6e0e Add enemy spawning 2024-06-26 00:17:14 +01:00
baz a4d66dc45d Remove UE_LOG 2024-06-26 00:16:41 +01:00
4 changed files with 81 additions and 4 deletions

BIN
Content/Gamemode/BP_DefaultGamemode.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -37,7 +37,6 @@ void APickup::Tick(float DeltaSeconds)
if (currentDistance <= PickupMovementRange) if (currentDistance <= PickupMovementRange)
{ {
double speed = 400 / currentDistance; double speed = 400 / currentDistance;
UE_LOG(LogTemp, Warning, TEXT("The integer value is: %f"), speed);
FVector location = FMath::VInterpTo(actorLocation, playerLocation, DeltaSeconds, speed); FVector location = FMath::VInterpTo(actorLocation, playerLocation, DeltaSeconds, speed);
SetActorLocation(location); SetActorLocation(location);
} }

View File

@ -3,3 +3,62 @@
#include "VampireGameMode.h" #include "VampireGameMode.h"
#include "Kismet/GameplayStatics.h"
void AVampireGameMode::BeginPlay()
{
Super::BeginPlay();
PlayerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
PlayerController = Cast<AVampirePlayerController>(UGameplayStatics::GetPlayerController(PlayerCharacter, 0));
GetWorldTimerManager().SetTimer(SpawnEnemyTimerDelegate, this, &AVampireGameMode::SpawnEnemy, 1.0f, true);
}
void AVampireGameMode::SpawnEnemy()
{
FVector TopLeft, TopLeftDir;
FVector TopRight, TopRightDir;
FVector BottomLeft, BottomLeftDir;
FVector BottomRight, BottomRightDir;
FVector CenterPos, CenterDir;
FVector2d ViewportSize;
GEngine->GameViewport->GetViewportSize(ViewportSize);
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);
PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X / 2, ViewportSize.Y / 2, CenterPos, CenterDir);
FVector SpawnLocation;
switch (FMath::RandRange(0, 3))
{
case 0:
SpawnLocation = FMath::Lerp(TopLeft, TopRight, FMath::RandRange(0.0f, 1.0f));
break;
case 1:
SpawnLocation = FMath::Lerp(TopRight, BottomRight, FMath::RandRange(0.0f, 1.0f));
break;
case 2:
SpawnLocation = FMath::Lerp(BottomRight, BottomLeft, FMath::RandRange(0.0f, 1.0f));
break;
case 3:
SpawnLocation = FMath::Lerp(BottomLeft, TopLeft, FMath::RandRange(0.0f, 1.0f));
break;
default:
UE_LOG(LogTemp, Warning, TEXT("Something broke"));
break;
}
SpawnLocation.Z = PlayerCharacter->GetActorLocation().Z;
FTransform Transform;
Transform.SetLocation(SpawnLocation);
FActorSpawnParameters SpawnParameters;
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
AEnemyCharacter* actor = GetWorld()->SpawnActor<AEnemyCharacter>(EnemyTemplate, Transform, SpawnParameters);
actor->SpawnDefaultController();
}

View File

@ -3,6 +3,9 @@
#pragma once #pragma once
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "EnemyCharacter.h"
#include "PlayerCharacter.h"
#include "VampirePlayerController.h"
#include "GameFramework/GameMode.h" #include "GameFramework/GameMode.h"
#include "VampireGameMode.generated.h" #include "VampireGameMode.generated.h"
@ -14,4 +17,20 @@ class VAMPIRES_API AVampireGameMode : public AGameMode
{ {
GENERATED_BODY() GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly)
TSubclassOf<AEnemyCharacter> EnemyTemplate;
private:
APlayerCharacter* PlayerCharacter;
AVampirePlayerController* PlayerController;
FTimerHandle SpawnEnemyTimerDelegate;
protected:
virtual void BeginPlay() override;
UFUNCTION()
void SpawnEnemy();
}; };