This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
user:ccornair:portfolio:sysprogproject1 [2013/05/07 02:59] – [Background] ccornair | user:ccornair:portfolio:sysprogproject1 [2013/05/07 03:15] (current) – [Reflection] ccornair | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======Project: | ||
+ | |||
+ | |||
+ | =====Objectives===== | ||
+ | the purpose is to learn the SDL libraries and build a pong game | ||
+ | =====Prerequisites===== | ||
+ | In order to successfully accomplish/ | ||
+ | |||
+ | install SDL libraries | ||
+ | |||
+ | |||
+ | =====Scope===== | ||
+ | I feel that this project will be tough and hope I am able to complete it by the end of the semester | ||
+ | |||
+ | =====procedure===== | ||
+ | |||
+ | I have commented my procedure in the code itself, see code section, I hope that was ok to do | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | =====Code===== | ||
+ | Upon completion of the project, if there is an applicable collection of created code, place a copy of your finished code within < | ||
+ | |||
+ | <code c> | ||
+ | |||
+ | |||
+ | //The headers | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | |||
+ | |||
+ | //The screen attributes | ||
+ | const int SCREEN_WIDTH = 640; | ||
+ | const int SCREEN_HEIGHT = 480; | ||
+ | const int SCREEN_BPP = 32; | ||
+ | |||
+ | //The frame rate | ||
+ | const int FRAMES_PER_SECOND = 20; | ||
+ | |||
+ | //The dimensions of the ball | ||
+ | const int BALL_WIDTH = 35; | ||
+ | const int BALL_HEIGHT = 35; | ||
+ | |||
+ | //The dimensions of the paddles | ||
+ | const int PADDLE_WIDTH = 15; | ||
+ | const int PADDLE_HEIGHT = 85; | ||
+ | |||
+ | //The surfaces | ||
+ | SDL_Surface *ball = NULL; | ||
+ | SDL_Surface *background = NULL; | ||
+ | SDL_Surface *screen = NULL; | ||
+ | SDL_Surface *paddleL = NULL; | ||
+ | SDL_Surface *paddleR = NULL; | ||
+ | |||
+ | //The event structure | ||
+ | SDL_Event event; | ||
+ | |||
+ | //The font | ||
+ | TTF_Font *font = NULL; | ||
+ | |||
+ | //The color of the font | ||
+ | SDL_Color textColor = { 255, 255, 255 }; | ||
+ | |||
+ | //The left paddle that will move | ||
+ | class PaddleL | ||
+ | { | ||
+ | private: | ||
+ | | ||
+ | //The velocity of left paddle | ||
+ | int xVel, yVel; | ||
+ | | ||
+ | public: | ||
+ | // | ||
+ | PaddleL(); | ||
+ | SDL_Rect boxL; | ||
+ | //Takes key presses and adjusts left paddle' | ||
+ | void handle_input(); | ||
+ | | ||
+ | //Moves left paddle | ||
+ | void move(); | ||
+ | | ||
+ | //Shows left paddle on the screen | ||
+ | void show(); | ||
+ | }; | ||
+ | |||
+ | //The right paddle that will move | ||
+ | class PaddleR | ||
+ | { | ||
+ | private: | ||
+ | | ||
+ | //The velocity of right paddle | ||
+ | int xVel, yVel; | ||
+ | | ||
+ | public: | ||
+ | | ||
+ | // | ||
+ | PaddleR(); | ||
+ | SDL_Rect boxR; | ||
+ | //Takes key presses and adjusts right paddle' | ||
+ | void handle_input(); | ||
+ | | ||
+ | //Moves right paddle | ||
+ | void move(); | ||
+ | | ||
+ | //Shows right paddle on the screen | ||
+ | void show(); | ||
+ | }; | ||
+ | |||
+ | //The ball that will move around the screen | ||
+ | class Ball | ||
+ | { | ||
+ | public: | ||
+ | // | ||
+ | Ball(); | ||
+ | SDL_Rect collbox; | ||
+ | int xVel, yVel; | ||
+ | | ||
+ | //Resets ball to center of screen | ||
+ | void reset(); | ||
+ | | ||
+ | //Takes key presses and adjusts the ball's velocity | ||
+ | void handle_input(); | ||
+ | | ||
+ | //Moves the ball | ||
+ | void move(); | ||
+ | | ||
+ | //Shows the ball on the screen | ||
+ | void show(); | ||
+ | }; | ||
+ | |||
+ | //The timer | ||
+ | class Timer | ||
+ | { | ||
+ | private: | ||
+ | //The clock time when the timer started | ||
+ | int startTicks; | ||
+ | | ||
+ | //The ticks stored when the timer was paused | ||
+ | int pausedTicks; | ||
+ | | ||
+ | //The timer status | ||
+ | bool paused; | ||
+ | bool started; | ||
+ | | ||
+ | public: | ||
+ | // | ||
+ | Timer(); | ||
+ | | ||
+ | //The various clock actions | ||
+ | void start(); | ||
+ | void stop(); | ||
+ | void pause(); | ||
+ | void unpause(); | ||
+ | | ||
+ | //Gets the timer' | ||
+ | int get_ticks(); | ||
+ | | ||
+ | //Checks the status of the timer | ||
+ | bool is_started(); | ||
+ | bool is_paused(); | ||
+ | }; | ||
+ | |||
+ | SDL_Surface *load_image( std::string filename ) | ||
+ | { | ||
+ | //The image that's loaded | ||
+ | SDL_Surface* loadedImage = NULL; | ||
+ | | ||
+ | //The optimized surface that will be used | ||
+ | SDL_Surface* optimizedImage = NULL; | ||
+ | | ||
+ | //Load the image | ||
+ | loadedImage = IMG_Load(filename.c_str()); | ||
+ | | ||
+ | //If the image loaded | ||
+ | if(loadedImage != NULL) | ||
+ | { | ||
+ | //Create an optimized surface | ||
+ | optimizedImage = SDL_DisplayFormat(loadedImage); | ||
+ | | ||
+ | //Free the old surface | ||
+ | SDL_FreeSurface(loadedImage); | ||
+ | | ||
+ | //If the surface was optimized | ||
+ | if(optimizedImage != NULL) | ||
+ | { | ||
+ | //Map the color key | ||
+ | Uint32 colorkey = SDL_MapRGB( optimizedImage-> | ||
+ | | ||
+ | //Set all pixels of color R 255, G 255, B 255 (white) to be transparent | ||
+ | SDL_SetColorKey( optimizedImage, | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | //Return the optimized surface | ||
+ | return optimizedImage; | ||
+ | } | ||
+ | |||
+ | void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination, | ||
+ | { | ||
+ | //Holds offsets | ||
+ | SDL_Rect offset; | ||
+ | | ||
+ | //Get offsets | ||
+ | offset.x = x; | ||
+ | offset.y = y; | ||
+ | | ||
+ | //Blit | ||
+ | SDL_BlitSurface(source, | ||
+ | } | ||
+ | |||
+ | bool check_collision( SDL_Rect A, SDL_Rect B) | ||
+ | { | ||
+ | //The sides of the rectangles | ||
+ | int leftA, leftB; | ||
+ | int rightA, rightB; | ||
+ | int topA, topB; | ||
+ | int bottomA, bottomB; | ||
+ | | ||
+ | //Calculate the sides of rect A and rect B | ||
+ | leftA = A.x; | ||
+ | rightA = A.x + A.w; | ||
+ | topA = A.y; | ||
+ | bottomA = A.y + A.h; | ||
+ | | ||
+ | leftB = B.x; | ||
+ | rightB = B.x + B.w; | ||
+ | topB = B.y; | ||
+ | bottomB = B.y + B.h; | ||
+ | | ||
+ | //If any of the sides from A are outside of B | ||
+ | if( bottomA <= topB) | ||
+ | { | ||
+ | return false; | ||
+ | } | ||
+ | | ||
+ | if( topA >= bottomB ) | ||
+ | { | ||
+ | return false; | ||
+ | } | ||
+ | |||
+ | if( rightA< | ||
+ | { | ||
+ | return false; | ||
+ | } | ||
+ | | ||
+ | if( leftA> | ||
+ | { | ||
+ | return false; | ||
+ | } | ||
+ | | ||
+ | //If none of the sides from A are outside B | ||
+ | return true; | ||
+ | } | ||
+ | |||
+ | bool init() | ||
+ | { | ||
+ | // | ||
+ | if(SDL_Init( SDL_INIT_EVERYTHING ) == -1) | ||
+ | { | ||
+ | return false; | ||
+ | } | ||
+ | | ||
+ | //Set up the screen | ||
+ | screen = SDL_SetVideoMode(SCREEN_WIDTH, | ||
+ | | ||
+ | //If there was an error in setting up the screen | ||
+ | if(screen == NULL) | ||
+ | { | ||
+ | return false; | ||
+ | } | ||
+ | | ||
+ | // | ||
+ | if( TTF_Init() == -1 ) | ||
+ | { | ||
+ | return false; | ||
+ | } | ||
+ | | ||
+ | //Set the window caption | ||
+ | SDL_WM_SetCaption(" | ||
+ | | ||
+ | //If everything initialized fine | ||
+ | return true; | ||
+ | } | ||
+ | |||
+ | bool load_files() | ||
+ | { | ||
+ | //Load the images | ||
+ | ball = load_image(" | ||
+ | background = load_image(" | ||
+ | paddleL = load_image(" | ||
+ | paddleR = load_image(" | ||
+ | | ||
+ | //Open the font | ||
+ | font = TTF_OpenFont(" | ||
+ | | ||
+ | //If there was a problem in loading the font | ||
+ | if(font == NULL) | ||
+ | { | ||
+ | return false; | ||
+ | } | ||
+ | | ||
+ | //If there was a problem loading the ball | ||
+ | if(ball == NULL) | ||
+ | { | ||
+ | return false; | ||
+ | } | ||
+ | | ||
+ | //If there was a problem in loading the background | ||
+ | if(background == NULL) | ||
+ | { | ||
+ | return false; | ||
+ | } | ||
+ | | ||
+ | //If there was a problem in loading a paddle | ||
+ | if(paddleL == NULL || paddleR == NULL) | ||
+ | { | ||
+ | return false; | ||
+ | } | ||
+ | | ||
+ | //If everything loaded fine | ||
+ | return true; | ||
+ | } | ||
+ | |||
+ | void clean_up() | ||
+ | { | ||
+ | //Free the surfaces | ||
+ | SDL_FreeSurface(ball); | ||
+ | SDL_FreeSurface(background); | ||
+ | SDL_FreeSurface(paddleL); | ||
+ | SDL_FreeSurface(paddleR); | ||
+ | | ||
+ | //Close the font | ||
+ | TTF_CloseFont(font); | ||
+ | | ||
+ | //Quit SDL_ttf | ||
+ | TTF_Quit(); | ||
+ | | ||
+ | //Quit SDL | ||
+ | SDL_Quit(); | ||
+ | } | ||
+ | |||
+ | PaddleL:: | ||
+ | { | ||
+ | // | ||
+ | boxL.x = 0; | ||
+ | boxL.y = SCREEN_HEIGHT/ | ||
+ | | ||
+ | //Set the collision box's dimensions | ||
+ | boxL.w = PADDLE_WIDTH; | ||
+ | boxL.h = PADDLE_HEIGHT; | ||
+ | | ||
+ | // | ||
+ | xVel = 0; | ||
+ | yVel = 0; | ||
+ | } | ||
+ | |||
+ | PaddleR:: | ||
+ | { | ||
+ | // | ||
+ | boxR.x = 625; | ||
+ | boxR.y = SCREEN_HEIGHT/ | ||
+ | | ||
+ | //Set the collision box's dimensions | ||
+ | boxR.w = PADDLE_WIDTH; | ||
+ | boxR.h = PADDLE_HEIGHT; | ||
+ | | ||
+ | // | ||
+ | xVel = 0; | ||
+ | yVel = 0; | ||
+ | } | ||
+ | |||
+ | void PaddleL:: | ||
+ | { | ||
+ | //If a key was pressed | ||
+ | if( event.type == SDL_KEYDOWN ) | ||
+ | { | ||
+ | //Adjust the velocity | ||
+ | switch( event.key.keysym.sym ) | ||
+ | { | ||
+ | case SDLK_a: yVel -= PADDLE_HEIGHT/ | ||
+ | case SDLK_z: yVel += PADDLE_HEIGHT/ | ||
+ | } | ||
+ | } | ||
+ | //If a key was released | ||
+ | else if( event.type == SDL_KEYUP ) | ||
+ | { | ||
+ | //Adjust the velocity | ||
+ | switch( event.key.keysym.sym ) | ||
+ | { | ||
+ | case SDLK_a: yVel += PADDLE_HEIGHT/ | ||
+ | case SDLK_z: yVel -= PADDLE_HEIGHT/ | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void PaddleR:: | ||
+ | { | ||
+ | //If a key was pressed | ||
+ | if( event.type == SDL_KEYDOWN ) | ||
+ | { | ||
+ | //Adjust the velocity | ||
+ | switch( event.key.keysym.sym ) | ||
+ | { | ||
+ | case SDLK_UP: yVel -= PADDLE_HEIGHT/ | ||
+ | case SDLK_DOWN: yVel += PADDLE_HEIGHT/ | ||
+ | } | ||
+ | } | ||
+ | //If a key was released | ||
+ | else if( event.type == SDL_KEYUP ) | ||
+ | { | ||
+ | //Adjust the velocity | ||
+ | switch( event.key.keysym.sym ) | ||
+ | { | ||
+ | case SDLK_UP: yVel += PADDLE_HEIGHT/ | ||
+ | case SDLK_DOWN: yVel -= PADDLE_HEIGHT/ | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void PaddleL:: | ||
+ | { | ||
+ | //Move the paddle up or down | ||
+ | boxL.y += 2*yVel; | ||
+ | | ||
+ | //If the paddle went to far up or down | ||
+ | if( (boxL.y< | ||
+ | { | ||
+ | //Move back | ||
+ | boxL.y -= 2*yVel; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void PaddleR:: | ||
+ | { | ||
+ | //Move the paddle up or down | ||
+ | boxR.y += 2*yVel; | ||
+ | | ||
+ | //If the paddle went to far up or down | ||
+ | if( (boxR.y< | ||
+ | { | ||
+ | //Move back | ||
+ | boxR.y -= 2*yVel; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void PaddleL:: | ||
+ | { | ||
+ | //Show the Paddle | ||
+ | apply_surface(boxL.x, | ||
+ | } | ||
+ | |||
+ | void PaddleR:: | ||
+ | { | ||
+ | //Show the Paddle | ||
+ | apply_surface(boxR.x, | ||
+ | } | ||
+ | |||
+ | Ball:: | ||
+ | { | ||
+ | // | ||
+ | collbox.x = SCREEN_WIDTH/ | ||
+ | collbox.y = SCREEN_HEIGHT/ | ||
+ | | ||
+ | //Set the square' | ||
+ | collbox.w = BALL_WIDTH - 5; | ||
+ | collbox.h = BALL_HEIGHT - 5; | ||
+ | | ||
+ | // | ||
+ | xVel = 0; | ||
+ | yVel = 0; | ||
+ | } | ||
+ | |||
+ | void Ball:: | ||
+ | { | ||
+ | //Reset the offsets | ||
+ | collbox.x = SCREEN_WIDTH/ | ||
+ | collbox.y = SCREEN_HEIGHT/ | ||
+ | | ||
+ | //Reset the velocity | ||
+ | xVel = 0; | ||
+ | yVel = 0; | ||
+ | } | ||
+ | |||
+ | void Ball:: | ||
+ | { | ||
+ | int lORr; //To determine if the ball starts going left or right | ||
+ | | ||
+ | //If a key was pressed | ||
+ | if( event.type == SDL_KEYDOWN ) | ||
+ | { | ||
+ | //Assign random initial velocity | ||
+ | if( event.key.keysym.sym == SDLK_SPACE ) | ||
+ | { | ||
+ | lORr = rand()%2; | ||
+ | if(lORr == 0){ | ||
+ | xVel = rand()%5+10; | ||
+ | yVel = rand()%15; | ||
+ | } | ||
+ | if(lORr == 1){ | ||
+ | xVel = (rand()%5+10*-1); | ||
+ | yVel = (rand()%15)*-1; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void Ball:: | ||
+ | { | ||
+ | //Move the ball left or right | ||
+ | collbox.x += xVel; | ||
+ | | ||
+ | //Move the ball up or down | ||
+ | collbox.y += yVel; | ||
+ | | ||
+ | //If the ball went to far up or down | ||
+ | if( (collbox.y< | ||
+ | { | ||
+ | //Move back | ||
+ | yVel = -1*yVel; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void Ball:: | ||
+ | { | ||
+ | //Show the ball | ||
+ | apply_surface(collbox.x, | ||
+ | } | ||
+ | |||
+ | Timer:: | ||
+ | { | ||
+ | // | ||
+ | startTicks = 0; | ||
+ | pausedTicks = 0; | ||
+ | paused = false; | ||
+ | started = false; | ||
+ | } | ||
+ | |||
+ | void Timer:: | ||
+ | { | ||
+ | //Start the timer | ||
+ | started = true; | ||
+ | | ||
+ | //Unpause the timer | ||
+ | paused = false; | ||
+ | | ||
+ | //Get the current clock time | ||
+ | startTicks = SDL_GetTicks(); | ||
+ | } | ||
+ | |||
+ | void Timer:: | ||
+ | { | ||
+ | //Stop the timer | ||
+ | started = false; | ||
+ | | ||
+ | //Unpause the timer | ||
+ | paused = false; | ||
+ | } | ||
+ | |||
+ | void Timer:: | ||
+ | { | ||
+ | //If the timer is running and isn't already paused | ||
+ | if( (started == true) && (paused == false) ) | ||
+ | { | ||
+ | //Pause the timer | ||
+ | paused == true; | ||
+ | | ||
+ | //Calculate the paused ticks | ||
+ | pausedTicks = SDL_GetTicks() - startTicks; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void Timer:: | ||
+ | { | ||
+ | //If the timer is paused | ||
+ | if(paused == true) | ||
+ | { | ||
+ | //Unpause the timer | ||
+ | paused = false; | ||
+ | | ||
+ | //Reset the starting ticks | ||
+ | startTicks = SDL_GetTicks() - pausedTicks; | ||
+ | | ||
+ | //Reset the paused ticks | ||
+ | pausedTicks = 0; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | int Timer:: | ||
+ | { | ||
+ | //If the timer is running | ||
+ | if(started == true) | ||
+ | { | ||
+ | //If the timer is paused | ||
+ | if(paused == true) | ||
+ | { | ||
+ | //Return the number of ticks when the timer was paused | ||
+ | return pausedTicks; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | //Return the current time minus the start time | ||
+ | return SDL_GetTicks() - startTicks; | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | //If the timer isn't running | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | bool Timer:: | ||
+ | { | ||
+ | return started; | ||
+ | } | ||
+ | |||
+ | bool Timer:: | ||
+ | { | ||
+ | return paused; | ||
+ | } | ||
+ | |||
+ | int main( int argc, char* args[] ) | ||
+ | { | ||
+ | //The surface for the winning message | ||
+ | SDL_Surface *message = NULL; | ||
+ | | ||
+ | //Quit flag | ||
+ | bool quit = false; | ||
+ | | ||
+ | //The ball that will be used | ||
+ | Ball myBall; | ||
+ | | ||
+ | //The paddles that will be used | ||
+ | PaddleL paddleL; | ||
+ | PaddleR paddleR; | ||
+ | | ||
+ | //The frame rate regulator | ||
+ | Timer fps; | ||
+ | | ||
+ | // | ||
+ | if(init() == false) | ||
+ | { | ||
+ | return 1; | ||
+ | } | ||
+ | | ||
+ | //Load the files | ||
+ | if(load_files() == false) | ||
+ | { | ||
+ | return 1; | ||
+ | } | ||
+ | | ||
+ | | ||
+ | | ||
+ | //While the user hasn't quit | ||
+ | while( quit == false ) | ||
+ | { | ||
+ | //Start the frame timer | ||
+ | fps.start(); | ||
+ | | ||
+ | //While there' | ||
+ | while( SDL_PollEvent(& | ||
+ | { | ||
+ | //Handle events for the ball | ||
+ | myBall.handle_input(); | ||
+ | | ||
+ | //Handle events for the paddles | ||
+ | paddleL.handle_input(); | ||
+ | paddleR.handle_input(); | ||
+ | | ||
+ | //If the user has Xed the window | ||
+ | if (event.type == SDL_QUIT) | ||
+ | { | ||
+ | //Quit the program | ||
+ | quit = true; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | //Move the ball | ||
+ | myBall.move(); | ||
+ | |||
+ | //If the ball hits left paddle | ||
+ | if(check_collision(myBall.collbox, | ||
+ | { | ||
+ | //Bounce ball back | ||
+ | myBall.xVel = rand()%30+15; | ||
+ | //Bounce ball back | ||
+ | |||
+ | if( myBall.yVel == 0 ) { | ||
+ | myBall.yVel = 1 ; | ||
+ | } | ||
+ | | ||
+ | myBall.yVel = (myBall.yVel/ | ||
+ | |||
+ | } | ||
+ | | ||
+ | //If the ball hits right paddle | ||
+ | if((check_collision(myBall.collbox, | ||
+ | { | ||
+ | // | ||
+ | myBall.xVel = (rand()%30+15)*-1; | ||
+ | |||
+ | if( myBall.yVel == 0 ) { | ||
+ | myBall.yVel = 1 ; | ||
+ | } | ||
+ | | ||
+ | |||
+ | myBall.yVel = (myBall.yVel/ | ||
+ | |||
+ | } | ||
+ | | ||
+ | //Move the paddles | ||
+ | paddleL.move(); | ||
+ | paddleR.move(); | ||
+ | | ||
+ | //Apply the background to the screen | ||
+ | apply_surface(0, | ||
+ | | ||
+ | //Show the ball on the screen | ||
+ | myBall.show(); | ||
+ | | ||
+ | //If the ball goes off the left side of the screen | ||
+ | if( (myBall.collbox.x + BALL_WIDTH) < 0) | ||
+ | { | ||
+ | //Print a message saying left paddle wins | ||
+ | message = TTF_RenderText_Solid(font, | ||
+ | | ||
+ | //If a message needs to be displayed | ||
+ | if( message != NULL ) | ||
+ | { | ||
+ | //Apply the background to the screen | ||
+ | apply_surface( 0, 0, background, screen ); | ||
+ | |||
+ | //Apply the message centered on the screen | ||
+ | apply_surface( ( SCREEN_WIDTH - message-> | ||
+ | |||
+ | //Null the surface pointer | ||
+ | message = NULL; | ||
+ | } | ||
+ | | ||
+ | //If space bar is hit then reset the ball | ||
+ | if( event.key.keysym.sym == SDLK_SPACE ) | ||
+ | { | ||
+ | myBall.reset(); | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | //If the ball goes off the right side of the screen | ||
+ | if( myBall.collbox.x > SCREEN_WIDTH) | ||
+ | { | ||
+ | //Print a message saying left paddle wins | ||
+ | message = TTF_RenderText_Solid(font, | ||
+ | | ||
+ | //If a message needs to be displayed | ||
+ | if( message != NULL ) | ||
+ | { | ||
+ | //Apply the background to the screen | ||
+ | apply_surface( 0, 0, background, screen ); | ||
+ | |||
+ | //Apply the message centered on the screen | ||
+ | apply_surface( ( SCREEN_WIDTH - message-> | ||
+ | |||
+ | //Null the surface pointer | ||
+ | message = NULL; | ||
+ | } | ||
+ | | ||
+ | //If space bar is hit then reset the ball | ||
+ | if( event.key.keysym.sym == SDLK_SPACE ) | ||
+ | { | ||
+ | myBall.reset(); | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | //Show the paddles on the screen | ||
+ | paddleL.show(); | ||
+ | paddleR.show(); | ||
+ | | ||
+ | //Update the screen | ||
+ | if( SDL_Flip( screen ) == -1 ) | ||
+ | { | ||
+ | return 1; | ||
+ | } | ||
+ | | ||
+ | //Cap the frame rate | ||
+ | if(fps.get_ticks() < 1000 / FRAMES_PER_SECOND) | ||
+ | { | ||
+ | SDL_Delay( (1000/ FRAMES_PER_SECOND) - fps.get_ticks() ); | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | //Clean up | ||
+ | clean_up(); | ||
+ | | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | | ||
+ | </ | ||
+ | |||
+ | =====Execution===== | ||
+ | Again, if there is associated code with the project, and you haven' | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | |||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | =====Reflection===== | ||
+ | This project was really stressing and frustrating at first but after a while I really started to catch on and it was pretty fun! | ||
+ | |||
+ | =====References===== | ||
+ | In performing this project, the following resources were referenced: | ||
+ | |||
+ | * http:// | ||
+ | * http:// | ||
+ | * http:// | ||
+ | * lair help from matt and other, thanks!!! | ||
+ | |||
+ | |||