示例#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++;
	}
}
示例#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];
		}
	}
}
示例#3
0
void main(void) {
  //set palette for sprites
  pal_spr(palSprites); 

  // set background color to black
  pal_col(0, 0x0f);

  //enable rendering
  ppu_on_all();

  //initialize invader parameters
  for(i=0;i<INVADERS_MAX;++i) {
    //starting coordinates
    invader_x[i]=rand8();
    invader_y[i]=rand8();

    //direction bits
    j=rand8();

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

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

  //the main loop
  while(1) {
    //wait for next TV frame
    ppu_wait_frame();

    spr=0;

    for(i=0;i<INVADERS_MAX;++i) {
      //set a sprite for current invader
      spr=oam_spr(invader_x[i],invader_y[i],0x40,i&3,spr);//0x40 is tile number, i&3 is palette

      //move the invader
      invader_x[i]+=invader_dx[i];
      invader_y[i]+=invader_dy[i];

      //bounce the invader off the edges
      if(invader_x[i]>=(256-8)) invader_dx[i]=-invader_dx[i];
      if(invader_y[i]>=(240-8)) invader_dy[i]=-invader_dy[i];
    }
  }
}
示例#4
0
void main(void)
{
	static unsigned char i,row;
	static int y;
	static unsigned int adr;

	pal_col(1,0x30);//set while color
	
	y=0;
	
	update_list[0]=0x20|NT_UPD_HORZ;//horizontal update sequence, dummy address
	update_list[1]=0x00;
	update_list[2]=32;//update sequence is 32 tiles wide
	update_list[3+32]=NT_UPD_EOF;
	
	set_vram_update(update_list);

	ppu_on_all();//enable rendering
	
	while(1)
	{
		scroll(0,y);//scroll value will be applied on the next nmi

		if(!(y&7))//put new row every 8 pixels
		{
			row=(y>>3)+59;//get row number for update, it is shifted just above the visible part of the screen
			
			if(row>=60) row-=60;//keep the row number within the limits
			
			adr=row<<5;//convert Y from pixels to tiles (row=y/8), then to nametable offset (offset=row*32)
			
			if(adr<960) adr=adr|NAMETABLE_A; else adr=(adr-960)|NAMETABLE_C;//add base address of one of two nametables
			
			update_list[0]=MSB(adr)|NT_UPD_HORZ;//set the address
			update_list[1]=LSB(adr);
			
			for(i=0;i<32;++i) update_list[3+i]=0x10+(rand8()&7);//fill row buffer with random tiles
		}

		--y;//next pixel
		
		if(y<0) y=240*2-1;//keep Y within the total height of two nametables

		ppu_wait_nmi();
	}