Example #1
0
int main(int argc, char **argv) {

	// Create the game window and initalise the VIDEO subsystem
	GameWindow gwd;
	gwd.InitVideo();
	
	gwd.SetBackground((GXColor){ 0, 30, 0, 255 });

	// Initialise Wiimote
	WPAD_Init();

	// Enable SD card stuff
	fatInitDefault();

	// Create a rectangle representing the net and set its properties
	Quad net;
	net.SetPosition(320-2, 0);
	net.SetWidth(4);
	net.SetHeight(480);
	net.SetFillColor((GXColor){ 0, 255, 0, 255 });

	// Create the two score boxes (x position, y position, width)
	ScoreBox firstScoreBox(35, 10, 250);
	ScoreBox secondScoreBox(355, 10, 250);

	// Create and spawn the first player
	Player firstPlayer;
	firstPlayer.spawn(0, 100);

	// Create and spawn the second player
	Player secondPlayer;
	secondPlayer.spawn(510, 610);

	// Create and spawn the ball (-3 seems like a good initial speed!)
	Ball theBall;
	theBall.spawn(-3);

	// Player 2 A.I. is turned on by default
	bool AImode = true;

	// This is the game's run loop. It is executed several times per second.
	while(1) {

		// Look for new Wii controllers
		WPAD_ScanPads();

		// Handle controller events

		// Quit the game (break out of the runloop) if HOME is pressed
		if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_HOME)
			break;

		// Player 1 Controls
		if(WPAD_ButtonsHeld(WPAD_CHAN_0)&WPAD_BUTTON_DOWN)
			firstPlayer.pushDown();
		if(WPAD_ButtonsHeld(WPAD_CHAN_0)&WPAD_BUTTON_UP)
			firstPlayer.pushUp();
		if(WPAD_ButtonsHeld(WPAD_CHAN_0)&WPAD_BUTTON_LEFT)
			firstPlayer.pushLeft();
		if(WPAD_ButtonsHeld(WPAD_CHAN_0)&WPAD_BUTTON_RIGHT)
			firstPlayer.pushRight();

		// Player 2 Controls
		if(WPAD_ButtonsDown(WPAD_CHAN_1)&WPAD_BUTTON_PLUS)
			AImode = !AImode;
		// If AI is enabled, control Player 2 using the following code.
		if ( AImode ) {
			// Player 2 AI
			if (theBall.getYcoord()+10 < secondPlayer.getYcoord()+32)
				secondPlayer.pushUp();
			else if (theBall.getYcoord()+10 > secondPlayer.getYcoord()+32)
				secondPlayer.pushDown();
		}
		// If AI is disabled, let the Wii remote control Player 2.
		else {
			if(WPAD_ButtonsHeld(WPAD_CHAN_1)&WPAD_BUTTON_DOWN)
				secondPlayer.pushDown();
			if(WPAD_ButtonsHeld(WPAD_CHAN_1)&WPAD_BUTTON_UP)
				secondPlayer.pushUp();
			if(WPAD_ButtonsHeld(WPAD_CHAN_1)&WPAD_BUTTON_LEFT)
				secondPlayer.pushLeft();
			if(WPAD_ButtonsHeld(WPAD_CHAN_1)&WPAD_BUTTON_RIGHT)
				secondPlayer.pushRight();
		}

		// Handle all the game objects

		net.Draw();					// Draw the net
		firstScoreBox.Draw();		// Draw the first score box
		secondScoreBox.Draw();		// Draw the second score box

		// Draw the ball, then react if it bounced off the side of the screen.
		switch (theBall.Draw()) {

			// If the ball hit the left side of the screen...
			case -1:
				// Player 1 has failed
				if (secondScoreBox.incrementScore() == false) return 0;
				theBall.spawn(-3);	// Reset ball going left
				firstPlayer.spawn(0, 100);
				break;

			// If the ball hit the right side of the screen...
			case +1:
				// Player 2 has failed
				if (firstScoreBox.incrementScore() == false) return 0;
				theBall.spawn(3);	// Reset ball going rightward
				secondPlayer.spawn(510, 610);
				break;

			// If neither of the above cases happened...
			default:
				// Nobody failed! :)
				break;
		}

		firstPlayer.Draw();		// Draw Player 1
		secondPlayer.Draw();	// Draw Player 2

		// Tell the ball where each player is, so that it can react
		// to them if they are touching.
		theBall.deflectFromPlayer(&firstPlayer);
		theBall.deflectFromPlayer(&secondPlayer);

		// Draw the buffer to the screen and reset it.
		gwd.Flush();

		// Increase our count of how many frames have been drawn.
		g_ticks++;
	}
	
	// The program has finished, so we return to the loader.
	return 0;
}
Example #2
0
    int main(int argc, char **argv){

	
	fatInitDefault();//Initialize the front SD for loading images
	
	// Create the game window and initalise the VIDEO subsystem
	gwd.InitVideo();
	
	WPAD_Init(); //Initialize the Wiimote
	
	MP3Player_Init(); //Initialze the MP3 Player
	
	WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);//Allows us to use the Wiimote pointer
	
	WPAD_SetPowerButtonCallback(doPadPowerOff);//Set up power button
	
    iball->LoadImage("/apps/Wiibreaker/data/ball.png");
	ibrick->LoadImage("/apps/Wiibreaker/data/brick.png");
	ibrick2->LoadImage("/apps/Wiibreaker/data/black.png");
	ibrick3->LoadImage("/apps/Wiibreaker/data/blue.png");
	ibrick4->LoadImage("/apps/Wiibreaker/data/gray.png");
	ibrick5->LoadImage("/apps/Wiibreaker/data/green.png");
	ibrick6->LoadImage("/apps/Wiibreaker/data/orange.png");
	ibrick7->LoadImage("/apps/Wiibreaker/data/red.png");
	ipaddle->LoadImage("/apps/Wiibreaker/data/paddle.png");
	background1->LoadImage("/apps/Wiibreaker/data/background1.png");
	background2->LoadImage("/apps/Wiibreaker/data/background2.png");
	background3->LoadImage("/apps/Wiibreaker/data/background3.png");
	pointer->LoadImage("/apps/Wiibreaker/data/pointer.png");
	
	shutdown = false;
	
	for(int i = 0; i < 30; i++){
	brick[i] = new Sprite();
	}
	
	ball->SetImage(iball);
	paddle->SetImage(ipaddle);
	Pointer->SetImage(pointer);
	
	LoadHighscores();
	
	while(true){
	
	firsthit = false;
	rows = 0;
	reset = 1;
	Menu();
	
	score = 0;
	lives = 3;
	helpescape = 0;
	
	if(quit == 1)
	break;
	
	ballx = 320 - (ball->GetWidth()/2);
	bally = 300;
	holdball = 0;
	
	balldir = rand() % 2 + 1;
	
	if(controlscheme == 0 || controlscheme == 2)
	paddle->SetRotation(0);
	
	if(controlscheme == 0 || controlscheme == 2)
	paddlex = 320 - (paddle->GetWidth()/2);
	
	if(controlscheme == 0 || controlscheme == 2)
	paddley = 400;
	
	if(controlscheme == 1)
	paddle->SetPosition(0, 0);
	
	wait = 0;
	
	if(mode == 3)
	leveleditor();

	for(;;)
	{
		WPAD_ScanPads();
		
		Background->Draw();
		
		if(reset == 1 && wait == 0){
		bricksetup();
		resetb();
		}
		
		for(int i = 0; i < 30; i++){
	    if(alive[i] == true){
		brick[i]->SetPosition(brickx[i], bricky[i]);
		brick[i]->Draw();
		}
	    }
		
		updateball();
		
		ball->SetPosition(ballx, bally);
		ball->Draw();
		
		//Get Controller Input
		if(controlscheme == 0){
		
        WPAD_Expansion(WPAD_CHAN_0, &exp);
        exp.type = WPAD_EXP_NUNCHUK;
		
		//Get rid of controller interference
		WPADData* data = WPAD_Data(WPAD_CHAN_0);
	    switch (data->exp.type) {
		
		case WPAD_EXP_NUNCHUK:
		    if(WPAD_ButtonsHeld(WPAD_CHAN_0)&WPAD_NUNCHUK_BUTTON_C)
			paddlex -= 8;
			if(WPAD_ButtonsHeld(WPAD_CHAN_0)&WPAD_NUNCHUK_BUTTON_Z)
			paddlex += 8;
			break;
			
		case WPAD_EXP_CLASSIC:
			if(WPAD_ButtonsHeld(WPAD_CHAN_0)&WPAD_CLASSIC_BUTTON_LEFT)
			paddlex -= 8;
			if(WPAD_ButtonsHeld(WPAD_CHAN_0)&WPAD_CLASSIC_BUTTON_RIGHT)
			paddlex += 8;
			break;
	    }
		
		if((WPAD_ButtonsHeld(WPAD_CHAN_0)&WPAD_BUTTON_LEFT)||(WPAD_ButtonsHeld(WPAD_CHAN_0)&WPAD_BUTTON_UP) || ((exp.nunchuk.js.ang>=270-45 && exp.nunchuk.js.ang<=270+45) && exp.nunchuk.js.mag>=0.9))
		paddlex -= 8;
		
		if((WPAD_ButtonsHeld(WPAD_CHAN_0)&WPAD_BUTTON_RIGHT)||(WPAD_ButtonsHeld(WPAD_CHAN_0)&WPAD_BUTTON_DOWN) || ((exp.nunchuk.js.ang>=90-45 && exp.nunchuk.js.ang<=90+45) && exp.nunchuk.js.mag>=0.9))
		paddlex += 8;
		
		if(paddlex < 0)
		paddlex = 0;
		
		if(paddlex + paddle->GetWidth() > 640)
		paddlex = 640 - paddle->GetWidth();
		
		paddle->SetPosition(paddlex, paddley);
		
		}
		
		if(controlscheme == 1){
		
		// Infrared calculation - The X and Y of the wiimote sprite
        ir_t ir; // The struct for infrared
	    WPAD_IR(WPAD_CHAN_0, &ir); // Let's get our infrared data
	    // Give our sprite the positions and the angle.
	    paddle->SetPosition(ir.sx-WSP_POINTER_CORRECTION_X, ir.sy-WSP_POINTER_CORRECTION_Y); // We use these constants to translate the position correctly to the screen
	    paddle->Move(-((f32)paddle->GetWidth()/2), -((f32)paddle->GetHeight()/2)); // And these to make our image appear at the center of this position.
	    paddle->SetRotation(ir.angle/2); // Set angle/2 to translate correctly
		
		}
		
		if(controlscheme == 2){
		
		if(wait == 0){

        WPAD_Expansion(WPAD_BALANCE_BOARD, &exp2);//Get data from the attached expansion (the balance board in this case)
		exp2.type = WPAD_EXP_WIIBOARD;
		
		x = exp2.wb.x;
		
		//Left Movements
		
		if(x < -4)//-4
		paddlex -= 4;
		
		if(x < -8)//-7
		paddlex -= 5;
		
		if(x < -13)//-9
		paddlex -= 6;
		
		if(x < -15)//-11
		paddlex -= 7;
		
		if(x < -18)//-13
		paddlex -= 8;
		
		//Right Movements
		
		if(x > 4)
		paddlex += 4;
		
		if(x > 8)
		paddlex += 5;
		
		if(x > 13)
		paddlex += 6;
		
		if(x > 15)
		paddlex += 7;
		
		if(x > 18)
		paddlex += 8;
	
		
		if(paddlex < 0)
		paddlex = 0;
		
		if(paddlex + paddle->GetWidth() > 640)
		paddlex = 640 - paddle->GetWidth();
		
		}
		
		paddle->SetPosition(paddlex, paddley);
		
		}
		
		if((WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_PLUS) || (WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_CLASSIC_BUTTON_PLUS))
		pausegame();
		
		paddle->Draw();
		
		if((WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_HOME) || (WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_CLASSIC_BUTTON_HOME))
		break;	
		
		if(shutdown == true)
		SYS_ResetSystem( SYS_POWEROFF, 0, 0 );
		
		if(rumblecounter == 7){
		WPAD_Rumble(WPAD_CHAN_0, 0);
		rumblecounter = 0;
		}
		
		if(rumblecounter != 0)
		rumblecounter++;
		
		if(controlscheme == 2)
		wait++;
		
		if(wait > 1)
		wait = 0;
		
		gwd.Flush();
		
		checkforreset();
		
		if(lives <= 0)
		break;
		
		if(holdball < 15)
		holdball++;
		
		if(sound && !MP3Player_IsPlaying()){
			
		MP3Player_Stop();
		
		if(sound == 1){
		  MP3Player_PlayBuffer(Peter_de_Man___Lightwaves_d090128_mp3, Peter_de_Man___Lightwaves_d090128_mp3_size, NULL);
		 }
		 
		 if(sound == 2){
		  MP3Player_PlayBuffer(Peter_de_Man___Cyborgs_Trip_d090128_mp3, Peter_de_Man___Cyborgs_Trip_d090128_mp3_size, NULL);
		 }

}
		
	}
	
	WPAD_Rumble(WPAD_CHAN_0, 0);
	
	switch(mode){
	case 1:
	switch(controlscheme){
	case 0:
	if(score > scores[0])
	scores[0] = score;
	break;
	
	case 1:
	if(score > scores[1])
	scores[1] = score;
	break;
	
	case 2:
	if(score > scores[2])
	scores[2] = score;
	break;
	}
	break;
	case 2:
	switch(controlscheme){
	case 0:
	if(score > scores[3])
	scores[3] = score;
	break;
	
	case 1:
	if(score > scores[4])
	scores[4] = score;
	break;
	
	case 2:
	if(score > scores[5])
	scores[5] = score;
	break;
	}
	break;
	}
	SaveHighscores();
   }
	return 0;
}