Sistemazione setup e controllo dimensioni finestra
This commit is contained in:
parent
24987d510a
commit
271bb01639
1 changed files with 32 additions and 28 deletions
60
main.c
60
main.c
|
|
@ -8,8 +8,9 @@
|
||||||
#define DELAY 30000
|
#define DELAY 30000
|
||||||
#define ENEMY_N 5
|
#define ENEMY_N 5
|
||||||
#define BULLET_N 3
|
#define BULLET_N 3
|
||||||
#define MIN_WIDTH 52
|
#define WIDTH 52
|
||||||
#define MIN_HEIGHT 30
|
#define HEIGHT 30
|
||||||
|
#define MIN_COLS 110
|
||||||
|
|
||||||
struct speed {
|
struct speed {
|
||||||
int slowness;
|
int slowness;
|
||||||
|
|
@ -24,16 +25,24 @@ struct game_obj {
|
||||||
};
|
};
|
||||||
|
|
||||||
/************** FUNZIONI GUI ***************/
|
/************** FUNZIONI GUI ***************/
|
||||||
char title[] =
|
#define TITLE_LINES 6
|
||||||
"###########################################################################################################\n"
|
char* title[] =
|
||||||
" # o8888o o8888o o8888o o8888o o8888o o8888o o8 80 o8888o o8888o o8888o o8888o o8888o #\n"
|
{
|
||||||
" # 888o 0oooo0 88 888 88 88oo oo 888o 888o88 88 888 88 888 88 88oo 88oo88 #\n"
|
"###########################################################################################################",
|
||||||
" # o888 88 888888 88 88 o888 88 88 88 888 88 888 88 88 88 88 #\n"
|
"# o8888o o8888o o8888o o8888o o8888o o8888o o8 80 o8888o o8888o o8888o o8888o o8888o #",
|
||||||
" # 088880 88 88 88 888880 088888 088880 08 80 088880 088880 00 088888 88 88o #\n"
|
"# 888o 0oooo0 88 888 88 88oo oo 888o 888o88 88 888 88 888 88 88oo 88oo88 #",
|
||||||
" ###########################################################################################################";
|
"# o888 88 888888 88 88 o888 88 88 88 888 88 888 88 88 88 88 #",
|
||||||
|
"# 088880 88 88 88 888880 088888 088880 08 80 088880 088880 00 088888 88 88o #",
|
||||||
|
"###########################################################################################################"
|
||||||
|
};
|
||||||
|
|
||||||
void print_menu(WINDOW* win) {
|
void print_menu(WINDOW* win) {
|
||||||
mvwprintw(win, 1, 1, "%s", title);
|
int height;
|
||||||
|
int width;
|
||||||
|
getmaxyx(win, height, width);
|
||||||
|
for(int i = 0; i < TITLE_LINES; i++) {
|
||||||
|
mvwprintw(win, i+1, (width-(strlen(title[0])))/2, "%s", title[i]);
|
||||||
|
}
|
||||||
mvwprintw(win, 7, 1, "BENVENUTO IN SPACE SHOOTER!\n");
|
mvwprintw(win, 7, 1, "BENVENUTO IN SPACE SHOOTER!\n");
|
||||||
wattron(win, A_BLINK);
|
wattron(win, A_BLINK);
|
||||||
mvwprintw(win, 8, 1, "Premi un tasto qualsiasi per giocare...");
|
mvwprintw(win, 8, 1, "Premi un tasto qualsiasi per giocare...");
|
||||||
|
|
@ -50,8 +59,6 @@ int main() {
|
||||||
int height, width, win_startx, win_starty;
|
int height, width, win_startx, win_starty;
|
||||||
char *pause_msg = "PAUSA: premi q per uscire dal gioco...";
|
char *pause_msg = "PAUSA: premi q per uscire dal gioco...";
|
||||||
int pause = 0;
|
int pause = 0;
|
||||||
int max_height;
|
|
||||||
int max_width;
|
|
||||||
int auto_shoot = 0;
|
int auto_shoot = 0;
|
||||||
|
|
||||||
// Giocatore
|
// Giocatore
|
||||||
|
|
@ -74,18 +81,15 @@ int main() {
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
// "menu"
|
// Dimensioni finestra di gioco e controlli
|
||||||
print_menu(stdscr);
|
// calcolo delle misure della finestra
|
||||||
werase(stdscr);
|
height = HEIGHT;
|
||||||
mvprintw(1, 1, "p per pausa, q per uscire");
|
width = WIDTH - (WIDTH%4);
|
||||||
refresh();
|
win_startx = (COLS - width)/2;
|
||||||
|
win_starty = (LINES - height)/2;
|
||||||
// Dimensioni finestra di gioco
|
|
||||||
max_height = LINES - 10;
|
|
||||||
max_width = COLS - 10;
|
|
||||||
|
|
||||||
// Schermo troppo piccolo ?
|
// Schermo troppo piccolo ?
|
||||||
if(max_width < MIN_WIDTH || max_height < MIN_HEIGHT) {
|
if(COLS < MIN_COLS || LINES < HEIGHT) {
|
||||||
delwin(game_window);
|
delwin(game_window);
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
endwin();
|
endwin();
|
||||||
|
|
@ -94,13 +98,13 @@ int main() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// calcolo delle misure della finestra
|
// MENU
|
||||||
height = max_height;
|
print_menu(stdscr);
|
||||||
width = MIN_WIDTH < max_width ? MIN_WIDTH - (MIN_WIDTH%4) : (max_width) - ((max_width)%4);
|
werase(stdscr);
|
||||||
win_startx = (COLS - width)/2;
|
mvprintw(1, 1, "p per pausa, q per uscire");
|
||||||
win_starty = (LINES - height)/2;
|
refresh();
|
||||||
|
|
||||||
// Crea la finestra di gioco
|
// GAME WINDOW
|
||||||
game_window = newwin(height, width, win_starty, win_startx);
|
game_window = newwin(height, width, win_starty, win_startx);
|
||||||
nodelay(game_window, TRUE); // input non bloccante
|
nodelay(game_window, TRUE); // input non bloccante
|
||||||
keypad(game_window, TRUE);
|
keypad(game_window, TRUE);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue