Advertisement
thecplusplusguy

Simple sidescroller game - bullet.cpp

Jul 14th, 2011
2,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. //This example program is created by thecplusplusuy for demonstration purposes. It's a simple mario like side-scroller game:
  2. //http://www.youtube.com/user/thecplusplusguy
  3. //Free source, modify if you want, LGPL licence (I guess), I would be happy, if you would not delete the link
  4. //so other people can see the tutorial
  5. //this file is bullet.cpp just a class (implementation) for a bullet.
  6. #include "bullet.h"
  7.  
  8. bullet::bullet(SDL_Surface* img,int x,int y,int xVel,int yVel)  //constructor
  9. {
  10.     //just set all of the variables, nothing new in here
  11.     box.x=x;
  12.     box.y=y;
  13.     image=img;
  14.     box.w=image->w;
  15.     box.h=image->h;
  16.     xvel=xVel;
  17.     yvel=yVel;
  18. }
  19.  
  20. void bullet::move()
  21. {
  22.     //move the bullet, we just add the velocity (speed) to the position
  23.     box.x+=xvel;
  24.     box.y+=yvel;
  25. }
  26.  
  27. void bullet::show(SDL_Surface* screen)
  28. {
  29.     //blit it to the screen
  30.     SDL_BlitSurface(image,NULL,screen,&box);
  31. }
  32.  
  33.  
  34. SDL_Rect* bullet::getRect()
  35. {
  36.     //return the address of the bound box (for collision detection)
  37.     return &box;
  38. }
  39. //that was one of the simplest class, nothing tricky.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement