switch(event.type)
{
case SDL_QUIT: /* Quit event - quit: */
- quit = 1;
+ quit = true;
break;
case SDL_KEYDOWN: /* A keypress! */
key = event.key.keysym.sym;
if(!game_pause)
{
if(st_gl_mode == ST_GL_TEST)
- quit = 1;
+ quit = true;
else if(show_menu)
{
Menu::set_current(game_menu);
}
else
{
- level_free_gfx();
+ world->get_level()->free_gfx();
world->get_level()->cleanup();
- level_free_song();
+ world->get_level()->free_song();
unloadshared();
world->arrays_free();
return(0);
if (score > hs_score)
save_hs(score);
}
- level_free_gfx();
+ world->get_level()->free_gfx();
world->get_level()->cleanup();
- level_free_song();
+ world->get_level()->free_song();
unloadshared();
world->arrays_free();
return(0);
world->arrays_free();
activate_bad_guys(world->get_level());
world->activate_particle_systems();
- level_free_gfx();
+
+ world->get_level()->free_gfx();
world->get_level()->load_gfx();
- level_free_song();
+ world->get_level()->free_song();
world->get_level()->load_song();
+
if(st_gl_mode != ST_GL_TEST)
levelintro();
start_timers();
void
GameSession::draw()
{
-
-
world->draw();
-
drawstatus();
if(game_pause)
}
if(show_menu)
- {
- menu_process_current();
- mouse_cursor->draw();
- }
+ {
+ menu_process_current();
+ mouse_cursor->draw();
+ }
- /* (Update it all!) */
updatescreen();
}
current_ = this;
int fps_cnt;
- bool jump;
bool done;
- /* --- MAIN GAME LOOP!!! --- */
- jump = false;
- done = false;
- quit = 0;
global_frame_counter = 0;
game_pause = 0;
timer_init(&fps_timer,true);
{}
draw();
- do
- {
- jump = false;
+ done = false;
+ quit = false;
+ while (!done && !quit)
+ {
/* Calculate the movement-factor */
frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE);
if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */
/* Pause till next frame, if the machine running the game is too fast: */
/* FIXME: Works great for in OpenGl mode, where the CPU doesn't have to do that much. But
the results in SDL mode aren't perfect (thought the 100 FPS are reached), even on an AMD2500+. */
- if(last_update_time >= update_time - 12 && !jump) {
+ if(last_update_time >= update_time - 12) {
SDL_Delay(10);
update_time = st_get_ticks();
}
/*if((update_time - last_update_time) < 10)
SDL_Delay((11 - (update_time - last_update_time))/2);*/
-
-
/* Handle time: */
-
if (timer_check(&time_left))
{
/* are we low on time ? */
else
tux.kill(KILL);
-
/* Calculate frames per second */
if(show_fps)
{
fps_cnt = 0;
}
}
-
}
- while (!done && !quit);
halt_music();
- level_free_gfx();
+ world->get_level()->free_gfx();
world->get_level()->cleanup();
- level_free_song();
+ world->get_level()->free_song();
+
unloadshared();
world->arrays_free();
world->arrays_free();
activate_bad_guys(world->get_level());
world->activate_particle_systems();
- level_free_gfx();
+
+ world->get_level()->free_gfx();
world->get_level()->load_gfx();
- level_free_song();
+ world->get_level()->free_song();
world->get_level()->load_song();
+
levelintro();
update_time = st_get_ticks();
class GameSession
{
private:
+ bool quit;
timer_type fps_timer, frame_timer;
World* world;
using namespace std;
-texture_type img_bkgd;
-
st_subset::st_subset()
{
levels = 0;
badguy_data.clear();
}
-/* Load graphics: */
-
void
Level::load_gfx()
{
- /*
- level_load_image(&img_brick[0],theme,"brick0.png", IGNORE_ALPHA);
- level_load_image(&img_brick[1],theme,"brick1.png", IGNORE_ALPHA);
-
- level_load_image(&img_solid[0],theme,"solid0.png", USE_ALPHA);
- level_load_image(&img_solid[1],theme,"solid1.png", USE_ALPHA);
- level_load_image(&img_solid[2],theme,"solid2.png", USE_ALPHA);
- level_load_image(&img_solid[3],theme,"solid3.png", USE_ALPHA);
-
- level_load_image(&img_bkgd_tile[0][0],theme,"bkgd-00.png", USE_ALPHA);
- level_load_image(&img_bkgd_tile[0][1],theme,"bkgd-01.png", USE_ALPHA);
- level_load_image(&img_bkgd_tile[0][2],theme,"bkgd-02.png", USE_ALPHA);
- level_load_image(&img_bkgd_tile[0][3],theme,"bkgd-03.png", USE_ALPHA);
-
- level_load_image(&img_bkgd_tile[1][0],theme,"bkgd-10.png", USE_ALPHA);
- level_load_image(&img_bkgd_tile[1][1],theme,"bkgd-11.png", USE_ALPHA);
- level_load_image(&img_bkgd_tile[1][2],theme,"bkgd-12.png", USE_ALPHA);
- level_load_image(&img_bkgd_tile[1][3],theme,"bkgd-13.png", USE_ALPHA);
- */
if(!bkgd_image.empty())
{
char fname[1024];
}
else
{
- /* Quick hack to make sure an image is loaded, when we are freeing it afterwards. */#
- level_load_image(&img_bkgd, theme,"solid0.png", IGNORE_ALPHA);
+ /* Quick hack to make sure an image is loaded, when we are freeing it afterwards. */
+ load_image(&img_bkgd, theme,"solid0.png", IGNORE_ALPHA);
}
}
-/* Free graphics data for this level: */
-void level_free_gfx(void)
+void
+Level::free_gfx()
{
texture_free(&img_bkgd);
}
/* Load a level-specific graphic... */
-
-void level_load_image(texture_type* ptexture, string theme,const char * file, int use_alpha)
+void
+Level::load_image(texture_type* ptexture, string theme,const char * file, int use_alpha)
{
char fname[1024];
}
}
-/* Free music data for this level: */
-
-void level_free_song(void)
+void
+Level::free_song(void)
{
free_music(level_song);
free_music(level_song_fast);
}
-/* Load music: */
-
void
Level::load_song()
{
strlen(song_title.c_str()) + 8 + 5);
song_subtitle = strdup(song_title.c_str());
strcpy(strstr(song_subtitle, "."), "\0");
- sprintf(song_path, "%s/music/%s-fast%s", datadir.c_str(), song_subtitle, strstr(song_title.c_str(), "."));
+ sprintf(song_path, "%s/music/%s-fast%s", datadir.c_str(),
+ song_subtitle, strstr(song_title.c_str(), "."));
level_song_fast = ::load_song(song_path);
free(song_subtitle);
free(song_path);
TM_FG
};
-extern texture_type img_bkgd;
-
class Level
{
public:
+ texture_type img_bkgd;
+
std::string name;
std::string theme;
std::string song_title;
int load(const std::string& filename);
void load_gfx();
+
void load_song();
+ void free_song();
void save(const char* subset, int level);
/** Return the id of the tile at position x/y */
unsigned int gettileid(float x, float y);
+
+ void free_gfx();
+
+ void load_image(texture_type* ptexture, std::string theme, const char * file, int use_alpha);
};
-void level_load_image(texture_type* ptexture, std::string theme, const char * file, int use_alpha);
-void level_free_song();
-void level_free_gfx();
#endif /*SUPERTUX_LEVEL_H*/
if(i)
{
- level_free_gfx();
+ le_current_level->free_gfx();
le_current_level->load_gfx();
}
le_set_defaults();
-
- level_free_gfx();
+ le_current_level->free_gfx();
le_current_level->load_gfx();
+
activate_bad_guys(le_current_level);
}
if(le_current_level != NULL)
{
- level_free_gfx();
+ le_current_level->free_gfx();
le_current_level->cleanup();
unloadshared();
world.arrays_free();
if(le_current_level->bkgd_image[0] != '\0')
{
s = pos_x / 30;
- texture_draw_part(&img_bkgd,s,0,0,0,img_bkgd.w - s - 32, img_bkgd.h);
- texture_draw_part(&img_bkgd,0,0,screen->w - s - 32 ,0,s,img_bkgd.h);
+ texture_draw_part(&le_current_level->img_bkgd,s,0,0,0,
+ le_current_level->img_bkgd.w - s - 32, le_current_level->img_bkgd.h);
+ texture_draw_part(&le_current_level->img_bkgd,0,0,screen->w - s - 32 ,0,s,
+ le_current_level->img_bkgd.h);
}
else
{
int level;
int next_level;
int game_pause;
-bool quit;
int score_multiplier;
int endpos;
bool counting_distros;
extern int level;
extern int next_level;
extern int game_pause;
-extern bool quit;
extern int score_multiplier;
extern int endpos;
extern bool counting_distros;
int main(int argc, char * argv[])
{
- int done;
+ bool done;
st_directory_setup();
parseargs(argc, argv);
}
else
{
- done = 0;
-
+ done = false;
while (!done)
{
done = title();
st_shutdown();
- return(0);
+ return 0;
}
/* --- TITLE SCREEN --- */
-int title(void)
+bool title(void)
{
- int done;
string_list_type level_subsets;
st_subset subset;
level_subsets = dsubdirs("/levels", "info");
texture_load(&img_choose_subset,datadir + "/images/status/choose-level-subset.png", USE_ALPHA);
/* --- Main title loop: --- */
-
- done = 0;
- quit = 0;
+ bool done = 0;
show_menu = 1;
frame = 0;
update_time = st_get_ticks();
timer_start(&random_timer, rand() % 2000 + 2000);
- while (!done && !quit)
+ while (!done)
{
-
/* Calculate the movement-factor */
frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE);
if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */
menu_event(event);
if (event.type == SDL_QUIT)
{
- /* Quit event - quit: */
- quit = 1;
+ done = true;
}
else if (event.type == SDL_KEYDOWN)
{
/* Keypress... */
-
key = event.key.keysym.sym;
/* Check for menu events */
if (key == SDLK_ESCAPE)
{
/* Escape: Quit: */
-
- quit = 1;
+ done = true;
}
}
}
*/
/* Don't draw menu, if quit is true */
- if(show_menu && !quit)
+ if(show_menu && !done)
menu_process_current();
if(current_menu == main_menu)
switch(event.type)
{
case SDL_QUIT:
- done = 1;
- quit = 1;
+ done = true;
break;
case SDL_KEYDOWN: // key pressed
// Keypress...
break;
case 3:
done = 1;
- quit = leveleditor(1);
+ done = leveleditor(1);
break;
case 4:
display_credits();
break;
case 5:
- quit = 1;
+ done = true;
break;
}
}
string_list_free(&level_subsets);
/* Return to main! */
-
- return(quit);
+ return done;
}
#define MAX_VEL 10
April 11, 2000 - March 15, 2004
*/
-int title(void);
+bool title(void);
#include "screen.h"
#include "defines.h"
#include "world.h"
+#include "level.h"
#include "tile.h"
texture_type img_distro[4];
if(get_level()->bkgd_image[0] != '\0')
{
int s = (int)scroll_x / 30;
- texture_draw_part(&img_bkgd,s,0,0,0,img_bkgd.w - s, img_bkgd.h);
- texture_draw_part(&img_bkgd,0,0,screen->w - s ,0,s,img_bkgd.h);
+ texture_draw_part(&level->img_bkgd, s, 0,0,0,level->img_bkgd.w - s, level->img_bkgd.h);
+ texture_draw_part(&level->img_bkgd, 0, 0,screen->w - s ,0,s,level->img_bkgd.h);
}
else
{
else
{
s = (int)scroll_x / 30;
- texture_draw_part(&img_bkgd,dest.x + s,dest.y,dest.x,dest.y,dest.w,dest.h);
+ texture_draw_part(&plevel->img_bkgd, dest.x + s, dest.y,
+ dest.x, dest.y,dest.w,dest.h);
}
drawshape(pbouncy_brick->base.x - scroll_x,