18.Setting Up the Play States
BatteryCollectorGameMode.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 |
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "GameFramework/GameMode.h"
#include "BatteryCollectorGameMode.generated.h"
//enum to store the current state of gameplay
UENUM(BlueprintType)
enum class EBatteryPlayState{
EPlaying,
EGameOver,
EWon,
EUnknown
};
UCLASS(minimalapi)
class ABatteryCollectorGameMode : public AGameMode
{
GENERATED_BODY()
public:
/**Returns the current playing state*/
UFUNCTION(Blueprintpure, Category = "Power")
EBatteryPlayState GetCurrentState() const;
//Sets a new playing state
void SetCurrentState(EBatteryPlayState NewState)
private:
/**Keeps track of the current playing state*/
EBatteryPlayState CurrentState;
};
|
cs |
8~14)상태. EUnknown = default
23) 현재상태 리턴
25) 새로운 상태 설정
BatteryCollectorGameMode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 |
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "BatteryCollector.h"
#include "BatteryCollectorGameMode.h"
#include "BatteryCollectorCharacter.h"
#include "Kismet/GameplayStatics.h"
#include "Blueprint/UserWidget.h"
void ABatteryCollectorGameMode::Tick(float DeltaTime){
Super::Tick(DeltaTime);
//Check that we are using the battery collector character
ABatteryCollectorCharacter* MyCharacter = Cast<ABatteryCollectorCharacter>(UGameplayStatics::GetPlayerPawn(this, 0));
if (MyCharacter){
//If our power is greater than needed to win, set the game's state to won
if (MyCharacter->GetCurrentPower() > PowerToWin){
SetCurrentState(EBatteryPlayState::EWon);
}
//if the character's power is positive
else if (MyCharacter->GetCurrentPower() > 0){
//decrease the character's power using the decay rate
MyCharacter->UpdatePower(-DeltaTime*DecayRate*(MyCharacter->GetInitialPower()));
}
else{
SetCurrentState(EBatteryPlayState::EGameOver);
}
}
}
EBatteryPlayState ABatteryCollectorGameMode::GetCurrentState() const{
return CurrentState;
}
void ABatteryCollectorGameMode::SetCurrentState(EBatteryPlayState NewState){
CurrentState = NewState;
}
|
cs |
state text binding
'프로그래밍 > Unreal' 카테고리의 다른 글
[16] UE4 C++ 프로그래밍 입문_0 (0) | 2017.05.15 |
---|---|
[15]Battery Collector_플레이 상태별 spawn volume작동, 플레이어 입력차단, 캐릭터 레그돌효과 (0) | 2017.05.14 |
[13]Battery Collector_HUD 블루프린트 만들기 (0) | 2017.05.12 |
[12]Battery Collector_UMG 활성화 (0) | 2017.05.11 |
[11]Battery Collector_particle추가 (0) | 2017.05.11 |