play_state.cpp 2.92 KB
Newer Older
1
2
#include <audio/sound_manager.hpp>
#include <audio/audio.hpp>
Elias Broschin's avatar
Elias Broschin committed
3
4
5
6
7
8
9
#include <game_state_machine/play_state.h>
#include <util/id.hpp>
#include <core/engine.hpp>
#include <ecs/entity_manager.hpp>
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
#include <ecs/entity.hpp>
Elias Broschin's avatar
Elias Broschin committed
10
11
#include <game_state_machine/game_state_machine.h>
#include <game_state_machine/menu_state.h>
Georg Schaefer's avatar
Georg Schaefer committed
12
13
14
#include <rendering/camera_component.hpp>
#include <rendering/directional_light_component.hpp>
#include <rendering/light_component.hpp>
15
#include <rendering/instanced_staticmesh_component.hpp>
Georg Schaefer's avatar
Georg Schaefer committed
16
17
#include <rendering/rendering_system.hpp>
#include <rendering/shadow_component.hpp>
Elias Broschin's avatar
Elias Broschin committed
18
19
#include <rendering/staticmesh_component.hpp>
#include <physics/movement/movement_component.h>
20
21
#include <physics/collision/collision_component.h>
#include <physics/collision/sphere.h>
Elias Broschin's avatar
Elias Broschin committed
22
#include <iostream>
Elias Broschin's avatar
Elias Broschin committed
23
24
#include <util/make_unique.hpp>
#include <util/logger.hpp>
25
#include <util/config.hpp>
Elias Broschin's avatar
Elias Broschin committed
26
#include <input/input.hpp>
Jerry's avatar
Jerry committed
27
#include <mapgen/maploader.hpp>
Elias Broschin's avatar
Elias Broschin committed
28
29
#include <time.h>
#include <gameplay/level_manager.h>
Elias Broschin's avatar
Elias Broschin committed
30
#include <glm/gtx/intersect.hpp>
Elias Broschin's avatar
Elias Broschin committed
31
32
#include <gameplay/game_input_manager.h>
#include <gameplay/game_play_system.h>
33
#include <audio/AudioEventHandler.hpp>
Jerry's avatar
Jerry committed
34
35
#include <ui/ui_system.hpp>
#include <ui/box_widget.hpp>
36
#include <ui/UIManager.hpp>
Jerry's avatar
Jerry committed
37
#include <ui/texture_widget.hpp>
Jerry's avatar
Jerry committed
38
#include <ui/text_widget.hpp>
Michael Ochmann's avatar
Michael Ochmann committed
39
#include <ui/ui_widget.hpp>
40
41
#include <ui/text_widget.hpp>
#include <util/fsi.hpp>
Elias Broschin's avatar
Elias Broschin committed
42
43
44

namespace gdw {

Michael Ochmann's avatar
Michael Ochmann committed
45
play_state::play_state(engine &engine):game_state(engine) {
Elias Broschin's avatar
Elias Broschin committed
46
    id_ = type_id<play_state>();
47
	this->uiManager = make_unique<gdw::UIManager>(this->engine_, "ui/HUD.json");
Elias Broschin's avatar
Elias Broschin committed
48
49
50
51
52
}

play_state::~play_state() {}

void play_state::on_enter() {
53
	this->engine_.game_play_system().gamemanager().timer().start();
Michael Ochmann's avatar
Michael Ochmann committed
54
	this->uiManager->render(true);
55
	this->engine_.audioEventHandler().trigger(AudioEventHandler::PLAY_STATE_ENTER);
56

57
    engine_.game_play_system().level_manager().build_stage();
Jerry's avatar
Jerry committed
58
	if (this->engine_.getConfig().get<bool>("test_ui", false)) {
Michael Ochmann's avatar
Michael Ochmann committed
59
	}
Elias Broschin's avatar
Elias Broschin committed
60
61
}

Elias Broschin's avatar
Elias Broschin committed
62
void play_state::update(float dt) {
63
64
65
66
67
68
69
70
	text_widget* timer = (text_widget*) this->uiManager->getElementById("timerText");
	text_widget* stage = (text_widget*) this->uiManager->getElementById("stage");
	text_widget* points = (text_widget*) this->uiManager->getElementById("points");

	timer->text(fsi::secondsToTimestamp(this->engine_.game_play_system().gamemanager().timer().time()));
	stage->text(std::to_string(this->engine_.game_play_system().gamemanager().stage()));
	points->text(std::to_string(this->engine_.game_play_system().gamemanager().points()));

Elias Broschin's avatar
Elias Broschin committed
71
	engine_.game_play_system().update(dt);
72
	this->engine_.audioEventHandler().playStateUpdate(dt);
Elias Broschin's avatar
Elias Broschin committed
73

74
	if (this->engine_.input().pressed("state_switch"))
75
		this->engine_.game_state_machine().change_state<menu_state>();
Elias Broschin's avatar
Elias Broschin committed
76
}
Elias Broschin's avatar
Elias Broschin committed
77
78

void play_state::on_exit() {
Michael Ochmann's avatar
Michael Ochmann committed
79
	this->uiManager->render(false);
80
	this->engine_.game_play_system().gamemanager().timer().stop();
81
	this->engine_.audioEventHandler().trigger(AudioEventHandler::PLAY_STATE_LEAVE);
Elias Broschin's avatar
Elias Broschin committed
82
83
84
}

} //namespace gdw