thecplusplusguy

Simple pong game (SDL) - paddle.cpp

Jul 4th, 2011
1,400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. //Simple pong game - paddle.cpp
  2. //created by thecplusplusguy
  3. //     http://www.youtube.com/user/thecplusplusguy
  4. #include "paddle.h"
  5.  
  6. paddle::paddle(SDL_Surface* img,int x,int y,int w,int h,int yVel)
  7. {
  8.     box.x=x;
  9.     box.y=y;
  10.     box.w=w;
  11.     box.h=h;
  12.     image=img;
  13.     yvel=yVel;
  14.     point=0;
  15. }
  16.  
  17. paddle::~paddle()
  18. {
  19.     SDL_FreeSurface(image);
  20. }
  21.  
  22. void paddle::moveUp()
  23. {
  24.     if(box.y>0)
  25.         box.y-=yvel;
  26. }
  27.  
  28. void paddle::moveDown()
  29. {
  30.     if(box.y+box.h<SDL_GetVideoSurface()->clip_rect.h)
  31.         box.y+=yvel;
  32. }
  33.  
  34. void paddle::show()
  35. {
  36.     SDL_BlitSurface(image,NULL,SDL_GetVideoSurface(),&box);
  37. }
  38.  
  39. SDL_Rect* paddle::getRect()
  40. {
  41.     return &box;
  42. }
  43.  
  44. void paddle::incpoint()
  45. {
  46.     point++;
  47. }
  48.  
  49. void paddle::setBack(int x,int y,int w,int h,int yVel)
  50. {
  51.     box.x=x;
  52.     box.y=y;
  53.     box.w=w;
  54.     box.h=h;
  55.     yvel=yVel;
  56. }
  57.  
  58. int paddle::getPoints()
  59. {
  60.     return point;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment