Newer
Older
SkyFrontier-Project-IADE-UE4-3D / Source / SkyFrontier / Private / ScoreAttackGameMode.cpp
  1. #include "ScoreAttackGameMode.h"
  2. #include "PointsComponent.h"
  3. #include <Kismet/GameplayStatics.h>
  4. #include "GameFramework/Controller.h"
  5. AScoreAttackGameMode::AScoreAttackGameMode()
  6. {
  7. GoalScore = 10;
  8. }
  9. void AScoreAttackGameMode::PostInitializeComponents()
  10. {
  11. Super::PostInitializeComponents();
  12. TArray<AActor*> FoundActors;
  13. UGameplayStatics::GetAllActorsOfClass(GetWorld(), APawn::StaticClass(), FoundActors);
  14. if (FoundActors.Num() == 2)
  15. {
  16. Pawn1 = Cast<APawn>(FoundActors[0]);
  17. Pawn2 = Cast<APawn>(FoundActors[1]);
  18. if (Pawn1 && Pawn2)
  19. {
  20. PointsComponent1 = Pawn1->FindComponentByClass<UPointsComponent>();
  21. PointsComponent2 = Pawn2->FindComponentByClass<UPointsComponent>();
  22. }
  23. }
  24. }
  25. void AScoreAttackGameMode::BeginPlay()
  26. {
  27. Super::BeginPlay();
  28. bGameEnded = false;
  29. UE_LOG(LogTemp, Warning, TEXT("IS THIS WORKING"));
  30. }
  31. void AScoreAttackGameMode::Tick(const float DeltaSeconds)
  32. {
  33. Super::Tick(DeltaSeconds);
  34. if (PointsComponent1 && PointsComponent2 && !bGameEnded)
  35. {
  36. if (PointsComponent1->Points >= GoalScore)
  37. {
  38. UE_LOG(LogTemp, Warning, TEXT("Player 1 Wins!"));
  39. bGameEnded = true;
  40. }
  41. else if (PointsComponent2->Points >= GoalScore)
  42. {
  43. UE_LOG(LogTemp, Warning, TEXT("Player 2 Wins!"));
  44. bGameEnded = true;
  45. }
  46. }
  47. }