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 ENEMY_N 5
|
||||
#define BULLET_N 3
|
||||
#define MIN_WIDTH 52
|
||||
#define MIN_HEIGHT 30
|
||||
#define WIDTH 52
|
||||
#define HEIGHT 30
|
||||
#define MIN_COLS 110
|
||||
|
||||
struct speed {
|
||||
int slowness;
|
||||
|
|
@ -24,16 +25,24 @@ struct game_obj {
|
|||
};
|
||||
|
||||
/************** FUNZIONI GUI ***************/
|
||||
char title[] =
|
||||
"###########################################################################################################\n"
|
||||
" # 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"
|
||||
" # 088880 88 88 88 888880 088888 088880 08 80 088880 088880 00 088888 88 88o #\n"
|
||||
" ###########################################################################################################";
|
||||
#define TITLE_LINES 6
|
||||
char* title[] =
|
||||
{
|
||||
"###########################################################################################################",
|
||||
"# o8888o o8888o o8888o o8888o o8888o o8888o o8 80 o8888o o8888o o8888o o8888o o8888o #",
|
||||
"# 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) {
|
||||
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");
|
||||
wattron(win, A_BLINK);
|
||||
mvwprintw(win, 8, 1, "Premi un tasto qualsiasi per giocare...");
|
||||
|
|
@ -50,8 +59,6 @@ int main() {
|
|||
int height, width, win_startx, win_starty;
|
||||
char *pause_msg = "PAUSA: premi q per uscire dal gioco...";
|
||||
int pause = 0;
|
||||
int max_height;
|
||||
int max_width;
|
||||
int auto_shoot = 0;
|
||||
|
||||
// Giocatore
|
||||
|
|
@ -74,18 +81,15 @@ int main() {
|
|||
curs_set(0);
|
||||
srand(time(NULL));
|
||||
|
||||
// "menu"
|
||||
print_menu(stdscr);
|
||||
werase(stdscr);
|
||||
mvprintw(1, 1, "p per pausa, q per uscire");
|
||||
refresh();
|
||||
|
||||
// Dimensioni finestra di gioco
|
||||
max_height = LINES - 10;
|
||||
max_width = COLS - 10;
|
||||
// Dimensioni finestra di gioco e controlli
|
||||
// calcolo delle misure della finestra
|
||||
height = HEIGHT;
|
||||
width = WIDTH - (WIDTH%4);
|
||||
win_startx = (COLS - width)/2;
|
||||
win_starty = (LINES - height)/2;
|
||||
|
||||
// Schermo troppo piccolo ?
|
||||
if(max_width < MIN_WIDTH || max_height < MIN_HEIGHT) {
|
||||
if(COLS < MIN_COLS || LINES < HEIGHT) {
|
||||
delwin(game_window);
|
||||
curs_set(1);
|
||||
endwin();
|
||||
|
|
@ -94,13 +98,13 @@ int main() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// calcolo delle misure della finestra
|
||||
height = max_height;
|
||||
width = MIN_WIDTH < max_width ? MIN_WIDTH - (MIN_WIDTH%4) : (max_width) - ((max_width)%4);
|
||||
win_startx = (COLS - width)/2;
|
||||
win_starty = (LINES - height)/2;
|
||||
// MENU
|
||||
print_menu(stdscr);
|
||||
werase(stdscr);
|
||||
mvprintw(1, 1, "p per pausa, q per uscire");
|
||||
refresh();
|
||||
|
||||
// Crea la finestra di gioco
|
||||
// GAME WINDOW
|
||||
game_window = newwin(height, width, win_starty, win_startx);
|
||||
nodelay(game_window, TRUE); // input non bloccante
|
||||
keypad(game_window, TRUE);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue