This repository has been archived by the owner on Jun 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
/
DebugKeys.cpp
217 lines (182 loc) · 5.39 KB
/
DebugKeys.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
* Copyright (C) 2006-2012 Christopho, Solarus - http://www.solarus-games.org
*
* Solarus is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Solarus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses */
#include "DebugKeys.h"
#include "MainLoop.h"
#include "Game.h"
#include "Map.h"
#include "DialogBox.h"
#include "Equipment.h"
#include "entities/Hero.h"
#include "entities/MapEntities.h"
#include "movements/Movement.h"
/**
* @brief Constructor.
* @param main_loop the Solarus main loop object
*/
DebugKeys::DebugKeys(MainLoop& main_loop):
main_loop(main_loop), game(NULL) {
}
/**
* @brief Destructor.
*/
DebugKeys::~DebugKeys() {
}
/**
* @brief Sets the current game.
* @param game the current game, or NULL if there is no game
*/
void DebugKeys::set_game(Game* game) {
this->game = game;
}
/**
* @brief This function is called when a keyboard key is pressed.
* @param key the key pressed
*/
void DebugKeys::key_pressed(InputEvent::KeyboardKey key) {
#ifdef SOLARUS_DEBUG_KEYS
// don't consider the debug keys in release mode
if (game != NULL) {
Equipment &equipment = game->get_equipment();
switch (key) {
case InputEvent::KEY_p:
equipment.add_life(12);
break;
case InputEvent::KEY_m:
equipment.remove_life(1);
break;
case InputEvent::KEY_o:
equipment.add_money(23);
break;
case InputEvent::KEY_l:
equipment.remove_money(14);
break;
case InputEvent::KEY_i:
equipment.add_magic(10);
break;
case InputEvent::KEY_k:
equipment.remove_magic(4);
break;
case InputEvent::KEY_j:
if (!equipment.is_magic_decreasing()) {
equipment.start_removing_magic(200);
}
else {
equipment.stop_removing_magic();
}
break;
case InputEvent::KEY_g:
{
Hero& hero = game->get_hero();
Layer layer = hero.get_layer();
if (layer != LAYER_LOW) {
layer = Layer(layer - 1);
game->get_current_map().get_entities().set_entity_layer(hero, layer);
hero.check_position();
}
break;
}
case InputEvent::KEY_t:
{
Hero& hero = game->get_hero();
Layer layer = hero.get_layer();
if (layer != LAYER_HIGH) {
layer = Layer(layer + 1);
game->get_current_map().get_entities().set_entity_layer(hero, layer);
hero.check_position();
}
break;
}
case InputEvent::KEY_KP7:
equipment.set_max_magic(0);
break;
case InputEvent::KEY_KP8:
equipment.set_max_magic(42);
break;
case InputEvent::KEY_KP9:
equipment.set_max_magic(84);
break;
case InputEvent::KEY_KP1:
equipment.set_ability("tunic", std::max(equipment.get_ability("tunic") - 1, 1));
game->get_hero().rebuild_equipment();
break;
case InputEvent::KEY_KP4:
equipment.set_ability("tunic", std::min(equipment.get_ability("tunic") + 1, 3));
game->get_hero().rebuild_equipment();
break;
case InputEvent::KEY_KP2:
equipment.set_ability("sword", std::max(equipment.get_ability("sword") - 1, 0));
game->get_hero().rebuild_equipment();
break;
case InputEvent::KEY_KP5:
equipment.set_ability("sword", std::min(equipment.get_ability("sword") + 1, 4));
game->get_hero().rebuild_equipment();
break;
case InputEvent::KEY_KP3:
equipment.set_ability("shield", std::max(equipment.get_ability("shield") - 1, 0));
game->get_hero().rebuild_equipment();
break;
case InputEvent::KEY_KP6:
equipment.set_ability("shield", std::min(equipment.get_ability("shield") + 1, 3));
game->get_hero().rebuild_equipment();
break;
default:
break;
}
}
else {
// no game yet
if (key == InputEvent::KEY_F1) {
main_loop.start_game("save1.dat");
}
else if (key == InputEvent::KEY_F2) {
main_loop.start_game("save2.dat");
}
else if (key == InputEvent::KEY_F3) {
main_loop.start_game("save3.dat");
}
}
#endif
}
/**
* @brief This function is called when a keyboard key is released.
* @param key the key released
*/
void DebugKeys::key_released(InputEvent::KeyboardKey key) {
}
/**
* @brief This function is called repeatedly by the engine.
*/
void DebugKeys::update() {
#ifdef SOLARUS_DEBUG_KEYS
if (InputEvent::is_shift_down()) {
if (game != NULL && game->is_showing_dialog()) {
game->get_dialog_box().show_all_now();
}
}
// traverse walls when control is pressed
if (game != NULL) {
Movement *movement = game->get_hero().get_movement();
if (movement != NULL) {
if (InputEvent::is_control_down()) {
movement->set_ignore_obstacles(true);
}
else {
movement->restore_default_ignore_obstacles();
}
}
}
#endif
}