Advertisement
thecplusplusguy

Mapcreator for the simple sidescroller (SDL) - mapcreator.h

Aug 7th, 2011
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. //This example program is created by thecplusplusuy for demonstration purposes (no video about this, I think, it's too simple, and not show nothing new, but I put the source up, to make a complete program with the simple sidescroller (there is video about that)). It's a map-creator for the simple sidescroller 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 mapcreator.h
  6. #include <SDL/SDL.h>    //for the 2D graphics
  7. #include <fstream>      //for write the finished map to a file
  8. #include <iostream>     //for write out error (only for test purposes, probobly, it's not need anything else)
  9. #include <vector>           //to store the map
  10. #include <cstdlib>      //for the random number generation
  11. #include <ctime>            //for seed the random number generator (it seems, that Linux is not need this header file for time(0)
  12. #include <cstring>      //and the simple C-style string handling
  13.  
  14. #ifndef MAPCREATOR_H    //we avoid multiple inclusion
  15. #define MAPCREATOR_H
  16.  
  17. class mapcreator{
  18.     static const int NUMRECT=8; //number of rectangle in the blocks.bmp file, change this number, if you want to add more rectangle
  19.                                                             //and than draw the 50x50 rectangle into the image
  20.     SDL_Rect coord,camera;          //the absolute and the relative coordinate (relative is needed for the endless background)
  21.     SDL_Rect blocks_rect[NUMRECT];  //the coordinates of the rectangles (probably you can avoid it, with a little trick)
  22.     SDL_Rect enemy_rect;                        //the coordinates of the enemy's first frame
  23.     SDL_Surface* screen,*background,*blocks,*enemy;     //an SDL_Surface for the screen (so the window), background image (endless.bmp), for the blocks
  24.                                                                                                         //(blocks.bmp) and the enemy (enemy.bmp)
  25.     int current;                                //the current block
  26.     int timeshift;                          //it's needed to set how often do you want to scroll the background, if your mouse is on the edge of the screen
  27.     std::vector<std::vector<int> > map; //it's represent the map (dynamically allocated to make our job easier)
  28.     void showmap(); //it will show the map on the screen
  29.     SDL_Surface* load_image(const char* c); //we load the images with this function
  30.     public:
  31.     mapcreator();   //constructor
  32.     ~mapcreator();  //destructor
  33.     void start();   //start the game
  34.     void save();    //save the map
  35. };
  36.  
  37. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement