Index: menuselect_curses.c =================================================================== --- menuselect_curses.c (revision 953) +++ menuselect_curses.c (working copy) @@ -565,7 +565,8 @@ BLIP_TANK = 0, BLIP_SHOT, BLIP_BOMB, - BLIP_ALIEN + BLIP_ALIEN, + BLIP_BARRIER }; struct blip { @@ -575,6 +576,7 @@ int ox; int oy; int goingleft; + int health; AST_LIST_ENTRY(blip) entry; }; @@ -588,10 +590,27 @@ /*! Probability of a bomb, out of 100 */ #define BOMB_PROB 1 +static int add_barrier(int x, int y) +{ + struct blip *cur = NULL; + + cur = calloc(1,sizeof(struct blip)); + if(!cur) { + return -1; + } + cur->type=BLIP_BARRIER; + cur->x = x; + cur->y=max_y - y; + cur->health = 1; + AST_LIST_INSERT_HEAD(&blips, cur,entry); + return 0; +} + static int init_blips(void) { int i, j; struct blip *cur; + int offset = 4; srandom(time(NULL) + getpid()); @@ -619,7 +638,24 @@ num_aliens++; } } + for(i=0; i < 4; i++) { + if (i > 0) + offset += 5 + ((max_x) -28) / 3; + add_barrier(offset + 1, 6); + add_barrier(offset + 2, 6); + add_barrier(offset + 3, 6); + add_barrier(offset, 5); + add_barrier(offset + 1, 5); + add_barrier(offset + 2, 5); + add_barrier(offset + 3, 5); + add_barrier(offset + 4, 5); + + add_barrier(offset, 4); + add_barrier(offset + 1, 4); + add_barrier(offset + 3, 4); + add_barrier(offset + 4, 4); + } return 0; } @@ -634,6 +670,8 @@ return '|'; case BLIP_BOMB: return 'o'; + case BLIP_BARRIER: + return '*'; default: break; } @@ -714,9 +752,28 @@ return 0; } +static int remove_blip(struct blip *blip) +{ + if (!blip) { + return -1; + } + + AST_LIST_REMOVE(&blips, blip, entry); + + if (blip->type == BLIP_ALIEN) { + num_aliens--; + } + wmove(stdscr, blip->oy, blip->ox); + waddch(stdscr, ' '); + free(blip); + + return 0; +} + static int move_aliens(void) { struct blip *cur; + struct blip *current_barrier; AST_LIST_TRAVERSE(&blips, cur, entry) { if (cur->type != BLIP_ALIEN) { @@ -737,6 +794,12 @@ /* Alien into the tank == game over */ if (cur->x == tank->x && cur->y == tank->y) return 1; + AST_LIST_TRAVERSE(&blips, current_barrier, entry){ + if(current_barrier->type!=BLIP_BARRIER) + continue; + if(cur->y == current_barrier->y && cur->x == current_barrier -> x) + remove_blip(current_barrier); + } if (random() % 100 < BOMB_PROB && cur->y != max_y) { struct blip *bomb = calloc(1, sizeof(struct blip)); if (!bomb) @@ -754,13 +817,29 @@ static int move_bombs(void) { struct blip *cur; + struct blip *current_barrier; AST_LIST_TRAVERSE(&blips, cur, entry) { + int mark = 0; if (cur->type != BLIP_BOMB) continue; cur->y++; - if (cur->x == tank->x && cur->y == tank->y) + if (cur->x == tank->x && cur->y == tank->y) { return 1; + } + + AST_LIST_TRAVERSE(&blips, current_barrier, entry) { + if (current_barrier->type != BLIP_BARRIER) + continue; + if (cur->x == current_barrier->x && cur->y == current_barrier->y) { + mark = 1; + current_barrier->health--; + if (current_barrier->health == 0) + remove_blip(current_barrier); + } + } + if (mark){ + remove_blip(cur);} } return 0; @@ -777,24 +856,7 @@ } } -static int remove_blip(struct blip *blip) -{ - if (!blip) - return -1; - AST_LIST_REMOVE(&blips, blip, entry); - - if (blip->type == BLIP_ALIEN) - num_aliens--; - - wmove(stdscr, blip->oy, blip->ox); - waddch(stdscr, ' '); - - free(blip); - - return 0; -} - static void game_over(int win) { clear(); @@ -816,14 +878,13 @@ static int check_shot(struct blip *shot) { struct blip *cur; + struct blip *current_barrier; AST_LIST_TRAVERSE(&blips, cur, entry) { - if (cur->type != BLIP_ALIEN) - continue; - if (cur->x == shot->x && cur->y == shot->y) { + if (cur->type == BLIP_ALIEN && cur->x == shot->x && cur->y == shot->y){ score += 20; + remove_blip(cur); remove_blip(shot); - remove_blip(cur); if (!num_aliens) { if(alien_sleeptime < 101) { game_over(1); @@ -833,7 +894,15 @@ return 1; } } + break; } + if (cur->type == BLIP_BARRIER) { + if (shot->x == cur->x && shot->y == cur->y) { + remove_blip(cur); + remove_blip(shot); + break; + } + } } return 0;