	
	
	
	#include "libgccvb.h"
	#include "titlescreenchar.h"
	#include "titlescreenmap.h"
	#include "spritechar.h"
	#include "spritesmap.h"
	#include "copyrightchar.h"
	#include "copyrightmap.h"
	#include "tilechar.h"
	#include "screen1.h"
	
	HWORD getBGMapChar(bgmap, x, y) 
	{  
    return (BGMM[bgmap*(0x1000) + (y * 64) + x]&0x7FF);   
	} 		
	
	
int jump=0, player0x=30, player0y=80, j=5, o=1, i=0, d=0, fall=2, dir=0, movetimer=0, a=1;
int jumpthing=32, jumptimer=0, birdx=0;
	
int main ()
	{
	
	
	vbSetWorld(31, WRLD_ON|1, 0, 0, 0, 0, 0, 0, 384, 224);	// world 31 is the scenery
	vbSetWorld(30, WRLD_ON, 30, 2, 55, 0, 0, 0, 48, 79);	 // world 30 is the big cactus in the background
	vbSetWorld(29, WRLD_ON, 260, -2, 110, 49, 0, 0, 32, 40);	 // world 29 is the small cactus in the background
	vbSetWorld(28, WRLD_ON|2, 260, 0, 180, 0, 0, 0, 96, 48);	// world 28 is the copyright notice. It won't work if I put it in the
    // same image as the scenery, it makes squares missing.		
	
	vbDisplayOn();
	vbDisplayShow();
	
	copymem((void*)CharSeg1, (void*)TITLESCREENCHAR, 256*16);
    copymem((void*)BGMap(1), (void*)TITLESCREENMAP, 256*16);
	
	copymem((void*)CharSeg0, (void*)SPRITECHAR, 256*16);
    copymem((void*)BGMap(0), (void*)SPRITESMAP, 256*16);	
	
	copymem((void*)CharSeg2, (void*)COPYRIGHTCHAR, 256*16);
    copymem((void*)BGMap(2), (void*)COPYRIGHTMAP, 256*16);	
	
	while(!(vbReadPad()&K_ANY)){}

	while(vbReadPad()&K_ANY){}	

	

	
	copymem((void*)CharSeg1, (void*)TILECHAR, 256*16);
    copymem((void*)BGMap(1), (void*)SCREEN1MAP, 256*16);	
	
	while(1)
	{
	vbSetWorld(31, WRLD_ON|1, 0, 0, 0, 0, 0, 0, 384, 224);	// world 31 is the ground
	vbSetWorld(30, WRLD_ON, player0x, 0, player0y, birdx, 0, 80, 31, 24);	 // world 30 is the bird
	vbSetWorld(29, WRLD_ON, 0, 0, 0, 0, 0, 0, 0, 0); // turn off world 29 for now
	vbSetWorld(28, WRLD_ON|2, 0, 0, 0, 0, 0, 0, 0, 0); // turn off world 28 for now
    
	// jump and falling code. jump=1 means character is jumping, fall=1 means character is falling.
	
	if ((fall>0) && (jump==0)) player0y++;
	
	if (jump==1) jumptimer++;
	if (!(vbReadPad()&(K_A)) && (jump==1)) jumptimer=0, jump=0, jumpthing=32, fall=1;
	if ((jump==1) && (jumpthing>0) && (jumptimer>20)) jumptimer=0, player0y=player0y-jumpthing, jumpthing=jumpthing/2;
	if (jumpthing<1) fall=1, jumpthing=32, jump=0;
	
	
	// controls.
	// I had to put a timer in because the controls are ultra-picky.
	if((vbReadPad()&(K_LR)) && (!(getBGMapChar(1, (player0x/8)+4, (player0y/8)+2)==512))) dir=1, movetimer++, birdx=32;
	if((vbReadPad()&(K_LL)) && (!(getBGMapChar(1, (player0x/8)+0, (player0y/8)+2)==512))) dir=2, movetimer++, birdx=0;
	if ((vbReadPad()&(K_A)) && (fall==0)) fall=0, jump=1;
	
	
	if ((movetimer>3) && (dir==1)) movetimer=0, player0x++;	
	if ((movetimer>3) && (dir==2)) movetimer=0, player0x--;	
	
	// collision to ground code

	if ((!(getBGMapChar(1, (player0x/8)+4, (player0y/8)-3)==512) && (fall==0) && (birdx==32))) fall=1;
 	if ((!(getBGMapChar(1, (player0x/8)+3, (player0y/8)-3)==512) && (fall==0) && (birdx==0))) fall=1;


	// if ((!(getBGMapChar(1, (player0x/8)+0, (player0y/8)-3)==512)) && (fall==0)) fall=1;	
	
 	// if ((!(getBGMapChar(1, (player0x/8)+3, (player0y/8)+3)==512)) && (fall==0)) fall=1; // (player0x/8)+3 	
	
	// if ((getBGMapChar(1, (player0x/8)+3, (player0y/8)+3)==512) && (fall==1)) player0y=player0y-1, fall=0;
		
	if ((getBGMapChar(1, (player0x/8)+4, (player0y/8)+3)==512)) fall=0;
 	if ((getBGMapChar(1, (player0x/8)+3, (player0y/8)+3)==512)) fall=0;	
	if ((getBGMapChar(1, (player0x/8)+2, (player0y/8)+3)==512)) fall=0;
 	if ((getBGMapChar(1, (player0x/8)+1, (player0y/8)+3)==512)) fall=0;	
	if ((getBGMapChar(1, (player0x/8)+0, (player0y/8)+3)==512)) fall=0;
	
 	// if ((getBGMapChar(1, (player0x/8)+3, (player0y/8)+3)==512) && (fall==1)) fall=0;

	if ((getBGMapChar(1, (player0x/8)+4, (player0y/8)+0)==512) && (jumpthing<32) && (jump==1) && (birdx==32)) jumptimer=0, jump=0, jumpthing=32, fall=1;
 	if ((getBGMapChar(1, (player0x/8)+3, (player0y/8)+0)==512) && (jumpthing<32) && (jump==1) && (birdx==0)) jumptimer=0, jump=0, jumpthing=32, fall=1;
	if ((getBGMapChar(1, (player0x/8)+2, (player0y/8)+0)==512) && (jumpthing<32) && (jump==1) && (birdx==32)) jumptimer=0, jump=0, jumpthing=32, fall=1;
 	if ((getBGMapChar(1, (player0x/8)+1, (player0y/8)+0)==512) && (jumpthing<32) && (jump==1) && (birdx==0)) jumptimer=0, jump=0, jumpthing=32, fall=1;
	if ((getBGMapChar(1, (player0x/8)+0, (player0y/8)+0)==512) && (jumpthing<32) && (jump==1) && (birdx==32)) jumptimer=0, jump=0, jumpthing=32, fall=1;


	}
	}
	
	