1 /******************************************************************************
2 * irrlamb - https://github.com/jazztickets/irrlamb
3 * Copyright (C) 2019  Alan Witkowski
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 *******************************************************************************/
18 #pragma once
19 
20 // Libraries
21 #include <state.h>
22 #include <replay.h>
23 #include <string>
24 
25 // Forward Declarations
26 class _Object;
27 class _Player;
28 class _Camera;
29 
30 // Classes
31 class _PlayState : public _State {
32 	friend class _Menu;
33 
34 	public:
35 
_PlayState()36 		_PlayState() : CurrentCampaign(0), CampaignLevel(0), ReplayInputs(false) { }
37 
38 		int Init();
39 		int Close();
40 
41 		bool HandleAction(int InputType, int Action, float Value);
42 		bool HandleKeyPress(int Key);
43 		bool HandleMousePress(int Button, int MouseX, int MouseY);
44 		void HandleMouseLift(int Button, int MouseX, int MouseY);
45 		void HandleMouseWheel(float Direction);
46 		void HandleGUI(irr::gui::EGUI_EVENT_TYPE EventType, irr::gui::IGUIElement *Element);
47 
48 		void Update(float FrameTime);
49 		void UpdateRender(float BlendFactor);
50 		void Draw();
51 
52 		bool IsPaused();
53 		void StartReset();
54 		void ResetLevel();
55 		void WinLevel(bool HideNextLevel=false);
56 		void LoseLevel();
57 
SetTestLevel(const std::string & Level)58 		void SetTestLevel(const std::string &Level) { TestLevel = Level; }
SetValidateReplay(const std::string & Replay)59 		void SetValidateReplay(const std::string &Replay) { InputReplayFilename = Replay; ReplayInputs = Replay != ""; }
SetCampaign(int Value)60 		void SetCampaign(int Value) { CurrentCampaign = Value; }
SetCampaignLevel(int Value)61 		void SetCampaignLevel(int Value) { CampaignLevel = Value; }
62 
GetCamera()63 		_Camera *GetCamera() { return Camera; }
GetTimer()64 		float GetTimer() { return Timer; }
65 
66 	private:
67 
68 		// Replays
69 		void RecordInput();
70 		void RecordPlayerSpeed();
71 		void GetInputFromReplay();
72 
73 		// States
74 		std::string TestLevel;
75 		float Timer;
76 		int HighScoreIndex;
77 		bool FirstLoad;
78 		bool Resetting;
79 		bool Jumped;
80 
81 		// Campaign
82 		uint32_t CurrentCampaign, CampaignLevel;
83 
84 		// Objects
85 		_Player *Player;
86 		_Camera *Camera;
87 
88 		// Replays
89 		std::string InputReplayFilename;
90 		bool ReplayInputs;
91 		_Replay *InputReplay;
92 		_ReplayEvent NextEvent;
93 };
94 
95 extern _PlayState PlayState;
96