Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //\====================================================================================
- //\ Author: Declan.corcoran
- //\ Date : 19 March 2012
- //\ About : main.cpp - Defines the entry point for our Simple SDL Project
- //\====================================================================================
- #include <Windows.h>
- #include "GL_Functions.h"
- #include "pctimer.h"
- #include <string>
- #include <cmath>
- #include <crtdbg.h>
- int main(int argc, char* argv[])
- {
- //Lets open the window and initialise opengl
- InitGL(1024,768);
- //Loads an Image,
- int ball = LoadTexture("./images/ball.png");
- int background = LoadTexture("./images/background.png");
- int leftpaddle = LoadTexture("./images/leftpaddle.png");
- int rightpaddle = LoadTexture("./images/rightpaddle.png");
- float Ball = 1;
- float ballx = 450;
- float bally = 350;
- float ballspeedx = 2;
- float ballspeedy = 3;
- float Background = 1;
- float backgroundx = 0;
- float backgroundy = 0;
- float Rightpaddle = 1;
- float rightpaddlex = 990;
- float rightpaddley = 20;
- float Leftpaddle = 1;
- float leftpaddlex = 15;
- float leftpaddley = 450;
- float paddle_width = 2;
- float paddle_length = 10;
- float ball_width = 2.5;
- float ball_length = 2.5;
- do
- {
- //Clear the screen, so previous frames don't build up
- ClearScreen();
- ballx = ballx + ballspeedx;
- bally = bally + ballspeedy;
- DrawSprite(background, backgroundx, backgroundy, 1024, 768);
- DrawLine(512,0,512,768);
- DrawSprite(ball, ballx, bally, 40, 40);
- DrawSprite(leftpaddle, leftpaddlex, leftpaddley, 20, 100);
- DrawSprite(rightpaddle, rightpaddlex, rightpaddley, 20, 100);
- // ball speed/control
- //
- if (ballx > 984)
- {
- ballx = 492;
- bally = 384;
- ballspeedx *= -1;
- }
- if ( ballx < 0)
- {
- ballx = 492;
- bally = 384;
- ballspeedx *= -1;
- }
- if (bally > 1024 || bally < 0)
- ballspeedy *= -.5;
- //paddle controlls
- // player one's controls ( 'w' and 's')
- // player two's controls ( 'up' and 'down')
- if (IsKeyDown(KEY_UP))
- {
- rightpaddley = rightpaddley -5;
- if( rightpaddley < 0 )
- {
- rightpaddley = 0;
- }
- }
- if (IsKeyDown(KEY_DOWN) && rightpaddley < 668)
- rightpaddley = rightpaddley +5;
- if (IsKeyDown('w') && leftpaddley > 0)
- leftpaddley = leftpaddley -5;
- if (IsKeyDown('s') && leftpaddley < 668)
- leftpaddley = leftpaddley +5;
- // closes program down atfer user presses escape!
- if (IsKeyDown(KEY_ESCAPE))
- CloseDown();
- //Stop it from running too fast! Sleep ZZzzz
- Sleep(5);
- } while (FrameworkUpdate()); //Do some secret stuff,
- //Before you exit, clean up after yourself
- FreeTexture(ball);
- FreeTexture(background);
- FreeTexture(leftpaddle);
- FreeTexture(rightpaddle);
- //Close down
- CloseDown();
- _CrtDumpMemoryLeaks();
- //Quit!
- return 0;
- }
- have fun =D
Advertisement
Add Comment
Please, Sign In to add comment