Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2012
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.35 KB | None | 0 0
  1. /////////////////////////////
  2. //Main Libary
  3. /////////////////////////////
  4. #include <SDL/SDL.h>
  5. #include <SDL/SDL_image.h>
  6. #include <SDL/SDL_mixer.h>
  7. /////////////////////////////
  8. //Other Files
  9. #include "CollisionFunction.h"
  10. /////////////////////////////
  11. #define SCREEN_HEIGHT 640
  12. #define SCREEN_WIDTH 480
  13. /////////////////////////////
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20. SDL_Rect OrangeGhostKnightRect;
  21.  
  22.             //Main Rectangles
  23.             SDL_Rect LevelOneRect;
  24.             SDL_Rect GroundOneRect;
  25.             SDL_Rect GroundTwoRect;
  26.             SDL_Rect GroundThreeRect;
  27.             SDL_Rect GroundFourRect;
  28.  
  29.             //Mario Rect
  30.             SDL_Rect MarioRect;
  31.  
  32.             //Water Rects
  33.             SDL_Rect WaterRect;
  34.             SDL_Rect WaterRect2;
  35.             SDL_Rect WaterRect3;
  36.             SDL_Rect WaterGroundRect;
  37.  
  38.  
  39.             //Storage Rectangles
  40.             SDL_Rect StorageRect1;
  41.             SDL_Rect StorageRect2;
  42.             SDL_Rect StorageRect3;
  43.             SDL_Rect StorageRect4;
  44.             SDL_Rect StorageRect5;
  45.             SDL_Rect StorageRect6;
  46.             SDL_Rect StorageRect7;
  47.             SDL_Rect StorageRect8;
  48.             SDL_Rect StorageRect9;
  49.             SDL_Rect StorageRect10;
  50.  
  51.             //BubbleGumRect Storage
  52.             SDL_Rect StorageRect11;
  53.             SDL_Rect StorageRect12;
  54.  
  55.  
  56.  
  57.             //BoundingBox
  58.             SDL_Rect BoundingBox1;
  59.             SDL_Rect BoundingBox2;
  60.  
  61.             //Timer Rect
  62.             SDL_Rect TimerTextRect;
  63.  
  64.             //Weather Rect
  65.             SDL_Rect BubbleGumCloudRect;
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.          //////////////////////////////////////////////////
  73.                      //Orange Ghost Knight Logic
  74.          /////////////////////////////////////////////////
  75.  
  76. /////////////////////////////////////////////////////////////////
  77. int EnemyFunction(void *unused)
  78.    {
  79.  
  80.    for(int d = 0; d <= 10; d++)
  81.             {
  82.  
  83.     OrangeGhostKnightRect = StorageRect10;
  84.             SDL_BlitSurface(OrangeGhostKnightSurf,NULL,Screen,&OrangeGhostKnightRect);
  85.  
  86.  
  87.  
  88.     if(StorageRect10.x >= 400)
  89.                         {
  90.  
  91.                                StorageRect10.x += 40;
  92.  
  93.                                    OrangeGhostKnightRect = StorageRect10;
  94.             SDL_BlitSurface(OrangeGhostKnightSurf,NULL,Screen,&OrangeGhostKnightRect);
  95.  
  96.                         }
  97.  
  98.  
  99.               if(StorageRect10.x >= 480)
  100.  
  101.                         {
  102.                            StorageRect10.x -=40;
  103.  
  104.                                OrangeGhostKnightRect = StorageRect10;
  105.             SDL_BlitSurface(OrangeGhostKnightSurf,NULL,Screen,&OrangeGhostKnightRect);
  106.  
  107.                         }
  108. }
  109.  
  110.  
  111.          /////////////////////////////////////////////////////////////////////////////////////////
  112.    }
  113.  
  114.  
  115. int DrawAndUpdate (void *unused)
  116. {
  117.             LevelOneRect = StorageRect1;
  118.             SDL_BlitSurface(LevelOneBG,NULL,Screen,&LevelOneRect);
  119.  
  120.             WaterGroundRect = StorageRect5;
  121.             SDL_BlitSurface(WaterGroundSurf,NULL,Screen,&WaterGroundRect);
  122.  
  123.             GroundOneRect = StorageRect2;
  124.             SDL_BlitSurface(GroundOneBG,NULL,Screen,&GroundOneRect);
  125.  
  126.             GroundTwoRect = StorageRect6;
  127.             SDL_BlitSurface(GroundTwoBG,NULL,Screen,&GroundTwoRect);
  128.  
  129.             GroundThreeRect = StorageRect7;
  130.             SDL_BlitSurface(GroundThreeBG,NULL,Screen,&GroundThreeRect);
  131.  
  132.             MarioRect = StorageRect3;
  133.             SDL_BlitSurface(SuperMarioWalk2Surf,NULL,Screen,&MarioRect);
  134.  
  135.  
  136.             OrangeGhostKnightRect = StorageRect10;
  137.             SDL_BlitSurface(OrangeGhostKnightSurf,NULL,Screen,&OrangeGhostKnightRect);
  138.  
  139.             BubbleGumCloudRect = StorageRect11;
  140.             SDL_BlitSurface(BubbleGumCloudSurf,NULL,Screen,&BubbleGumCloudRect);
  141.  
  142.             SDL_BlitSurface(Text,NULL,Screen,&TimerTextRect);
  143.  
  144.  
  145. }
  146.  
  147.  
  148.  
  149.  
  150. ////////////////////////////////////////////////////////////////////////////////////////////////
  151.  
  152.  
  153. int LevelOneFunction(void *unused)
  154. {
  155.  
  156.             ////////////////////////////////////////////////////////////////////////////////
  157.             //Color Selections
  158.             Uint32 RedColor =SDL_MapRGB(Screen->format,255,0,0);
  159.             Uint32 OrangeColor =SDL_MapRGB(Screen->format,255,100,0);
  160.             Uint32 BlackColor =SDL_MapRGB(Screen->format,0,0,0);
  161.             Uint32 GreyColor = SDL_MapRGB(Screen->format,192,192,192);
  162.             Uint32 MintGreenColor = SDL_MapRGB(Screen->format,39,216,176);
  163.             Uint32 LightOliveGreenColor = SDL_MapRGB(Screen->format,135,179,77);
  164.  
  165.             //SDL COLOR Colors
  166.              SDL_Color WhiteColor = {255,255,255};
  167.             ////////////////////////////////////////////////////////////////////////////////
  168.  
  169.             ////////////////////////
  170.             //Storage Rect Positions
  171.             ///////////////////////
  172.  
  173.             StorageRect1.x = 0;
  174.             StorageRect1.y = 0;
  175.  
  176.             StorageRect2.x = 0;
  177.             StorageRect2.y = 380;
  178.  
  179.             StorageRect3.x = 0;
  180.             StorageRect3.y = 310;
  181.  
  182.             StorageRect4.x = 0;
  183.             StorageRect4.y = 360;
  184.  
  185.             StorageRect5.x = 0;
  186.             StorageRect5.y = 400;
  187.  
  188.             StorageRect6.x = 320;
  189.             StorageRect6.y = 400;
  190.  
  191.             StorageRect7.x = 580;
  192.             StorageRect7.y = 400;
  193.  
  194.             StorageRect10.x = 400;
  195.             StorageRect10.y = 320;
  196.  
  197.             StorageRect11.y = -200;
  198.  
  199.             StorageRect12.x = 5;
  200.  
  201.             ///////////////////////////////
  202.  
  203.             //BoundingBox 1 Values
  204.             BoundingBox1.x =160;
  205.             BoundingBox1.y =360;
  206.             BoundingBox1.w = 60;
  207.             BoundingBox1.h = 108;
  208.  
  209.             //BoundingBox 2 Values
  210.             BoundingBox2.x =300;
  211.             BoundingBox2.y =300;
  212.             BoundingBox2.w = 60;
  213.             BoundingBox2.h = 120;
  214.  
  215.  
  216.             //Mario Rect Values
  217.             MarioRect.x = 0;
  218.             MarioRect.y = 0;
  219.  
  220.             //LevelOneBG Values
  221.             LevelOneRect.x = 0;
  222.             LevelOneRect.y = 0;
  223.  
  224.             //PurpleAmal Rock 1 Values
  225.             GroundOneRect.x = 0;
  226.             GroundOneRect.y = 0;
  227.  
  228.             ////////////////////////////
  229.  
  230.  
  231.  
  232.  
  233.  
  234.    //Bool Variable
  235.     bool done = false;
  236.  
  237.     //Event Creation
  238.     SDL_Event event;
  239.  
  240.      while(!done)
  241.             {
  242.  
  243.             //Other Stuff
  244.             StorageRect11.x += 1;
  245.  
  246.              SDL_Thread *TestThread;
  247.          TestThread = SDL_CreateThread(DrawAndUpdate,NULL);
  248.              //Update Screen
  249.             SDL_Flip(Screen);
  250.  
  251.  
  252.             //Collision Testing
  253.             SDL_FillRect(Screen,&BoundingBox2,MintGreenColor);
  254.  
  255.  
  256.  
  257.         ////////////////////////////////////////////////////
  258.        //While continous events are running in event
  259.        ////////////////////////////////////////////////////
  260.  
  261.           while(SDL_PollEvent(&event))
  262.           {
  263.  
  264.  
  265.  
  266.             //allow to be able to switch events
  267.             switch(event.type)
  268.             {
  269.  
  270.             ////////////////////////////////////
  271.  
  272.             //While Any Key is Down
  273.             case SDL_KEYDOWN:
  274.  
  275.             //Allow Keyboard Events
  276.             switch(event.key.keysym.sym)
  277.             {
  278.  
  279.                 //Up is Pressed
  280.                    case SDLK_RIGHT:
  281.  
  282.                      //Movements of actual visual objects
  283.                     StorageRect3.x +=10;
  284.                     StorageRect3.y += 5;
  285.                     StorageRect1.x -=6;
  286.                     StorageRect2.x -=2;
  287.                     StorageRect4.x -=1;
  288.                     StorageRect5.x -= 4;
  289.                     StorageRect6.x -=2;
  290.                     StorageRect7.x -=2;
  291.                     BoundingBox2.x -=2;
  292.  
  293.                     /////////////////////////////////////////////////
  294.  
  295.                              //Movements of BoundingBoxes
  296.  
  297.  
  298.                     if(StorageRect3.x > SCREEN_WIDTH)
  299.                     {
  300.                         StorageRect3.x -=20;
  301.                         StorageRect2.x -=3;
  302.                         StorageRect6.x -=3;
  303.                         StorageRect1.x -=10;
  304.                     }
  305.  
  306.  
  307.  
  308.  
  309.  
  310.                      ////////////////////////////
  311.                     //Collision Boxes
  312.                     ////////////////////////////
  313.  
  314.                     if(Check_Collision(MarioRect,GroundOneRect))
  315.                     {
  316.                         StorageRect3.y -= 5;
  317.                     }
  318.  
  319.  
  320.                     if(Check_Collision(MarioRect,BoundingBox1))
  321.                     {
  322.                         StorageRect3.y += 6;
  323.                     }
  324.  
  325.  
  326.  
  327.  
  328.                ////////////////////////
  329.  
  330.                //KEYSYSTEM EVENTS ^^
  331.                     }
  332.  
  333.  
  334.             //SDL KEYDOWN
  335.                     break;
  336.  
  337.                       ////////////////////////////////
  338.  
  339.                 //if user presses on close
  340.                 case SDL_QUIT:
  341.  
  342.                     //Close Application
  343.                     return 0;
  344.  
  345.  
  346.                         //break case
  347.                         break;
  348.  
  349.          //SWITCH EVENT TYPE
  350.  
  351.             }
  352.  
  353.  
  354.  
  355. /////////
  356. //POLL
  357. /////////
  358.  
  359.  
  360.  
  361.                                 }
  362.  
  363.  
  364. //////////////////////////////////////
  365. //END OF THE MAIN WHILE LOOP
  366. /////////////////////////////////////
  367.  
  368.  
  369.             }
  370. /////////////////////////////////////
  371.  
  372.  
  373. //DONT KNOW
  374. //COULD BE THE RIGHT POINT
  375.  
  376.  
  377. }
  378.  
  379. ////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement