Punteggi, vite, status bar e gameover
This commit is contained in:
parent
550885f97b
commit
d985458100
2 changed files with 71 additions and 11 deletions
2
TODO
2
TODO
|
|
@ -1,4 +1,4 @@
|
|||
Da fare:
|
||||
|
||||
- punteggio +1 quando uccidi, -1 se passano, se < 0 perdi, se ti colpisce perdi
|
||||
- iniziare a spostare in delle funzioni la GUI
|
||||
- salvataggio e menu
|
||||
|
|
|
|||
80
main.c
80
main.c
|
|
@ -11,6 +11,7 @@
|
|||
#define WIDTH 52
|
||||
#define HEIGHT 30
|
||||
#define MIN_COLS 110
|
||||
#define LIVES_N 5
|
||||
|
||||
struct speed {
|
||||
int slowness;
|
||||
|
|
@ -36,7 +37,18 @@ char* title[] =
|
|||
"###########################################################################################################"
|
||||
};
|
||||
|
||||
char menu_desc[] = "BENVENUTO. Premi un tasto qualsiasi per giocare...";
|
||||
char menu_desc[] = "BENVENUTO. Premi qualsiasi tasto per giocare...";
|
||||
|
||||
#define GAMEOVER_LINES 4
|
||||
char* gameover[] =
|
||||
{
|
||||
"o8888o o8888o o8oo8o o8888o o8888o 88 8o o8888o o8888o",
|
||||
"888 oo 88 888 88\\/88 88oo oo 88 888 88 88 88oo 88oo88",
|
||||
"888 8 888888 88 88 88 88 888 88 o8 88 88 88 ",
|
||||
"O88880 88 88 88 88 888880 088880 888O 888880 88 88o"
|
||||
};
|
||||
|
||||
char gameover_desc[] = "HAI PERSO. Premi q per uscire...";
|
||||
|
||||
void print_menu(WINDOW* win) {
|
||||
int height;
|
||||
|
|
@ -49,7 +61,42 @@ void print_menu(WINDOW* win) {
|
|||
mvwprintw(win, TITLE_LINES+1, (width-(strlen(menu_desc)))/2, "%s", menu_desc);
|
||||
wattroff(win, A_BLINK);
|
||||
refresh();
|
||||
getch();
|
||||
return;
|
||||
}
|
||||
|
||||
void print_gameover(WINDOW* win) {
|
||||
int height;
|
||||
int width;
|
||||
int ch;
|
||||
wclear(win);
|
||||
getmaxyx(win, height, width);
|
||||
for(int i = 0; i < GAMEOVER_LINES; i++) {
|
||||
mvwprintw(win, i+1, (width-(strlen(gameover[0])))/2, "%s", gameover[i]);
|
||||
}
|
||||
wattron(win, A_BLINK);
|
||||
mvwprintw(win, GAMEOVER_LINES+1, (width-(strlen(gameover_desc)))/2, "%s", gameover_desc);
|
||||
wattroff(win, A_BLINK);
|
||||
refresh();
|
||||
while((ch = wgetch(win)) != 'q');
|
||||
return;
|
||||
}
|
||||
|
||||
void print_status_bar(WINDOW* main_win, int y, int x, int lives, int score, int top_score, int shots) {
|
||||
int status_x = x + 1;
|
||||
int status_y = y;
|
||||
status_x++;
|
||||
|
||||
// lives
|
||||
mvwprintw(main_win, status_y, status_x, "LIVES:\t%d", lives);
|
||||
// score
|
||||
mvwprintw(main_win, status_y+1, status_x, "SCORE:\t%d", score);
|
||||
// top score
|
||||
mvwprintw(main_win, status_y+2, status_x, "TOP SCORE:\t%d", top_score);
|
||||
// bullets
|
||||
mvwprintw(main_win, status_y+3, status_x, "BULLETS:\t%d", shots);
|
||||
|
||||
// refresh window
|
||||
wrefresh(main_win);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -60,11 +107,14 @@ int main() {
|
|||
int height, width, win_startx, win_starty;
|
||||
char *pause_msg = "PAUSA: premi q per uscire dal gioco...";
|
||||
int pause = 0;
|
||||
int auto_shoot = 0;
|
||||
int auto_shoot = 0;
|
||||
|
||||
// Giocatore
|
||||
struct game_obj player = {};
|
||||
int input;
|
||||
int top_score = 0;
|
||||
int score = 0;
|
||||
int lives = LIVES_N;
|
||||
|
||||
// Proiettile
|
||||
struct game_obj bullet[BULLET_N] = {};
|
||||
|
|
@ -101,6 +151,7 @@ int main() {
|
|||
|
||||
// MENU
|
||||
print_menu(stdscr);
|
||||
getch();
|
||||
werase(stdscr);
|
||||
mvprintw(1, 1, "p per pausa, q per uscire");
|
||||
refresh();
|
||||
|
|
@ -175,9 +226,9 @@ int main() {
|
|||
if(bullet[j].active && !pause) {
|
||||
for(int i = 0; i < ENEMY_N; i++) {
|
||||
if(bullet[j].x == enemy[i].x && bullet[j].y == enemy[i].y) {
|
||||
enemy[i].active = 0;
|
||||
bullet[j].active = 0;
|
||||
// TODO aggiorna punteggio
|
||||
enemy[i].active = 0;
|
||||
bullet[j].active = 0;
|
||||
score++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -203,7 +254,11 @@ int main() {
|
|||
}
|
||||
if(enemy[i].y > height - 2) {
|
||||
enemy[i].active = 0;
|
||||
// TODO aggiorna punteggio
|
||||
lives--;
|
||||
if(lives == 0) {
|
||||
player.active = 0;
|
||||
print_gameover(stdscr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -213,9 +268,9 @@ int main() {
|
|||
if(bullet[j].active && !pause) {
|
||||
for(int i = 0; i < ENEMY_N; i++) {
|
||||
if(bullet[j].x == enemy[i].x && bullet[j].y == enemy[i].y) {
|
||||
enemy[i].active = 0;
|
||||
bullet[j].active = 0;
|
||||
// TODO aggiorna punteggio
|
||||
enemy[i].active = 0;
|
||||
bullet[j].active = 0;
|
||||
score++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -248,10 +303,15 @@ int main() {
|
|||
for(int i = 0; i < BULLET_N; i++) {
|
||||
if (bullet[i].active) mvwprintw(game_window, bullet[i].y, bullet[i].x, "%c", bullet[i].symbol);
|
||||
}
|
||||
|
||||
// Nemici
|
||||
for(int i = 0; i < ENEMY_N; i++) {
|
||||
if (enemy[i].active) mvwprintw(game_window, enemy[i].y, enemy[i].x, "%c", enemy[i].symbol);
|
||||
}
|
||||
|
||||
// Status Bar
|
||||
print_status_bar(stdscr, win_starty, (win_startx + width), lives, score, top_score, (BULLET_N - bullet_attivi));
|
||||
|
||||
}
|
||||
|
||||
wrefresh(game_window);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue