コード例 #1
0
/**
 * Called by the assembler initialization routines, should not be called directly.
 */
void InitConsole(void){

#if INTRO_LOGO ==1 
	InitMusicPlayer(initPatches);	
	SetTileTable(uzeboxlogo);
	SetFontTable(uzeboxlogo);
	
	//draw logo
	ClearVram();
	WaitVsync(15);

	TriggerFx(0,0xff,true);
	DrawMap(LOGO_X_POS,12,map_uzeboxlogo);
	WaitVsync(3);
	DrawMap(LOGO_X_POS,12,map_uzeboxlogo2);
	WaitVsync(2);
	DrawMap(LOGO_X_POS,12,map_uzeboxlogo);
	WaitVsync(40);

	ClearVram();
	WaitVsync(20);
#endif
}
コード例 #2
0
ファイル: Maze.c プロジェクト: SteveMaddison/uzebox
int main()
{
  unsigned char x,corner;
  unsigned char frames;
  unsigned int joypad;
  unsigned char player_x, player_y;
  unsigned char exit_x=0, exit_y=0;
  unsigned int z=0;
  int ay,ax,j; 

   SetFontTable(fonts);  // this tells Print___() commands what font to use
   ClearVram();          // clears out display memory (like a 'clear screen')

  //DDRD &= 0xF7; // These are used by the "power" switch and LED on the "Gamer" baseboard that 
  //PORTD|= 0x08; // is paired with the AVCore.  The 'power' button is used to switch mazes for now.
  
  



new_maze:
  for(ay=0; ay<Y_SIZE; ay++) 
  { 
    for(ax=0; ax<X_SIZE; ax++) 
      if(ax>0 && ay>0 && ax<X_SIZE-1 && ay<Y_SIZE-1) // fills the maze with walls, that are then 'drilled' out
        maze[ay][ax]=WALL; 
      else 
        maze[ay][ax]=BLANK; 
  } 

  ay=2; // 2,2 is the top left corner of the maze
  ax=2; 
  maze[ay][ax]=4; // starting state for the maze generator
  
  do 
  { 
    while(drill(&ay,&ax,(int)(rand()&0x03))) {}  // start drilling things out (using random)
    j=maze[ay][ax];                              // note that the first time the game runs, the maze will always be 
    maze[ay][ax]=BLANK;                          // the same because of the random number generator always starting
    if(j<4)                                      // in the same state.  (Normally I will 'sum' the contents of RAM
    {                                            // on power-up to make a random seed, but I don't know how to mess
      /* back-track */                           // with WinAVR's C-startup yet.)
      ax=ax-2*dx[j]; 
      ay=ay-2*dy[j]; 
    } 
  } while(j<4); 
 
 do{                                             // This generates a random position inside the maze to start the
 	do player_x=rand();                          // player.  Seems more interesting than a corner.
	while ((player_x>=X_SIZE-1)||(player_x<=1));
	do player_y=rand();
	while ((player_y>=Y_SIZE-1)||(player_y<=1));
	}	
 while (maze[player_y][player_x]==WALL);         // (repeats until it picks a random spot that's not a wall)
 
 maze[player_y][player_x]=PLAYER;                // place the player in the maze

 do                                              // here we choose a random number from 0-3, representing one of the
 	{                                            // four corners of the maze.
 	corner=rand()&0x03;
 	switch (corner)                              
 		{
	 	case 0:
			exit_x=2; exit_y=2; break;
		case 1:
			exit_x=X_SIZE-3; exit_y=2; break;
		case 2:
			exit_x=X_SIZE-3; exit_y=Y_SIZE-3;break;
		case 3:
			exit_x=2; exit_y=Y_SIZE-3; break;
 		}
	}
 while (abs(player_x-exit_x)<16);                // we compare the distance from the player to the exit (horizontally)
                                                 // and only accept the corner if it's relatively far away from the player
	                                             // (could use both x and y distance for better effect)
	maze[exit_y][exit_x]=EXIT;                   // place the exit in the maze
	
	redraw();                                    // draw the screen for the player

 
 // This is what happens when you turn a static demo into a 'game'
 // For a real game, you probably don't want to do this, but it works here and is simple...
 
 //while(PIND&0x04)       // if the button on the Gamer Baseboard isn't pressed
 while(ReadPowerSwitch()==0) // if the button on the Gamer Baseboard isn't pressed
 {z++;                  // the z counter is used later on for a seed for the random number generator (user interaction = randomness)
 joypad=ReadJoypad(0);  // get the joypad state

 WaitVsync(1);          // this waits a frame and essentially slows the gameplay down
 frames++;              // frame counter can be used for animations (later)
 if (joypad&0xff)       // if the D-pad has a bit or more pressed
 	{
 	maze[player_y][player_x]=BLANK;            // erase the old player position
 	if (joypad&BTN_DOWN)                           // down?
 		if (maze[player_y+1][player_x]!=WALL)  // don't move if a wall is blocking your path
			player_y++;                        // you could 'switch/case' these with breaks to easily disable diagonal moves...
	if (joypad&BTN_UP)                           // up?
	 	if (maze[player_y-1][player_x]!=WALL)
			player_y--;
 	if (joypad&BTN_LEFT)                           // left?
 		if (maze[player_y][player_x-1]!=WALL)
			player_x--;
	if (joypad&BTN_RIGHT)                           // right
 		if (maze[player_y][player_x+1]!=WALL)
			player_x++;
	if (maze[player_y][player_x]==EXIT)        // if the new position is the EXIT, you just won
		{
		maze[exit_y][exit_x]=PLAYER;           // place the player on top of the exit
		redraw();                              // draw the screen for the user
		Print(14,25,strWin);                   // prints the "YOU ESCAPED!" message
		WaitVsync(30);                         // and waits for a while.
		for (x=14;x<26;x++)                    // this loops over the "YOU ESCAPED!" message
			SetTile(x,25,11);                  // and erases it.
		break;                                 // this breaks out of the while(PIND...) loop, causing a new maze to be generated 
		}
	
	maze[player_y][player_x]=PLAYER;           // after the movement calculations, put the player in the new spot
 	}
 else
 	{
	// check for idle time                     // use the frame counter to make the player graphic change if you wait around. ;-)
	}

	srand(z);    // our player-influenced 'z' value is now used to reseed the random number generator, resulting in a 'new' maze
 
	redraw();    // redraw the screen to update new player position
 }

 goto new_maze;  // this is just a hack to go do everything over again.  Before anyone lectures me about using GOTO, think about
                 // why every CPU has a 'jump/goto' instruction in its assembly language and uses it-- frequently. :-) 
}