Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MAIN.CPP
- ///////////////////////////////////
- //Main Libary
- #include "SDL/SDL.h"
- #include "SDL/SDL_image.h"
- //////////////////////////////////
- //Other Files
- #include "SurfaceStorage.h"
- #include "ThreadFunction.h"
- //////////////////////////////////
- //Main Application On and Off Switch
- int main(int argc,char *argv[])
- {
- //////////////////////////////////////////////////////////////////////////
- //Image Loading
- //TitleScreen
- TitleScreenBG = IMG_Load("ArtWork/TitleScreen/titlescreenbg.png");
- //Level One BackGround
- LevelOneBGSurf = IMG_Load("ArtWork/LevelOne/LevelOneBG.png");
- GroundSurf = IMG_Load("ArtWork/LevelOne/Ground.png");
- //Player
- PlayerSurf = IMG_Load("ArtWork/Player/Player.png");
- //////////////////////////////////////////////////////////////////////////
- //On and Off Switch for Application
- bool done = false;
- //////////////////////////////////////////////////////////////////////////
- //Screen Setup
- Screen = SDL_SetVideoMode(640,480,32,SDL_HWSURFACE);
- //Screen Title
- SDL_WM_SetCaption("Super Mario Kid - The Lost Presents", NULL);
- ////////////////////////////////////////////////////////////////////////////
- //TitleScreen Blitting
- SDL_BlitSurface(TitleScreenBG,NULL,Screen,NULL);
- //Updating Screen
- SDL_Flip(Screen);
- /////////////////////////////////////////////////////////////////////////////
- //Event Creation
- SDL_Event event;
- ////////////////////////////////////////////////////////////////////////////
- SDL_WarpMouse(320,220);
- //While Done is Equal False
- while(!done)
- {
- //While Keep Doing Events of Event
- while(SDL_PollEvent(&event))
- {
- //Give Access to switch event types
- switch(event.type)
- {
- //if user pressed x button on window
- case SDL_QUIT:
- //return calls 0
- return 0;
- //break the case
- break;
- //if mouse is button is pressed here
- case SDL_MOUSEBUTTONUP:
- //Container for mouse_x values
- int mouse_x;
- //Container for mouse_y values
- int mouse_y;
- //getting mouse position
- SDL_GetMouseState(&mouse_x,&mouse_y);
- //If Mouse Position = this
- if(mouse_x <= 320, mouse_y <= 240)
- {
- //////////////////////////////////////////////////////////////////////
- fprintf(stderr,"Works");
- SDL_Thread *LevelOneThread;
- LevelOneThread = SDL_CreateThread(LevelOneFunction,NULL);
- ////////////////////////////////////////////////////////////////////
- }
- }
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////////////
- THREADFUNCTION.H
- //////////////////////////////////
- #include "SDL/SDL.h"
- #include "SDL/SDL_image.h"
- /////////////////////////////////
- void draw()
- {
- // Create a black background using the screen pixel format (32 bpp)
- SDL_FillRect (Screen, NULL, 0x000000);
- // Set the image offset
- SDL_BlitSurface(LevelOneBGSurf, NULL, Screen, NULL);
- // Flip the working image buffer with the screen buffer
- SDL_Flip (Screen);
- // Add a little pause...
- SDL_Delay (1);
- SDL_FillRect (Screen, NULL, 0x000000);
- // Set the image offset
- SDL_BlitSurface(GroundSurf, NULL, Screen, NULL);
- // Flip the working image buffer with the screen buffer
- SDL_Flip (Screen);
- // Add a little pause...
- SDL_Delay (1);
- }
- /////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////
- int LevelOneFunction(void *unused)
- {
- //////////////////////////
- //Camera
- /////////////////////////
- /////////////////////////
- //Rectangles
- SDL_Rect playersurfrect;
- playersurfrect.x = 100;
- playersurfrect.y = 0;
- SDL_Rect Backgroundrect;
- Backgroundrect.x = 100;
- Backgroundrect.y =0;
- SDL_Rect GroundRect;
- GroundRect.x = 100;
- GroundRect.y = 0;
- SDL_BlitSurface(LevelOneBGSurf,NULL,Screen,&Backgroundrect);
- SDL_Flip(Screen);
- SDL_BlitSurface(GroundSurf,NULL,Screen,&GroundRect);
- SDL_Flip(Screen);
- SDL_BlitSurface(PlayerSurf,NULL,Screen,&playersurfrect);
- SDL_Flip(Screen);
- bool LevelOneToggle = false;
- SDL_Event event;
- while(!LevelOneToggle)
- {
- while(SDL_PollEvent(&event))
- {
- switch(event.type)
- {
- draw();
- case SDL_QUIT:
- return 0;
- break;
- case SDL_KEYDOWN:
- switch(event.key.keysym.sym)
- {
- ///////////////////////////////////////////////////////////////
- case SDLK_LEFT:
- fprintf(stderr,"FUCKING PRESSED LEFT");
- SDL_FillRect (Screen, NULL, 0x000000);
- playersurfrect.x += 10;
- Backgroundrect.x -= 10;
- GroundRect.x -=9;
- SDL_BlitSurface(LevelOneBGSurf,NULL,Screen,&Backgroundrect);
- SDL_BlitSurface(GroundSurf,NULL,Screen,&GroundRect);
- SDL_BlitSurface(PlayerSurf,NULL,Screen,&playersurfrect);
- SDL_Flip(Screen);
- break;
- /////////////////////////////////////////////////////////////
- case SDLK_RIGHT:
- SDL_FillRect (Screen, NULL, 0x000000);
- playersurfrect.x -= 10;
- Backgroundrect.x += 1;
- GroundRect.x +=2;
- SDL_BlitSurface(LevelOneBGSurf,NULL,Screen,&Backgroundrect);
- SDL_BlitSurface(GroundSurf,NULL,Screen,&GroundRect);
- SDL_BlitSurface(PlayerSurf,NULL,Screen,&playersurfrect);
- SDL_Flip(Screen);
- break;
- }
- }
- }
- }
- }
- ///////////////////////////////////////////////////////////////////
- SURFACESTORAGE.H
- #include "SDL/SDL.h"
- //TitleScreen
- SDL_Surface *Screen = NULL;
- SDL_Surface *TitleScreenBG = NULL;
- //Level One BG
- SDL_Surface *LevelOneBGSurf = NULL;
- //Player
- SDL_Surface *PlayerSurf = NULL;
- SDL_Surface *GroundSurf = NULL;
Advertisement
Add Comment
Please, Sign In to add comment