//The headers
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <stdio.h>
#include <stdlib.h>
#include <string>
//SDL_Event event;
//Screen attributes
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 600;
const int SCREEN_BPP = 32;
//The surfaces
SDL_Surface *screen = NULL;
SDL_Surface *intro1 = NULL;
SDL_Surface *intro2 = NULL;
SDL_Surface *tuxKiller = NULL;
SDL_Surface *killTux = NULL;
SDL_Surface *muro = NULL;
SDL_Surface *mappa1 = NULL;
SDL_Surface *buf = NULL;
SDL_Event event;
SDL_Surface *load_image( std::string filename )
{
//The image that's loaded
SDL_Surface* loadedImage = NULL;
//The optimized image that will be used
SDL_Surface* optimizedImage = NULL;
//Load the image using SDL_image
loadedImage = IMG_Load( filename.c_str() );
//If the image loaded
if( loadedImage != NULL )
{
//Create an optimized image
optimizedImage = SDL_DisplayFormat( loadedImage );
//Free the old image
SDL_FreeSurface( loadedImage );
}
//Return the optimized image
return optimizedImage;
}
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
//Rectangle to hold the offsets
SDL_Rect offset;
//Get offsets
offset.x = x;
offset.y = y;
//Blit the surface
SDL_BlitSurface( source, NULL, destination, &offset );
}
bool init()
{
//Initialize all SDL subsystems
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return false;
}
//Set up the screen
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
buf = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
//If there was an error in setting up the screen
if( screen == NULL || buf == NULL )
{
return false;
}
//Set the window caption
SDL_WM_SetCaption( "The TuxWars", NULL );
//If everything initialized fine
return true;
}
void clean_up_intro()
{
//Free the surface
SDL_FreeSurface( intro1 );
SDL_FreeSurface( intro2 );
//Quit SDL
//SDL_Quit();
}
void clean_up_map1()
{
SDL_FreeSurface( killTux );
SDL_FreeSurface( tuxKiller );
SDL_FreeSurface( muro );
SDL_FreeSurface( mappa1 );
SDL_Quit();
}
int intro()
{
//
//Intro al gioco!
//
//intro1
apply_surface( 0, 0, intro1, screen );
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
SDL_Delay( 3000 );
//intro1
apply_surface( 0, 0, intro2, screen );
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
SDL_Delay( 6000 );
}
int CaricaImmagini()
{
//Load the image
intro1 = load_image( "intro1.jpg" );
intro2 = load_image( "intro2.png" );
killTux = load_image( "TUX_TRIB.gif" );
tuxKiller = load_image( "tuxkiller.gif" );
muro = load_image( "muro.gif" );
mappa1 = load_image( "mappa1.png" );
//If there was a problem in loading the image
if( intro1 == NULL || intro2 == NULL || killTux == NULL || tuxKiller == NULL || muro == NULL)
{
return 1;
}
}
int map1()
{
SDL_Event event;
int x_tuxKiller, y_tuxKiller, x_killTux, y_killTux;
int full_s=0;
x_tuxKiller = 20;
y_tuxKiller = 495;
bool gameover = 0;
bool quit = false;
apply_surface( 0, 0, mappa1, buf );
apply_surface( 0, 0, killTux, buf );
apply_surface( x_tuxKiller, y_tuxKiller, tuxKiller, buf );
apply_surface( 0, 0, buf, screen );
while( quit == false )
{
//While there's an event to handle
while( SDL_PollEvent( &event ) )
{
//If the user has Xed out the window
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
}
}
}
int main( int argc, char* args[] )
{
int x_tuxKiller, y_tuxKiller, x_killTux, y_killTux;
x_tuxKiller = 20;
y_tuxKiller = 495;
//Initialize
if( init() == false )
{
return 1;
}
CaricaImmagini();
intro();
map1();
//Free the surface and quit SDL
clean_up_map1();
return 0;
}