space-shooter/src/input.c

51 lines
1.5 KiB
C

#include "../include/input.h"
#include "../include/gui.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);
int choice = print_menu(stdscr, PAUSE_MODE);
switch(choice) {
case 0: {
werase(stdscr);
mvprintw(LINES-1, 1, "p per pausa");
*pause = !(*pause);
break;
}
case 1: return 0; break;
}
} 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;
}