Exemplo n.º 1
0
/**
 * \brief Performs setup and re-initialization needed before each new game.
 *
 * Resets the player score, resets variables for drawing columns, sets a new random ghost color, moves the player back to the starting position, erases columns from last game,
 * turns scrolling back on and makes the player visible again.
 */
static void gameSetup()
{
	randomSky();
	//fill screen with tile 1 again to erase menu
	ClearVram();

	for(u8 i = 0; i < 4; i++) //reset column data with 0's to start fresh
	{
		pipe_x[i] = 0;
		pipe_y[i] = 0;
	}
	for(u8 k = 0; k < 32; k++)
	{
		bg[k] = 1;
	}

	//reset all score data from last game to 0
	score = 0;//score = 0;
	score_ones=0;
	score_tens=0;
	score_hundreds=0;

	fake_x = 80; //reset how far we've flown
	player_x = 80; //reset player position
	player_y = 40;
	yspeed = 0; //make sure we start at 0 speed

	//draw the background
	for(u8 i = 0; i < VRAM_TILES_H; i++)
	{
		pipe_alarm=2; //make sure we never draw a column while we're drawing the starting screen
		loadNextStripe(); //go through each column and draw the background
	}

	//select a random color for the ghost and set the appropriate sprite
	ghost_color=(prng()%3); //the ghost has 3 frames and 3 color options, so we set the active sprite to the frame count (0 - 2) + the color (0, 3, or 6) to get the correct sprite
	ghost_color=(ghost_color+(ghost_color<<1));
	current_sprite = player_sprites[current_frame+ghost_color];
	//assign and move the player image to start the new game
	MoveSprite(0,player_x,player_y,3,3);
	MapSprite2(0,current_sprite,0);
	//make player visible
	SetSpriteVisibility(true);

	//reset variables to draw new columns correctly
	current_pipe=0;
	build_pipe=0;
	pipe_alarm = 1;
	pipe_col_drawn = 0;

	//turn scrolling on to begin the game
	scrollingOn=true;

}
Exemplo n.º 2
0
/**
 * \brief Handles screen scrolling.
 */
void processScrollSpeed(void)
{

	if(scrollingOn)
	{
		Scroll(1,0); //scroll background tiles left 1 pixel horizontally and 0 vertically
		scroll++; //track how far we've scrolled the background since loading a new column of tiles
		fake_x++; //track how far player has flown since start of game, used for column collision checking

		//if we've scrolled at least one whole tile since loading a new column of tiles
		if(scroll>=8){
			loadNextStripe(); //load a new column of background tiles to the far right off screen
			scroll=0; //reset pixels scrolled since we last loaded new tiles
		}
	}

}
Exemplo n.º 3
0
unsigned char processControls(void){
	static unsigned char ov=4,scroll=0;
	static int lastbuttons=0;
	unsigned int joy=ReadJoypad(0);


	if(joy&BTN_A){
		if(action!=ACTION_JUMP){
			action=ACTION_JUMP;
			frame=0;
			jmpPos=0;
		}
	
	}else if(joy&BTN_X){
		Scroll(0,1);	
	//	while(ReadJoypad(0)!=0);
	}else if(joy&BTN_Y){
		Scroll(0,-1);
	//	while(ReadJoypad(0)!=0);
	}else if(joy&BTN_SR){
	//	Scroll(1,0);
	//	while(ReadJoypad(0)!=0);
	}else if(joy&BTN_SL){
	//	Scroll(-1,0);
	//	while(ReadJoypad(0)!=0);
	}else if(joy&BTN_UP){
		//if(sy==0)sy=(VRAM_TILES_V*8);
		//sy--;
		//while(ReadJoypad(0)!=0);

	}else if(joy&BTN_DOWN){
		//sy++;
		//if(sy>=(VRAM_TILES_V*8))sy=0;
	//	while(ReadJoypad(0)!=0);
	
	}
	
	if(joy&BTN_LEFT){
		
		//while(ReadJoypad(0)!=0);
		
		if(action==ACTION_IDLE){
			action=ACTION_WALK;
			dx=-1;
			frame=0;
			stopping=false;
			walkFrame=0;
			lastWalkDir=BTN_LEFT;
			sprDir=-1;
		}
		
		
	}else if(joy&BTN_RIGHT){

		//while(ReadJoypad(0)!=0);

		
		if(action==ACTION_IDLE){
			action=ACTION_WALK;
			dx=1;
			frame=0;
			stopping=false;
			walkFrame=0;
			lastWalkDir=BTN_RIGHT;
			sprDir=1;
		}
		
		if(sx>=110){

			if(joy&BTN_B){
				Scroll(2,0);
				scroll+=2;
			}else{
				Scroll(1,0);
				scroll++;
			}
			
			if(scroll>=8){
				loadNextStripe();
				scroll=0;
			}
		}

	
	}

	if(joy&BTN_START){
		ov++;
		if(ov>OVERLAY_LINES)ov=0;

		Screen.overlayHeight=ov;
		while(ReadJoypad(0)!=0);
	}

	if(joy&BTN_SELECT){
		StopSong();
		while((ReadJoypad(0)&BTN_SELECT)!=0);
	}


	


	if(stopping==true && stopFrame==1){
		action=ACTION_IDLE;
		stopping=false;
		dx=0;
	}else if(lastWalkDir!= (joy & (BTN_LEFT+BTN_RIGHT)) && action==ACTION_WALK){
		
		if((joy & (BTN_LEFT+BTN_RIGHT))!=0 ){
			frame=17;
		}else{
			stopping=true;
			stopFrame=0;
		}
	}
	

	lastbuttons=joy;
	lastWalkDir= joy & (BTN_LEFT+BTN_RIGHT);


	return 0;
}