int main() { int i,ic,height=650, width=1200; int lives=5, level=1; int fgx=12, fgy=11, *frogx=&fgx, *frogy=&fgy; int row=13,col=25,board[row][col]; //dimensions char direction='R', play; int wnum=50, wseg=width/wnum, hnum=100, hseg=height/hnum, boardw=2*wseg, boardh=8*hseg; gfx_open(width,height,"Frogger"); //open graphics window play=welcome(); //begin game while(play!='q'){ //while user wants to play the game and not quit background(width,height,level); //eventaully this will be in draw function draw_lives(lives); //evnetually in draw function drawfrog(*frogx,*frogy,boardw,boardh,direction);//eventuall in draw function usleep(500000); if (gfx_event_waiting() == 1){ //if user tries to move frog direction = hopper(frogx,frogy); //move frog according to input if valid } /*switch(board[*frogx][*frogy]){ case 0: //frog dies in this location lives=lives-1; if(lives==0){ play=blood(); //game over, play again or end lives=5; } level=1; //reset everything here NEED TO DO break; case 1: //frog can be in this location and game continues break; case 2: //frog made it to lilly pad level++; if (level>5){ play=win();//you won! if (play != 'q'){ level = 1; lives = 5; } } break; }*/ } }
void reset_terminal(void){ clear_terminal(); set_display_attribute(BAR_COLOUR); draw_horizontal_line(1,1,WIDTH); set_display_attribute(BAR_COLOUR); draw_vertical_line(40,1,HEIGHT); move_cursor(TITLE_X,TITLE_Y); printf_P(PSTR("FROGGER")); draw_lives(); draw_score(); draw_level(); draw_time(16); display_scores(); draw_status(0); draw_frog(); set_display_attribute(8); }
void draw_level(t_level *level) { t_list_node *cursor; t_brick *cur_brick; cursor = level->brick_list; while (cursor) { cur_brick = (t_brick *)cursor->value; if (cur_brick->val > 0) draw_brick(cur_brick); cursor = cursor->next; } update_ball(level->ball, level->brick_list); draw_ball(level->ball); update_pad(level->pad, level->ball); draw_pad(level->pad); draw_level_border(); draw_lives(level->lives); draw_score(level->score); }
//-------------------------------------------------------------- void ofApp::draw(){ if(game_state=="start"){ start_screen.draw(0,0,ofGetWidth(),ofGetHeight());//初期画面の描画 draw_score();//score表示 }else if(game_state=="tutorial"){ tutorial_screen.draw(0,0,ofGetWidth(),ofGetHeight()); }else if(game_state=="game"){//ゲーム画面の描画 game_screen.draw(0,0,ofGetWidth(),ofGetHeight()); player_1.draw();//player1を表示 draw_lives();//draw_livesを表示 draw_score();//score表示 boss_1.draw(); //Enemyのvectorによる配列 for(int i=0;i<enemies.size();i++){ enemies[i].draw(); } //Bulletのvectorによる配列 for(int i=0;i<bullets.size();i++){ bullets[i].draw(); } //bonusesのvectorによる配列 for(int i=0;i<bonuses.size();i++){ bonuses[i].draw(); } }else if(game_state=="end"){//終了画面の描画 end_screen.draw(0,0,ofGetWidth(),ofGetHeight()); draw_score(); } }
int main(void) { asteroids.lives = START_LIVES; asteroids.display = NULL; asteroids.timer = NULL; asteroids.event_queue = NULL; SHIP *ship; bool redraw = true; bool quit = false; bool key[7] = { false }; seed_rand(); atexit(shutdown); if(!init()) exit(EXIT_FAILURE); if((asteroids.high_score = get_config_value("high_score")) == NULL) asteroids.high_score = "0"; asteroids.level = level_create(0, 0); if(!(ship = ship_create())) exit(EXIT_FAILURE); al_flip_display(); al_start_timer(asteroids.timer); while(!quit) { ALLEGRO_EVENT ev; al_wait_for_event(asteroids.event_queue, &ev); if(ev.type == ALLEGRO_EVENT_TIMER) { /* start game */ if(asteroids.level->number == 0 && key[KEY_S]) { start(); continue; } /* are we out of asteroids to destroy? */ if(list_length(asteroids.level->asteroids) == 0) asteroids.level = level_next(asteroids.level); /* update objects */ ship = ship_update(ship, key, asteroids.timer); explosions_update(); asteroids.level = level_update(asteroids.level, ship, key, asteroids.timer); /* ship->asteroid collisions. */ check_ship_asteroid_collisions(ship, asteroids.level->asteroids); /* ship[missile] -> asteroid collisions. */ check_ship_missile_asteroid_collisions(asteroids.level, ship); /* ship[missile] -> saucer collisions. */ check_ship_missile_saucer_collisions(asteroids.level, ship); /* saucer[missile] -> ship collisions. */ check_saucer_missile_ship_collisions(asteroids.level, ship); /* saucer[missile] -> asteroid collisions. */ check_saucer_missile_asteroids_collisions(asteroids.level); /* saucer->asteroid collisions. */ check_saucer_asteroid_collisions(asteroids.level); redraw = true; } else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { keydown(ev, key); quit = key[KEY_ESCAPE]; } else if(ev.type == ALLEGRO_EVENT_KEY_UP) { keyup(ev, key); ship->fire_debounce = key[KEY_SPACE]; ship->hyper_debounce = key[KEY_LCONTROL]; } if(redraw && al_is_event_queue_empty(asteroids.event_queue)) { redraw = false; al_clear_to_color(al_map_rgb(BLACK)); level_draw(asteroids.level); draw_lives(); draw_high_score(); animation_draw_list(asteroids.explosions); if(asteroids.level->number == 0) { draw_home(); al_flip_display(); continue; } if(asteroids.lives > 0) { ship_draw(ship, key[KEY_UP]); missile_draw_list(ship->missiles); } else { if(ship->explosion) ship_draw(ship, false); draw_gameover(); } al_flip_display(); } }; /* FIXME: cleanup */ if(asteroids.timer != NULL) al_destroy_timer(asteroids.timer); if(asteroids.event_queue != NULL) al_destroy_event_queue(asteroids.event_queue); if(asteroids.display != NULL) al_destroy_display(asteroids.display); LIST *head = list_first(asteroids.level->asteroids); while(head != NULL) { ASTEROID *rock = (ASTEROID *) head->data; asteroid_free(rock); head = head->next; } ship_free(ship); al_destroy_bitmap(asteroids.lives_sprite); ship_shutdown(); missile_shutdown(); asteroid_shutdown(); explosion_shutdown(); al_uninstall_keyboard(); exit(EXIT_SUCCESS); }
int main() { int i,ic; //variables for incrementing in for loops int lives=5, level=1; //initialize lives and level int fgx=12, fgy=11, *frogx=&fgx, *frogy=&fgy; //initialize frog position int row=12,col=25,board[row][col]; //dimensions for board char play; //declare play character int x[19]= {5-width/4,width+5,10-width/4,15-width/4,width+10,5-width/2,1.2*width,10-width/2,15-width/2,1.2*width,5-width,1.5*width,10-width,15-width,1.5*width,width+5,5-width,width+10,10-width/2}; //array of starting positions of moving objects //initialize board for(i=0; i<6; i++) for(ic=0; ic<col; ic++) board[i][ic]=0; for(i=6; i<row; i++) for(ic=0; ic<col; ic++) board[i][ic]=1; for(i=2; i<col; i+=4) board[0][i]=2; gfx_open(width,height,"Frogger"); //open graphics window play=welcome(); //begin game while(play!='q') { //while user wants to play the game and not quit background(level); draw_lives(lives); draw(col,board,level,x,frogx,frogy); drawfrog(*frogx,*frogy,play); gfx_flush(); usleep(100000); /* for(i=0;i<row;i++){ //prints board in terminal for(ic=0;ic<col;ic++) printf("%d",board[i][ic]); printf("\n"); } //end for(i=0;i<row;i++) printf("\n"); */ if (gfx_event_waiting()) { //if user tries to move frog play = hopper(frogx,frogy,row,col); //move frog according to input if valid } //end if (gfx_event_waiting()) switch(board[*frogy][*frogx]) { case 0: //frog dies in this location lives--; //lose a life *frogx=12; *frogy=11; if(lives==0) { play=blood(); //game over, play again or end lives=5; level=1; } //end if(lives==0) break; case 1: //frog can be in this location and game continues break; case 2: //frog made it to lilly pad level++; //level up *frogx=12; *frogy=11; if (level>5) { play=win();//you won! level = 1; lives = 5; } //end if (level>5) break; } //end switch(board[*frogx][*frogy]) } //end while(play!='q') } //end main
/* The main game loop */ static void do_game(game_t *p_game) { uint8_t exit=FALSE; while(!exit) { uint16_t input = get_input(p_game); uint16_t fire; int i; exit = input & FE_EVENT_EXIT; fire = input & FE_EVENT_SELECT; /* Move the paddle (according to input) */ update_paddle(&p_game->paddle, input & FE_EVENT_LEFT ? 4:0, input & FE_EVENT_RIGHT ? 4:0); /* Handle the ball(s) */ p_game->free_ball = -1; for (i=0; i<MAX_BALLS; i++) { /* Unused balls are skipped */ if (!(p_game->p_balls[i].state & BALL_STATE_ACTIVE)) { draw_ball(&p_game->p_balls[i]); p_game->free_ball = i; continue; } /* The player is holding the ball */ if (p_game->p_balls[i].state & BALL_STATE_HOLDING) { p_game->p_balls[i].lastx = p_game->p_balls[i].x; p_game->p_balls[i].x += p_game->paddle.x-p_game->paddle.lastx; if (fire) { /* The player relases the ball. The following will * clear the HOLDING-bit. It will also shoot the * ball away upwards. */ p_game->p_balls[i].dx = 1; p_game->p_balls[i].state &= (0xff ^ BALL_STATE_HOLDING); bounce_ball_paddle(p_game, &p_game->p_balls[i]); } } else if (paddle_ball_collide(&p_game->paddle, &p_game->p_balls[i])) { /* Hold the ball if the pad is sticky */ if (p_game->paddle.type & SPECIAL_STICKY) { p_game->p_balls[i].dy = 0; p_game->p_balls[i].dx = 0; p_game->p_balls[i].state |= BALL_STATE_HOLDING; p_game->paddle.type--; /* Sticky for maximum 3 rounds */ } else bounce_ball_paddle(p_game, &p_game->p_balls[i]); } /* Check collisions against blocks */ block_ball_collide(p_game, &p_game->p_balls[i]); draw_ball(&p_game->p_balls[i]); /* Update the ball (and check if it moves out of the playfield) */ if (update_ball(p_game, &p_game->p_balls[i])) { /* Ball is out of bounds - Remove it */ init_ball(&p_game->p_balls[i], 0, 0, 0); p_game->nr_balls--; } } /* Handle the specials */ p_game->free_special = -1; for (i=0; i<MAX_SPECIALS; i++) { int res; /* Always draw the specials for timing-reasons */ draw_special(&p_game->p_specials[i]); /* Inactive special - continue */ if (!p_game->p_specials[i].type) { p_game->free_special = i; continue; } /* This moves the special and also checks if it collides with the paddle */ res = update_special(p_game, &p_game->p_specials[i]); switch(res) { case 1: /* Player took the special */ switch(p_game->p_specials[i].type) { case SPECIAL_EXTRA_BALL: if (p_game->free_ball != -1) /* Check if there is free space for the ball */ { p_game->nr_balls++; init_ball(&p_game->p_balls[p_game->free_ball], p_game->paddle.x+PADDLE_WIDTH/2, PADDLE_Y-PADDLE_HEIGHT, BALL_STATE_ACTIVE); } break; case SPECIAL_LONG_PADDLE: p_game->paddle.width = PADDLE_LONG_WIDTH; break; case SPECIAL_SHORT_PADDLE: p_game->paddle.width = PADDLE_SHORT_WIDTH; break; case SPECIAL_EXTRA_LIFE: if (p_game->lives < MAX_LIVES) { p_game->lives++; draw_lives(p_game); } break; case SPECIAL_STICKY: /* * For the sticky and destroyers, we use the bits * from the flag and downwards as counters. * * i.e: SPECIAL_STICKY is the third bit, which means * that type becomes 0b00000111. type is then * lowered when the ball hits the paddle and after * zeroing the lower bits, the SPECIAL_STICKY bit is * finally cleared. This gives a maximum of three * sticky rounds. * * These two only adds 30 bytes to the binary :-) */ p_game->paddle.type = (SPECIAL_STICKY | (SPECIAL_STICKY-1)); break; case SPECIAL_DESTROYER: p_game->p_balls[0].state |= (BALL_STATE_DESTROYER | (BALL_STATE_DESTROYER-1)); break; case SPECIAL_FLOOR: p_game->state |= (SPECIAL_FLOOR | 2); /* Three times */ fe_fill_area(0, SCREEN_HEIGHT-FLOOR_HEIGHT, SCREEN_WIDTH, FLOOR_HEIGHT); break; } /* Fall through */ case -1: /* Remove the special */ p_game->nr_specials--; fe_clear_area(p_game->p_specials[i].x, p_game->p_specials[i].y-1, SPECIAL_WIDTH, SPECIAL_HEIGHT+1); p_game->p_specials[i].type = SPECIAL_NONE; break; } } /* No balls left in play */ if (!p_game->nr_balls) { if (--p_game->lives == 0) exit = TRUE; /* No lives left! */ else { /* Restart the game */ p_game->nr_balls = 1; draw_screen(p_game); init_paddle(&p_game->paddle, SPECIAL_NONE, SCREEN_WIDTH/2-PADDLE_WIDTH/2); init_ball(&p_game->p_balls[0], p_game->paddle.x+p_game->paddle.width/2, PADDLE_Y-PADDLE_HEIGHT, BALL_STATE_HOLDING | BALL_STATE_ACTIVE); } } /* No blocks left to remove */ if (!p_game->nr_blocks) { fe_sleep(LEVEL_SLEEP_PERIOD); if (handle_level_finished(p_game) < 0) exit = TRUE; /* Last level */ } draw_paddle(&p_game->paddle); /* Sleep for a short while. */ #if !defined(TARGET_REX) fe_sleep(SLEEP_PERIOD); #endif /* TARGET_REX */ } }