Ejemplo n.º 1
0
void main(void)
{
	ppu_on_all();//enable rendering

	//set initial coords
	
	cat_x[0]=52;
	cat_y[0]=100;
	cat_x[1]=180;
	cat_y[1]=100;

	//init other vars
	
	touch=0;//collision flag
	frame=0;//frame counter

	//now the main loop

	while(1)
	{
		ppu_waitnmi();//wait for next TV frame

		//flashing color for touch
		
		i=frame&1?0x30:0x2a;

		pal_col(17,touch?i:0x21);//set first sprite color
		pal_col(21,touch?i:0x26);//set second sprite color

		//process players
		
		spr=0;

		for(i=0;i<2;++i)
		{
			//display metasprite
			
			spr=oam_meta_spr(cat_x[i],cat_y[i],spr,!i?metaCat1:metaCat2);

			//poll pad and change coordinates
			
			pad=pad_poll(i);

			if(pad&PAD_LEFT &&cat_x[i]>  0) cat_x[i]-=2;
			if(pad&PAD_RIGHT&&cat_x[i]<232) cat_x[i]+=2;
			if(pad&PAD_UP   &&cat_y[i]>  0) cat_y[i]-=2;
			if(pad&PAD_DOWN &&cat_y[i]<212) cat_y[i]+=2;
		}

		//check for collision for a smaller bounding box
		//metasprite is 24x24, collision box is 20x20
		
		if(!(cat_x[0]+22< cat_x[1]+2 ||
		     cat_x[0]+ 2>=cat_x[1]+22||
	         cat_y[0]+22< cat_y[1]+2 ||
		     cat_y[0]+ 2>=cat_y[1]+22)) touch=1; else touch=0;

		frame++;
	}
}
Ejemplo n.º 2
0
void main(void)
{
	pal_spr(palSprites);//set palette for sprites
	oam_size(0);
	ppu_on_all();//enable rendering

	//initialize balls parameters

	for(i=0;i<BALLS_MAX;++i)
	{
		//starting coordinates

		ball_x[i]=rand8();
		ball_y[i]=rand8();

		//direction bits

		j=rand8();

		//horizontal speed -3..-3, excluding 0
		spr=1+(rand8()%3);
		ball_dx[i]=j&1?-spr:spr;

		//vertical speed

		spr=1+(rand8()%3);
		ball_dy[i]=j&2?-spr:spr;
	}

	
	//now the main loop

	while(1)
	{
		ppu_waitnmi();//wait for next TV frame

		spr=0;

		for(i=0;i<BALLS_MAX;++i)
		{
			//set a sprite for current ball

			spr=oam_spr(ball_x[i],ball_y[i],0x40,i&3,spr);//0x40 is tile number, i&3 is palette

			//move the ball

			ball_x[i]+=ball_dx[i];
			ball_y[i]+=ball_dy[i];

			//bounce the ball off the edges

			if(ball_x[i]>=(256-8)) ball_dx[i]=-ball_dx[i];
			if(ball_y[i]>=(240-8)) ball_dy[i]=-ball_dy[i];
		}
	}
}
Ejemplo n.º 3
0
void title_screen(void)
{
	scroll(-8,240);//title is aligned to the color attributes, so shift it a bit to the right
	unrle_vram(title_nam,0x2000);
	vram_adr(0x2800);//clear second nametable, as it is visible in the jumping effect
	vram_fill(0,1024);
	pal_bg(palTitle);
	pal_bright(4);
	ppu_on_bg();
	delay(20);//delay just to make it look better

	iy=240<<FP_BITS;
	dy=-8<<FP_BITS;
	frame_cnt=0;
	wait=160;
	bright=4;

	while(1)
	{
		ppu_waitnmi();
		scroll(-8,iy>>FP_BITS);

		if(pad_trigger(0)&PAD_START) break;

		iy+=dy;

		if(iy<0)
		{
			iy=0;
			dy=-dy>>1;
		}

		if(dy>(-8<<FP_BITS)) dy-=2;

		if(wait)
		{
			--wait;
		}
		else
		{
			pal_col(2,(frame_cnt&32)?0x0f:0x20);//blinking press start text
			++frame_cnt;
		}
	}
Ejemplo n.º 4
0
void delay(unsigned char time)
{
	for(wait=0;wait<time;++wait) ppu_waitnmi();
}