|
0
|
1 |
/*
|
|
|
2 |
Copyright (c) 2023 MCL Software
|
|
|
3 |
|
|
|
4 |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”),
|
|
|
5 |
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
6 |
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
|
7 |
|
|
|
8 |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
|
9 |
|
|
|
10 |
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
11 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
12 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
13 |
*/
|
|
|
14 |
|
|
|
15 |
#include "kbdinput.h"
|
|
|
16 |
|
|
|
17 |
bool keysHeldDown[128];
|
|
|
18 |
|
|
|
19 |
Uint8 performYesNo()
|
|
|
20 |
{
|
|
|
21 |
if(keysHeldDown[28])
|
|
|
22 |
{
|
|
|
23 |
return 1;
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
else if(keysHeldDown[17])
|
|
|
27 |
{
|
|
|
28 |
return 2;
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
return 0;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
bool performMenuKeyActions()
|
|
|
35 |
{
|
|
|
36 |
/*if(keysHeldDown[44])
|
|
|
37 |
{
|
|
|
38 |
gameRunning = 1;
|
|
|
39 |
}*/
|
|
|
40 |
|
|
|
41 |
if(keysHeldDown[81])
|
|
|
42 |
{
|
|
|
43 |
selectedMenuItem += selectedMenuItem < 3 ? 1 : -3;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
else if(keysHeldDown[82])
|
|
|
47 |
{
|
|
|
48 |
selectedMenuItem -= selectedMenuItem > 0 ? 1 : -3;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
else if(keysHeldDown[40])
|
|
|
52 |
{
|
|
|
53 |
if(selectedMenuItem == 0)
|
|
|
54 |
{
|
|
|
55 |
gameRunning = 1;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
else if(selectedMenuItem == 3)
|
|
|
59 |
{
|
|
|
60 |
return 0;
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
return 1;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
bool performPlayerMovement()
|
|
|
68 |
{
|
|
|
69 |
SDL_Point trans = {0, 0};
|
|
|
70 |
/*for(int i = 0; i < 128; i++)
|
|
|
71 |
{
|
|
|
72 |
if(keysHeldDown[i] == 1)
|
|
|
73 |
{
|
|
|
74 |
printf("\n% is pressed", i);
|
|
|
75 |
}
|
|
|
76 |
}*/
|
|
|
77 |
|
|
|
78 |
if(!player.canMove)
|
|
|
79 |
{
|
|
|
80 |
return false;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
if(keysHeldDown[79])
|
|
|
84 |
{
|
|
|
85 |
if(getObjectFromIdent(levelTiles[(player.x + 1) * LEVEL_WIDTH + player.y]).passable)
|
|
|
86 |
{
|
|
|
87 |
trans = getTransformation(1, 0);
|
|
|
88 |
offset.x -= TILE_WIDTH / 2;
|
|
|
89 |
offset.y -= TILE_HEIGHT / 4;
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
else if(keysHeldDown[80])
|
|
|
94 |
{
|
|
|
95 |
if(getObjectFromIdent(levelTiles[(player.x - 1) * LEVEL_WIDTH + player.y]).passable)
|
|
|
96 |
{
|
|
|
97 |
trans = getTransformation(-1, 0);
|
|
|
98 |
offset.y += TILE_HEIGHT / 4;
|
|
|
99 |
offset.x += TILE_WIDTH / 2;
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
if(keysHeldDown[81])
|
|
|
104 |
{
|
|
|
105 |
if(getObjectFromIdent(levelTiles[player.x * LEVEL_WIDTH + player.y + 1]).passable)
|
|
|
106 |
{
|
|
|
107 |
trans = (SDL_Point){trans.x + getTransformation(0, 1).x, trans.y + getTransformation(0, 1).y};
|
|
|
108 |
offset.y -= TILE_HEIGHT / 4;
|
|
|
109 |
offset.x += TILE_WIDTH / 2;
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
else if(keysHeldDown[82])
|
|
|
114 |
{
|
|
|
115 |
if(getObjectFromIdent(levelTiles[player.x * LEVEL_WIDTH + player.y - 1]).passable)
|
|
|
116 |
{
|
|
|
117 |
trans = (SDL_Point){trans.x + getTransformation(0, -1).x, trans.y + getTransformation(0, -1).y};
|
|
|
118 |
offset.y += TILE_HEIGHT / 4;
|
|
|
119 |
offset.x -= TILE_WIDTH / 2;
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
// Cam movm't
|
|
|
124 |
if(keysHeldDown[7])
|
|
|
125 |
{
|
|
|
126 |
offset.x -= TILE_WIDTH / 2;
|
|
|
127 |
offset.y -= TILE_HEIGHT / 4;
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
else if(keysHeldDown[4])
|
|
|
131 |
{
|
|
|
132 |
offset.y += TILE_HEIGHT / 4;
|
|
|
133 |
offset.x += TILE_WIDTH / 2;
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
if(keysHeldDown[26])
|
|
|
137 |
{
|
|
|
138 |
offset.y -= TILE_HEIGHT / 4;
|
|
|
139 |
offset.x += TILE_WIDTH / 2;
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
else if(keysHeldDown[22])
|
|
|
143 |
{
|
|
|
144 |
offset.y += TILE_HEIGHT / 4;
|
|
|
145 |
offset.x -= TILE_WIDTH / 2;
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
// G - steal
|
|
|
149 |
if(keysHeldDown[10])
|
|
|
150 |
{
|
|
|
151 |
if(getObjectFromIdent(levelTiles[player.x * LEVEL_WIDTH + player.y]).stealable)
|
|
|
152 |
{
|
|
|
153 |
stealItem(levelTiles[player.x * LEVEL_WIDTH + player.y]);
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
return true;
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
player.x += trans.x;
|
|
|
161 |
player.y += trans.y;
|
|
|
162 |
|
|
|
163 |
if(keysHeldDown[79] || keysHeldDown[80] || keysHeldDown[81] || keysHeldDown[82])
|
|
|
164 |
{
|
|
|
165 |
return true;
|
|
|
166 |
}
|
|
|
167 |
return false;
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
void handleKeyboard(SDL_Event event)
|
|
|
172 |
{
|
|
|
173 |
if(event.type == SDL_KEYDOWN)
|
|
|
174 |
{
|
|
|
175 |
keysHeldDown[event.key.keysym.scancode] = 1;
|
|
|
176 |
|
|
|
177 |
|
|
|
178 |
//printf("%i", event.key.keysym.scancode);
|
|
|
179 |
if(event.key.keysym.scancode == 9 && !event.key.repeat)
|
|
|
180 |
{
|
|
|
181 |
orientation += 1;
|
|
|
182 |
if(orientation == 4)
|
|
|
183 |
orientation = 0;
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
if(event.key.keysym.scancode == 46 && !event.key.repeat)
|
|
|
187 |
{
|
|
|
188 |
zoomFactor += zoomFactor == -2 ? 3 : 1;
|
|
|
189 |
updateZoomFactor();
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
else if(event.key.keysym.scancode == 45 && !event.key.repeat)
|
|
|
193 |
{
|
|
|
194 |
zoomFactor -= zoomFactor == 1 ? 3 : 1;
|
|
|
195 |
updateZoomFactor();
|
|
|
196 |
}
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
else if(event.type == SDL_KEYUP)
|
|
|
200 |
{
|
|
|
201 |
keysHeldDown[event.key.keysym.scancode] = 0;
|
|
|
202 |
}
|
|
|
203 |
}
|