Revision 200
zoom controls
proj/include/proj_func.h | ||
---|---|---|
3 | 3 |
|
4 | 4 |
#include "ent.h" |
5 | 5 |
|
6 |
#include <stdint.h> |
|
7 |
|
|
6 | 8 |
/** |
7 | 9 |
* @brief Cleans up all memory, unsubscribes interrupts. |
8 | 10 |
* @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK |
... | ... | |
17 | 19 |
*/ |
18 | 20 |
void update_movement(ent_t *p); |
19 | 21 |
|
22 |
typedef struct keys { |
|
23 |
uint8_t w_pressed : 1; |
|
24 |
uint8_t a_pressed : 1; |
|
25 |
uint8_t s_pressed : 1; |
|
26 |
uint8_t d_pressed : 1; |
|
27 |
uint8_t ctrl_pressed : 1; |
|
28 |
uint8_t plus_pressed : 1; |
|
29 |
uint8_t minus_pressed : 1; |
|
30 |
} keys_t; |
|
31 |
|
|
20 | 32 |
void update_mouse_position(struct packet *p); |
21 | 33 |
|
34 |
void update_scale(void); |
|
35 |
|
|
22 | 36 |
int32_t get_mouse_X(void); |
23 | 37 |
|
24 | 38 |
int32_t get_mouse_Y(void); |
proj/include/proj_macros.h | ||
---|---|---|
4 | 4 |
#include "graph_macros.h" |
5 | 5 |
|
6 | 6 |
// WASD Movement Keys |
7 |
#define W_MAKE_CODE 0x11 /** @brief W Make Code */ |
|
8 |
#define W_BREAK_CODE 0x91 /** @brief W Break Code */ |
|
9 |
#define A_MAKE_CODE 0x1E /** @brief A Make Code */ |
|
10 |
#define A_BREAK_CODE 0x9E /** @brief A Break Code */ |
|
11 |
#define S_MAKE_CODE 0x1F /** @brief S Make Code */ |
|
12 |
#define S_BREAK_CODE 0x9F /** @brief S Break Code */ |
|
13 |
#define D_MAKE_CODE 0x20 /** @brief D Make Code */ |
|
14 |
#define D_BREAK_CODE 0xA0 /** @brief D Break Code */ |
|
7 |
#define W_MAKE_CODE 0x11 /** @brief W Make Code */ |
|
8 |
#define W_BREAK_CODE 0x91 /** @brief W Break Code */ |
|
9 |
#define A_MAKE_CODE 0x1E /** @brief A Make Code */ |
|
10 |
#define A_BREAK_CODE 0x9E /** @brief A Break Code */ |
|
11 |
#define S_MAKE_CODE 0x1F /** @brief S Make Code */ |
|
12 |
#define S_BREAK_CODE 0x9F /** @brief S Break Code */ |
|
13 |
#define D_MAKE_CODE 0x20 /** @brief D Make Code */ |
|
14 |
#define D_BREAK_CODE 0xA0 /** @brief D Break Code */ |
|
15 |
#define CTRL_MAKE_CODE 0x1D /** @brief CTRL Make Code */ |
|
16 |
#define CTRL_BREAK_CODE 0x9D /** @brief CTRL Break Code */ |
|
17 |
#define PLUS_MAKE_CODE 0x1A /** @brief Plus (+) Make Code */ |
|
18 |
#define PLUS_BREAK_CODE 0x9A /** @brief Plus (+) Break Code */ |
|
19 |
#define MINUS_MAKE_CODE 0x35 /** @brief Minus (-) Make Code */ |
|
20 |
#define MINUS_BREAK_CODE 0xB5 /** @brief Minus (-) Break Code */ |
|
15 | 21 |
|
16 | 22 |
// Movement Directions |
17 | 23 |
#define UP -1 /** @brief Moving to the top side of screen */ |
... | ... | |
29 | 35 |
|
30 | 36 |
//Graphics mode |
31 | 37 |
#define GRAPH_MODE DIRECT_1280_1024_888 /** @brief Graphic mode used */ |
38 |
#define MIN_SCALE 0.3 /** @brief Minimum zoom */ |
|
39 |
#define DEFAULT_SCALE 1.0 /** @brief Default zoom */ |
|
40 |
#define MAX_SCALE 10.0 /** @brief Maximum zoom */ |
|
32 | 41 |
|
33 | 42 |
#endif /* end of include guard: PROJ_MACROS_H_INCLUDED */ |
proj/include/utils.h | ||
---|---|---|
49 | 49 |
*/ |
50 | 50 |
int32_t max(int32_t a, int32_t b); |
51 | 51 |
|
52 |
/** |
|
53 |
* @brief Gets the minimum value out of two doubles. |
|
54 |
* @param a First value |
|
55 |
* @param b Second value |
|
56 |
* @return The minimum of the two values |
|
57 |
*/ |
|
58 |
double min_d(double a, double b); |
|
52 | 59 |
|
60 |
/** |
|
61 |
* @brief Gets the maximum value out of two doubles. |
|
62 |
* @param a First value |
|
63 |
* @param b Second value |
|
64 |
* @return The maximum of the two values |
|
65 |
*/ |
|
66 |
double max_d(double a, double b); |
|
67 |
|
|
68 |
|
|
53 | 69 |
#endif //UTILS_H_INCLUDED |
proj/src/proj.c | ||
---|---|---|
121 | 121 |
ent_draw(shooter1); |
122 | 122 |
sprite_draw(sp_crosshair); |
123 | 123 |
graph_draw(); |
124 |
|
|
125 |
uint32_t refresh_count_value = sys_hz() / REFRESH_RATE; |
|
124 | 126 |
#endif |
125 | 127 |
|
126 | 128 |
/// loop stuff |
... | ... | |
147 | 149 |
if ((scancode[0]) == ESC_BREAK_CODE) good = 0; |
148 | 150 |
#ifdef TELMO |
149 | 151 |
if (i == 0) { |
150 |
uint32_t refresh_count_value = sys_hz() / REFRESH_RATE; |
|
151 | 152 |
if (no_interrupts % refresh_count_value == 0) { |
152 | 153 |
update_movement(shooter1); |
154 |
update_scale(); |
|
153 | 155 |
ent_set_origin(ent_get_x(shooter1)-ent_get_XLength()/2.0, |
154 | 156 |
ent_get_y(shooter1)-ent_get_YLength()/2.0); |
155 | 157 |
|
... | ... | |
182 | 184 |
} else { /* received standart message, not a notification */ |
183 | 185 |
/* no standart message expected: do nothing */ |
184 | 186 |
} |
185 |
#ifdef TELMO |
|
186 |
switch (get_hor_movement()) { |
|
187 |
case LEFT: |
|
188 |
printf("GOING LEFT.\n"); |
|
189 |
break; |
|
190 |
case RIGHT: |
|
191 |
printf("GOING RIGHT.\n"); |
|
192 |
break; |
|
193 |
} |
|
194 |
switch (get_ver_movement()) { |
|
195 |
case UP: |
|
196 |
printf("GOING UP.\n"); |
|
197 |
break; |
|
198 |
case DOWN: |
|
199 |
printf("GOING DOWN.\n"); |
|
200 |
break; |
|
201 |
} |
|
202 |
#endif |
|
203 | 187 |
} |
204 | 188 |
|
205 | 189 |
#ifdef TELMO |
proj/src/proj_func.c | ||
---|---|---|
8 | 8 |
#include "errors.h" |
9 | 9 |
#include "proj_macros.h" |
10 | 10 |
#include "utils.h" |
11 |
#include "ent.h" |
|
11 | 12 |
|
12 | 13 |
#include "kbc_macros.h" |
13 | 14 |
|
... | ... | |
24 | 25 |
} |
25 | 26 |
|
26 | 27 |
static int hor_mov = REST, ver_mov = REST; |
28 |
static keys_t key_presses; |
|
27 | 29 |
|
28 | 30 |
void update_key_presses(void) { |
29 |
static int w_pressed = 0, a_pressed = 0, s_pressed = 0, d_pressed = 0; |
|
30 | 31 |
if (sz == 1) { |
31 | 32 |
switch(scancode[0]) { |
32 |
case W_MAKE_CODE : w_pressed = 1; break; |
|
33 |
case W_BREAK_CODE : w_pressed = 0; break; |
|
34 |
case A_MAKE_CODE : a_pressed = 1; break; |
|
35 |
case A_BREAK_CODE : a_pressed = 0; break; |
|
36 |
case S_MAKE_CODE : s_pressed = 1; break; |
|
37 |
case S_BREAK_CODE : s_pressed = 0; break; |
|
38 |
case D_MAKE_CODE : d_pressed = 1; break; |
|
39 |
case D_BREAK_CODE : d_pressed = 0; break; |
|
33 |
case W_MAKE_CODE : key_presses.w_pressed = 1; break; |
|
34 |
case W_BREAK_CODE : key_presses.w_pressed = 0; break; |
|
35 |
case A_MAKE_CODE : key_presses.a_pressed = 1; break; |
|
36 |
case A_BREAK_CODE : key_presses.a_pressed = 0; break; |
|
37 |
case S_MAKE_CODE : key_presses.s_pressed = 1; break; |
|
38 |
case S_BREAK_CODE : key_presses.s_pressed = 0; break; |
|
39 |
case D_MAKE_CODE : key_presses.d_pressed = 1; break; |
|
40 |
case D_BREAK_CODE : key_presses.d_pressed = 0; break; |
|
41 |
case CTRL_MAKE_CODE : key_presses.ctrl_pressed = 1; break; |
|
42 |
case CTRL_BREAK_CODE : key_presses.ctrl_pressed = 0; break; |
|
43 |
case PLUS_MAKE_CODE : key_presses.plus_pressed = 1; break; |
|
44 |
case PLUS_BREAK_CODE : key_presses.plus_pressed = 0; break; |
|
45 |
case MINUS_MAKE_CODE : key_presses.minus_pressed = 1; break; |
|
46 |
case MINUS_BREAK_CODE : key_presses.minus_pressed = 0; break; |
|
40 | 47 |
} |
41 | 48 |
} |
42 |
ver_mov = s_pressed - w_pressed;
|
|
43 |
hor_mov = d_pressed - a_pressed;
|
|
49 |
ver_mov = key_presses.s_pressed - key_presses.w_pressed;
|
|
50 |
hor_mov = key_presses.d_pressed - key_presses.a_pressed;
|
|
44 | 51 |
} |
45 | 52 |
|
46 | 53 |
void update_movement(ent_t *p) { |
... | ... | |
48 | 55 |
ent_set_pos(p, ent_get_x(p) + speed * hor_mov, ent_get_y(p) + speed * ver_mov); |
49 | 56 |
} |
50 | 57 |
|
58 |
void update_scale(void) { |
|
59 |
static uint8_t last_plus = 0, last_minus = 0; |
|
60 |
if (key_presses.ctrl_pressed) { |
|
61 |
if (key_presses.plus_pressed && !last_plus) { |
|
62 |
double scale = ent_get_scale(); |
|
63 |
scale *= 1.1; |
|
64 |
if (scale <= MAX_SCALE) ent_set_scale(scale); |
|
65 |
} |
|
66 |
else if (key_presses.minus_pressed && !last_minus) { |
|
67 |
double scale = ent_get_scale(); |
|
68 |
scale /= 1.1; |
|
69 |
if (scale >= MIN_SCALE) ent_set_scale(scale); |
|
70 |
} |
|
71 |
|
|
72 |
printf("SCALE: %d\n", (int)(ent_get_scale()*1000)); |
|
73 |
} |
|
74 |
|
|
75 |
last_plus = key_presses.plus_pressed; |
|
76 |
last_minus = key_presses.minus_pressed; |
|
77 |
} |
|
78 |
|
|
51 | 79 |
static int32_t mouse_x = 0, mouse_y = 0; |
52 | 80 |
|
53 | 81 |
void update_mouse_position(struct packet *p) { |
proj/src/utils.c | ||
---|---|---|
33 | 33 |
|
34 | 34 |
int32_t min(int32_t a, int32_t b){ return (b < a ? b : a); } |
35 | 35 |
int32_t max(int32_t a, int32_t b){ return (a < b ? b : a); } |
36 |
|
|
37 |
double min_d(double a, double b){ return (b < a ? b : a); } |
|
38 |
double max_d(double a, double b){ return (a < b ? b : a); } |
Also available in: Unified diff