Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "PoBlockBase.h"
- #include "PoPlayerState.h"
- #include "Kismet/GameplayStatics.h"
- #include "PoGameModeBase.h"
- #include "Components/StaticMeshComponent.h"
- class APoGameModeBase;
- APoBlockBase::APoBlockBase()
- {
- PrimaryActorTick.bCanEverTick = true;
- Block = CreateDefaultSubobject<UStaticMeshComponent>(FName("Brick"));
- if (Block)
- {
- RootComponent = Block;
- Block->SetWorldScale3D(FVector{0.25, 0.75, 0.5});
- }
- }
- void APoBlockBase::BeginPlay()
- {
- Super::BeginPlay();
- Block->OnComponentHit.AddDynamic(this, &APoBlockBase::OnHit);
- KillBlockDelegate.BindUObject(this, &APoBlockBase::KillSelfBlock);
- KillMultiBlockDelegate.AddUObject(this, &APoBlockBase::KillMultiBlock);
- APoGameModeBase* gm = Cast<APoGameModeBase>(GetWorld()->GetAuthGameMode());
- if (gm)
- gm->RegisterBlocks(this);
- }
- void APoBlockBase::OnHit
- (
- UPrimitiveComponent* HitComponent,
- AActor* OtherActor,
- UPrimitiveComponent* OtherComponent,
- FVector NormalImpulse,
- const FHitResult& Hit
- )
- {
- //if (KillBlockDelegate.IsBound())
- KillBlockDelegate.ExecuteIfBound();
- //KillMultiBlockDelegate.Broadcast();
- this->SetActorHiddenInGame(true);
- this->SetActorEnableCollision(false);
- LoadSkill();
- }
- void APoBlockBase::LoadSkill()
- {
- APoPlayerState* pState = Cast<APoPlayerState>(UGameplayStatics::GetPlayerController(GetWorld(), 0)->GetPawn()->GetPlayerState());
- //Destroy();
- if (pState)
- {
- pState->AddScore(10);
- }
- }
- void APoBlockBase::KillSelfBlock()
- {
- APoGameModeBase* gm = Cast<APoGameModeBase>(GetWorld()->GetAuthGameMode());
- if(gm)
- gm->DeRegisterBlocks();
- }
- void APoBlockBase::KillMultiBlock()
- {
- FString str = this->GetName();
- //UE_LOG(LogTemp, Warning, TEXT("Multi Kill Block %s"), *str);
- }
- void APoBlockBase::MakeVisible()
- {
- this->SetActorHiddenInGame(false);
- this->SetActorEnableCollision(true);
- }
- void APoBlockBase::MakeInvisible()
- {
- this->SetActorHiddenInGame(true);
- this->SetActorEnableCollision(false);
- }
Add Comment
Please, Sign In to add comment