Exemplo n.º 1
0
int main()
{	
	if (!glfwInit())
	{
		std::cout << "GLFW failed to initialize!\n";
	}
	glfwOpenWindow(Width,Height,0,0,0,0,32,0,GLFW_WINDOW);
	if (glewInit() != GLEW_OK)
	{
		std::cout << "GLEW failed to initialize!\n";
	}
	glfwSetWindowTitle("PongOut");
	glViewport(0,0,Width, Height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,0,0,0,0,100);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glClearColor(1,0,0,1);
	
	glfwSwapInterval (0);
	
	//Camera.CameraInit(45.0f , Width , Height , Model);   use ortho instead \/
	Camera.CameraInit (Width, Height, glm::mat4 (1.0f));
	
	GLuint vao;
	glGenVertexArrays (1 , &vao);
	glBindVertexArray(vao);
	
	Ball ball;
	ball.Init();
	
	float LastTime = glfwGetTime(); // (for deltatime)
	
	while (true)
	{
		float DeltaTime = glfwGetTime() - LastTime; // Deltatime init
		LastTime = glfwGetTime(); // update for deltatime
	
		glClearColor (0.0f , 0.0f , 0.0f , 1.0f);
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			
		ball.Draw();
		
		std::cout << glGetError() << std::flush; // 1281?
		
		glfwSwapBuffers();

		if (glfwGetKey (GLFW_KEY_ESC) || !glfwGetWindowParam(GLFW_OPENED))
		{
			std::cout << "\nShutdown command. Exiting...\n" << std::flush;
			return 0;
		}
		
		
	}
}
Exemplo n.º 2
0
void Render(Paddle p1, Paddle p2, Ball b, GLuint wins){
	glClear(GL_COLOR_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);


	p1.Draw();
	p2.Draw();
	b.Draw();

	if (b.x + b.size < p1.x - p1.w){
		DrawSprite(wins, 1.1, 0.8, 0.1, 0.08, 0);
	}
	else if (b.x - b.size > p2.x + p2.w){
		DrawSprite(wins, -1.1, 0.8, 0.1, 0.08, 0);
	}
}
Exemplo n.º 3
0
int main(int argc, char* argv[])
{
	Initialise(SCREEN_WIDTH, SCREEN_HEIGHT, false, "pong");

	Ball joe;
	joe.postionX = (float)(SCREEN_WIDTH / 2);
	joe.postionY = (float)(SCREEN_HEIGHT / 2);
	joe.speedX = 5.0f;
	joe.speedY = -1.0f;
	joe.width = 30;
	joe.height = 30;
	
	joe.spriteID = CreateSprite("./images/ball.png", joe.width,joe.height, true);

	Padle may;
	may.postionX = 20.0f;
	may.postionY = 300.0f;
	may.speedX = 2.0f;
	may.speedY = 2.0f;
	may.width = 20;
	may.height = 30;
	may.spriteID = CreateSprite("./images/padle.png", may.width, may.height, true);


	SetBackgroundColour(SColour(14, 0, 24, 8));



	//GameLoop...
	do
	{
		float DeltaTime = GetDeltaTime();
		may.Move(DeltaTime);

		ClearScreen();
		joe.Move(GetDeltaTime() * 100);
		joe.Draw();
		may.Move(GetDeltaTime() * 100);
		may.Draw();


	} while (!FrameworkUpdate());

	Shutdown();

	return 0;
}
Exemplo n.º 4
0
/**************************************************************************//**
* @author Paul Blasi, Caitlin Taggart
*
* @par Description:
* The display callback. Draws each of the objects and displays score for each
* player. If the game is currently paused, it also draws a translucent box
* over the play area and the text "Paused".
*
*****************************************************************************/
void Display(void) 
{
	int length;
	
	glClear(GL_COLOR_BUFFER_BIT);
    
    BALL.Draw();
    LEFT_PLAYER.Draw();
    RIGHT_PLAYER.Draw();
    LEFT_WALL.Draw();
    RIGHT_WALL.Draw();
    TOP_WALL.Draw();
    BOTTOM_WALL.Draw();
    NET.Draw();

	string right_score = to_string(RIGHT_PLAYER.Score);
	string left_score = to_string(LEFT_PLAYER.Score);


	glColor4fv(WHITE);

	length = glutBitmapLength(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)left_score.c_str());
	glRasterPos2i(50 - (200.0 / SCREEN_WIDTH * length / 2.0), 90);
	glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)left_score.c_str());

	length = glutBitmapLength(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)right_score.c_str());
	glRasterPos2i(150 - (200.0 / SCREEN_WIDTH * length / 2.0), 90);
	glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)right_score.c_str());

    if (PAUSED)
    {
		float alphaBlack[4] = { 0.0, 0.0, 0.0, .60 };
		Paddle temp;
		temp = Paddle(Point(100, 50), 200, 100, alphaBlack);
		temp.Draw();

		glColor4fv(WHITE);
		length = glutBitmapLength(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)"PAUSED");
		glRasterPos2i(100 - (200.0/SCREEN_WIDTH * length / 2.0), 50);
		glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)"PAUSED");
    }	

    //glFlush();
    glutSwapBuffers();
}
Exemplo n.º 5
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;
}