Fieol

PoBlockBase.cpp

Jun 14th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3.  
  4. #include "PoBlockBase.h"
  5. #include "PoPlayerState.h"
  6. #include "Kismet/GameplayStatics.h"
  7. #include "PoGameModeBase.h"
  8. #include "Components/StaticMeshComponent.h"
  9.  
  10. class APoGameModeBase;
  11.  
  12. APoBlockBase::APoBlockBase()
  13. {
  14.     PrimaryActorTick.bCanEverTick = true;
  15.  
  16.     Block = CreateDefaultSubobject<UStaticMeshComponent>(FName("Brick"));
  17.     if (Block)
  18.     {
  19.         RootComponent = Block;
  20.         Block->SetWorldScale3D(FVector{0.25, 0.75, 0.5});
  21.     }
  22. }
  23.  
  24. void APoBlockBase::BeginPlay()
  25. {
  26.     Super::BeginPlay();
  27.     Block->OnComponentHit.AddDynamic(this, &APoBlockBase::OnHit);
  28.     KillBlockDelegate.BindUObject(this, &APoBlockBase::KillSelfBlock);
  29.     KillMultiBlockDelegate.AddUObject(this, &APoBlockBase::KillMultiBlock);
  30.    
  31.  
  32.     APoGameModeBase* gm = Cast<APoGameModeBase>(GetWorld()->GetAuthGameMode());
  33.  
  34.     if (gm)
  35.         gm->RegisterBlocks(this);
  36. }
  37.  
  38. void APoBlockBase::OnHit
  39. (
  40.     UPrimitiveComponent* HitComponent,
  41.     AActor* OtherActor,
  42.     UPrimitiveComponent* OtherComponent,
  43.     FVector NormalImpulse,
  44.     const FHitResult& Hit
  45. )
  46. {
  47.     //if (KillBlockDelegate.IsBound())
  48.         KillBlockDelegate.ExecuteIfBound();
  49.  
  50.     //KillMultiBlockDelegate.Broadcast();
  51.  
  52.     this->SetActorHiddenInGame(true);
  53.     this->SetActorEnableCollision(false);
  54.     LoadSkill();
  55.    
  56. }
  57.  
  58. void APoBlockBase::LoadSkill()
  59. {
  60.     APoPlayerState* pState = Cast<APoPlayerState>(UGameplayStatics::GetPlayerController(GetWorld(), 0)->GetPawn()->GetPlayerState());
  61.     //Destroy();
  62.     if (pState)
  63.     {
  64.         pState->AddScore(10);
  65.     }
  66. }
  67.  
  68. void APoBlockBase::KillSelfBlock()
  69. {
  70.     APoGameModeBase* gm = Cast<APoGameModeBase>(GetWorld()->GetAuthGameMode());
  71.  
  72.     if(gm)
  73.     gm->DeRegisterBlocks();
  74. }
  75.  
  76. void APoBlockBase::KillMultiBlock()
  77. {
  78.     FString str = this->GetName();
  79.     //UE_LOG(LogTemp, Warning, TEXT("Multi Kill Block %s"), *str);
  80. }
  81.  
  82. void APoBlockBase::MakeVisible()
  83. {
  84.     this->SetActorHiddenInGame(false);
  85.     this->SetActorEnableCollision(true);
  86. }
  87.  
  88. void APoBlockBase::MakeInvisible()
  89. {
  90.     this->SetActorHiddenInGame(true);
  91.     this->SetActorEnableCollision(false);
  92. }
Add Comment
Please, Sign In to add comment