Guest User

Untitled

a guest
Feb 8th, 2012
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.25 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.    //Enemy Rectangles
  16.    SDL_Rect OrangeGhostKnightRect;
  17.  
  18.    //Main Rectangles
  19.    SDL_Rect LevelOneRect;
  20.    SDL_Rect GroundOneRect;
  21.    SDL_Rect GroundTwoRect;
  22.    SDL_Rect GroundThreeRect;
  23.    SDL_Rect GroundFourRect;
  24.  
  25.    //Mario Rect
  26.    SDL_Rect MarioRect;
  27.  
  28.    //Water Rects
  29.    SDL_Rect WaterRect;
  30.    SDL_Rect WaterRect2;
  31.    SDL_Rect WaterRect3;
  32.    SDL_Rect WaterGroundRect;
  33.  
  34.  
  35.    //Storage Rectangles
  36.    SDL_Rect StorageRect[24];
  37.  
  38.  
  39.    //BoundingBox
  40.    SDL_Rect BoundingBox[10];
  41.  
  42.  
  43.    //Timer Rect
  44.    SDL_Rect TextRect[1];
  45.  
  46.    //Weather Rect
  47.    SDL_Rect BubbleGumCloudRect[3];
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.          ////////////////////////////////////////////////////////////////////////////////////////////////
  58.  
  59.          //The First Level Function
  60.          int LevelOneFunction(void *unused)
  61.          {
  62.             //Frames Container
  63.             int frame = 1;
  64.  
  65.             //Timer Container
  66.             int timer = 1;
  67.  
  68.             //Enemy Container
  69.             int Enemy1 = 1;
  70.  
  71.             //Frame Container
  72.             int EnemyFrame = 0;
  73.  
  74.              //Time Container
  75.             int time = 0;
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.             //Create a KeyState
  88.              Uint8 *keystate = SDL_GetKeyState(NULL);
  89.  
  90.  
  91.  
  92.  
  93.  
  94.          ////////////////////////////////////////////////////////////////////////////////
  95.          //Color Selections
  96.          Uint32 RedColor =SDL_MapRGB(Screen->format,255,0,0);
  97.          Uint32 OrangeColor =SDL_MapRGB(Screen->format,255,100,0);
  98.          Uint32 BlackColor =SDL_MapRGB(Screen->format,0,0,0);
  99.          Uint32 GreyColor = SDL_MapRGB(Screen->format,192,192,192);
  100.          Uint32 MintGreenColor = SDL_MapRGB(Screen->format,39,216,176);
  101.          Uint32 LightOliveGreenColor = SDL_MapRGB(Screen->format,135,179,77);
  102.  
  103.          //SDL COLOR Colors
  104.           SDL_Color WhiteColor = {255,255,255};
  105.  
  106.          ////////////////////////////////////////////////////////////////////////////////
  107.  
  108.  
  109.          ////////////////////////
  110.          //Storage Rect Positions
  111.          ///////////////////////
  112.  
  113.          StorageRect[1].x = 0;
  114.          StorageRect[1].y = 0;
  115.  
  116.          StorageRect[2].x = 0;
  117.          StorageRect[2].y = 380;
  118.  
  119.          StorageRect[3].x = 0;
  120.          StorageRect[3].y = 310;
  121.  
  122.          StorageRect[4].x = 0;
  123.          StorageRect[4].y = 360;
  124.  
  125.          StorageRect[5].x = 0;
  126.          StorageRect[5].y = 400;
  127.  
  128.          StorageRect[6].x = 320;
  129.          StorageRect[6].y = 400;
  130.  
  131.          StorageRect[7].x = 580;
  132.          StorageRect[7].y = 400;
  133.  
  134.          StorageRect[10].x = 300;
  135.          StorageRect[10].y = 320;
  136.  
  137.          StorageRect[11].x = 400;
  138.  
  139.  
  140.          StorageRect[13].x = -500;
  141.          StorageRect[13].y = -70;
  142.          StorageRect[14].y = -80;
  143.          StorageRect[14].x = -1000;
  144.          StorageRect[15].y =-90;
  145.          StorageRect[15].x = 0;
  146.  
  147.          //TIMER STUFF
  148.          ///////////////////////
  149.          StorageRect[16].x = 5;
  150.          StorageRect[16].y = 0;
  151.          ///////////////////////
  152.  
  153.          ///////////////////////////////
  154.  
  155.          //BoundingBox 1 Values
  156.          BoundingBox[1].x =160;
  157.          BoundingBox[1].y =360;
  158.          BoundingBox[1].w = 60;
  159.          BoundingBox[1].h = 108;
  160.  
  161.          //BoundingBox 2 Values
  162.          BoundingBox[2].x =300;
  163.          BoundingBox[2].y =300;
  164.          BoundingBox[2].w = 60;
  165.          BoundingBox[2].h = 120;
  166.  
  167.          //Mario Rect Values
  168.          MarioRect.x = 0;
  169.          MarioRect.y = 0;
  170.  
  171.          //LevelOneBG Values
  172.          LevelOneRect.x = 0;
  173.          LevelOneRect.y = 0;
  174.  
  175.          //PurpleAmal Rock 1 Values
  176.          GroundOneRect.x = 0;
  177.          GroundOneRect.y = 0;
  178.  
  179.  
  180.  
  181.  
  182.  
  183.          ////////////////////////////
  184.  
  185.       //set done too false using a boolean *which gives access*
  186.        bool done = false;
  187.  
  188.        //Event Creation
  189.        SDL_Event event;
  190.  
  191.       //While Done is Equal False
  192.         while(!done)
  193.             {
  194.  
  195.              time++;
  196.  
  197.               //////////
  198.          //Timer
  199.          /////////
  200.  
  201.  
  202.             //Font Setup
  203.             TTF_Font *TimerFont = TTF_OpenFont("wendy.ttf",20);
  204.  
  205.             //Create A Buffer
  206.             char buffer[128];
  207.  
  208.             //String Print for buffer
  209.             sprintf(buffer, "Level One - BubbleGum Sunset - "  " Timer"  "  " "%d", time);
  210.  
  211.  
  212.             //Font Style
  213.             Text[0] = TTF_RenderText_Blended( TimerFont, buffer, WhiteColor);
  214.  
  215.  
  216.  
  217.  
  218.          /////////////////////////////////////////
  219.          //Logic
  220.          ////////////////////////////////////////
  221.  
  222.          //////////////////////////////////////////////////
  223.          //Orange Ghost Knight Logic
  224.          /////////////////////////////////////////////////
  225.  
  226.  
  227.  
  228.             //Orange Ghost Knight Moves to 400
  229.             if(StorageRect[10].x == 400)
  230.                   {
  231.                      //Move OrangeGhostKnight Forward by 40
  232.                            StorageRect[10].x += 40;
  233.                   }
  234.  
  235.             //Orange Ghost Knight Moves to 480
  236.             if(StorageRect[10].x == 480)
  237.  
  238.                   {
  239.                         //Move OrangeGhostKnight Back by 40
  240.                          StorageRect[10].x -=40;
  241.                   }
  242.  
  243.          //Move Objects Constantly
  244.          StorageRect[10].x += 1;
  245.          StorageRect[11].x +=1;
  246.  
  247.             //Clouds
  248.             StorageRect[13].x += 3;
  249.             StorageRect[14].x += 2;
  250.             StorageRect[15].x += 1;
  251.  
  252.  
  253.          //If Mario Hits the Screen Width
  254.          if(StorageRect[3].x > SCREEN_WIDTH)
  255.          {
  256.  
  257.                //Move All VisualObjects
  258.                StorageRect[3].x -=20;
  259.                StorageRect[2].x -=3;
  260.                StorageRect[6].x -=3;
  261.                StorageRect[1].x -=10;
  262.  
  263.          }
  264.  
  265.  
  266.          if(StorageRect[13].x == 800)
  267.          {
  268.             StorageRect[13].x = -500;
  269.          }
  270.  
  271.           if(StorageRect[14].x == 500)
  272.          {
  273.             StorageRect[14].x = -1000;
  274.          }
  275.  
  276.          if(StorageRect[15].x == 0)
  277.          {
  278.             StorageRect[15].x = 0;
  279.          }
  280.  
  281.  
  282.  
  283.  
  284.             ////////////////////////////
  285.             //Collision Boxes
  286.             ////////////////////////////
  287.  
  288.             //If Collision of Mario Rect and GroundOneRect Intersect
  289.             if(Check_Collision(MarioRect,GroundOneRect))
  290.             {
  291.                      StorageRect[3].y -= 5;
  292.             }
  293.  
  294.             //If Collision of Mario Rect and BoundingBox Intersect
  295.             if(Check_Collision(MarioRect,BoundingBox[1]))
  296.             {
  297.                   StorageRect[3].y += 6;
  298.             }
  299.  
  300.           //////////////////////////////////////
  301.          //Drawing
  302.          /////////////////////////////////////
  303.  
  304.          //Put LevelOneBG onto FrameBuffer
  305.          LevelOneRect = StorageRect[1];
  306.          SDL_BlitSurface(LevelOneBG,NULL,Screen,&LevelOneRect);
  307.  
  308.              //Put WaterGround onto FrameBuffer
  309.          WaterGroundRect = StorageRect[5];
  310.          SDL_BlitSurface(WaterGroundSurf,NULL,Screen,&WaterGroundRect);
  311.  
  312.          //Put GroundOne onto FrameBuffer
  313.          GroundOneRect = StorageRect[2];
  314.          SDL_BlitSurface(GroundOneBG,NULL,Screen,&GroundOneRect);
  315.  
  316.          //Put GroundTwo onto FrameBuffer
  317.          GroundTwoRect = StorageRect[6];
  318.          SDL_BlitSurface(GroundTwoBG,NULL,Screen,&GroundTwoRect);
  319.  
  320.          //Put GroundThree onto FrameBuffer
  321.          GroundThreeRect = StorageRect[7];
  322.          SDL_BlitSurface(GroundThreeBG,NULL,Screen,&GroundThreeRect);
  323.  
  324.       ////////////////////////////////////////////////////////////////////
  325.  
  326.          ////////////
  327.          //Enemy
  328.          ///////////
  329.  
  330.  
  331.  
  332.             ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  333.  
  334.                ///////////////
  335.                //OGK Timer
  336.                ///////////////
  337.  
  338.             Enemy1++;
  339.       //increment timer "Add too the value of timer"
  340.  
  341.          switch(Enemy1)
  342.          {
  343.  
  344.             case(0) : {EnemyFrame = 0;} break;
  345.  
  346.             case(2) : {EnemyFrame = 1;} break;
  347.  
  348.             case(4) : {EnemyFrame = 2;} break;
  349.  
  350.             case(6) : {EnemyFrame = 3;} break;
  351.  
  352.             case(8) : {EnemyFrame = 4;} break;
  353.  
  354.             case(10) : {EnemyFrame = 5;} break;
  355.  
  356.             case(12) : {Enemy1 = 0;} break;
  357.  
  358.          }
  359.  
  360.          OrangeGhostKnightRect = StorageRect[10];
  361.          SDL_BlitSurface(OrangeGhostKnightSurf[EnemyFrame],NULL,Screen,&OrangeGhostKnightRect);
  362.  
  363.  
  364.  
  365. //GET RID OF RECTANGLES
  366.  
  367.  
  368.  
  369.  
  370.  
  371. //Could Be Rect but did try
  372.  
  373.  
  374.       ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  375.  
  376.  
  377. //TO BE FINISHED
  378.  
  379.  
  380.             //Put Bubble Gum Cloud onto FrameBuffer
  381.             BubbleGumCloudRect[3] = StorageRect[13];
  382.             SDL_BlitSurface(BubbleGumCloudSurf[3],NULL,Screen,&BubbleGumCloudRect[3]);
  383.  
  384.             BubbleGumCloudRect[1] = StorageRect[14];
  385.             SDL_BlitSurface(BubbleGumCloudSurf[1],NULL,Screen,&BubbleGumCloudRect[1]);
  386.  
  387.             BubbleGumCloudRect[2] = StorageRect[15];
  388.             SDL_BlitSurface(BubbleGumCloudSurf[2],NULL,Screen,&BubbleGumCloudRect[2]);
  389.  
  390.        //Put Timer Text onto FrameBuffer
  391.  
  392.             SDL_BlitSurface(Text[0],NULL,Screen,&StorageRect[16]);
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.          //////////////////////////////////////////////////////
  400.  
  401.  
  402.       ////////////////////
  403.       //Right Arrow Key
  404.       ///////////////////
  405.  
  406.       //If user doesn't press right key on keyboard
  407.       if(keystate[SDLK_RIGHT])
  408.       {
  409.  
  410.                //increment timer "Add too the value of timer"
  411.                timer++;
  412.  
  413.  
  414.                //First Frame
  415.                if(timer  == 1)
  416.                   {
  417.                      frame = 1;
  418.                   }
  419.                //Second Frame
  420.               if(timer  == 2)
  421.                   {
  422.                         frame = 2;
  423.                   }
  424.  
  425.                //Third Frame
  426.                if(timer == 3)
  427.                   {
  428.                      frame = 3;
  429.                   }
  430.                //Fourth Frame
  431.                if(timer == 4)
  432.                   {
  433.                        timer = 0;
  434.                   }
  435.  
  436.                 //Put Super Mario onto FrameBuffer
  437.                MarioRect = StorageRect[3];
  438.                SDL_BlitSurface(SuperMarioWalkSurf[frame],NULL,Screen,&MarioRect);
  439.  
  440.  
  441.                      //Movements of actual visual objects
  442.                     StorageRect[3].x +=5;
  443.                     StorageRect[3].y += 5;
  444.                     StorageRect[1].x -=6;
  445.                     StorageRect[2].x -=2;
  446.                     StorageRect[4].x -=1;
  447.                     StorageRect[5].x -= 4;
  448.                     StorageRect[6].x -=2;
  449.                     StorageRect[7].x -=2;
  450.                     BoundingBox[2].x -=2;
  451.                     BoundingBox[3].x -=2;
  452.                     BoundingBox[4].x -=2;
  453.                     BoundingBox[5].x -=2;
  454.  
  455.  
  456.  
  457.                      }
  458.  
  459.  
  460.             /////////////////////////////////////////////////////////////////////////////////////////////
  461.  
  462.             //If user doesn't press right key on keyboard
  463.            if(!keystate[SDLK_RIGHT])
  464.                   {
  465.                         //Put SuperMario onto FrameBuffer
  466.                         MarioRect = StorageRect[3];
  467.                         SDL_BlitSurface(SuperMarioWalkSurf[frame = 1],NULL,Screen,&MarioRect);
  468.                   }
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479. //0 in surfaces
  480. //0 in rects
  481. //0 in image loading
  482. // could be the problem
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.             //Rect Testing
  493.             SDL_FillRect(Screen,&BoundingBox[3],BlackColor);
  494.             SDL_FillRect(Screen,&BoundingBox[2],BlackColor);
  495.             SDL_FillRect(Screen,&BoundingBox[1],BlackColor);
  496.             SDL_FillRect(Screen,&BoundingBox[4],BlackColor);
  497.             SDL_FillRect(Screen,&BoundingBox[5],GreyColor);
  498.  
  499.  
  500.  
  501.  
  502.  
  503.             ////////////////////////////////////////////////////
  504.  
  505.        //While continous events are running in event
  506.          while(SDL_PollEvent(&event))
  507.          {
  508.  
  509.  
  510.             //allow to be able to switch events
  511.             switch(event.type)
  512.             {
  513.  
  514.           //if user presses on close
  515.                 case SDL_QUIT:
  516.  
  517.                     //Close Application
  518.                     return 0;
  519.  
  520.  
  521.                         //break case
  522.                         break;
  523.  
  524.  
  525. //////////////////////////////////////
  526. //END OF SWITCH
  527. /////////////////////////////////////
  528.  
  529.             }
  530.  
  531. //////////////////////////////////////
  532. //END OF POLL
  533. /////////////////////////////////////
  534.  
  535.                                 }
  536.  
  537. //////////////////////////////////////
  538. //END OF THE MAIN WHILE LOOP
  539. /////////////////////////////////////
  540.  
  541.    ///////////////////////
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.       //Update Screen
  549.       SDL_Flip(Screen);
  550.  
  551.  
  552.    /////////////////////
  553.  
  554.             }
  555.  
  556. }
  557.  
  558. //////////////////////////////////////////////////////////
  559.  
  560.  
  561. //END OF FIRST LEVEL FUNCTION
  562.  
  563.  
  564. ////////////////////////////////////////////////////////
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571. ////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment