42 lines
1.3 KiB
C
42 lines
1.3 KiB
C
|
|
#include "../include/input.h"
|
||
|
|
#include <ncurses.h>
|
||
|
|
|
||
|
|
/* Returns 1 to continue, 0 if quit requested (player inactive). */
|
||
|
|
int process_input(int input,
|
||
|
|
int *pause,
|
||
|
|
int *auto_shoot,
|
||
|
|
struct game_obj *player,
|
||
|
|
struct game_obj bullets[],
|
||
|
|
int bullet_attivi,
|
||
|
|
int *next_bullet) {
|
||
|
|
|
||
|
|
if (input == KEY_RIGHT && !(*pause) && player->x < (WIDTH - 2)) {
|
||
|
|
player->x += 2;
|
||
|
|
} else if (input == KEY_LEFT && !(*pause) && player->x > 2) {
|
||
|
|
player->x -= 2;
|
||
|
|
} else if (!(*auto_shoot) && input == ' ' && bullet_attivi < BULLET_N && !(*pause)) {
|
||
|
|
if (*next_bullet != -1) {
|
||
|
|
bullets[*next_bullet].x = player->x;
|
||
|
|
bullets[*next_bullet].y = player->y - 1;
|
||
|
|
bullets[*next_bullet].active = 1;
|
||
|
|
}
|
||
|
|
} else if (input == 'p') {
|
||
|
|
*pause = !(*pause);
|
||
|
|
} else if (input == 'q') {
|
||
|
|
/* signal to caller to quit by marking player inactive */
|
||
|
|
return 0;
|
||
|
|
} else if (input == 'g') {
|
||
|
|
*auto_shoot = !(*auto_shoot);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (*auto_shoot && bullet_attivi < BULLET_N && !(*pause)) {
|
||
|
|
if (*next_bullet != -1) {
|
||
|
|
bullets[*next_bullet].x = player->x;
|
||
|
|
bullets[*next_bullet].y = player->y - 1;
|
||
|
|
bullets[*next_bullet].active = 1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return 1;
|
||
|
|
}
|