problems with event handle in diffrent functions
Hello, Im new to SDL event handles. Im trying to load play_level1(); from show_title(); function. It loads show_title(); but when I click New Game button, the program exits when its supposed to load level 1. Here is my code:
//includes
//SDL includes
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#include <SDL/SDL_mixer.h>
//basic utility includes
#include <string>
#include <cmath>
#include <fstream>
#include <sstream>
#include <vector>
using namespace std;
//Quit flag
bool quit = false;
//Game over flag
bool gameOver = false;
//Function prototypes
void clean_up();
void easter_egg();
bool init();
bool load_files();
void play_level1();
void load_images(std::string filename);
void set_buttonClips();
void show_company();
void show_credits();
void show_story();
void show_title();
//The attributes for the screen
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;
//Set the frame rate
const int FRAMES_PER_SECOND = 20;
//The button states in the sprite sheet
const int CLIP_MOUSEOVER = 0;
const int CLIP_MOUSEOUT = 1;
const int CLIP_MOUSEDOWN = 2;
const int CLIP_MOUSEUP = 3;
//The button surfaces
SDL_Surface *newGameButton = NULL;
SDL_Surface *storyButton = NULL;
SDL_Surface *creditsButton = NULL;
SDL_Surface *exitButton = NULL;
//The background surfaces
SDL_Surface *screen = NULL;
SDL_Surface *intro_background = NULL;
SDL_Surface *title_gun = NULL;
SDL_Surface *company_logo = NULL;
SDL_Surface *level_1B = NULL;
SDL_Surface *level_2B = NULL;
SDL_Surface *level_3B = NULL;
SDL_Surface *creditB = NULL;
//The player suface
SDL_Surface *player = NULL;
//The bullet surface
SDL_Surface *bullet = NULL;
//The enemy surfaces
SDL_Surface *enemy_A = NULL;
SDL_Surface *enemy_B = NULL;
SDL_Surface *enemy_C = NULL;
SDL_Surface *enemy_D = NULL;
//more to be added later...
//The music data types
Mix_Music *introMusic = NULL;
Mix_Music *level_1M = NULL;
Mix_Music *level_2M = NULL;
Mix_Music *level_3M = NULL;
Mix_Music *creditMusic = NULL;
//The soundeffect data types
//soon to be added
//SDL event structure
SDL_Event event;
//Surface for font
TTF_Font *font= NULL;
//The rectangle for the camera to be used
SDL_Rect camera = {0,0,SCREEN_WIDTH,SCREEN_HEIGHT};
//The rectangle for the intro button's
SDL_Rect button_clips[2];
//Dims for the Player
const int PLAYER_WIDTH = 32;
const int PLAYER_HEIGHT = 32;
//Dims for the bullet
const int BULLET_WIDTH = 8;
const int BULLET_HEIGHT = 8;
//Dims for the Enemy_A
const int ENEMY_A_WIDTH = 32;
const int ENEMY_A_HEIGHT =32;
//Dims for the Enemy_B
const int ENEMY_B_WIDTH = 32;
const int ENEMY_B_HEIGHT = 32;
//Dims for the Enemy_C
const int ENEMY_C_WIDTH = 32;
const int ENEMY_C_HEIGHT = 32;
//Dims for the Enemy_D
const int ENEMY_D_WIDTH = 32;
const int ENEMY_D_HEIGHT = 32;
//Dims for level map
const int LEVEL_WIDTH = 640;
const int LEVEL_HEIGHT = 10000;
//******************************************************************
//******************************************************************
//* CLASS DECLARATIONS *
//******************************************************************
//******************************************************************
class Button
{
private:
//The attributes for the button
SDL_Rect box;
//The part of the button sprite sheet that will be shown
SDL_Rect* clip;
public:
Button( int x, int y, int w, int h);
//Handles the events and changes the sprites
void handle_newGame();
void handle_story();
void handle_credits();
void handle_exit();
//Show the button to screen
void show_newGame();
void show_story();
void show_credits();
void show_exit();
};
class Bullet
{
private:
//x and y offsets
int x, y;
//Velocity of x and y
int xVel;
int yVel;
public:
Bullet();
void show_bullet(int x, int y);
};
class Player :public Bullet
{
private:
//x and y offsets
int x, y;
//velocity of x and y
int xVel;
int yVel;
//The life of player
int life;
public:
Player();
void handle_input();
void move();
void show();
void set_camera();
void set_life(int x);
int get_life();
void shoot_bullet();
void halt_fire();
};
class Enemy_A
{
private:
//x and y offsets
int x, y;
//velocity of x and y
int xVel;
int yVel;
public:
Enemy_A();
void move();
void show();
};
class Enemy_B
{
private:
//x and y offsets
int x, y;
//velocity of x and y
int xVel;
int yVel;
public:
Enemy_B();
void move();
void show();
};
class Enemy_C
{
private:
//x and y offsets
int x, y;
//velocity of x and y
int xVel;
int yVel;
public:
Enemy_C();
void move();
void show();
};
class Enemy_D
{
private:
//x and y offsets
int x, y;
//velocity of x and y
int xVel;
int yVel;
public:
Enemy_D();
void move();
void show();
};
//Timer class
class Timer
{
private:
//The clock time when the timer started
int startTicks;
//The ticks stored when the timer was paused
int pausedTicks;
//The timer status
bool paused;
bool started;
public:
//Initializes variables
Timer();
//The various clock actions
void start();
void stop();
void pause();
void unpause();
//Gets the timer's time
int get_ticks();
//Checks the status of the timer
bool is_started();
bool is_paused();
};
//Image loading function
SDL_Surface *load_image( std::string filename )
{
//The image that's loaded
SDL_Surface* loadedImage = NULL;
//The optimized surface that will be used
SDL_Surface* optimizedImage = NULL;
//Load the image
loadedImage = IMG_Load( filename.c_str() );
//If the image loaded
if( loadedImage != NULL )
{
//Create an optimized surface
optimizedImage = SDL_DisplayFormat( loadedImage );
//Free the old surface
SDL_FreeSurface( loadedImage );
//If the surface was optimized
if( optimizedImage != NULL )
{
//Color key surface
SDL_SetColorKey( optimizedImage, SDL_RLEACCEL | SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
}
}
//Return the optimized surface
return optimizedImage;
}
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
//Holds offsets
SDL_Rect offset;
//Get offsets
offset.x = x;
offset.y = y;
//Blit
SDL_BlitSurface( source, clip, 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 );
//If there was in error in setting up the screen
if( screen == NULL )
{
return false;
}
//Initialize SDL_ttf
if( TTF_Init() == -1 )
{
return false;
}
//Initialize SDL_mixer
if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 )
{
return false;
}
//Set the window caption
SDL_WM_SetCaption( "Super Thug", NULL );
//If everything initialized fine
return true;
}
//This loads all necassary files
bool load_files()
{
//Load the backgrounds image
intro_background = load_image( "graphics/intro_background.png" );
company_logo = load_image( "graphics/logo.png" );
level_1B = load_image( "graphics/level_1.png" );
level_2B = load_image( "graphics/level_2.png" );
level_3B = load_image( "graphics/level_3.png" );
creditB = load_image( "graphics/credits.png" );
//If there was a problem in loading the backgrounds
if( intro_background == NULL )
{
return false;
}
if(company_logo == NULL)
{
return false;
}
if( level_1B == NULL )
{
return false;
}
if( level_2B == NULL )
{
return false;
}
if( level_3B == NULL )
{
return false;
}
if( creditB == NULL )
{
return false;
}
//Load the intro buttons images
newGameButton = load_image( "graphics/newgame_button.png" );
storyButton = load_image( "graphics/story_button.png" );
creditsButton = load_image ( "graphics/credits_button.png" );
exitButton = load_image ( "graphics/exit_button.png" );
//Error loading the buttons
if(newGameButton == NULL)
{
return false;
}
if(storyButton == NULL)
{
return false;
}
if(creditsButton == NULL)
{
return false;
}
if(exitButton == NULL)
{
return false;
}
//Load the title gun
title_gun = load_image( "graphics/title_gun.png" );
//Error loading the gun
if(title_gun == NULL)
{
return false;
}
//Load the player stick figure
player = load_image( "graphics/player_1.png" );
//Error loading player
if(player == NULL)
{
return false;
}
//Load the bullet
bullet = load_image( "graphics/bullet.png" );
//Error loading bullet
if(bullet == NULL)
{
return false;
}
//Open the font
font = TTF_OpenFont( "lazy.ttf", 30 );
//If there is a problem in loading the font
if( font == NULL )
{
return false;
}
//Load the music
introMusic = Mix_LoadMUS( "audio/introMusic.ogg" );
level_1M = Mix_LoadMUS( "audio/level1.ogg" );
level_2M = Mix_LoadMUS( "audio/level2.ogg" );
level_3M = Mix_LoadMUS( "audio/level3.ogg" );
creditMusic = Mix_LoadMUS( "audio/credits.ogg" );
//If there was a problem loading the music
if( introMusic == NULL )
{
return false;
}
if( level_1M == NULL )
{
return false;
}
if( level_2M == NULL )
{
return false;
}
if( level_3M == NULL )
{
return false;
}
if( creditMusic == NULL )
{
return false;
}
//Load the sound effects
//will add later
//If everything loaded fine
return true;
}
void clean_up()
{
//Free the screen surface
SDL_FreeSurface(screen);
//Free the background surfaces
SDL_FreeSurface(company_logo);
SDL_FreeSurface(intro_background);
SDL_FreeSurface(level_1B);
SDL_FreeSurface(level_2B);
SDL_FreeSurface(level_3B);
SDL_FreeSurface(creditB);
//Free the intro button surfaces
SDL_FreeSurface(newGameButton);
SDL_FreeSurface(storyButton);
SDL_FreeSurface(creditsButton);
SDL_FreeSurface(exitButton);
//Free the title_gun surface
SDL_FreeSurface(title_gun);
//Free the player surface
SDL_FreeSurface(player);
//Free the sound effects
//Mix_FreeChunk();
//Mix_FreeChunk();
//Mix_FreeChunk();
//Mix_FreeChunk();
//Free the music
Mix_FreeMusic(introMusic);
Mix_FreeMusic(level_1M);
Mix_FreeMusic(level_2M);
Mix_FreeMusic(level_3M);
Mix_FreeMusic(creditMusic);
//Close the font
TTF_CloseFont( font );
//Quit SDL_mixer
Mix_CloseAudio();
//Quit SDL_ttf
TTF_Quit();
//Quit SDL
SDL_Quit();
}
void set_buttonClips()
{
//Clip the sprite sheet
button_clips[ CLIP_MOUSEOVER ].x = 0;
button_clips[ CLIP_MOUSEOVER ].y = 40;
button_clips[ CLIP_MOUSEOVER ].w = 120;
button_clips[ CLIP_MOUSEOVER ].h = 40;
button_clips[ CLIP_MOUSEOUT ].x = 0;
button_clips[ CLIP_MOUSEOUT ].y = 0;
button_clips[ CLIP_MOUSEOUT ].w = 120;
button_clips[ CLIP_MOUSEOUT ].h = 40;
}
//******************************************************************
//******************************************************************
//* CLASS IMPLEMETATIONS *
//******************************************************************
//******************************************************************
Button::Button(int x, int y, int w, int h)
{
box.x = x;
box.y = y;
box.w = w;
box.h = h;
}
void Button::handle_newGame()
{
//The mouse offsets
int x = 0, y = 0;
//If the mouse moved
if( event.type == SDL_MOUSEMOTION )
{
//Get the mouse offsets
x = event.button.x;
y = event.button.y;
//If the mouse is over the button
if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
{
//Set the button sprite
clip = &button_clips[ CLIP_MOUSEOVER ];
}
//If not
else
{
//Set the button sprite
clip = &button_clips[ CLIP_MOUSEOUT ];
}
}
//If a mouse button was pressed
if( event.type == SDL_MOUSEBUTTONDOWN )
{
//If the left mouse button was pressed
if( event.button.button == SDL_BUTTON_LEFT )
{
//Get the mouse offsets
x = event.button.x;
y = event.button.y;
//If the mouse is over the button
if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
{
play_level1();
}
}
}
}
void Button::handle_story()
{
//The mouse offsets
int x = 0, y = 0;
//If the mouse moved
if( event.type == SDL_MOUSEMOTION )
{
//Get the mouse offsets
x = event.button.x;
y = event.button.y;
//If the mouse is over the button
if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
{
//Set the button sprite
clip = &button_clips[ CLIP_MOUSEOVER ];
}
//If not
else
{
//Set the button sprite
clip = &button_clips[ CLIP_MOUSEOUT ];
}
}
//If a mouse button was pressed
if( event.type == SDL_MOUSEBUTTONDOWN )
{
//If the left mouse button was pressed
if( event.button.button == SDL_BUTTON_LEFT )
{
//Get the mouse offsets
x = event.button.x;
y = event.button.y;
//If the mouse is over the button
if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
{
}
}
}
}
void Button::handle_credits()
{
//The mouse offsets
int x = 0, y = 0;
//If the mouse moved
if( event.type == SDL_MOUSEMOTION )
{
//Get the mouse offsets
x = event.button.x;
y = event.button.y;
//If the mouse is over the button
if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
{
//Set the button sprite
clip = &button_clips[ CLIP_MOUSEOVER ];
}
//If not
else
{
//Set the button sprite
clip = &button_clips[ CLIP_MOUSEOUT ];
}
}
//If a mouse button was pressed
if( event.type == SDL_MOUSEBUTTONDOWN )
{
//If the left mouse button was pressed
if( event.button.button == SDL_BUTTON_LEFT )
{
//Get the mouse offsets
x = event.button.x;
y = event.button.y;
//If the mouse is over the button
if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
{
}
}
}
}
void Button::handle_exit()
{
//The mouse offsets
int x = 0, y = 0;
//If the mouse moved
if( event.type == SDL_MOUSEMOTION )
{
//Get the mouse offsets
x = event.button.x;
y = event.button.y;
//If the mouse is over the button
if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
{
//Set the button sprite
clip = &button_clips[ CLIP_MOUSEOVER ];
}
//If not
else
{
//Set the button sprite
clip = &button_clips[ CLIP_MOUSEOUT ];
}
}
//If a mouse button was pressed
if( event.type == SDL_MOUSEBUTTONDOWN )
{
//If the left mouse button was pressed
if( event.button.button == SDL_BUTTON_LEFT )
{
//Get the mouse offsets
x = event.button.x;
y = event.button.y;
//If the mouse is over the button
if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
{
quit = true;
}
}
}
}
void Button::show_newGame()
{
apply_surface(box.x,box.y,newGameButton, screen, clip);
}
void Button::show_story()
{
apply_surface(box.x,box.y,storyButton, screen, clip);
}
void Button::show_credits()
{
apply_surface(box.x,box.y,creditsButton, screen, clip);
}
void Button::show_exit()
{
apply_surface(box.x,box.y,exitButton, screen, clip);
}
//New Bullet constructor
Bullet::Bullet()
{
//int the offsets
x = 0;
y = 0;
//init the velocity
xVel = 0;
yVel = 0;
}
void Bullet::show_bullet(int x, int y)
{
//apply the bullet surface
apply_surface(x, y, bullet, screen);
}
//New Player constructor
Player::Player()
{
//Init the offsets
x = 0;
y = 0;
//Init the velocity
xVel = 0;
yVel = 0;
life = 0;
Bullet myBullet;
}
void Player::shoot_bullet()
{
//If player decides to shoot a bullet, then show it
//Bullet.show_bullet(int x, int y);
}
void Player::set_life(int x)
{
Player::life = x;
}
int Player::get_life()
{
return Player::life;
}
void Player::halt_fire()
{
}
//Handle the input for the player
void Player::handle_input()
{
//If a key was pressed
if( event.type == SDL_KEYDOWN )
{
//Adjust the velocity
switch( event.key.keysym.sym )
{
case SDLK_UP: yVel -= PLAYER_HEIGHT / 3; break;
case SDLK_DOWN: yVel += PLAYER_HEIGHT / 3; break;
case SDLK_LEFT: xVel -= PLAYER_WIDTH / 3; break;
case SDLK_RIGHT: xVel += PLAYER_WIDTH / 3; break;
case SDLK_SPACE: shoot_bullet(); break;
}
}
//If a key was released
else if( event.type == SDL_KEYUP )
{
//Adjust the velocity
switch( event.key.keysym.sym )
{
case SDLK_UP: yVel += PLAYER_HEIGHT / 3; break;
case SDLK_DOWN: yVel -= PLAYER_HEIGHT / 3; break;
case SDLK_LEFT: xVel += PLAYER_WIDTH / 3; break;
case SDLK_RIGHT: xVel -= PLAYER_WIDTH / 3; break;
case SDLK_SPACE: halt_fire(); break;
}
}
}
//Dot move() function
void Player::move()
{
//Move the dot left or right
x += xVel;
//If the dot went too far to the left or right or has collided with the other shapes
if( ( x < 0 ) || ( x + PLAYER_WIDTH > LEVEL_WIDTH ))
{
//Move back
x -= xVel;
}
//Move the dot up or down
y += yVel;
//If the dot went too far up or down or has collided with the other shapes
if( ( y < 0 ) || ( y + PLAYER_HEIGHT > LEVEL_HEIGHT ))
{
//Move back
y -= yVel;
}
}
//dot show(); function
void Player::show()
{
//show the Player
apply_surface(x - camera.x, y - camera.y, player, screen);
}
//For the Player to set the camera above the player
void Player::set_camera()
{
camera.x= (x + PLAYER_WIDTH / 2) - SCREEN_WIDTH / 2;
camera.y= (y + PLAYER_HEIGHT / 2) - SCREEN_HEIGHT / 2;
//keep camera in bounds
if(camera.x < 0)
{
camera.x = 0;
}
if(camera.y < 0)
{
camera.y = 0;
}
if(camera.x > LEVEL_WIDTH - camera.w)
{
camera.x = LEVEL_WIDTH - camera.w;
}
if(camera.y > LEVEL_HEIGHT - camera.h)
{
camera.y = LEVEL_HEIGHT - camera.h;
}
}
//Enemy_A implementations
//New Enemy_A constructor
Enemy_A::Enemy_A()
{
//init the offsets and dims
x = 0;
y = 0;
//int the velocity
xVel = 0;
yVel = 0;
}
//Enemy_A move() function
void Enemy_A::move()
{
//Move the dot left or right
x += xVel;
//If the dot went too far to the left or right or has collided with the other shapes
if( ( x < 0 ) || ( x + ENEMY_A_WIDTH > SCREEN_WIDTH ))
{
//Move back
x -= xVel;
}
//Move the dot up or down
y += yVel;
//If the dot went too far up or down or has collided with the other shapes
if( ( y < 0 ) || ( y + ENEMY_A_HEIGHT > SCREEN_HEIGHT ))
{
//Move back
y -= yVel;
}
}
//Enemy_A show(); function
void Enemy_A::show()
{
//show the Dot
apply_surface(x - camera.x, y - camera.y, enemy_A, screen);
}
//Enemy_B implementations
//Enemy_B constructor
Enemy_B::Enemy_B()
{
//init the offsets and dims
x = 0;
y = 0;
//int the velocity
xVel = 0;
yVel = 0;
}
//Enemy_B move() function
void Enemy_B::move()
{
//Move the dot left or right
x += xVel;
//If the dot went too far to the left or right or has collided with the other shapes
if( ( x < 0 ) || ( x + ENEMY_B_WIDTH > SCREEN_WIDTH ))
{
//Move back
x -= xVel;
}
//Move the dot up or down
y += yVel;
//If the dot went too far up or down or has collided with the other shapes
if( ( y < 0 ) || ( y + ENEMY_B_HEIGHT > SCREEN_HEIGHT ))
{
//Move back
y -= yVel;
}
}
//Enemy_B show(); function
void Enemy_B::show()
{
//show the Dot
apply_surface(x - camera.x, y - camera.y, enemy_B, screen);
}
//Enemy_C implementations
//Enemy_C constructor
Enemy_C::Enemy_C()
{
//init the offsets and dims
x = 0;
y = 0;
//int the velocity
xVel = 0;
yVel = 0;
}
//Enemy_C move() function
void Enemy_C::move()
{
//Move the dot left or right
x += xVel;
//If the dot went too far to the left or right or has collided with the other shapes
if( ( x < 0 ) || ( x + ENEMY_C_WIDTH > SCREEN_WIDTH ))
{
//Move back
x -= xVel;
}
//Move the dot up or down
y += yVel;
//If the dot went too far up or down or has collided with the other shapes
if( ( y < 0 ) || ( y + ENEMY_C_HEIGHT > SCREEN_HEIGHT ))
{
//Move back
y -= yVel;
}
}
//Enemy_C show(); function
void Enemy_C::show()
{
//show the Dot
apply_surface(x - camera.x, y - camera.y, enemy_C, screen);
}
//Enemy_D implementions
//Enemy_D constructor
Enemy_D::Enemy_D()
{
//init the offsets and dims
x = 0;
y = 0;
//int the velocity
xVel = 0;
yVel = 0;
}
//Enemy_D move() function
void Enemy_D::move()
{
//Move the dot left or right
x += xVel;
//If the dot went too far to the left or right or has collided with the other shapes
if( ( x < 0 ) || ( x + ENEMY_D_WIDTH > SCREEN_WIDTH ))
{
//Move back
x -= xVel;
}
//Move the dot up or down
y += yVel;
//If the dot went too far up or down or has collided with the other shapes
if( ( y < 0 ) || ( y + ENEMY_D_HEIGHT > SCREEN_HEIGHT ))
{
//Move back
y -= yVel;
}
}
//dot show(); function
void Enemy_D::show()
{
//show the Dot
apply_surface(x - camera.x, y - camera.y, enemy_D, screen);
}
//Timer implementation
Timer::Timer()
{
//Initialize the variables
startTicks = 0;
pausedTicks = 0;
paused = false;
started = false;
}
void Timer::start()
{
//Start the timer
started = true;
//Unpause the timer
paused = false;
//Get the current clock time
startTicks = SDL_GetTicks();
}
void Timer::stop()
{
//Stop the timer
started = false;
//Unpause the timer
paused = false;
}
void Timer::pause()
{
//If the timer is running and isn't already paused
if( ( started == true ) && ( paused == false ) )
{
//Pause the timer
paused = true;
//Calculate the paused ticks
pausedTicks = SDL_GetTicks() - startTicks;
}
}
void Timer::unpause()
{
//If the timer is paused
if( paused == true )
{
//Unpause the timer
paused = false;
//Reset the starting ticks
startTicks = SDL_GetTicks() - pausedTicks;
//Reset the paused ticks
pausedTicks = 0;
}
}
int Timer::get_ticks()
{
//If the timer is running
if( started == true )
{
//If the timer is paused
if( paused == true )
{
//Return the number of ticks when the the timer was paused
return pausedTicks;
}
else
{
//Return the current time minus the start time
return SDL_GetTicks() - startTicks;
}
}
//If the timer isn't running
return 0;
}
bool Timer::is_started()
{
return started;
}
bool Timer::is_paused()
{
return paused;
}
void show_story()
{
}
void easter_egg()
{
}
void play_level1()
{
apply_surface( 0, 0, level_1B, screen,&camera);
Player newPlayer;
newPlayer.set_life(30);
if(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN: newPlayer.handle_input();
break;
}
}
newPlayer.show();
}
void show_company()
{
//Apply the company logo
apply_surface( 0, 0, company_logo, screen );
}
void show_credits()
{
}
void show_title()
{
apply_surface(0,0,intro_background,screen);
set_buttonClips();
Button newButton (200,200,120,40);
Button storyButton (200,240,120,40);
Button creditsButton(200,280,120,40);
Button exitButton (200,320,120,40);
if(SDL_WaitEvent(&event))
{
newButton.handle_newGame();
storyButton.handle_story();
creditsButton.handle_credits();
exitButton.handle_exit();
if(event.type == SDL_QUIT)
{
//Quit program
quit = true;
}
}
newButton.show_newGame();
storyButton.show_story();
creditsButton.show_credits();
exitButton.show_exit();
}
//******************************************************************
//******************************************************************
//* MAIN FUNCTION *
//******************************************************************
//******************************************************************
int main( int argc, char* args[] )
{
//Frame rate cap timer
Timer fps;
//Game Over flag
bool game_over = false;
//Initialize
if( init() == false )
{
return 1;
}
//Load the files
if( load_files() == false )
{
return 1;
}
//Make the timer
Timer myTimer;
//Make the player
Player newPlayer;
//Make the bullet
Bullet newBullet;
//Start the timer
myTimer.start();
//While the user hasn't quit
while( quit == false )
{
fps.start();
show_company();
if(myTimer.get_ticks() > 800)
{
show_title();
//play_level1();
}
//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;
}
}
//Update the screen
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
//Cap the frame rate with fps
while(fps.get_ticks() < 1000 / FRAMES_PER_SECOND)
{
//wait...
}
}
//Clean up
clean_up();
return 0;
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement