コード例 #1
0
ファイル: example4.c プロジェクト: fourks/cc65-nes-examples
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
ファイル: syntax_error.c プロジェクト: manlycode/nesdev
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];
    }
  }
}
コード例 #3
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();
	}
コード例 #4
0
ファイル: game.c プロジェクト: AmarildoK/BreakingBad-NES
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;
		}
	}