Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////
- //Main Libary
- /////////////////////////////
- #include <SDL/SDL.h>
- #include <SDL/SDL_image.h>
- #include <SDL/SDL_mixer.h>
- /////////////////////////////
- //Other Files
- #include "CollisionFunction.h"
- /////////////////////////////
- #define SCREEN_HEIGHT 640
- #define SCREEN_WIDTH 480
- /////////////////////////////
- //Enemy Rectangles
- SDL_Rect OrangeGhostKnightRect;
- //Main Rectangles
- SDL_Rect LevelOneRect;
- SDL_Rect GroundOneRect;
- SDL_Rect GroundTwoRect;
- SDL_Rect GroundThreeRect;
- SDL_Rect GroundFourRect;
- //Mario Rect
- SDL_Rect MarioRect;
- //Water Rects
- SDL_Rect WaterRect;
- SDL_Rect WaterRect2;
- SDL_Rect WaterRect3;
- SDL_Rect WaterGroundRect;
- //Storage Rectangles
- SDL_Rect StorageRect[24];
- //BoundingBox
- SDL_Rect BoundingBox[10];
- //Timer Rect
- SDL_Rect TextRect[1];
- //Weather Rect
- SDL_Rect BubbleGumCloudRect[3];
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //The First Level Function
- int LevelOneFunction(void *unused)
- {
- //Frames Container
- int frame = 1;
- //Timer Container
- int timer = 1;
- //Enemy Container
- int Enemy1 = 1;
- //Frame Container
- int EnemyFrame = 0;
- //Time Container
- int time = 0;
- //Create a KeyState
- Uint8 *keystate = SDL_GetKeyState(NULL);
- ////////////////////////////////////////////////////////////////////////////////
- //Color Selections
- Uint32 RedColor =SDL_MapRGB(Screen->format,255,0,0);
- Uint32 OrangeColor =SDL_MapRGB(Screen->format,255,100,0);
- Uint32 BlackColor =SDL_MapRGB(Screen->format,0,0,0);
- Uint32 GreyColor = SDL_MapRGB(Screen->format,192,192,192);
- Uint32 MintGreenColor = SDL_MapRGB(Screen->format,39,216,176);
- Uint32 LightOliveGreenColor = SDL_MapRGB(Screen->format,135,179,77);
- //SDL COLOR Colors
- SDL_Color WhiteColor = {255,255,255};
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////
- //Storage Rect Positions
- ///////////////////////
- StorageRect[1].x = 0;
- StorageRect[1].y = 0;
- StorageRect[2].x = 0;
- StorageRect[2].y = 380;
- StorageRect[3].x = 0;
- StorageRect[3].y = 310;
- StorageRect[4].x = 0;
- StorageRect[4].y = 360;
- StorageRect[5].x = 0;
- StorageRect[5].y = 400;
- StorageRect[6].x = 320;
- StorageRect[6].y = 400;
- StorageRect[7].x = 580;
- StorageRect[7].y = 400;
- StorageRect[10].x = 300;
- StorageRect[10].y = 320;
- StorageRect[11].x = 400;
- StorageRect[13].x = -500;
- StorageRect[13].y = -70;
- StorageRect[14].y = -80;
- StorageRect[14].x = -1000;
- StorageRect[15].y =-90;
- StorageRect[15].x = 0;
- //TIMER STUFF
- ///////////////////////
- StorageRect[16].x = 5;
- StorageRect[16].y = 0;
- ///////////////////////
- ///////////////////////////////
- //BoundingBox 1 Values
- BoundingBox[1].x =160;
- BoundingBox[1].y =360;
- BoundingBox[1].w = 60;
- BoundingBox[1].h = 108;
- //BoundingBox 2 Values
- BoundingBox[2].x =300;
- BoundingBox[2].y =300;
- BoundingBox[2].w = 60;
- BoundingBox[2].h = 120;
- //Mario Rect Values
- MarioRect.x = 0;
- MarioRect.y = 0;
- //LevelOneBG Values
- LevelOneRect.x = 0;
- LevelOneRect.y = 0;
- //PurpleAmal Rock 1 Values
- GroundOneRect.x = 0;
- GroundOneRect.y = 0;
- ////////////////////////////
- //set done too false using a boolean *which gives access*
- bool done = false;
- //Event Creation
- SDL_Event event;
- //While Done is Equal False
- while(!done)
- {
- time++;
- //////////
- //Timer
- /////////
- //Font Setup
- TTF_Font *TimerFont = TTF_OpenFont("wendy.ttf",20);
- //Create A Buffer
- char buffer[128];
- //String Print for buffer
- sprintf(buffer, "Level One - BubbleGum Sunset - " " Timer" " " "%d", time);
- //Font Style
- Text[0] = TTF_RenderText_Blended( TimerFont, buffer, WhiteColor);
- /////////////////////////////////////////
- //Logic
- ////////////////////////////////////////
- //////////////////////////////////////////////////
- //Orange Ghost Knight Logic
- /////////////////////////////////////////////////
- //Orange Ghost Knight Moves to 400
- if(StorageRect[10].x == 400)
- {
- //Move OrangeGhostKnight Forward by 40
- StorageRect[10].x += 40;
- }
- //Orange Ghost Knight Moves to 480
- if(StorageRect[10].x == 480)
- {
- //Move OrangeGhostKnight Back by 40
- StorageRect[10].x -=40;
- }
- //Move Objects Constantly
- StorageRect[10].x += 1;
- StorageRect[11].x +=1;
- //Clouds
- StorageRect[13].x += 3;
- StorageRect[14].x += 2;
- StorageRect[15].x += 1;
- //If Mario Hits the Screen Width
- if(StorageRect[3].x > SCREEN_WIDTH)
- {
- //Move All VisualObjects
- StorageRect[3].x -=20;
- StorageRect[2].x -=3;
- StorageRect[6].x -=3;
- StorageRect[1].x -=10;
- }
- if(StorageRect[13].x == 800)
- {
- StorageRect[13].x = -500;
- }
- if(StorageRect[14].x == 500)
- {
- StorageRect[14].x = -1000;
- }
- if(StorageRect[15].x == 0)
- {
- StorageRect[15].x = 0;
- }
- ////////////////////////////
- //Collision Boxes
- ////////////////////////////
- //If Collision of Mario Rect and GroundOneRect Intersect
- if(Check_Collision(MarioRect,GroundOneRect))
- {
- StorageRect[3].y -= 5;
- }
- //If Collision of Mario Rect and BoundingBox Intersect
- if(Check_Collision(MarioRect,BoundingBox[1]))
- {
- StorageRect[3].y += 6;
- }
- //////////////////////////////////////
- //Drawing
- /////////////////////////////////////
- //Put LevelOneBG onto FrameBuffer
- LevelOneRect = StorageRect[1];
- SDL_BlitSurface(LevelOneBG,NULL,Screen,&LevelOneRect);
- //Put WaterGround onto FrameBuffer
- WaterGroundRect = StorageRect[5];
- SDL_BlitSurface(WaterGroundSurf,NULL,Screen,&WaterGroundRect);
- //Put GroundOne onto FrameBuffer
- GroundOneRect = StorageRect[2];
- SDL_BlitSurface(GroundOneBG,NULL,Screen,&GroundOneRect);
- //Put GroundTwo onto FrameBuffer
- GroundTwoRect = StorageRect[6];
- SDL_BlitSurface(GroundTwoBG,NULL,Screen,&GroundTwoRect);
- //Put GroundThree onto FrameBuffer
- GroundThreeRect = StorageRect[7];
- SDL_BlitSurface(GroundThreeBG,NULL,Screen,&GroundThreeRect);
- ////////////////////////////////////////////////////////////////////
- ////////////
- //Enemy
- ///////////
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////
- ///////////////
- //OGK Timer
- ///////////////
- Enemy1++;
- //increment timer "Add too the value of timer"
- switch(Enemy1)
- {
- case(0) : {EnemyFrame = 0;} break;
- case(2) : {EnemyFrame = 1;} break;
- case(4) : {EnemyFrame = 2;} break;
- case(6) : {EnemyFrame = 3;} break;
- case(8) : {EnemyFrame = 4;} break;
- case(10) : {EnemyFrame = 5;} break;
- case(12) : {Enemy1 = 0;} break;
- }
- OrangeGhostKnightRect = StorageRect[10];
- SDL_BlitSurface(OrangeGhostKnightSurf[EnemyFrame],NULL,Screen,&OrangeGhostKnightRect);
- //GET RID OF RECTANGLES
- //Could Be Rect but did try
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //TO BE FINISHED
- //Put Bubble Gum Cloud onto FrameBuffer
- BubbleGumCloudRect[3] = StorageRect[13];
- SDL_BlitSurface(BubbleGumCloudSurf[3],NULL,Screen,&BubbleGumCloudRect[3]);
- BubbleGumCloudRect[1] = StorageRect[14];
- SDL_BlitSurface(BubbleGumCloudSurf[1],NULL,Screen,&BubbleGumCloudRect[1]);
- BubbleGumCloudRect[2] = StorageRect[15];
- SDL_BlitSurface(BubbleGumCloudSurf[2],NULL,Screen,&BubbleGumCloudRect[2]);
- //Put Timer Text onto FrameBuffer
- SDL_BlitSurface(Text[0],NULL,Screen,&StorageRect[16]);
- //////////////////////////////////////////////////////
- ////////////////////
- //Right Arrow Key
- ///////////////////
- //If user doesn't press right key on keyboard
- if(keystate[SDLK_RIGHT])
- {
- //increment timer "Add too the value of timer"
- timer++;
- //First Frame
- if(timer == 1)
- {
- frame = 1;
- }
- //Second Frame
- if(timer == 2)
- {
- frame = 2;
- }
- //Third Frame
- if(timer == 3)
- {
- frame = 3;
- }
- //Fourth Frame
- if(timer == 4)
- {
- timer = 0;
- }
- //Put Super Mario onto FrameBuffer
- MarioRect = StorageRect[3];
- SDL_BlitSurface(SuperMarioWalkSurf[frame],NULL,Screen,&MarioRect);
- //Movements of actual visual objects
- StorageRect[3].x +=5;
- StorageRect[3].y += 5;
- StorageRect[1].x -=6;
- StorageRect[2].x -=2;
- StorageRect[4].x -=1;
- StorageRect[5].x -= 4;
- StorageRect[6].x -=2;
- StorageRect[7].x -=2;
- BoundingBox[2].x -=2;
- BoundingBox[3].x -=2;
- BoundingBox[4].x -=2;
- BoundingBox[5].x -=2;
- }
- /////////////////////////////////////////////////////////////////////////////////////////////
- //If user doesn't press right key on keyboard
- if(!keystate[SDLK_RIGHT])
- {
- //Put SuperMario onto FrameBuffer
- MarioRect = StorageRect[3];
- SDL_BlitSurface(SuperMarioWalkSurf[frame = 1],NULL,Screen,&MarioRect);
- }
- //0 in surfaces
- //0 in rects
- //0 in image loading
- // could be the problem
- //Rect Testing
- SDL_FillRect(Screen,&BoundingBox[3],BlackColor);
- SDL_FillRect(Screen,&BoundingBox[2],BlackColor);
- SDL_FillRect(Screen,&BoundingBox[1],BlackColor);
- SDL_FillRect(Screen,&BoundingBox[4],BlackColor);
- SDL_FillRect(Screen,&BoundingBox[5],GreyColor);
- ////////////////////////////////////////////////////
- //While continous events are running in event
- while(SDL_PollEvent(&event))
- {
- //allow to be able to switch events
- switch(event.type)
- {
- //if user presses on close
- case SDL_QUIT:
- //Close Application
- return 0;
- //break case
- break;
- //////////////////////////////////////
- //END OF SWITCH
- /////////////////////////////////////
- }
- //////////////////////////////////////
- //END OF POLL
- /////////////////////////////////////
- }
- //////////////////////////////////////
- //END OF THE MAIN WHILE LOOP
- /////////////////////////////////////
- ///////////////////////
- //Update Screen
- SDL_Flip(Screen);
- /////////////////////
- }
- }
- //////////////////////////////////////////////////////////
- //END OF FIRST LEVEL FUNCTION
- ////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment