示例#1
0
void updateGraphics()
{
	disable_interrupts();

	scroll_bkg(1, 0);

	move_sprite(0, playerX, playerY);

	move_sprite(1, badGuyX, badGuyY);

	move_sprite(2, playerShotX, playerShotY);

	enable_interrupts();
}
示例#2
0
int main()
{
	//setup

	//sprite stuff
	set_sprite_palette(0,1,&spritepalette[0]);
	SPRITES_8x8;
	set_sprite_data(MARIO, 4, mario);
	set_sprite_tile(0,0);
	set_sprite_tile(1,1);
	set_sprite_tile(2,2);
	set_sprite_tile(3,3);

/*
	set_sprite_location(0, 0, 20, 0, MARIO, current_map);
	set_camera_location(0, 0, 2, 0);
*/



	//background stuff
	set_bkg_palette(0,1,&backgroundpalette[0]);
	set_bkg_palette(1,1,&backgroundpalette[4]);
	set_bkg_data(0,4,backgroundcharacters);
	VBK_REG=1;
	set_bkg_tiles(0,0,20,24,cgbmap);
	VBK_REG=0;
	set_bkg_tiles(0,0,20,24,bgmap);
	SHOW_BKG;
	enable_interrupts();
	DISPLAY_ON;
	scroll_bkg(0,1);
	
	while(1) {/*
		printf("camera_x: %i\n", camera_x);
		printf("camera_y: %i\n", camera_y);
		printf("spritex: %i\n", spritex);
		printf("spritey: %i\n", spritey);*/

		//read
		input = joypad();



		//eval
		if(input & J_UP) {
			spritey--;
		}
		if(input & J_DOWN) {
			spritey++;  
		}
		if(input & J_LEFT) {
			if(spritex != 0) {
				spritex--;
			}
			camera_x = spritex - 80;
			if(spritex <= 80) {
				camera_x = 0;
			}
			if(spritex >= world_width_px - 80) {
				camera_x = world_width_px - SCREEN_WIDTH;
			}
			scrolled = 0;
		}
		if(input & J_RIGHT) {
			if(spritex != world_width_px - 16) {
				spritex++;
			}
			camera_x = spritex - 80;
			if(spritex <= 80) {
				camera_x = 0;
			}
			if(spritex >= world_width_px - 80) {
				camera_x = world_width_px - SCREEN_WIDTH;
			}
			scrolled = 0;
		}

		//print
		for(y = 0; y <= 18; y++) {
		/*			VBK_REG=1;
		set_bkg_tiles(0,3,20,19,cgbmap);
		VBK_REG=0;
		set_bkg_tiles(0,0,20,19,bgmap);
		*/
			map_row = camera_y/8;
			map_row *= tile_width;
			map_row += (camera_x/8);

			VBK_REG=1;
			set_bkg_tiles(0,y,21,1,&cgbmap[map_row]);
			VBK_REG=0;
			set_bkg_tiles(0,y,21,1,&bgmap[map_row]);
		}

		move_sprite(0,spritex-camera_x+8,spritey-camera_y+16);
		move_sprite(1,spritex-camera_x+16,spritey-camera_y+16);
		move_sprite(2,spritex-camera_x+8,spritey-camera_y+24);
		move_sprite(3,spritex-camera_x+16,spritey-camera_y+24);

		//print
		for(i = 0; i < 4; i++) {
			//slow down animation
			wait_vbl_done();
		}
		SHOW_BKG;
		SHOW_SPRITES;
	}
	return 0;
}
int player()                 /* player moving func (see sprite4a.zip for more info) */
{
 key=joypad();                   /* key = what was pressed */

 if(key==J_RIGHT)
  {
   x++;         
   if(collide(x,y)==1){x--; return 0;} /* check we can move right */
    if(!fall)
     {
      current+=2;                      /* if we aren't falling continue animation */
      if(current==8) current=0;
      set_sprite_tile(0,current);
     }
   set_sprite_prop(0,0); 
   move_sprite(0,x,y);                 /* put sprite on screen */
   if(!fall)
    { delay(25); }                     /* delay if not falling */
  return 1;
  } 

 if(key==J_LEFT)
  {
   x--;
   if(collide(x,y)==1){x++; return 0;}
    if(!fall)
     {
      current+=2;
      if(current==8) current=0;
      set_sprite_tile(0,current);
     }
   set_sprite_prop(0,S_FLIPX | 0x01);  /* flips horizontatly l/r sprite */
   move_sprite(0,x,y);
   if(!fall)
    { delay(25); }          
  return 1;
  } 

 if(key==J_UP)
  {
   y--;
  if(test){ if (collide(x,y)==1) {y++; return 0;} }  /* for testing purposes */
  else if(collide(x,y)!=2){y++; return 0;}
   updwn+=2;
   if(updwn==16)
     { updwn=8; }
   set_sprite_tile(0,updwn);
   move_sprite(0,x,y);
   if(!fall)
    { delay(25); }
  return 1;
  }

 if(key==J_DOWN)
  {
   y++;
   if(test){ if (collide(x,y)==1) {y--; return 0;} }
   else if(collide(x,y)!=2){y--; return 0;}
   updwn+=2;
   if(updwn==16)
    { updwn=8; }
   set_sprite_tile(0,updwn);
   move_sprite(0,x,y);
   if(!fall)
    { delay(25); }
  return 1;
  }

if(key==J_B)              /* just for testing purposes */
  {
  move_sprite(0,200,200);
  delay(500);
  for(temp=0;temp<=127;temp++)
   {
    scroll_bkg(0,2);
    delay(5);  
   }
  delay(500);
  move_sprite(0,15,16);
  x=15;
  y=16;
  return 1;
  }

if(key==J_A+J_RIGHT || key==J_A+J_LEFT || key==J_A)
 {
 if(!fall){ jump();}
 return 1;
 }

return 0;
}                        /* end of player func */
示例#4
0
文件: main.c 项目: jowan/kBANG
/*
 * main loop
 *
**/
void main(){
// LOCAL VARIABLES
UBYTE ch_1,ch_2,ch_3,ch_4,ch_5,ch_6,ch_7,ch_8,key;
int x,y,c,d;
int p;
unsigned int len;
unsigned int lcnt;
unsigned int speed;
unsigned int scrl;
SHOW_BKG;                           // needed for gameboy original
set_bkg_data(0,70,bangtiles);       // imports the sprites
set_bkg_tiles(0,0,32,18,bangmap01); // sets the tiles
gb_out(0x00);                       // set all pins low

x=0;y=1;                            // set coordinates to 0,1 top left of screen
c=0;d=0;
ch_1=0x00;ch_2=0x00;                // give channel variables hex value of 0
ch_3=0x00;ch_4=0x00;                // "
ch_5=0x00;ch_6=0x00;                // "
ch_7=0x00;ch_8=0x00;                // "

lcnt=0;                             // play position in loop
speed=100;                          // initial delay in milisecs -> speed
len=15;                             // initial length of loop value
scrl=1;                             // initial scroll value

move(x,y,NOTEOFFOVER);              // NOTEOFFOVER is labeled wrong, it is actually the position pointer,
move(len,10,LBEG);                   // places loop end sprite

for( c=0; c<9; c++ ) {              // empty matrix
    for( d=0; d<31; d++ ) {
     matrix[c][d]=0;
    }
}

for( c=0; c<9; c++ ) {              // set all mute values to off - 1
     ch_mute[c]=0;
}
// infinate loop for main app
while(1){
    
    addr = 0x00;                    // set addr all off
    gb_out(addr);                   // set output to addr - all off
    delay(speed);                   // delay by speed value
    key = joypad();                 // copy joypad value to key

    if(lcnt>=len){                  // increment play position counter to the right,
        move(lcnt,9,EMPTY);         // until reaches loop end, then back to start
        lcnt=-1;
    }
    lcnt++;
    move(lcnt,9,POINTER);           // places counter sprite
    move(lcnt-1,9,EMPTY);           // hides trailing sprite with blank
    
    
    // checks to see if there is a value in the matrix at position x by y and if the mute is off
    // if neither true, adds a hex value representing the physcal pin on hardware
    // this is much easier with binary but C has no support for that fot some reason
    if(matrix[1][lcnt]==1 && ch_mute[1]==0){  move(1,0,MUTEON);  ch_1=0x01;}else{ch_1=0x00;}
    if(matrix[2][lcnt]==1 && ch_mute[2]==0){  move(5,0,MUTEON);  ch_2=0x02;}else{ch_2=0x00;}
    if(matrix[3][lcnt]==1 && ch_mute[3]==0){  move(9,0,MUTEON);  ch_3=0x04;}else{ch_3=0x00;}
    if(matrix[4][lcnt]==1 && ch_mute[4]==0){  move(13,0,MUTEON);  ch_4=0x08;}else{ch_4=0x00;}
    if(matrix[5][lcnt]==1 && ch_mute[5]==0){  move(17,0,MUTEON);  ch_5=0x10;}else{ch_5=0x00;}
    if(matrix[6][lcnt]==1 && ch_mute[6]==0){  move(21,0,MUTEON);  ch_6=0x20;}else{ch_6=0x00;}
    if(matrix[7][lcnt]==1 && ch_mute[7]==0){  move(25,0,MUTEON);  ch_7=0x40;}else{ch_7=0x00;}
    if(matrix[8][lcnt]==1 && ch_mute[8]==0){  move(29,0,MUTEON);  ch_8=0x80;}else{ch_8=0x00;}
    // add channel values together in hex
    addr = ch_1 + ch_2 + ch_3 + ch_4 + ch_5 + ch_6 + ch_7 + ch_8;
    // set pins high / low according to value
    gb_out(addr);        
    // min system delay for master loops
    delay(50);

    p=1;
    // turns all channel indicator led sprites off on top of screen
    while(p<30){
       move(p,0,MUTEOFF);
       p+=4;
    }
    p=y*4-2;
    // combination moves picked up slightly differnently
    if(key & J_UP) {
        if (key & J_START ){                // start and up -> speeds up
            if(speed>=10){                  // 10 min
                speed=speed-5;              // decrease speed / delay value
            };
        }
    }
    if(key & J_DOWN) {
        if (key & J_START ){                // start and up -> speeds down
          if(speed<=200){                   // 200 max
              speed=speed+10;               // increases speed / delay value
           };
        }
    }
    if(key & J_UP) {                        // select and up -> mutes channel cursor is on
        if (key & J_SELECT ){               // SPEEUP wrongly labled -> muteon
            move(p,0,SPEEUP);               // place muteon sprite in place
            ch_mute[y]=1;                   // give channel mute value 1
        }
    }
    if(key & J_DOWN) {                      // select and down -> unmutes channel cursor is on
        if (key & J_SELECT ){               // SPEEDWN wrongly labled -> muteoff
            move(p,0,SPEEDWN);              // place muteoff sprite in place
            ch_mute[y]=0;                   // give channel mute value 0
        }
    }
    if(key & J_RIGHT) {                     // start and right -> increase loop length
        if (key & J_START ){
            if (len < 31){                  // max is 31 -> 2 bar 32 steps
                len++;                      // increment
                move(len,10,LBEG);          // move sprite
                move(len-1,10,EMPTY);       // hide trail
            }
        }
    }
    if(key & J_LEFT) {                      // start and left -> decrease loop length
        if (key & J_START ){
            if (len > 2){                   // min is 2
                len--;                      // decrement
                move(len,10,LBEG);          // move sprite
                move(len+1,10,EMPTY);       // hide trail
            }
        }
    }
    if(key & J_RIGHT) {                     // select and right -> scroll screen to right
        if (key & J_SELECT ){
           if(scrl<7){                      // only 7 steps
                scroll_bkg(+16,0);          // each step is 16 pixels, move by 16 in x axis
                scrl++;                     // increment
            }
        }
    }
    if(key & J_LEFT) {                      // select and right -> scroll screen to right
        if (key & J_SELECT ){
            if(scrl>2){                     
               scroll_bkg(-16,0);
               scrl--;                      // decrement
           }
        }
    }
    // single button moves picked up by switch method
    switch (joypad(0))
    {
      case (J_RIGHT):                       // move cursor right
        if(x<=31){
          if(matrix[y][x]==1){
            move(x,y,NOTEON);
            x=x+1;
          }else{
            move(x,y,NOTEOFF);
            x=x+1;
          }
          if(matrix[y][x]==1){
            move(x,y,NOTEONOVER);
          }else{
            move(x,y,NOTEOFFOVER);
          }
        }
      break;  // end right

      case (J_LEFT):                        // move cursor left
        if(x>=1){
          if(matrix[y][x]==1){
             move(x,y,NOTEON);
             x=x-1;
          }else{
            move(x,y,NOTEOFF);
            x=x-1;
          }
          if(matrix[y][x]==1){
            move(x,y,NOTEONOVER);
          }else{
            move(x,y,NOTEOFFOVER);
          }
        }
      break;  // end left

      case (J_UP):                          // move cursor up
        if(y>=2){
          if(matrix[y][x]==1){
            move(x,y,NOTEON);
            y=y-1;
          }else{
            move(x,y,NOTEOFF);
            y=y-1;
          }
          if(matrix[y][x]==1){
            move(x,y,NOTEONOVER);
          }else{
            move(x,y,NOTEOFFOVER);
          }
        }
      break;  // end up

      case (J_DOWN):                        // move cursor down
        if(y<=8){
          if(matrix[y][x]==1){
            move(x,y,NOTEON);
            y=y+1;
            move(x,y,NOTEONOVER);
          }else{
            move(x,y,NOTEOFF);
            y=y+1;
            move(x,y,NOTEOFFOVER);
          }
          if(matrix[y][x]==1){
            move(x,y,NOTEONOVER);
          }else{
            move(x,y,NOTEOFFOVER);
          }
        };
      break;  // end down

      case (J_A):                           // note off at x y
        move(x,y,NOTEOFFOVER);              // place noteoff sprite
        matrix[y][x]=0;                     // give matrix x y value of 0
      break;  // end start

      case (J_B):                           // note on at x y
        move(x,y,NOTEON);                   // place noteon sprite
        matrix[y][x]=1;                     // give matrix x y value of 1
      break;  // end select

    }    // end button switch
  }      // end constant loop
}        // end void
示例#5
0
void main() {
	int x = 0;
	int y = 0;
	int	 i, j;
	int ply_x = 120;
	int ply_y = 92;
	int ply_tile = 'H';
	int ply2_x = 120;
	int ply2_y = 100;
	int ply2_tile = 'H';
	int raster[10], speeds[10], *p, *p2;
	char *c;


	for (y = 2; y < 22; y += 2) {
		for (x = 0; x != 32; x += 2) {
			set_bkg_map(road_pattern, x, y, 2, 2);
		}
		for (x = 0; x != 32; x += 4) {
			if (y < 12) {
				set_bkg_map(car1_map_r, x, y+1, 2, 1);
			} else {
				set_bkg_map(car1_map_l, x, y+1, 2, 1);
			}
		}
	}

	for (x = 0; x != 32; x ++) {
		set_bkg_map(top_sidewalk_pattern, x, 0, 1, 3);
		set_bkg_map(bottom_sidewalk_pattern, x, 22, 1, 3);
		set_bkg_map(central_strip_pattern, x, 12, 1, 1);
	}

	for (i = 0, p2 = speeds; i != 5; i++, p2++) {
		(*p2) = rand_speed();
	}
	for (i = 0; i != 5; i++, p2++) {
		(*p2) = -rand_speed();
	}

	set_vdp_reg(VDP_REG_FLAGS1, VDP_REG_FLAGS1_SCREEN);

	load_tiles(chicken_graphics, 0, 255, 4);
	load_palette(pal1, 0, 16);
	load_palette(pal2, 16, 16);

//	add_pause_int(pause_handler);

	for (;;) {
		p = raster;
		p2 = speeds;
		j = 0;
		x = 1;
		y = 16;
		while (get_vcount() != 0) {
		}
		x = (*p) >> 4;
		while (y < 176) {
			while (get_vcount() < y) {
			}
			if (j & 0x01) {
				load_palette(pal1, 0, 16);
			} else {
				load_palette(pal2, 0, 16);
			}
			scroll_bkg(x, y);
			(*p) += (*p2);
			p++;
			p2++;
			x = (*p) >> 4;
			y += 14;
			j++;

			while (get_vcount() < y) {
			}
			scroll_bkg(0, 0);
			y += 2;
		}
		load_palette(pal1, 0, 16);
		scroll_bkg(0, 0);

		wait_vblank_noint();
	}
}