Exemplo n.º 1
0
int main()
{

  /* Variable declarations within main() only */
  char keypress=0;

  do /* restart game loop */
  {
    obstacles=4; level=1; score=0; speed=14;

    //randomize(); /* Ensure random seed initiated */

    setup_level();

    /* main loop */
    do
    {
      delay(speed * pause_length / 50000); /*pause*/

      /* If key has been hit, then check it is a direction key - if so,
         change direction */
      if (kbhit())
      {
        keypress=(char)getch();
        if((keypress==right_key)||(keypress==left_key)||
           (keypress==up_key)||(keypress==down_key))
          direction = keypress;
      }

      /* Add a segment to the end of the snake */
      add_segment();

      /* Blank last segment of snake */
      gotoxy(snake[0].col,snake[0].row);
      cprintf(" ");
      /* ... and remove it from the array */
        for (int i=1;i<=snake_length;i++)
          snake[i-1]=snake[i];
      /* Display snake in yellow */
      textcolor(YELLOW);
      for (int i=0;i<=snake_length;i++)
      {
        gotoxy(snake[i].col,snake[i].row);
        cprintf("O");
      }
      /* keeps cursor flashing in one place instead of following snake */
      gotoxy(1,1);

      /* If first press on each level, pause until a key is pressed */
      if (firstpress) { while(!kbhit()); firstpress = 0; }

      /* Collision detection - walls (bad!) */
      if ((snake[snake_length-1].row>maxrow+1)||(snake[snake_length-1].row<=1)||
          (snake[snake_length-1].col>maxcol+1)||(snake[snake_length-1].col<=1)||
      /* Collision detection - obstacles (bad!) */
          (screen_grid[snake[snake_length-1].row-2][snake[snake_length-1].col-2]=='x'))
        keypress='x'; /* i.e. exit loop - game over */
      /* Collision detection - snake (bad!) */
      for (int i=0;i<snake_length-1;i++)
        if ( (snake[snake_length-1].row)==(snake[i].row) &&
             (snake[snake_length-1].col)==(snake[i].col))
        {
          keypress='x'; /* i.e. exit loop - game over */
          break; /* no need to check any more segments */
        }
      /* Collision detection - food (good!) */
      if (screen_grid[snake[snake_length-1].row-2][snake[snake_length-1].col-2]=='.')
      {
        /* increase score and length of snake */
        score+=snake_length*obstacles; show_score(); snake_length++; add_segment();
        /* if length of snake reaches certain size, onto next level */
        if (snake_length==(level+3)*2)
        {
          score+=level*1000; obstacles+=2; level++;  /* add to obstacles */
          if ((level%5==0)&&(speed>1)) speed--; /* increase speed every 5 levels */
          setup_level(); /* display next level */
        }
      }
    } while (keypress!='x');

    /* game over message */
    if (score > high_score) high_score = score;
    show_score();
    gotoxy(30,6); textcolor(LIGHTRED); cprintf("G A M E   O V E R");
    gotoxy(30,9); textcolor(YELLOW); cprintf("Another Game (y/n)? ");
    do keypress=getch(); while((keypress!='y')&&(keypress!='n'));

  } while (keypress=='y');
}
Exemplo n.º 2
0
void TrackLoader::init_original_tracks(bool jap)
{
    stage_data = jap ? STAGE_MAPPING_JAP : STAGE_MAPPING_USA;

    display_start_line = true;

    // --------------------------------------------------------------------------------------------
    // Setup Shared Data
    // --------------------------------------------------------------------------------------------

    // Height Map Entries
    heightmap_offset  = outrun.adr.road_height_lookup;
    heightmap_data    = &roms.rom1p->rom[0];  

    // Scenery Map Entries
    scenerymap_offset = outrun.adr.sprite_master_table;
    scenerymap_data   = &roms.rom0p->rom[0]; 

    // Palette Entries
    pal_sky_offset    = PAL_SKY_TABLE;
    pal_sky_data      = &roms.rom0.rom[0];

    pal_gnd_offset    = PAL_GND_TABLE;
    pal_gnd_data      = &roms.rom0.rom[0];

    // --------------------------------------------------------------------------------------------
    // Iterate and setup 15 stages
    // --------------------------------------------------------------------------------------------

    static const uint32_t STAGE_ORDER[] = { 0, 
                                            0x8, 0x9, 
                                            0x10, 0x11, 0x12, 
                                            0x18, 0x19, 0x1A, 0x1B, 
                                            0x20, 0x21, 0x22, 0x23, 0x24};

    for (int i = 0; i < STAGES; i++)
    {
        const uint16_t STAGE_OFFSET = stage_data[STAGE_ORDER[i]] << 2;

        // CPU 0 Data
        const uint32_t STAGE_ADR = roms.rom0p->read32(outrun.adr.road_seg_table + STAGE_OFFSET);
        setup_level(&levels[i], roms.rom0p, STAGE_ADR);

        // CPU 1 Data
        const uint32_t PATH_ADR = roms.rom1p->read32(ROAD_DATA_LOOKUP + STAGE_OFFSET);
        levels[i].path = &roms.rom1p->rom[PATH_ADR];        
    }

    // --------------------------------------------------------------------------------------------
    // Setup End Sections & Split Stages
    // --------------------------------------------------------------------------------------------

    // Split stages don't contain palette information
    setup_section(level_split, roms.rom0p, outrun.adr.road_seg_split);
    level_split->path         = &roms.rom1p->rom[ROAD_DATA_SPLIT];

    for (int i = 0; i < 5; i++)
    {
        const uint32_t STAGE_ADR = roms.rom0p->read32(outrun.adr.road_seg_end + (i << 2));
        setup_section(&levels_end[i], roms.rom0p, STAGE_ADR);
        levels_end[i].path  = &roms.rom1p->rom[ROAD_DATA_BONUS];
    }
}
Exemplo n.º 3
0
int main()
{
  
	char keypress = start;
	int i,j;
	char str[15];
	int champion = 0;

	set_graphics(VGA_320X200X256);
  	set_coordinates(X_coord, Y_coord); //initialize bulb coordinates

	do{
		erase(1,1,400,220);

	  	header(8,5); //print menu

		level=1; //initialize level
		champion = 0; //falsify championhood
		
		keypress=(char)getch();
		erase(1,1,400,220); //erase menu

		if(keypress==start){
		do{

			if(keypress == start){
				setup_level(); 
				row=0;
				col=0;
				flips=0;

				//update level display
				erase(25,125,40,30);
				write_text("0",25,125,WHITE,0);

			}		
			else
				print_board(X_coord, Y_coord);

			do{

				if (keypress=(char)getch()){
				
					// update selected bulb
					if(keypress==right_key){
						oldrow = row;
						oldcol = col;
						col = (col + 1) % maxcol;
					}
					
					else if(keypress==left_key){
						oldrow = row;
						oldcol = col;
						if(col <= 0)
							col = maxcol - 1;
						else
							col--;
					}
					
					else if(keypress==up_key){
						oldrow = row;
						oldcol = col;keypress=(char)getch();
						if(row <= 0)
							row = maxrow - 1;
						else
							row--;
					}
					
					else if(keypress==down_key){
						oldrow = row;
						oldcol = col;
						row = (row + 1) % maxrow;
					}
					
					else if(keypress == flip){				
						flips++;
						erase(25,125,30,30);
						sprintf(str,"%d",flips);
					   	write_text(str,25,125,WHITE,0);
						
						// flip bulbs
					
						// selected bulb
						if(board[row][col] == son){
							board[row][col] = soff;
							remaining_bulb--;
							flip_fxn(row, col);
						}
						else{
							board[row][col] = son;
							remaining_bulb++;
							flip_fxn(row, col);
						}
						
						// top
						if(row -1 >= 0){
							if(board[row-1][col] == on){
								board[row-1][col] = off;
								remaining_bulb--;
								flip_fxn(row-1, col);
							}
							else{
								board[row-1][col] = on;
								remaining_bulb++;
								flip_fxn(row-1, col);
							}
						}
						
						// down
						if(row + 1 < maxrow){
							if(board[row+1][col] == on){
								board[row+1][col] = off;
								remaining_bulb--;
								flip_fxn(row+1, col);
							}
							else{
								board[row+1][col] = on;
								remaining_bulb++;
								flip_fxn(row+1, col);
							}
						}
						
						// left
						if(col -1 >= 0){
							if(board[row][col-1] == on){
								board[row][col-1] = off;
								remaining_bulb--;
								flip_fxn(row, col-1);
							}
							else{
								board[row][col-1] = on;
								remaining_bulb++;
								flip_fxn(row, col-1);
							}
						}
						
						// right
						if(col + 1 < maxcol){
							if(board[row][col+1] == on){
								board[row][col+1] = off;
								remaining_bulb--;
								flip_fxn(row, col+1);
							}
							else{
								board[row][col+1] = on;
								remaining_bulb++;
								flip_fxn(row, col+1);
							}
						}
						
					}
					
					if(remaining_bulb <= 0){

						level++; //update level
						if(level==max_level){ //finished all puzzles

							write_text("Congratulations!",89,160,YELLOW,0);
							write_text("You finished all levels.",65,170,YELLOW,0);
							write_text("(Press any key)",101, 180,YELLOW,0);
							keypress=(char)getch();
							erase(1,1,350,280); //clear screen
							champion=1; //player is now champion

						}else{ //finished a puzzle
							write_text("Congratulations!",89,160,WHITE,0);
							write_text("Press any key",101, 170,WHITE,0);
							keypress=(char)getch();
							erase(80,160,150,40); //erase congratulations
							keypress = start;
						}
						break;
					}
					
					// update the display of the selected and previously selected
					if(keypress==right_key || keypress==left_key || keypress==up_key || keypress==down_key){
						board[row][col] = board[row][col] == on? son: soff;
						board[oldrow][oldcol] = board[oldrow][oldcol] == son? on: off;					
						edit_board();
					}
				}			
		      		
			} while (keypress != quit && keypress != reset && champion!=1);
				//continue while player is not quitting, restarting or champion

			if(champion==1){keypress = yes;}
			else if(keypress == quit){
				//prompt confirmation then erase message
				write_text("Do you want to exit? y/n ",60,160,WHITE,0); 
				keypress=(char)getch();
				erase(60,160,220,40);			
			}
			else if(keypress == reset){
				//prompt confirmation then erase message
				write_text("Do you want to restart? y/n ",50,160,WHITE,0);
				keypress=(char)getch();
				if(keypress == yes) keypress = start;
				erase(50,160,260,40);			
			}
			
			

			} while (keypress != yes);
		}
	} while (keypress != quit_game);

	set_graphics(VGA_TEXT80X25X16);
	clrscr();
}
Exemplo n.º 4
0
void TrackLoader::init_layout_tracks(bool jap)
{
    stage_data = STAGE_MAPPING_USA;

    // --------------------------------------------------------------------------------------------
    // Check Version is Correct
    // --------------------------------------------------------------------------------------------
    if (layout->read32(LayOut::HEADER) != LayOut::EXPECTED_VERSION)
    {
        std::cout << "Incompatible LayOut Version Detected. Try upgrading CannonBall to the latest version" << std::endl;
        init_original_tracks(jap);
        return;
    }

    display_start_line = layout->read8((uint32_t)LayOut::HEADER + (uint32_t)sizeof(uint32_t));

    // --------------------------------------------------------------------------------------------
    // Setup Shared Data
    // --------------------------------------------------------------------------------------------

    // Height Map Entries
    heightmap_offset  = layout->read32(LayOut::HEIGHT_MAPS);
    heightmap_data    = &layout->rom[0];  

    // Scenery Map Entries
    scenerymap_offset = layout->read32(LayOut::SPRITE_MAPS);
    scenerymap_data   = &layout->rom[0]; 

    // Palette Entries
    pal_sky_offset    = layout->read32(LayOut::PAL_SKY);
    pal_sky_data      = &layout->rom[0];

    pal_gnd_offset    = layout->read32(LayOut::PAL_GND);
    pal_gnd_data      = &layout->rom[0];

    // --------------------------------------------------------------------------------------------
    // Iterate and setup 15 stages
    // --------------------------------------------------------------------------------------------
    for (int i = 0; i < STAGES; i++)
    {
        // CPU 0 Data
        const uint32_t STAGE_ADR = layout->read32(LayOut::LEVELS + (i * sizeof(uint32_t)));
        setup_level(&levels[i], layout, STAGE_ADR);

        // CPU 1 Data
        const uint32_t PATH_ADR = layout->read32(LayOut::PATH);
        levels[i].path = &layout->rom[ PATH_ADR + ((ROAD_END_CPU1 * sizeof(uint32_t)) * i) ];
    }

    // --------------------------------------------------------------------------------------------
    // Setup End Sections & Split Stages
    // --------------------------------------------------------------------------------------------

    // Split stages don't contain palette information
    setup_section(level_split, layout, layout->read32(LayOut::SPLIT_LEVEL));
    level_split->path = &layout->rom[ layout->read32(LayOut::SPLIT_PATH) ];

    // End sections don't contain palette information. Shared path.
    uint8_t* end_path = &layout->rom[ layout->read32(LayOut::END_PATH) ];
    for (int i = 0; i < 5; i++)
    {
        const uint32_t STAGE_ADR = layout->read32(LayOut::END_LEVELS + (i * sizeof(uint32_t)));
        setup_section(&levels_end[i], layout, STAGE_ADR);
        levels_end[i].path = end_path;
    }
}