Guest User

Untitled

a guest
Dec 28th, 2011
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.69 KB | None | 0 0
  1. MAIN.CPP
  2.  
  3. ///////////////////////////////////
  4. //Main Libary
  5. #include "SDL/SDL.h"
  6. #include "SDL/SDL_image.h"
  7. //////////////////////////////////
  8. //Other Files
  9. #include "SurfaceStorage.h"
  10. #include "ThreadFunction.h"
  11. //////////////////////////////////
  12.  
  13. //Main Application On and Off Switch
  14. int main(int argc,char *argv[])
  15.  
  16. {
  17.     //////////////////////////////////////////////////////////////////////////
  18.  
  19.      //Image Loading
  20.  
  21.     //TitleScreen
  22.     TitleScreenBG = IMG_Load("ArtWork/TitleScreen/titlescreenbg.png");
  23.  
  24.     //Level One BackGround
  25.     LevelOneBGSurf = IMG_Load("ArtWork/LevelOne/LevelOneBG.png");
  26.     GroundSurf = IMG_Load("ArtWork/LevelOne/Ground.png");
  27.  
  28.     //Player
  29.     PlayerSurf = IMG_Load("ArtWork/Player/Player.png");
  30.  
  31.     //////////////////////////////////////////////////////////////////////////
  32.  
  33.     //On and Off Switch for Application
  34.     bool done = false;
  35.     //////////////////////////////////////////////////////////////////////////
  36.  
  37.  
  38.     //Screen Setup
  39.     Screen = SDL_SetVideoMode(640,480,32,SDL_HWSURFACE);
  40.  
  41.     //Screen Title
  42.     SDL_WM_SetCaption("Super Mario Kid - The Lost Presents", NULL);
  43.  
  44.     ////////////////////////////////////////////////////////////////////////////
  45.  
  46.     //TitleScreen Blitting
  47.     SDL_BlitSurface(TitleScreenBG,NULL,Screen,NULL);
  48.  
  49.     //Updating Screen
  50.     SDL_Flip(Screen);
  51.  
  52.     /////////////////////////////////////////////////////////////////////////////
  53.  
  54.      //Event Creation
  55.     SDL_Event event;
  56.  
  57.     ////////////////////////////////////////////////////////////////////////////
  58.  
  59.     SDL_WarpMouse(320,220);
  60.  
  61.     //While Done is Equal False
  62.     while(!done)
  63.     {
  64.         //While Keep Doing Events of Event
  65.         while(SDL_PollEvent(&event))
  66.         {
  67.             //Give Access to switch event types
  68.             switch(event.type)
  69.             {
  70.                 //if user pressed x button on window
  71.                 case SDL_QUIT:
  72.  
  73.                 //return calls 0
  74.                 return 0;
  75.  
  76.                 //break the case
  77.                 break;
  78.  
  79.                 //if mouse is button is pressed here
  80.                 case SDL_MOUSEBUTTONUP:
  81.  
  82.                 //Container for mouse_x values
  83.                 int mouse_x;
  84.  
  85.                 //Container for mouse_y values
  86.                 int mouse_y;
  87.  
  88.                 //getting mouse position
  89.                 SDL_GetMouseState(&mouse_x,&mouse_y);
  90.  
  91.                 //If Mouse Position = this
  92.                 if(mouse_x <= 320, mouse_y <= 240)
  93.                 {
  94.                     //////////////////////////////////////////////////////////////////////
  95.                     fprintf(stderr,"Works");
  96.  
  97.                     SDL_Thread *LevelOneThread;
  98.  
  99.                     LevelOneThread = SDL_CreateThread(LevelOneFunction,NULL);
  100.                     ////////////////////////////////////////////////////////////////////
  101.                 }
  102.  
  103.             }
  104.         }
  105.     }
  106.  
  107. }
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117. /////////////////////////////////////////////////////////////////////////////////////
  118. THREADFUNCTION.H
  119. //////////////////////////////////
  120. #include "SDL/SDL.h"
  121. #include "SDL/SDL_image.h"
  122. /////////////////////////////////
  123.  
  124. void draw()
  125. {
  126.  
  127.  
  128.     // Create a black background using the screen pixel format (32 bpp)
  129.  
  130.     SDL_FillRect (Screen, NULL, 0x000000);
  131.  
  132.     // Set the image offset
  133.     SDL_BlitSurface(LevelOneBGSurf, NULL, Screen, NULL);
  134.  
  135.     // Flip the working image buffer with the screen buffer
  136.     SDL_Flip (Screen);
  137.  
  138.     // Add a little pause...
  139.     SDL_Delay (1);
  140.  
  141.     SDL_FillRect (Screen, NULL, 0x000000);
  142.  
  143.     // Set the image offset
  144.     SDL_BlitSurface(GroundSurf, NULL, Screen, NULL);
  145.  
  146.     // Flip the working image buffer with the screen buffer
  147.     SDL_Flip (Screen);
  148.  
  149.     // Add a little pause...
  150.     SDL_Delay (1);
  151.  
  152.  
  153. }
  154. /////////////////////////////////////////////////////////
  155.  
  156.  
  157.  
  158. //////////////////////////////////////////////////////
  159. int LevelOneFunction(void *unused)
  160. {
  161.     //////////////////////////
  162.     //Camera
  163.     /////////////////////////
  164.  
  165.  
  166.     /////////////////////////
  167.           //Rectangles
  168.  
  169.  
  170.      SDL_Rect playersurfrect;
  171.  
  172.      playersurfrect.x = 100;
  173.      playersurfrect.y = 0;
  174.  
  175.  
  176.  
  177.  
  178.     SDL_Rect Backgroundrect;
  179.  
  180.  
  181.     Backgroundrect.x = 100;
  182.     Backgroundrect.y =0;
  183.  
  184.     SDL_Rect GroundRect;
  185.  
  186.     GroundRect.x = 100;
  187.     GroundRect.y = 0;
  188.  
  189.     SDL_BlitSurface(LevelOneBGSurf,NULL,Screen,&Backgroundrect);
  190.     SDL_Flip(Screen);
  191.  
  192.     SDL_BlitSurface(GroundSurf,NULL,Screen,&GroundRect);
  193.     SDL_Flip(Screen);
  194.  
  195.     SDL_BlitSurface(PlayerSurf,NULL,Screen,&playersurfrect);
  196.    SDL_Flip(Screen);
  197.  
  198.  
  199.     bool LevelOneToggle = false;
  200.  
  201.     SDL_Event event;
  202.  
  203.     while(!LevelOneToggle)
  204.     {
  205.         while(SDL_PollEvent(&event))
  206.         {
  207.             switch(event.type)
  208.             {
  209.  
  210.                  draw();
  211.  
  212.                 case SDL_QUIT:
  213.  
  214.                 return 0;
  215.  
  216.                 break;
  217.  
  218.                 case SDL_KEYDOWN:
  219.  
  220.                 switch(event.key.keysym.sym)
  221.                 {
  222.                     ///////////////////////////////////////////////////////////////
  223.                     case SDLK_LEFT:
  224.  
  225.  
  226.                     fprintf(stderr,"FUCKING PRESSED LEFT");
  227.  
  228.                     SDL_FillRect (Screen, NULL, 0x000000);
  229.  
  230.                     playersurfrect.x += 10;
  231.  
  232.                    Backgroundrect.x -= 10;
  233.  
  234.                     GroundRect.x -=9;
  235.  
  236.  
  237.  
  238.                     SDL_BlitSurface(LevelOneBGSurf,NULL,Screen,&Backgroundrect);
  239.                      SDL_BlitSurface(GroundSurf,NULL,Screen,&GroundRect);
  240.                     SDL_BlitSurface(PlayerSurf,NULL,Screen,&playersurfrect);
  241.  
  242.                     SDL_Flip(Screen);
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.                     break;
  250.                     /////////////////////////////////////////////////////////////
  251.  
  252.                       case SDLK_RIGHT:
  253.  
  254.                     SDL_FillRect (Screen, NULL, 0x000000);
  255.  
  256.                     playersurfrect.x -= 10;
  257.  
  258.                    Backgroundrect.x += 1;
  259.  
  260.                     GroundRect.x +=2;
  261.  
  262.                     SDL_BlitSurface(LevelOneBGSurf,NULL,Screen,&Backgroundrect);
  263.                       SDL_BlitSurface(GroundSurf,NULL,Screen,&GroundRect);
  264.                     SDL_BlitSurface(PlayerSurf,NULL,Screen,&playersurfrect);
  265.  
  266.                     SDL_Flip(Screen);
  267.  
  268.                       break;
  269.  
  270.  
  271.  
  272.                 }
  273.  
  274.  
  275.             }
  276.         }
  277.     }
  278. }
  279. ///////////////////////////////////////////////////////////////////
  280.  
  281. SURFACESTORAGE.H
  282.  
  283.  
  284. #include "SDL/SDL.h"
  285.  
  286. //TitleScreen
  287. SDL_Surface *Screen = NULL;
  288. SDL_Surface *TitleScreenBG = NULL;
  289.  
  290. //Level One BG
  291. SDL_Surface *LevelOneBGSurf = NULL;
  292.  
  293.  
  294. //Player
  295. SDL_Surface *PlayerSurf = NULL;
  296. SDL_Surface *GroundSurf = NULL;
Advertisement
Add Comment
Please, Sign In to add comment