void APickUpItem::Prox_Implementation(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult) { // if the overlapped actor is NOT the player, // you simply should return if (Cast<AActor>(OtherActor) == nullptr) { return; } // Get a reference to the player avatar, to give him // the item AAvatar *avatar = Cast<AAvatar>(UGameplayStatics::GetPlayerPawn( GetWorld(), 0)); // Let the player pick up item // Notice use of keyword this! // That is how _this_ Pickup can refer to itself. avatar->Pickup(this); if (CoinSound != NULL) { UGameplayStatics::PlaySoundAtLocation(this, CoinSound, GetActorLocation()); } // Get a reference to the controller APlayerController* PController = GetWorld() ->GetFirstPlayerController(); // Get a reference to the HUD from the controller AMyHUD* hud = Cast<AMyHUD>(PController->GetHUD()); hud->addMessage(Message(Icon, FString("Picked up ") + FString(" ") + Name + FString(" ")+FString::FromInt(Quantity), 2.0f, FColor::Black, FColor::Black)); Destroy(); }
void AAvatar::ToggleInventory() { APlayerController* PController = GetWorld()->GetFirstPlayerController(); AMyHUD* hud = Cast<AMyHUD>( PController->GetHUD() ); // If inventory is displayed, undisplay it. if( inventoryShowing ) { hud->clearWidgets(); inventoryShowing = false; PController->bShowMouseCursor = false; return; } // Otherwise, display the player's inventory inventoryShowing = true; PController->bShowMouseCursor = true; for( TMap<FString,int>::TIterator it = Backpack.CreateIterator(); it; ++it ) { // Combine string name of the item, with qty eg Cow x 5 FString fs = it->Key + FString::Printf( TEXT(" x %d"), it->Value ); UTexture2D* tex = NULL; if( Icons.Find( it->Key ) ) { tex = Icons[it->Key]; Widget w( Icon( fs, tex ), Classes[it->Key] ); w.bpSpell = Spells[it->Key]; hud->addWidget( w ); } } }
void AAvatar::MouseRightClicked() { if( inventoryShowing ) { APlayerController* PController = GetWorld()->GetFirstPlayerController(); AMyHUD* hud = Cast<AMyHUD>( PController->GetHUD() ); hud->MouseRightClicked(); } }
void APawnWithCamera::LMB_Out() { APlayerController* MyController = GetWorld()->GetFirstPlayerController(); AMyHUD *Hudref = Cast<AMyHUD>(MyController->GetHUD()); FVector WorldMousePos = Hudref->GetMOuseWorldPosition(); FVector Start = GetActorLocation(); DistanceWithToPoints = FVector::Dist(Start, WorldMousePos); //DrawDebugSphere(GetWorld(), WorldMousePos, 16.f, 8, FColor(83, 155, 83, 255), false, 0.15f); DrawDebugLine(GetWorld(), Start, WorldMousePos, FColor(255, 0, 0), true, 0.5f, 0, 5.0f); }
void ANPCDialogue::Prox_Implementation(AActor* otherActor, UPrimitiveComponent* otherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult) { if (Cast<AFPSHorrorCharacter>(otherActor) == nullptr) { return; } APlayerController* PController = GetWorld()->GetFirstPlayerController(); if (PController) { AMyHUD* hud = Cast<AMyHUD>(PController->GetHUD()); hud->addMessage(FMessage(NPCmessage, 5.0f, FColor::White)); } }
void AAvatar::Pitch( float amount ) { //y if( inventoryShowing ) { // if the button is down click drag APlayerController* PController = GetWorld()->GetFirstPlayerController(); AMyHUD* hud = Cast<AMyHUD>( PController->GetHUD() ); hud->MouseMoved(); } //else { AddControllerPitchInput(200.f*amount * GetWorld()->GetDeltaSeconds()); } }
void AShell::OnHit(AActor* SelfActor, AActor *otherActor, FVector NormalImpulse, const FHitResult& Hit) { if (GEngine){ //If the object hit is a wall, check if it is a breakable wall, update its hit counter and "destroy" the //Wall if it has been hit 2 or more times. Allows the shell to bounce if (otherActor->GetActorLabel().Contains(TEXT("Wall"), ESearchCase::IgnoreCase, ESearchDir::FromEnd)){ AWall* ThisWall = Cast<AWall>(otherActor); if (ThisWall->canBreak){ ThisWall->hits++; if (ThisWall->hits >= 2){ ThisWall->SetActorHiddenInGame(true); ThisWall->SetActorEnableCollision(false); } } } //If the object hit is an AI bot, update its hit counter and destroy the actor if it has been hit more than 3 times //Destroys the shell projectile on impact else if (otherActor->GetActorLabel().Contains(TEXT("Bot"), ESearchCase::IgnoreCase, ESearchDir::FromEnd)){ ABot* ThisBot = Cast<ABot>(otherActor); ThisBot->hits += 1; if (ThisBot->hits >= 3){ //Call the BotsDead function in HUD to decrement the number of bots alive AMyHUD* HUD = Cast<AMyHUD>(GetWorld()->GetFirstPlayerController()->GetHUD()); HUD->BotsDead(); otherActor->Destroy(); } this->Destroy(); } //If the object hit is a player tank, decrement the tank's health. Destroys the shell projectile on impact else if(otherActor->GetActorLabel().Contains(TEXT("Tank"), ESearchCase::IgnoreCase, ESearchDir::FromEnd)){ AMyHUD* HUD = Cast<AMyHUD>(GetWorld()->GetFirstPlayerController()->GetHUD()); HUD->LoseHealth(); this->Destroy(); } //If the object hit is a health pack, increment the tank's health. Destroys the shell projectile on impact else if (otherActor->GetActorLabel().Contains(TEXT("HealthPack"), ESearchCase::IgnoreCase, ESearchDir::FromEnd)){ AMyHUD* HUD = Cast<AMyHUD>(GetWorld()->GetFirstPlayerController()->GetHUD()); HUD->AddHealth(); AHealthPack* ThisPack = Cast<AHealthPack>(otherActor); ThisPack->SetActorHiddenInGame(true); ThisPack->SetActorEnableCollision(false); this->Destroy(); } } }