Example #1
0
void init_bkg()
{
	/* Initialize the background */
	set_bkg_data( 0, 9, frame_lcd);
	set_bkg_data( 9, 9, break_btn);
	set_bkg_data(18, 9, press_btn);
	
	set_bkg_tiles(0, 0, 20, 18, dtmf_tile);
}
void main(){
	int xpos = 8 + GRAPHICS_WIDTH / 2;
	int ypos = 16 + GRAPHICS_HEIGHT / 2;
	int count = 0;
	int joy, i;
	set_sprite_data(0, 1, crosshair_tiledata);
	set_sprite_data(1, 6, explode_tiledata);
	SWITCH_ROM_MBC1(3);
	set_bkg_data(0, 179, title_tiledata);
	set_bkg_tiles(0, 0, 20, 18, title_tilemap);
	SHOW_BKG;
	DISPLAY_ON;
	waitpad(J_START);
	DISPLAY_OFF;
	SWITCH_ROM_MBC1(2);
	set_bkg_data(0, 182, earth_tiledata);
	set_bkg_tiles(0, 0, 20, 18, earth_tilemap);
	set_sprite_tile(0,0);
	move_sprite(0, xpos, ypos);
	SHOW_SPRITES;
	DISPLAY_ON;
	waitpadup();
	while (1){
		wait_vbl_done();
		joy = joypad();
		if (joy & J_UP && ypos > 14)
			--ypos;
		if (joy & J_DOWN && ypos < GRAPHICS_HEIGHT + 13)
			++ypos;
		if (joy & J_LEFT && xpos > 8)
			--xpos;
		if (joy & J_RIGHT && xpos < GRAPHICS_WIDTH + 8)
			++xpos;
		if (joy & J_A || joy & J_B){
			++count;
			move_sprite(count, xpos - 2, ypos - 2);
			for (i = 1; i != 7; ++i){
				set_sprite_tile(count, i);
				wait_vbl_done();
				wait_vbl_done();
			}
			set_sprite_tile(count, 4);
			set_sprite_prop(count, 1 << 4);
			if (count == 39){
				delay(500);
				end();
			}
		}		
		move_sprite(0, xpos, ypos);
	}
}
Example #3
0
void initialize_view(){

    TILE_WHITE = next_tile++;
    TILE_LIGHT_GREY = next_tile++;
    TILE_DARK_GREY = next_tile++;
    TILE_BLACK = next_tile++;

    set_bkg_data(TILE_WHITE, 4, colorRects);

    TILE_BLOCKS_START = next_tile;
    next_tile += 7;
    set_bkg_data(TILE_BLOCKS_START, 7, blocks);

}
Example #4
0
void background_init(){
  UBYTE i, j, k;
  SHOW_BKG;
  BGP_REG = background_palettes[player_data.position.z];

  /* Initialize the background */
  // load background tiles into VRAM
  set_bkg_data(0x01, BACKGROUND_DATA_SIZE, background_sprite_data);

  background_data.speed.x.w = 0;
  background_data.speed.y.w = 0;

  // create a random background
  for(i = 0, k=0; i != 32; i++){
    for(j = 0; j != 32; j++){
      k++;
      if (k == BACKGROUND_DATA_SIZE){
        k = 0;
      }
      set_bkg_tiles(i, j, 
                    1, 1, 
                    background_tiles +
                      (((UBYTE)rand()) % BACKGROUND_DATA_SIZE));
    }
  }

  //start at 0,0
  background_data.position.x.w = 0;
  background_data.position.y.w = 0;
  SCX_REG = 0;
  SCY_REG = 0;
}
Example #5
0
void INIT()
{
	UBYTE i;

	disable_interrupts();
	HIDE_BKG;
	HIDE_SPRITES;
	HIDE_WIN;
	DISPLAY_OFF;

	set_bkg_data( 0, 5, bgtile1 );
	set_bkg_tiles( 0, 0, bgmap3Width, bgmap3Height, bgmap3 );

	set_sprite_data( 0, 32, girl );
	SPRITES_8x8;

	gx = gy = 1;
	gd = 2;
	gp = 1;

	SET_MOVE_SPRITE();

	for( i = 0; i < 4; i++ ){
		set_sprite_prop( i, 0 );
	}

	SHOW_BKG;
	SHOW_SPRITES;
	DISPLAY_ON;
	enable_interrupts();
}
Example #6
0
void Start_STATE_GAME_OVER() {
	set_bkg_data(0, 81, tilesgameover);
	InitScroll(gameoverWidth, gameoverHeight, gameover, 0, 2);
	SHOW_BKG;

	PlayMusic(gameover_mod_Data, 3, 0);
}
void main()
{
    printf("Welcome to GAMEBOY\nProgramming");
    printf("\n-------------------\n");
    printf("  (\\" "\\" "_/)    (\\" "\\" "_/)\n");
    printf("  (0.o)    (0.o)\n");
    printf("  (> <)    (> <)\n");
    printf("-------------------\n");
    printf("PROGRAMED BY JAMES \n");
    printf("\nPress Start");
    waitpad(J_START);  // other keys are J_A, J_UP, J_SELECT, etc.
    //printf("\nIsn't it easy!");

    // Turn the display off
    DISPLAY_OFF;

    // Load up the tile data
    set_bkg_data(0,255,logo_tile_data);

    // Switch to VRAM
    VBK_REG = 1;

    // Switch out of VRAM
    VBK_REG = 0;

    // Set screen x,y pos to 0,0 and draw the map 20,18(size of the screen)
    set_bkg_tiles(0,0,20,18,logo_map_data);

    // Show the background
    SHOW_BKG;

    // Turn the display on
    DISPLAY_ON;
}
Example #8
0
void displaySetup()
{
	DISPLAY_OFF;
	set_bkg_palette( 0, 1, &bgpalette[0] ); 

	/* Initialize the background */
	set_bkg_data(0, 92, data_font);	
	//set_bkg_tiles(1,0, 20, 18, bgmap);
	
	set_sprite_palette(0,2,&spritepalette[0]);
	
	for(j=0;j!=4;j++) {
		cursorBigStartX[j] = SCREEN_XO + SCREEN_PSTARTX + (j * SCREEN_XSPACE) - 1;
		cursorBigStartY[j] = SCREEN_YO + SCREEN_PSTARTY - 8;
		cursorStartX[j] = SCREEN_XO + SCREEN_PSTARTX + (j * SCREEN_XSPACE) - 8;
		cursorStartY[j] = SCREEN_YO + SCREEN_PSTARTY;
		cursorRow[j] = cursorStartY[j];
	}
	
	SPRITES_8x8;
	
	set_sprite_data(SPRITE_ARRT,0x01U, data_barrow);
	set_sprite_data(SPRITE_ARRL,0x01U, data_larrow);
	
	
	set_sprite_tile(SPRITE_ARRT_START, SPRITE_ARRT);
	for(j=0;j!=4;j++) set_sprite_tile(j+SPRITE_ARRL_START, SPRITE_ARRL);
	
	for(j=0;j!=4;j++) set_sprite_prop(j+SPRITE_ARRT_START,1);
	for(j=0;j!=4;j++) set_sprite_prop(j+SPRITE_ARRL_START,1);
	
	DISPLAY_ON;
}
Example #9
0
int main()
{
  /* Transfer color palettes */
  set_bkg_palette( 7, 1, &bar_p[0] );
  set_bkg_palette( 6, 1, &bar_p[4] );
  set_bkg_palette( 5, 1, &bar_p[8] );
  set_bkg_palette( 4, 1, &bar_p[12] );
  set_bkg_palette( 3, 1, &bar_p[16] );
  set_bkg_palette( 2, 1, &bar_p[20] );
  set_bkg_palette( 1, 1, &bar_p[24] );
  set_bkg_palette( 0, 1, &bar_p[28] );

  /* CHR code transfer */
  set_bkg_data( 0x0, 32, bar_c );

  /* Select VRAM bank 1 */
  VBK_REG = 1;
  /* Set attributes */
  set_bkg_tiles( 0, 0, bar_mWidth, bar_mHeight, bar_a );

  /* Select VRAM bank 0 */
  VBK_REG = 0;
  /* Set data */
  set_bkg_tiles( 0, 0, bar_mWidth, bar_mHeight, bar_m );

  SHOW_BKG;
  enable_interrupts();
  DISPLAY_ON;

  /* Loop forever */
  while(1)
    ;

  return(0);
}
Example #10
0
unsigned int mainMenu()
{
   int selection;
   unsigned long int loopCount;

   DISPLAY_OFF;
   HIDE_BKG;

   move_bkg(0,0);

   set_bkg_palette( 7, 1, &menuPalCGB[28] );
   set_bkg_palette( 6, 1, &menuPalCGB[24] );
   set_bkg_palette( 5, 1, &menuPalCGB[20] );
   set_bkg_palette( 4, 1, &menuPalCGB[16] );
   set_bkg_palette( 3, 1, &menuPalCGB[12] );
   set_bkg_palette( 2, 1, &menuPalCGB[8] );
   set_bkg_palette( 1, 1, &menuPalCGB[4] );
   set_bkg_palette( 0, 1, &menuPalCGB[0] );

   set_bkg_data( 0, 141, menuTiles );

   VBK_REG = 1;
   set_bkg_tiles(0,0,menuMapWidth,menuMapHeight,menuPal);

   VBK_REG = 0;
   set_bkg_tiles(0,0,menuMapWidth,menuMapHeight,menuMap);

   SHOW_BKG;
   DISPLAY_ON;

   setupPointer();

   loopCount = 0;
   do
   {
      loopCount++;
      if((loopCount % 125) == 0)
         updatePointer(); /* animate the pointer */

      selection = checkButtons();

   } while(!selection); /* user hasn't made a selection */
   set_sprite_tile(0, 0); /* set to straight pointer while waiting */
   while(joypad() & (J_A | J_START)); /* wait for the user to let up */

   /* "Shoot" the pointer across the screen */
   loopCount = 0;
   while((pointerX + loopCount) <= 168)
   {
   	move_sprite(0, pointerX + loopCount, pointerYPositions[currSelection]);
      loopCount++;
      delay(4);
   }


   hidePointer();

   return selection;
}
Example #11
0
void hideLogo() {
	char* p = bg_map;
	set_bkg_data(0, background_tileset_size, background_tileset);
	for (y = 2; y < flappybird_map_height+2; ++y ) {
		set_bkg_tiles(4, y, flappybird_map_width, 1, p);
		p += flappybird_map_width;
	}
}
Example #12
0
void init_background()
{
    HIDE_BKG;
    SWITCH_ROM_MBC1(4);
    set_bkg_data(0, 0x21, bkgdata);
    SHOW_BKG;

    generate_visual_map( _tmpmap );

}
void end(){
	wait_vbl_done();
	DISPLAY_OFF;
	HIDE_SPRITES;
	SWITCH_ROM_MBC1(1);
	set_bkg_data(0, 221, end_tiledata);
	set_bkg_tiles(0, 0, 20, 18, end_tilemap);
	SHOW_BKG;
	DISPLAY_ON;
	while(1);
}
Example #14
0
void main()
{
	INT8 i;
	UINT8 input;

	UFIX16 amount;
	amount.U16 = 0x0000U;


	set_bkg_data(0, 42, roadTiles);
	set_bkg_tiles(0, 0, 32, 32, roadGrid);

	offsetIndex = 0;
	for (i = 0; i < 80; i++)
	{
		roadOffset[i] = 0;
	}

	SPRITES_8x8;
	SHOW_SPRITES;
	SHOW_BKG;
	HIDE_WIN;

	LYC_REG = 0x07U;
	STAT_REG = 0x20U;
	set_interrupts(VBL_IFLAG | LCD_IFLAG);

	add_LCD(HBLANK);
	add_VBL(VBLANK);

	enable_interrupts();

	frameReady = 0;
	while (1)
	{
		if (frameReady == 0)
		{
			input = joypad();
			if (input & J_LEFT)
			{
				amount.U8.intp -= 10;
			}

			if (input & J_RIGHT)
			{
				amount.U8.intp += 10;
			}

			MoveHr(&amount);

			frameReady = 1;
		}
	}
}
Example #15
0
/*--------------------------------------------------------*/
void INIT()
{
	UBYTE i;

	printf(" ");

	disable_interrupts();
	HIDE_BKG;
	HIDE_SPRITES;
	HIDE_WIN;
	DISPLAY_OFF;

	set_bkg_data( 0, 5, bgtile1 );
	set_bkg_data( 160, 65, hamumoji );    // ハム子文字に使うタイルデータ 160番〜 65枚 hamumoji(で作ったタイル)をセットする

	set_sprite_data( 0, 32, hamuko );
	SPRITES_8x8;

	SHOW_BKG;
	SHOW_SPRITES;
	DISPLAY_ON;
	enable_interrupts();

	//------------------------------乱数の初期化の為にオープニングにメッセージを追加
	OPENING_MESSAGE();
	RANSUU_INIT();
	//------------------------------

	set_bkg_tiles( 0, 0, bgmap4Width, bgmap4Height, bgmap4 );

	hx = hy = 1;
	hd = 2;
	hp = 0;

	SET_MOVE_HAMUKO();

	for( i = 0; i < 4; i++ ){
		set_sprite_prop( i, 0 );
	}

}
Example #16
0
void INIT()  // 画面の初期化
{
	printf( " " );     // 画面の初期化の前に この1行がないと ハム子文字も文字化けします

	disable_interrupts();
	HIDE_BKG;
	HIDE_SPRITES;
	HIDE_WIN;
	DISPLAY_OFF;

	set_bkg_data( 160, 65, hamumoji );    // ハム子文字に使うタイルデータ 160番〜 65枚 hamumoji(で作ったタイル)をセットする

	SHOW_BKG; 
	DISPLAY_ON;
	enable_interrupts();
}
Example #17
0
void INIT()  // ‰æ–Ê‚Ì�‰Šú‰»
{
    printf( " " );     // ‰æ–Ê‚Ì�‰Šú‰»‚Ì‘O‚É�@‚±‚Ì1�s‚ª‚È‚¢‚Æ�@ƒnƒ€Žq•¶Žš‚à•¶Žš‰»‚¯‚µ‚Ü‚·

    disable_interrupts();
    HIDE_BKG;
    HIDE_SPRITES;
    HIDE_WIN;
    DISPLAY_OFF;

    set_bkg_data( 160, 65, hamumoji );    // ƒnƒ€Žq•¶Žš‚ÉŽg‚¤ƒ^ƒCƒ‹ƒf�[ƒ^�@160”Ô�`�@65–‡�@hamumoji�i‚Å�ì‚Á‚½ƒ^ƒCƒ‹�j‚ðƒZƒbƒg‚·‚é

    SHOW_BKG;
    DISPLAY_ON;
    enable_interrupts();
}
void back()                  /* bkg func */
{
 set_bkg_data(1,3,briks);      /* start bkg display (platforms,ladders etc.) */
 for(x=0;x<20;x++)
 {
   for(y=0;y<40;y++)
   set_bkg_tiles(x,y,1,1,bkgtilea); 
 }

  for(i=0;i<array_size;i=i+5) /* gets the x,y coords from lev_data array */
   {
    j=i+1;
    k=i+2;
    l=i+3;
    m=i+4;  
    x=lev_data[i];
    u=lev_data[j];
    y=lev_data[k];
    v=lev_data[l];
    w=lev_data[m];

     if(w==1)                /* draws the bricks */
      {  for(x;x<u;x++)
          {
           set_bkg_tiles(x,y,1,1,brik);
           }

       if((v-y)!=2)
        { for(y;y<u;y++)
           {
            set_bkg_tiles(x,y,1,1,brik);
            }
        }
       }
    if(w==2)                 /* draws the ladders */
      {  
       if((v-y)!=2)
        { for(y;y<v;y++)
           {
            set_bkg_tiles(x,y,1,1,ladder);
            }
        }
       }
    }
 SHOW_BKG;                             
}                            /* end of bkg func */ 
Example #19
0
/**
 * Draws the title screen
 * and halts until START is pushed.
 */
void showTitle() {
	UWORD seed;

	// Load titlescreen and seed RNG
	DISPLAY_OFF;
	LCDC_REG = B8(01000001);
	set_bkg_data(0, title_dataLen, title_data);
	set_bkg_tiles(0, 0, 20, 18, title_tiles);
	DISPLAY_ON;

	waitpad(J_START);
	seed = DIV_REG;

	waitpadup();
	seed |= (UWORD)DIV_REG << 8;
	initarand(seed);
}
Example #20
0
main(){
	UBYTE counter,x,y;
	x=40;
	y=17;
	
	disable_interrupts();
	DISPLAY_OFF;
	
	/*load background
	 *
	 */
	set_bkg_data(0,4,backgroundcharacters);
	for(counter=0;counter<=16;counter+=2)
		set_bkg_tiles( 0, counter, 20, 2, bgmap);
	
	//load sprite
	SPRITES_8x8;
	set_sprite_data(0, 1, spritetiles);
	set_sprite_tile(0,0);
	move_sprite(0,x,y);
	
	SHOW_BKG;
	SHOW_SPRITES; 
	DISPLAY_ON;
	enable_interrupts();
	
	while(1) {
	/* Skip four VBLs (slow down animation) */
		for(counter = 0; counter < 4; counter++){
			wait_vbl_done();
		}
		counter = joypad();
		
		if(counter & J_UP)
			y--;
		if(counter & J_DOWN)
			y++;
		if(counter & J_LEFT)
			x--;
		if(counter & J_RIGHT)
			x++;
			
		move_sprite(0,x,y);
	}
}
Example #21
0
void main()
{
     // Load up the tile data
     set_bkg_data(0,255,logo_tile_data);

     // Switch to VRAM
     VBK_REG = 1;

     // Switch out of VRAM
     VBK_REG = 0;

     // Set screen x,y pos to 0,0 and draw the map 20,18(size of the screen)
     set_bkg_tiles(0,0,20,18,logo_map_data);

     // Show the background
     SHOW_BKG;

     // Turn the display on
     DISPLAY_ON; 
}
Example #22
0
void recordSounds()
{
   int joy;

	DISPLAY_OFF;
	HIDE_BKG;

  /*************************************************************************/
  /* the following set of routines loads the palettes into the display.    */
  /* each palette is send (one by one) by using the command:               */
  /*   set_bkg_palette( palette-no, first color in palette, Palette-data ) */
  /*************************************************************************/

  set_bkg_palette( 7, 1, &recordPalCGB[28] );
  set_bkg_palette( 6, 1, &recordPalCGB[24] );
  set_bkg_palette( 5, 1, &recordPalCGB[20] );
  set_bkg_palette( 4, 1, &recordPalCGB[16] );
  set_bkg_palette( 3, 1, &recordPalCGB[12] );
  set_bkg_palette( 2, 1, &recordPalCGB[8] );
  set_bkg_palette( 1, 1, &recordPalCGB[4] );
  set_bkg_palette( 0, 1, &recordPalCGB[0] );


  /*************************************************************************/
  /* Next, the tile-data is send to the display;
  /*************************************************************************/

  set_bkg_data( 0, 235, recordTiles );

  /*************************************************************************/
  /* Now it's time to send the map-data to the display. Again, in two      */
  /* steps, as the tiles and attributes reside in different banks.         */
  /* The data is send to the display by using the command:                 */
  /*   set_bkg_tiles( Left, Top, Width, Height, Map-data )                 */
  /*************************************************************************/

  VBK_REG = 1;
  set_bkg_tiles(0,0,recordMapWidth,recordMapHeight,recordPal);

  VBK_REG = 0;
  set_bkg_tiles(0,0,recordMapWidth,recordMapHeight,recordMap);



  /*************************************************************************/
  /* the remaining code init the Gameboy and makes it wait untill you turn */
  /* it off..                                                              */
  /*************************************************************************/

  SHOW_BKG;
  DISPLAY_ON;

   do
   {
   	joy = joypad();
   } while (!joy);
	waitpadup();

  	HIDE_BKG;

   return;
}
Example #23
0
/* clear display */
void clr_disp()
{
	set_bkg_data(OFFSET, 50, dtmf_lcd);
	set_bkg_tiles(LCD_X, LCD_Y, LCD_WIDTH, LCD_HIGHT, init_disp);
}
Example #24
0
main()
{
	UBYTE key;
//	selchannel=0;
	programs[0]=0;programs[1]=0;programs[2]=0;programs[3]=0;

	offset=0;

	// load palette sets
	set_bkg_palette( 0, 7, &dsppalette[0] );

	// load in tiles
	set_bkg_data(0,214,tileData);
	SHOW_BKG;
	DISPLAY_ON;

	VBK_REG = 1;

	// set palettes per tile
	set_bkg_tiles( 0,0,   20,18, mapAttr);
	VBK_REG = 0;

	// set actual tiles
	set_bkg_tiles( 0,0, 20,18, mapData);


	key = 0;
      while(key != J_START) {
      	key = getkey();
	      if ( (key & J_DOWN)&&(offset >  0) ) offset --;
      	if ( (key & J_UP)&&(offset < 12) ) offset ++;
		draw_number(offset+1,17,14);
		draw_number(offset+2,17,15);
		draw_number(offset+3,17,16);
		draw_number(offset+4,17,17);
      }

	VBK_REG = 1;



	VBK_REG=1;
	set_bkg_tiles(0,14,17,1,clear_pal);
	set_bkg_tiles(0,15,17,1,clear_pal);
	set_bkg_tiles(0,16,17,1,clear_pal);
	set_bkg_tiles(0,17,17,1,clear_pal);
	VBK_REG=0;
	set_bkg_tiles(0,14,17,1,msg_clear);
	set_bkg_tiles(0,15,17,1,msg_clear);
	set_bkg_tiles(0,16,17,1,msg_clear);
	set_bkg_tiles(0,17,17,1,msg_clear);

	draw_number(0,17,14);
	draw_number(0,17,15);
	draw_number(0,17,16);
	draw_number(0,17,17);

	set_bkg_tiles(16,14,1,1,hardmap);
	set_bkg_tiles(16,15,1,1,hardmap);
	set_bkg_tiles(16,16,1,1,hardmap);
	set_bkg_tiles(16,17,1,1,hardmap);

	// Go onto pushpin proper
	midi_server();

	return(0);
}
Example #25
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;
}
void main()                                   /* main program  */ 
{
int spr,spl,spud,x,y,old,key,fall;      

set_bkg_data(1,3,briks);          /* start bkg display (platforms,ladders etc.) */

for(x=0;x<20;x++)
 {for(y=0;y<18;y++)
   set_bkg_tiles(x,y,1,1,bkgtilea); 
 }

for(x=0;x<10;x++)
 {
  set_bkg_tiles(x,2,1,1,brik); 
 }

for(x=9;x<14;x++)
 {
  set_bkg_tiles(x,4,1,1,brik);
 }

for(y=4;y<18;y++)
 {
  set_bkg_tiles(14,y,1,1,ladder); 
 }
SHOW_BKG;                         /* end bkg */


SPRITES_8x16;           /* sets sprites to, yep you guessed it, 8x16 mode */

set_sprite_data(0, 24, bloke);   /* defines the main sprite data */

for(i=0;i<=11;i++)
{
set_sprite_tile(i,i*2);          /* defines the tiles numbers */
}


/* spr = sprite movement right (sprite numbers 0 - 3)
   spl = sprite movement left (sprite numbers 4 - 7)
   spud = sprite movement up/down (sprite numbers 8 - 11)  */

spr=0;                          /* right movement sprite starts at no.0 */
spl=4;                          /* left movement sprite starts at no.4 */
spud=8;                         /* up / down movement sprite starts at no.8 */
x=15;                           /* x cordinate to start at */
y=16;                           /* y cordinate to start at */
old=0;                          /* the last sprite displayed */
m=0;

move_sprite(spr,x,y);         /* puts the first sprite on screen */
old=spr;
SHOW_SPRITES;

 while(!0)                      /* infinate game loop */
 {

 check:     
 y++;                                     /* check we are stood on something using the arrary*/
 if(collide(x,y)){y--; fall=0; goto ok; }
 fall=1;                                   /* if NOT, we fall.... */
 move_sprite(old,x,y);            
 delay(10); 
 y++;                                     /* Do this twice so we fall down 2 before l/r movement*/
 if(collide(x,y)){y--; fall=0; goto ok; }
 move_sprite(old,x,y);            
 delay(10);        

ok:

key=joypad();                    /* key = what was pressed */

 if(key==J_RIGHT)                /* IF it was right ...    */
  {
  x++;                           /* increment x , so we can check boundry before moving */
if(x==scrxr){x--; goto check; }        /* if x position is equal to max screen right, decerement
                                          x and goto check, not allowing movement            */
if(collide(x,y)==1){x--; goto check;}  /* call the collide function, if it returns 1(wall) do not
                                          allow right movement   */
   move_sprite(old,200,0);             /* move the old sprite off screen */
   move_sprite(spr,x,y);               /* move new sprite onto screen    */
   old=spr;                            /* save the current sprite number in old */
   if(!fall){delay(25);}               /* delay if not falling */
   if(!fall){spr++;}                   /* increment sprite number if not falling */
   if(spr==4) spr=0;                   /* check if we have reached the end of the 
                                          animation, if so start again  */
  }                                     /* end of right IF statment */


  if(key==J_LEFT)           /* see above */
   {
   x--;
if(x==scrxl){x++; goto check; }
if(collide(x,y)==1){x++; goto check;} 
   move_sprite(old,200,0);  
   move_sprite(spl,x,y);
   old=spl;  
   if(!fall){delay(25);}                          
   if(!fall){spl++;}                              
   if(spl==8) spl=4;
   }

  if(key==J_UP)           /* see above */
   {
   y--;
if(y==scryt){y++; goto check; }
if(collide(x,y)!=2){y++; goto check;}  /* call the collide function, if it's not a ladder (2),
                                          don't allow up or down movement                     */
   move_sprite(old,200,0);  
   move_sprite(spud,x,y);
   delay(25);
   old=spud;  
   spud++;
   if(spud==12) spud=8;
   }

  if(key==J_DOWN)           /* see above */
   {
   y++;
if(y==scryb){y--; goto check; }
if(collide(x,y)!=2){y--; goto check;} 
   move_sprite(old,200,0);  
   move_sprite(spud,x,y);
   delay(25);
   old=spud;  
   spud++;
   if(spud==12) spud=8;
   }

  if(key==J_B)              /* just for testing purposes */
  {
  spr=0;
  move_sprite(old,200,200);
  move_sprite(spr,15,16);
  x=15;
  y=16;
  old=spr;
  }

 }                              /* end of infinate loop */


}                               /* end main */
Example #27
0
void main()
{
  UBYTE i, j;

  disable_interrupts();
  DISPLAY_OFF;
  LCDC_REG = 0x67;
  /*
   * LCD        = Off
   * WindowBank = 0x9C00
   * Window     = On
   * BG Chr     = 0x8800
   * BG Bank    = 0x9800
   * OBJ        = 8x16
   * OBJ        = On
   * BG         = On
   */

  doorstate = CLOSED;

  /* Set palettes */
  BGP_REG = OBP0_REG = OBP1_REG = 0xE4U;

  /* Initialize the background */
  set_bkg_data(0xFC, 0x04, std_data);
  set_bkg_data(0x00, 0x2D, bkg_data);
  /*
   * Draw the background
   *
   * Width  = 0x100 = 0x20 * 8
   * Height = 0x100 = 0x20 * 8
   */
  for(i = 0; i < 32; i+=8)
    for(j = 0; j < 32; j+=8)
      set_bkg_tiles(i, j, 8, 8, bkg_tiles);
  bposx.w = 0;
  SCX_REG = 0;
  bposy.w = 0;
  SCY_REG = 0;
  bspx.w = 0xFF00;
  bspy.w = 0x0080;

  /* Initialize the window */
  set_win_data(0x80, 0x21, frame_data);
  /*
   * Draw the frame in the window
   *
   * Width  = 0x80 = 0x10 * 8
   * Height = 0x50 = 0x0A * 8
   */
  set_win_tiles(0, 0, 16, 10, frame_tiles);
  /*
   * Draw the door in the window
   *
   * Width  = 0x60 = 0x20 * 12
   * Height = 0x30 = 0x20 * 6
   */
  set_win_tiles(2, 2, 12, 6, door1_tiles);
  wposx.b.h = MAXWNDPOSX;
  wposx.b.l = 0;
  WX_REG = MAXWNDPOSX;
  wposy.b.h = MAXWNDPOSY;
  wposy.b.l = 0;
  WY_REG = MAXWNDPOSY;
  wspx.w = 0xFF80;
  wspy.w = 0xFFC0;

  /* Initialize the sprite */
  set_sprite_data(0x00, 0x1C, earth_data);
  set_sprite_prop(0, 0x00);
  set_sprite_prop(1, 0x00);
  sframe = 0;
  sposx.w  = 0x1000;
  sposy.w  = 0x1000;
  sspx.w  = 0x0040;
  sspy.w  = 0x0040;
  tile_sprite();
  place_sprite();

  DISPLAY_ON;
  enable_interrupts();

  while(1) {
    /* Skip four VBLs (slow down animation) */
    for(i = 0; i < 4; i++)
      wait_vbl_done();
    time++;
    fade();
    door();
    scroll();
    animate_sprite();
    i = joypad();
    if(i & J_B) {
      if(i & J_UP)
	bspy.w -= 0x0010;
      if(i & J_DOWN)
	bspy.w += 0x0010;
      if(i & J_LEFT)
	bspx.w -= 0x0010;
      if(i & J_RIGHT)
	bspx.w += 0x0010;
    } else if(i & J_A) {
      if(i & J_UP)
	wspy.w -= 0x0010;
      if(i & J_DOWN)
	wspy.w += 0x0010;
      if(i & J_LEFT)
	wspx.w -= 0x0010;
      if(i & J_RIGHT)
	wspx.w += 0x0010;
    } else {
      if(i & J_SELECT)
	color = STARTFADE;
      if(i & J_START)
	if(doorstate == CLOSED) {
	  doorstate = OPENING;
	  doorpos = 0;
	} else if(doorstate == OPENED) {
	  doorstate = CLOSING;
	  doorpos = NBDFRAMES;
	}
      if(i & J_UP)
	sspy.w -= 0x0010;
      if(i & J_DOWN)
	sspy.w += 0x0010;
      if(i & J_LEFT)
	sspx.w -= 0x0010;
      if(i & J_RIGHT)
	sspx.w += 0x0010;
    }
  }
}
Example #28
0
int main (void) {
	char* p = bg_map;
	
	//Setup rand
	rand_seed = DIV_REG;
	
	//Turn off
	disable_interrupts();
	DISPLAY_OFF;
	
	//Setup LCD
	SHOW_BKG;
	SHOW_SPRITES;
	SHOW_WIN;
	
	//Load bg
	BGP_REG = OBP1_REG = 0xE4;
	OBP0_REG = 0xE1;
	
	set_bkg_data(0, background_tileset_size, background_tileset);
	for (y = 0; y < bg_map_height; ++y ) {
		set_bkg_tiles(0, y, bg_map_width, 1, p);
		p += bg_map_width;
	}
	
	//Load window
	x = 0;
	for (i = 0; i < 21; ++i ) {
		set_win_tiles(x, 0, ground_map_width, ground_map_height, ground_map);
		x += ground_map_width;
	}
	WX_REG = 0;
	WY_REG = 120;
	
	//Load Sprite
	
	set_sprite_data(0, sprites_size, sprites_data);
	SPRITES_8x16;
	
	//Load Bird
	
	setupBird();
	
	//Reset
	resetGame();
	
	//Turn on display
	DISPLAY_ON;
	enable_interrupts();
	
	//Finish rand
	rand_seed |= DIV_REG << 8;
	initarand(rand_seed);
	
	//RunLoop
	while (1) {
		joy = joypad();
		wait_vbl_done();
		
		switch (gameState) {
			case GAME_STATE_INTRO: {
				introLoop();
			}
				break;
			case GAME_STATE_GAME: {
				gameLoop();
			}
				break;
			case GAME_STATE_DEAD: {
				deadLoop();
			}
				break;
		}
	}
	
	return 0;
}
Example #29
0
/**
 * Main ingame loop.
 */
void gameLoop() {
	BYTE xdist, ydist;
	UBYTE cx, cy;

	// Init player
	pposx = 80;
	pposy = 64;
	pdir = DIR_DOWN;
	alive = 1;

	// Set game variables
	score = 0;
	nextUpdate = 0;
	switch_delay = START_DELAY;

	// Load game map BG tiles
	DISPLAY_OFF;
	// Load tile data sets
	LCDC_REG = B8(01000011);
	set_sprite_data(0, sprite_dataLen, sprite_data);
	set_bkg_data(0, game_dataLen, game_data);
	set_bkg_tiles(0, 0, 20, 18, map_tiles);

	// Score counter
	set_sprite_tile(5, 64);
	move_sprite(5, 15, 148);

	set_sprite_tile(6, 65);
	set_sprite_tile(7, 65);
	move_sprite(6, 26, 148);
	move_sprite(7, 35, 148);

	set_sprite_tile(4, 64);

	clearMap();
	addBox();

	DISPLAY_ON;


	// Game loop
	while(alive) {
		wait_vbl_done();
		time++;
		nextUpdate++;
		if(nextUpdate >= switch_delay) {
			nextUpdate = 0;
			updateMap();
			spawnCells();
		}
		updatePlayer();

		// Check if player has picked up box
		xdist = pposx - boxx;
		ydist = pposy - boxy;
		if(xdist > -COLDISTX && xdist < COLDISTX
		&& ydist > -COLDISTY && ydist < COLDISTY) {
			score++;
			updateScore();
			addBox();
			switch_delay--;
		}

		// Check if player is on black hole
		cx = pposx/16 - 1;
		cy = pposy/16 - 1;
		if(map[cx + cy*MAPW] >= CELL_BLACK) {
			alive = 0;
		}
	}
}
Example #30
0
File: main.c Project: 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