Advertisement
thecplusplusguy

Simple sidescroller game - game.h

Jul 14th, 2011
2,125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 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 game.h it's a class, which put everything other together to one program
  6. #include <iostream> //for write out things
  7. #include <fstream>  //to read the map from file (and you could write error messages to file)
  8. #include <vector>       //for the map
  9. #include <SDL/SDL.h>//for SDL
  10. #include <SDL/SDL_ttf.h>    //for the menu and showmessage function
  11. #include "base.h"   //we include our own header files
  12. #include "player.h"
  13. #include "bullet.h"
  14. #include "enemy.h"
  15. #ifndef GAME_H  //avoid multiple inclusion
  16. #define GAME_H
  17. class game:public baseclass{    //we inherit it from baseclass, because of the collision funtion
  18.     SDL_Surface* screen,*background,*block,*bul,*ene;   //images and screen
  19.     SDL_Rect camera;    //for the scrolling background (the current position of the background)
  20.     std::vector<std::vector<int> > map; //a multidimensional dynamically allocated vector for the map
  21.     std::vector<bullet*> bullets;               //a dynamically allocated vector for the bullets (which will contain address of dynamically allocated bullets)
  22.     std::vector<enemy*> enemies;                //vector for the enemies (which will contain address of dynamically allocated enemies)
  23.     bool direction[2];                                  //what key are we pressing?
  24.     TTF_Font* font;                                         //the font
  25.     SDL_Rect finish;                                        //the finish coordinates
  26.     //obvious
  27.     SDL_Surface* load_image(const char* filename); 
  28.     void loadmap(const char* filename);                        
  29.     void showmap();                                                                
  30.     void handleEvents();                           
  31.     bool running;   //is the program running?
  32.     static const int SCREEN_WIDTH=640;  //few const
  33.     static const int SCREEN_HEIGHT=480;
  34.     player* player1;    //Pointer to a dynamically allocated player
  35.     int showmenu(SDL_Surface*);
  36.     void showmessage(const char* c);
  37.     public:
  38.     game();
  39.     ~game();
  40.     void start();
  41. };
  42. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement