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);
	}
}
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);
}
Ejemplo n.º 3
0
void doGameplay()
{
	playing = 1;
	playerX = 10;
	playerY = 10;
	badGuyX = 230;
	badGuyY = 230;

	while( playing == 1 ) {
		updateJoypad();
		updateBadGuy();
		collisionDetection();
		delay(10);
		wait_vbl_done();
	}
}
Ejemplo n.º 4
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);
	}
}
Ejemplo n.º 5
0
void main()
{
	disable_interrupts();
	DISPLAY_OFF;
	SPRITES_8x8;

	game_start();

	SHOW_BKG;
	SHOW_SPRITES;
	DISPLAY_ON;

	enable_interrupts();

	while(1)
	{
		wait_vbl_done();
		joypad_state = joypad();
		gameplay(joypad_state);
	}
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
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;
    }
  }
}
Ejemplo n.º 8
0
void Main()
{
    u16 i,j,boton,ok=0;

    init_props_map();

REINICIA:
    init_var();

    while(1) {
        j++;

        boton=joypad();
        if(!(boton & J_A)) retraso=10;
        if((boton & J_A)) retraso=50;

        pieza(pzY[0],pzY[1],pzY[2],pzY[3],pzY[4],pzY[5],a0_,a1_,a2_,a3_,a4_,a5_);

        if(j>=retraso) {
            if((pzY[0]<mapV[0].y-pz_alto) && a0_!=0) {
                pzY[0]++;
                j=0;
            }
            else if((pzY[0]>=mapV[0].y-pz_alto) && a0_!=0) {
                mapV[0].y-=16;
                ok++;
            }
            if((pzY[1]<mapV[1].y-pz_alto) && a1_!=0) {
                pzY[1]++;
                j=0;
            }
            else if((pzY[1]>mapV[1].y-pz_alto) && a1_!=0)  {
                mapV[1].y-=16;
                ok++;
            }
            if((pzY[2]<mapV[2].y-pz_alto) && a2_!=0) {
                pzY[2]++;
                j=0;
            }
            else if((pzY[2]>mapV[2].y-pz_alto) && a2_!=0)  {
                mapV[2].y-=16;
                ok++;
            }
            if((pzY[3]<mapV[3].y-pz_alto) && a3_!=0) {
                pzY[3]++;
                j=0;
            }
            else if((pzY[3]>mapV[3].y-pz_alto) && a3_!=0)  {
                mapV[3].y-=16;
                ok++;
            }
            if((pzY[4]<mapV[4].y-pz_alto) && a4_!=0) {
                pzY[4]++;
                j=0;
            }
            else if((pzY[4]>mapV[4].y-pz_alto) && a4_!=0)  {
                mapV[4].y-=16;
                ok++;
            }
            if((pzY[5]<mapV[5].y-pz_alto) && a5_!=0) {
                pzY[5]++;
                j=0;
            }
            else if((pzY[5]>mapV[5].y-pz_alto) && a5_!=0)  {
                mapV[5].y-=16;
                ok++;
            }

            if(ok>=6) {
                goto REINICIA;
                ok=0;
            }
        }

        wait_vbl_done();
    }
}
Ejemplo n.º 9
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;
		}
	}
}
Ejemplo n.º 10
0
void main()
{
	UBYTE key1, key2, i, j, pos_x, pos_y, ch_pos;
	UBYTE non_flick = OFF;
	UWORD on_time, off_time;

	char str[MAX_DTMF];
	char str_ms[10];

	/* default dialling time setting */
	on_time = DTMF_ON;
	off_time = DTMF_OFF;

	disable_interrupts();
	
	SPRITES_8x8;   /* sprites are 8x8 */

	init_dial();
	
	init_bkg();
	
	init_key();

	init_cursor();

	disp(TITLE);

	SHOW_BKG;
	SHOW_SPRITES;
	DISPLAY_ON;

	enable_interrupts();
	
	i = j = 0;

	ch_pos = 0;
	
	while(1) {
		wait_vbl_done();
		key1 = joypad();

		if(key1 != key2){
			pos_x = i * KEY_STEP + START_CURSOR_X;
			pos_y = j * KEY_STEP + START_CURSOR_Y;
			move_cursor(pos_x, pos_y);
		}

		if(key2 & J_A){
			if(key1 & J_A){
				/* value set for each sound reg only numeric key pad*/
				if(i <= 3 && j <= 3){
					/* frequncy register set up for DTMF */
					NR13_REG = row[i];
					NR23_REG = col[j];
					NR24_REG = 0x87U;

					/* sound output on */
					NR51_REG = 0x33U;
				}
				
				/* '?' button */
				/* appear the title during press A button */
				if(i == 5 && j == 0 && !non_flick){
					disp(TITLE);
					non_flick = ON;
				}

				/* incremental button */
				/* decremental button */
				/* appear the delay during press A button */
				if(i == 5 && (j == 1 || j == 2) && !non_flick){
					sprintf(str_ms, "%lu MS", on_time);
					disp(str_ms);
					non_flick = ON;
				}
			}
			else{
				/* sound output off */
				NR51_REG = 0x00U;

				break_button(i, j);

				/* '?' button */
				/* incremental button */
				/* decremental button */
				/* return to normal display at release the A button */
				if(i == 5 && (j == 0 || j == 1 || j == 2)){
					non_flick = OFF;
					if(ch_pos == 0)
						clr_disp();
					else
						disp(str);
				}
			}
		}
		else{
			if(key1 & J_A){
				/* button display handle */
				press_button(i, j);

				/* numeric key pad handling */
				if(i <= 3 && j <= 3){
					/* string length check */
					if(ch_pos < MAX_DTMF-1){
						str[ch_pos] = pad[j][i];
						ch_pos++;
						str[ch_pos] = 0x00;
						disp(str);
					}
				}

				/* ',' button */
				if(i == 4 && j == 2){
					/* string length check */
					if(ch_pos < MAX_DTMF-1){
						str[ch_pos] = pad[j][i];
						ch_pos++;
						str[ch_pos] = 0x00;
						disp(str);
					}
				}

				/* all clear button */
				if(i == 4 && j == 0){
					ch_pos = 0x00;
					strcpy(str,"");
					clr_disp();
				}

				/* delete button */
				if(i == 4 && j == 1){
					if(ch_pos > 0){
						ch_pos--;
						str[ch_pos] = 0x00;
						if(ch_pos == 0)
							clr_disp();
						else
							disp(str);
					}
				}

				/* incremental button */
				if(i == 5 && j == 1){
					if(on_time >= DTMF_ON / 2){
						on_time = on_time - 10;
						off_time = off_time - 10;
					}
				}

				/* decremental button */
				if(i == 5 && j == 2){
					if(on_time <= DTMF_ON * 2){
						on_time = on_time + 10;
						off_time = off_time + 10;
					}
				}

				/* dialing button */
				if((i==4 || i==5) && j==3){
					dialtone(on_time, off_time, str);
				}
			}
		}

		if(!(key1 & J_A)){
			if((key1 & J_UP) && !(key2 & J_UP) && j > 0)
				j--;
			else if((key1 & J_DOWN) && !(key2 & J_DOWN) && j < 3)
				j++;

			if((key1 & J_LEFT) && !(key2 & J_LEFT) && i > 0)
				i--;
			else if((key1 & J_RIGHT) && !(key2 & J_RIGHT) && i < 5)
				i++;
		}
		key2 = key1;
	}
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
0
void Muestra_prsj1_(u16 x, u16 y, u16 frame, u16 lado, u16 estilo)
{
	Muestra_prsj1_XY(x,y,frame, lado, estilo);
	wait_vbl_done();
}
Ejemplo n.º 13
0
main(){
	disable_interrupts();
	DISPLAY_OFF;
	
	resetKoords();
	
	//set score to 0
	score_p1=0;
	score_p2=0;

	//background
	set_bkg_data(0,10,backgroundcharacters);
	//background oben
	set_bkg_tiles(0, 0, 20, 1, bgmap);
	//background mitte
	for(counter=1;counter<=13;counter++) set_bkg_tiles(0,counter,20,1,bgmap+20);
	//background unten
	set_bkg_tiles(0,14,20,1,bgmap+40);
	//leer für score etc
	for(counter=15;counter<=17;counter++) set_bkg_tiles(0,counter,20,1,bgmap+20);
	set_bkg_tiles(0,14,20,1,bgmap+40);
	
	//load sprite
	SPRITES_8x8;
	//load paddle tile
	set_sprite_data(0, 1, spritetiles);
	//load ball tile
	set_sprite_data(1, 1, spritetiles+16);
	//load score
	set_sprite_data(2, 1, spritetiles+32);
	set_sprite_data(3, 1, spritetiles+48);
	set_sprite_data(4, 1, spritetiles+64);
	set_sprite_data(5, 1, spritetiles+80);
	set_sprite_data(6, 1, spritetiles+96);
	set_sprite_data(7, 1, spritetiles+112);
	set_sprite_data(8, 1, spritetiles+128);
	set_sprite_data(9, 1, spritetiles+144);
	set_sprite_data(10, 1, spritetiles+160);
	set_sprite_data(11, 1, spritetiles+176);
	set_sprite_data(12, 1, spritetiles+192);
	
	//paddle 0
	set_sprite_tile(0,0);
	set_sprite_tile(1,0);
	set_sprite_tile(2,0);
	//paddle 1
	set_sprite_tile(3,0);
	set_sprite_tile(4,0);
	set_sprite_tile(5,0);
	//ball
	set_sprite_tile(6,1);
	
	//aktiviere bildschirm
	SHOW_BKG;
	SHOW_SPRITES; 
	DISPLAY_ON;
	enable_interrupts();
	
	while(1) {
	/* Skip four VBLs (slow down animation) */
		//for(counter = 0; counter < 10; counter++){ //64
			wait_vbl_done();
		//}
		counter = joypad();
		
		//set score score
		set_sprite_tile(7,2+score_p1);
		set_sprite_tile(8,2+score_p2);

		//check paddle 0 for move
		if(counter & J_UP && y1>=20){
			y1-=1;
			y2-=1;
			y3-=1;
			if(checkCollisionBallPaddle(0)<16){
				y1+=1;
				y2+=1;
				y3+=1;
			}
		}
		if(counter & J_DOWN && y3<=124){
			y1+=1;
			y2+=1;
			y3+=1;
			if(checkCollisionBallPaddle(0)<16){
				y1-=1;
				y2-=1;
				y3-=1;
			}
		}

		//check paddle 1 for move
		if(y5 > ball_pos_y && y4 >= 20){
			y4-=1;
			y5-=1;
			y6-=1;
			if(checkCollisionBallPaddle(1)<16){
				y4+=1;
				y5+=1;
				y6+=1;
			}
		}
		if(y5 < ball_pos_y && y6 <= 124){
			y4+=1;
			y5+=1;
			y6+=1;
			if(checkCollisionBallPaddle(1)<16){
				y4-=1;
				y5-=1;
				y6-=1;
			}
		}

		//start game?
		if(counter & J_START && game_status==0){
			//if gameover, reset score
			if(score_p1==10 || score_p2==10){
				score_p1=0;
				score_p2=0;
			}
			ball_vektor_x1=1;
			ball_vektor_x2=1;
			ball_vektor_y1=1;
			ball_vektor_y2=1;
			game_status=1; //game is now running
		}
		
		//move ball
		if(vektor_pointer==0){
			temp1=ball_vektor_x1;
			temp2=ball_vektor_y1;
			vektor_pointer=1;
		}
		else{
			temp1=ball_vektor_x2;
			temp2=ball_vektor_y2;
			vektor_pointer=0;
		}
		ball_pos_x+=temp1;
		ball_pos_y+=temp2;
		col0=checkCollisionBallPaddle(0);
		if(col0<16){
			while(temp1!=0 || temp2!=0){
				if(temp1>0){
					temp1--;
					ball_pos_x--;
				}
				if(temp1<0){
					temp1++;
					ball_pos_x++;
				}
				if(temp2>0){
					temp2--;
					ball_pos_y--;
				}
				if(temp2<0){
					temp2++;
					ball_pos_y++;
				}
				if (checkCollisionBallPaddle(0)>=16) break;
			}
		}
		col1=checkCollisionBallPaddle(1);
		if (col1<16){
			while(temp1!=0 || temp2!=0){
				if(temp1>0){
					temp1--;
					ball_pos_x--;
				}
				if(temp1<0){
					temp1++;
					ball_pos_x++;
				}
				if(temp2>0){
					temp2--;
					ball_pos_y--;
				}
				if(temp2<0){
					temp2++;
					ball_pos_y++;
				}
				if (checkCollisionBallPaddle(1)>=16) break;
			}
		}

		//collision detection
		//left wall
		if(ball_pos_x<9){
			resetKoords();
			score_p2++;
		}
		//right wall
		if(ball_pos_x>163){
			resetKoords();
			score_p1++;
		}
		//upper wall
		if(ball_pos_y<19){
			ball_pos_y=19;
			ball_vektor_y1--;
			ball_vektor_y1=ball_vektor_y1 ^ 255;
			ball_vektor_y2--;
			ball_vektor_y2=ball_vektor_y2 ^ 255;
		}
		//lower wall
		if(ball_pos_y>125){
			ball_pos_y=125;
			ball_vektor_y1--;
			ball_vektor_y1=ball_vektor_y1 ^ 255;
			ball_vektor_y2--;
			ball_vektor_y2=ball_vektor_y2 ^ 255;
		}
		
		//col0
		if(col0<16 && ball_pos_x==23){
			//ball moves up
			if(ball_vektor_y1<0 || ball_vektor_y2<0) col_table = &collision_left_up;
			//ball moves down
			else col_table = &collision_left_down;
			col_table+=col0*4;
			ball_vektor_x1 = *col_table;
			ball_vektor_y1 = *(col_table+1);
			ball_vektor_x2 = *(col_table+2);
			ball_vektor_y2 = *(col_table+3);
		}

		//col1
		if(col1<16 && ball_pos_x==145){
			//ball moves up
			if(ball_vektor_y1<0 || ball_vektor_y2<0) col_table = &collision_right_up;
			//ball moves down
			else col_table = &collision_right_down;
			col_table+=col1*4;
			ball_vektor_x1 = *col_table;
			ball_vektor_y1 = *(col_table+1);
			ball_vektor_x2 = *(col_table+2);
			ball_vektor_y2 = *(col_table+3);
		}

		//sonderfall col0
		if(col0<16 && ball_pos_x!=23){
			ball_vektor_y1--;
			ball_vektor_y2--;
			ball_vektor_y1=ball_vektor_y1^255;
			ball_vektor_y2=ball_vektor_y2^255;
		}

		//sonderfall col1
		if(col1<16 && ball_pos_x!=145){
			ball_vektor_y1--;
			ball_vektor_y2--;
			ball_vektor_y1=ball_vektor_y1^255;
			ball_vektor_y2=ball_vektor_y2^255;
		}

		//paint p0
		move_sprite(0,15,y1);
		move_sprite(1,15,y2);
		move_sprite(2,15,y3);
		//paint p1
		move_sprite(3,153,y4);
		move_sprite(4,153,y5);
		move_sprite(5,153,y6);
		//paint ball
		move_sprite(6,ball_pos_x,ball_pos_y);
		//paint score
		move_sprite(7,15,140);
		move_sprite(8,153,140);
	}
}
Ejemplo n.º 14
0
void Main(u16 PLAYERS)
{
	int incl, incl_x, incl_y, i, delay;
	u16 boton, PLAYER=1;
	u16 bx, by, incl_c;
	u16 rx = 16,
	      ry = 144,
	      saltoX = 1,
	      saltoY = 1,
		incRaqueta;
	u16 LifeCount = 3;
	u32 ScoreCount = 0;
	boolean jugando, rastro;
	u16 direccion, tipoBola, long_r, mesias;
	u16 nivel = 1;
	u8 *nivelMap;

	GANA_NIVEL:

	if(nivel>1) fade_out(30, 1, 0);
	RefrescaBG(nivel,mesias);
	limpia_oam();
	Wait(100);	//Espera 3 segundos
	fade_in(30, 1, 0);

	IniciaPropiedadesBloques(nivel);
	RefrescaNivel(nivel);

	if(nivel==1) { nivelMap = blockMap_1; }//N1 = N2 = 12; }
	if(nivel==2) { nivelMap = blockMap_2; }//N1 = N2 = 13; }
	if(nivel==3) { nivelMap = blockMap_3; }//N1 = N2 = 14; }
	if(nivel==4) { nivelMap = blockMap_4; }//N1 = N2 = 15; }
	if(nivel==5) { nivelMap = blockMap_5; }//N1 = N2 = 16; }

	REINICIA:

	RefrescaLife(LifeCount);
	limpia_activoBonXY();

	jugando=TRUE;
	mesias=FALSE;
	RefrescaBG(nivel,mesias);

	tipoBola=BOLA1;
	ANCHO_BOLA=6;
	ALTO_BOLA=6;
	long_r=FALSE;
	ANCHO_RAQUETA=32;

	if(PLAYERS==2) {
		if(PLAYER==2) { PLAYER=1; goto DO_PLAYER; }
		if(PLAYER==1) { PLAYER=2; goto DO_PLAYER; }
	}
	DO_PLAYER:
	if(LifeCount==0 || nivel==6) jugando=FALSE;

	if(jugando==TRUE) IniciaMovimientoRaqueta(rx,ry,long_r,PLAYER,ScoreCount);

	rastro=FALSE;
	MAX_Y=160;

	delay=0;

	bx = Inicio_Bx;
	by = ry - ALTO_BOLA;
	rx = Inicio_Rx;

	while (LifeCount > 0 && nivel<=5)

		{

		/*<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><*/

		if(bx>( MAX_X - ANCHO_BOLA ) ) incl_x=-1;
		if(bx< MIN_X ) incl_x=1;
		if(by>( MAX_Y - ALTO_BOLA) )
		{
			incl_y=-1;
			if(mesias==FALSE) { LifeCount--; goto REINICIA; }
			if(mesias==TRUE) { mesias=FALSE; MAX_Y=160; }
		}
		if(by<= MIN_Y ) incl_y=1;

	if(long_r==FALSE)
	{
		if (by == (ry-ALTO_BOLA) && bx >= (rx-ANCHO_BOLA) && bx <= (rx-ANCHO_BOLA)+8 ) {incl_x=-1; incl_y=-1; incl=supizq;}
		if (by == (ry-ALTO_BOLA) && bx >= (rx-ANCHO_BOLA)+9 && bx <= (rx-ANCHO_BOLA)+16 ) {incl_x=-1; incl_y=-1; incl=supsupizq;}
		if (by == (ry-ALTO_BOLA) && bx >= (rx-ANCHO_BOLA)+17 && bx <= (rx-ANCHO_BOLA)+24 ) {incl_x=1; incl_y=-1; incl=supsupder;}
		if (by == (ry-ALTO_BOLA) && bx >= (rx-ANCHO_BOLA)+25 && bx <= (rx-ANCHO_BOLA)+32 ) {incl_x=1; incl_y=-1; incl=supder;}
			if (bx == (rx-ANCHO_BOLA) && ( by>=ry-ALTO_BOLA && by<=ry+8) ) {incl_x=-1; incl_y=-1; incl=izqizqsup;}
			if (bx == (rx+ANCHO_RAQUETA) && ( by>=ry-ALTO_BOLA && by<=ry+8) ) {incl_x=1; incl_y=-1; incl=derdersup;}
	}
	if(long_r==TRUE)
	{
		if (by == (ry-ALTO_BOLA) && bx >= (rx-ANCHO_BOLA) && bx <= (rx-ANCHO_BOLA)+8 ) {incl_x=-1; incl_y=-1; incl=supizq;}
		if (by == (ry-ALTO_BOLA) && bx >= (rx-ANCHO_BOLA)+9 && bx <= (rx-ANCHO_BOLA)+16 ) {incl_x=-1; incl_y=-1; incl=supizq;}
		if (by == (ry-ALTO_BOLA) && bx >= (rx-ANCHO_BOLA)+17 && bx <= (rx-ANCHO_BOLA)+24 ) {incl_x=-1; incl_y=-1; incl=supsupizq;}
		if (by == (ry-ALTO_BOLA) && bx >= (rx-ANCHO_BOLA)+25 && bx <= (rx-ANCHO_BOLA)+32 ) {incl_x=1; incl_y=-1; incl=supsupder;}
		if (by == (ry-ALTO_BOLA) && bx >= (rx-ANCHO_BOLA)+33 && bx <= (rx-ANCHO_BOLA)+40 ) {incl_x=1; incl_y=-1; incl=supder;}
		if (by == (ry-ALTO_BOLA) && bx >= (rx-ANCHO_BOLA)+41 && bx <= (rx-ANCHO_BOLA)+48 ) {incl_x=1; incl_y=-1; incl=supder;}
			if (bx == (rx-ANCHO_BOLA) && ( by>=ry-ALTO_BOLA && by<=ry+8) ) {incl_x=-1; incl_y=-1; incl=izqizqsup;}
			if (bx == (rx+ANCHO_RAQUETA) && ( by>=ry-ALTO_BOLA && by<=ry+8) ) {incl_x=1; incl_y=-1; incl=derdersup;}
	}

for (i=0 ; i <= 162 ; i++)
		{
		if ( by == L[i].y-ALTO_BOLA && (bx >= L[i].x-ANCHO_BOLA && bx <= L[i].xM) )
			{ incl_y=-1;
			if(L[i].BONUS!=NO_BONUS && L[i].golpes <= 1) { L[i].activoBonus=TRUE; }
			if(rastro==TRUE && L[i].destruye==TRUE)
			{
				L[i].golpes = 0;
				incl_y=1;
			}
			if (L[i].golpes > 0)
				{
				L[i].golpes--;
				ScoreCount+=25;
				}
			if (L[i].destruye == TRUE && L[i].golpes == 0)
				{ 
				L[i].x = L[i].y = L[i].xM = L[i].yM = 0;
				nivelMap[L[i].tile1] = O1; nivelMap[L[i].tile2] = O2;
				ScoreCount+=100;
				}
			}

		if ( by == L[i].yM && (bx >= L[i].x-ANCHO_BOLA && bx <= L[i].xM) )
			{ incl_y=1;
			if(L[i].BONUS!=NO_BONUS && L[i].golpes <= 1) { L[i].activoBonus=TRUE; }
			if(rastro==TRUE && L[i].destruye==TRUE)
			{
				L[i].golpes = 0;
				incl_y=-1;
			}
			if (L[i].golpes > 0)
				{
				L[i].golpes--;
				ScoreCount+=25;
				}
			if (L[i].destruye == TRUE && L[i].golpes == 0)
				{ 
				L[i].x = L[i].y = L[i].xM = L[i].yM = 0;
				nivelMap[L[i].tile1] = O1; nivelMap[L[i].tile2] = O2;
				ScoreCount+=100;
				}
			}

		if ( bx == L[i].x-ANCHO_BOLA && (by >= L[i].y-ALTO_BOLA && by <= L[i].yM) )
			{ incl_x=-1;
			if(L[i].BONUS!=NO_BONUS && L[i].golpes <= 1) { L[i].activoBonus=TRUE; }
			if(rastro==TRUE && L[i].destruye==TRUE)
			{
				L[i].golpes = 0;
				incl_x=1;
			}
			if (L[i].golpes > 0)
				{
				L[i].golpes--;
				ScoreCount+=25;
				}
			if (L[i].destruye == TRUE)
				{ 
				L[i].x = L[i].y = L[i].xM = L[i].yM = 0;
				nivelMap[L[i].tile1] = O1; nivelMap[L[i].tile2] = O2;
				ScoreCount+=100;
				}
			}

		if ( bx == L[i].xM && (by >= L[i].y-ALTO_BOLA && by <= L[i].yM) )
			{ incl_x=1;
			if(L[i].BONUS!=NO_BONUS && L[i].golpes <= 1) { L[i].activoBonus=TRUE; }
			if(rastro==TRUE && L[i].destruye==TRUE)
			{
				L[i].golpes = 0;
				incl_x=-1;
			}
			if (L[i].golpes > 0)
				{
				L[i].golpes--;
				ScoreCount+=25;
				}
			if (L[i].destruye == TRUE && L[i].golpes == 0)
				{ 
				L[i].x = L[i].y = L[i].xM = L[i].yM = 0;
				nivelMap[L[i].tile1] = O1; nivelMap[L[i].tile2] = O2;
				ScoreCount+=100;
				}
			}
		}

	for (i=0 ; i <= 108 ; i++)
		if(L[i].activoBonus == TRUE)	
		{
			if(L[i].BONUS!=NO_BONUS)
				{
					RefrescaBonus(L[i].bonX,L[i].bonY,L[i].BONUS,L[i].bonN);
					L[i].bonY++;
					if(L[i].bonX+16>=rx && L[i].bonX<=rx+ANCHO_RAQUETA && L[i].bonY>=ry && L[i].bonY<=ry+ALTO_RAQUETA)
					{
						if(L[i].BONUS==COMET_BONUS)
							{
							rastro=TRUE;
							L[i].BONUS=NO_BONUS;
							L[i].activoBonus=FALSE;
							RefrescaBonus(240+8,160+8,L[i].BONUS,L[i].bonN);
							}
						if(L[i].BONUS==LONG_R_BONUS)
							{
							ANCHO_RAQUETA=48;
							long_r=TRUE;
							L[i].BONUS=NO_BONUS;
							L[i].activoBonus=FALSE;
							RefrescaBonus(240+8,160+8,L[i].BONUS,L[i].bonN);
							}
						if(L[i].BONUS==LIFE_BONUS)
							{
							LifeCount++;
							L[i].BONUS=NO_BONUS;
							L[i].activoBonus=FALSE;
							RefrescaBonus(240+8,160+8,L[i].BONUS,L[i].bonN);
							}
						if(L[i].BONUS==BIGBALL_BONUS)
							{
							rastro=FALSE;
							tipoBola = BOLA2;
							ANCHO_BOLA=8;
							ALTO_BOLA=8;
							L[i].BONUS=NO_BONUS;
							L[i].activoBonus=FALSE;
							RefrescaBonus(240+8,160+8,L[i].BONUS,L[i].bonN);
							}
						if(L[i].BONUS==MESIAS_BONUS)
							{
							mesias=TRUE;
							MAX_Y=160-12;
							L[i].BONUS=NO_BONUS;
							L[i].activoBonus=FALSE;
							RefrescaBonus(240+8,160+8,L[i].BONUS,L[i].bonN);
							}
					}
					if(L[i].bonY>=MAX_Y+16)
					{
						L[i].BONUS=NO_BONUS;
						L[i].activoBonus=FALSE;
						RefrescaBonus(240+8,160+8,L[i].BONUS,L[i].bonN);
					}
				}
		}

		boton = joypad();
		if ( (boton & J_B)) incRaqueta=3;
		if (!(boton & J_B)) incRaqueta=4;

		if (!(boton & J_RIGHT) && rx < (MAX_X - ANCHO_RAQUETA) ) rx+=incRaqueta;
		if (!(boton & J_LEFT) && rx > MIN_X ) rx-=incRaqueta;
		if (rx > MAX_X - ANCHO_RAQUETA) rx=MAX_X - ANCHO_RAQUETA;

		if (!(boton & J_SELECT)) goto REINICIA;

		//bx += col;
		//by += fil;

		if(incl_x==1) {	if(incl==0) incl=1;	if(incl==2) incl=3;	if(incl==4) incl=5;
					if(incl==6) incl=7;	if(incl==8) incl=9;	if(incl==10) incl=11; }
		if(incl_x==-1) {	if(incl==1) incl=0;	if(incl==3) incl=2;	if(incl==5) incl=4;
					if(incl==7) incl=6;	if(incl==9) incl=8;	if(incl==11) incl=10; }
		if(incl_y==1) {	if(incl==4) incl=6;	if(incl==2) incl=8;	if(incl==0) incl=10;
					if(incl==1) incl=11;	if(incl==3) incl=9;	if(incl==5) incl=7; }
		if(incl_y==-1) {	if(incl==6) incl=4;	if(incl==8) incl=2;	if(incl==10) incl=0;
					if(incl==11) incl=1;	if(incl==9) incl=3;	if(incl==7) incl=5; }

		if(incl==0) {
			if(incl_c<2) { by--; }
			if(incl_c>=2) { by--; bx--; incl_c=0; }
		}
		if(incl==1) {
			if(incl_c<2) { by--; }
			if(incl_c>=2) { by--; bx++; incl_c=0; }
		}
		if(incl==2) if(incl_c>=1) {bx--; by--; incl_c=0;}
		if(incl==3) if(incl_c>=1) {by--; bx++; incl_c=0;}
		if(incl==4) {
			if(incl_c<2) { bx--; }
			if(incl_c>=2) { bx--; by--; incl_c=0; }
		}
		if(incl==5) {
			if(incl_c<2) { bx++; }
			if(incl_c>=2) { bx++; by--; incl_c=0; }
		}
		if(incl==6) {
			if(incl_c<2) { bx--; }
			if(incl_c>=2) { bx--; by++; incl_c=0; }
		}
		if(incl==7) {
			if(incl_c<2) { bx++; }
			if(incl_c>=2) { bx++; by++; incl_c=0; }
		}
		if(incl==8) if(incl_c>=1) {bx--; by++; incl_c=0;}
		if(incl==9) if(incl_c>=1) {bx++; by++; incl_c=0;}
		if(incl==10) {
			if(incl_c<2) { by++; }
			if(incl_c>=2) { by++; bx--; incl_c=0; }
		}
		if(incl==11) {
			if(incl_c<2) { by++; }
			if(incl_c>=2) { by++; bx++; incl_c=0; }
		}

		wait_vbl_done();
		//Wait(2);

		EstableceRaqueta(rx, ry, long_r, PLAYER);
		if(incl_x<0 && incl_y<0) direccion=0;
		if(incl_x>0 && incl_y<0) direccion=1;
		if(incl_x<0 && incl_y>0) direccion=2;
		if(incl_x>0 && incl_y>0) direccion=3;
		EstableceBola(bx, by, rastro, direccion, tipoBola);
		RefrescaScore(ScoreCount);

		if(LifeCount>99) LifeCount=99;
		RefrescaLife(LifeCount);

		if(ChecaTerminadoNivel()==TRUE) {nivel++; goto GANA_NIVEL;}
		RefrescaBG(nivel,mesias);

		incl_c++;
		}

}