-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModuleDebug.cpp
148 lines (128 loc) · 4.52 KB
/
ModuleDebug.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "Application.h"
#include "ModuleEntities.h"
#include "ModuleInput.h"
#include "ModuleRender.h"
#include "ModuleFonts.h"
#include "ModuleCollision.h"
#include "ModuleUI.h"
#include "ModuleDebug.h"
#include "ModuleWindow.h"
#include "JsonHandler.h"
#include "Player.h"
ModuleDebug::ModuleDebug() : Module(MODULE_DEBUG)
{
number_string = new char[5];
}
ModuleDebug::~ModuleDebug()
{
RELEASE_ARRAY(number_string);
}
bool ModuleDebug::Start()
{
if (App->parser->LoadObject(DEBUG_SECTION))
{
number_keys = App->parser->GetInt("FunctionKeyNumber");
fkey_strings = new const char*[number_keys];
fkey_positions = new iPoint[number_keys];
App->parser->LoadArrayInObject("FunctionKeys");
for (int i = 0; i < number_keys; i++)
fkey_strings[i] = App->parser->GetStringFromArray(i);
App->parser->LoadArrayInObject("FunctionPositions");
for (int i = 0; i < number_keys; i++)
{
fkey_positions[i].x = App->parser->GetIntFromArrayInArray(i, 0);
fkey_positions[i].y = App->parser->GetIntFromArrayInArray(i, 1);
}
App->parser->GetPoint(position_letter, "Letter_Init");
App->parser->GetPoint(position_number, "Number_Init");
x_increment = App->parser->GetInt("XIncrement");
unactivated_font = App->parser->GetInt("UnactivatedFontId");
activated_font = App->parser->GetInt("ActivatedFontId");
App->parser->UnloadObject();
}
return true;
}
bool ModuleDebug::CleanUp()
{
RELEASE_ARRAY(fkey_positions);
RELEASE_ARRAY(fkey_strings);
return true;
}
update_status ModuleDebug::Update()
{
if (App->input->GetKey(SDL_SCANCODE_F12) == KEY_DOWN)
bdebug_mode = !bdebug_mode;
if (bdebug_mode)
{
if (App->input->GetKey(SDL_SCANCODE_F1) == KEY_DOWN)
bdebug_colliders = !bdebug_colliders;
if (App->input->GetKey(SDL_SCANCODE_F2) == KEY_DOWN)
{
bdebug_camera = !bdebug_camera;
App->renderer->bCenterCamera = !App->renderer->bCenterCamera;
}
if (App->input->GetKey(SDL_SCANCODE_F3) == KEY_DOWN)
bdebug_positions = !bdebug_positions;
if (App->input->GetKey(SDL_SCANCODE_F4) == KEY_DOWN)
{
bdebug_god = !bdebug_god;
int number_players = App->entities->GetNumberPlayers();
for (int i = 0; i < number_players; i++)
{
Player* player = App->entities->GetPlayerByNumber(i);
if (bdebug_god == true)
player->immunity_after_attack->SetMaxTime(0);
else
{
player->immunity_after_attack->SetMaxTime((Uint32)(player->immunity_seconds * 1000.0f));
player->immunity_after_attack->Start();
}
}
}
if (bdebug_colliders)
{
App->collision->DebugDraw();
App->fonts->Blit(activated_font, fkey_positions[0], fkey_strings[0], 0.0f);
}
else
App->fonts->Blit(unactivated_font, fkey_positions[0], fkey_strings[0], 0.0f);
if (bdebug_camera)
{
App->renderer->DebugCamera();
App->fonts->Blit(activated_font, fkey_positions[1], fkey_strings[1], 0.0f);
}
else
App->fonts->Blit(unactivated_font, fkey_positions[1], fkey_strings[1], 0.0f);
if (bdebug_positions)
{
int num_players = App->user_interface->GetNumberOfUIs();
num_players = (num_players > 2) ? 2 : num_players;
int shift = 0;
for (int i = 0; i < num_players; i++)
{
Player* player = App->entities->GetPlayerByNumber(i);
if (player->active)
{
App->fonts->Blit(activated_font, { position_letter.x + shift, position_letter.y }, "x", 0.0f);
App->fonts->Blit(activated_font, { position_letter.x + x_increment + shift, position_letter.y }, "y", 0.0f);
App->fonts->Blit(activated_font, { position_letter.x + 2 * x_increment + shift, position_letter.y }, "z", 0.0f);
App->user_interface->IntToString(player->position.x, number_string);
App->fonts->BlitFromRight(activated_font, { position_number.x + shift, position_number.y }, number_string);
App->user_interface->IntToString(player->position.y, number_string);
App->fonts->BlitFromRight(activated_font, { position_number.x + x_increment + shift, position_number.y }, number_string);
App->user_interface->IntToString(player->position.z, number_string);
App->fonts->BlitFromRight(activated_font, { position_number.x + 2 * x_increment + shift, position_number.y }, number_string);
}
shift += App->window->GetScreenWidth() / 2;
}
App->fonts->Blit(activated_font, fkey_positions[2], fkey_strings[2], 0.0f);
}
else
App->fonts->Blit(unactivated_font, fkey_positions[2], fkey_strings[2], 0.0f);
if (bdebug_god)
App->fonts->Blit(activated_font, fkey_positions[3], fkey_strings[3], 0.0f);
else
App->fonts->Blit(unactivated_font, fkey_positions[3], fkey_strings[3], 0.0f);
}
return UPDATE_CONTINUE;
}