Fieol

PoGameModeBase.cpp

Jun 14th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3.  
  4. #include "PoGameModeBase.h"
  5. #include "Kismet/GameplayStatics.h"
  6. #include "PoPlayerController.h"
  7. #include "PoPawn.h"
  8. #include "PoPlayerState.h"
  9. #include "PoBlockBase.h"
  10. #include "GameFramework/PlayerStart.h"
  11.  
  12. class APoBlockBase;
  13.  
  14. APoGameModeBase::APoGameModeBase()
  15. {
  16.     PlayerControllerClass = APoPlayerController::StaticClass();
  17.     DefaultPawnClass = APoPawn::StaticClass();
  18.     PlayerStateClass = APoPlayerState::StaticClass();
  19.  
  20.     BlockCount = 0;
  21. }
  22.  
  23. void APoGameModeBase::RegisterBlocks(APoBlockBase* blockActor)
  24. {
  25.     BlockCount++;
  26.  
  27.     if (blockActor)
  28.     {
  29.         BlockList.Add(blockActor);
  30.     }
  31.  
  32.     UE_LOG(LogTemp, Warning, TEXT("Total Number of Blocks: %s"), *FString::FromInt(BlockCount));
  33. }
  34.  
  35. void APoGameModeBase::DeRegisterBlocks()
  36. {
  37.     BlockCount--;
  38.  
  39.     if (CheckWinCondition())
  40.     {
  41.         UE_LOG(LogTemp, Warning, TEXT("Player Won!"));
  42.         WinningCall();
  43.     }
  44.  
  45.     UE_LOG(LogTemp, Warning, TEXT("Total Number of Blocks: %s"), *FString::FromInt(BlockCount));
  46. }
  47.  
  48. bool APoGameModeBase::CheckWinCondition()
  49. {
  50.     bool bStatus = false;
  51.  
  52.     if (BlockCount == 0)
  53.         bStatus = true;
  54.  
  55.     return bStatus;
  56. }
  57.  
  58.  
  59. void APoGameModeBase::SpawnBall()
  60. {
  61.     AActor* playerStart = UGameplayStatics::GetActorOfClass(GetWorld(), APlayerStart::StaticClass());
  62.    
  63.     if (playerStart)
  64.     {
  65.         UE_LOG(LogTemp, Warning, TEXT("got player start"));
  66.         FActorSpawnParameters params;
  67.         BallRef = GetWorld()->SpawnActor<APoBallBase>(BallBP, playerStart->GetActorTransform(), params);
  68.  
  69.         if(BallRef)
  70.             UE_LOG(LogTemp, Warning, TEXT("Ball is spawned"));
  71.     }
  72. }
  73.  
  74. void APoGameModeBase::BeginPlay()
  75. {
  76.     Super::BeginPlay();
  77.  
  78.    
  79.  
  80. }
  81.  
  82. void APoGameModeBase::PostInitializeComponents()
  83. {
  84.     Super::PostInitializeComponents();
  85.  
  86.     SpawnBall();
  87. }
  88.  
  89. void APoGameModeBase::RandomBlocks()
  90. {
  91.     UE_LOG(LogTemp, Warning, TEXT("random Command Executed"));
  92. }
  93.  
  94. void APoGameModeBase::SpawnBlocks()
  95. {
  96.     int totalBlocks = 10;
  97.     FVector Pos1(10, 10, 10);
  98.     FRotator Rot1(0, 0, 0);
  99.     FActorSpawnParameters SpawnInfo;
  100.     for (int i = 0; i < 10; i++)
  101.     {
  102.         FActorSpawnParameters params;
  103.         APoBlockBase* bBlock = GetWorld()->SpawnActor<APoBlockBase>(Pos1,Rot1,SpawnInfo);
  104.     }
  105. }
Add Comment
Please, Sign In to add comment