i am using the sdl libary to create an air hockey game, and i wish to check when the paddle is out of bounds. the paddle is its own class, when the code is tested so when it goes it goes out of bounds. it should move several pixel's back into the screen, however this does not happen.
can anyone help?
this is the code for the paddle class
this is the game loopCode:// Paddle.cpp: implementation of the CPaddle class. // ////////////////////////////////////////////////////////////////////// #include <iostream> #include <stdlib.h> #include <stdio.h> #include <SDL/SDL.h> #include "Paddle.h" using namespace std; ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CPaddle::CPaddle() { //set paddle location m_locx = 150; m_locy = 770; //set paddle velocity m_velx = 0; m_vely = 0; } CPaddle::~CPaddle() { } //draw the images void CPaddle::drawImage(SDL_Surface *p_buffer) { SDL_Rect tempRect; tempRect.x = m_locx; tempRect.y = m_locy; //set transparency colour as pink. shown by RGB values SDL_SetColorKey(m_image, SDL_SRCCOLORKEY,SDL_MapRGB(m_image->format, 255, 0, 255)); SDL_BlitSurface(m_image, NULL, p_buffer, &tempRect); } void CPaddle::update() { // update location due to velocity m_locx += m_velx; m_locy += m_vely; // space for more update code if (m_locx == 0) m_locx = 10; else if (m_locx + 100 == 400) m_locx = 350; } void CPaddle::outofbounds() { }
player is the paddle class objectCode:while (gameloop == true) { checkInput(); drawBackdrop(); player.update(); player.drawImage(buffer); computer.drawImage(buffer); AIpuck.drawImage(buffer); SDL_Flip(buffer); player.outofbounds(); }
the out of bounds code has been moved to the update function from the out of bounds function



LinkBack URL
About LinkBacks


