2025-11-10 11:02:50 +01:00
|
|
|
#include "../include/input.h"
|
2025-11-10 19:22:43 +01:00
|
|
|
#include "../include/gui.h"
|
2025-11-10 11:02:50 +01:00
|
|
|
#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);
|
2025-11-10 19:22:43 +01:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2025-11-10 11:02:50 +01:00
|
|
|
} 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;
|
|
|
|
|
}
|