time_left.init(true);
start_timers();
-
- if(st_gl_mode == ST_GL_LOAD_GAME)
- loadgame(levelnb);
}
GameSession::~GameSession()
void
GameSession::levelintro(void)
{
- Player& tux = *world->get_tux();
-
char str[60];
/* Level Intro: */
clearscreen(0, 0, 0);
sprintf(str, "by %s", world->get_level()->author.c_str());
red_text->drawf(str, 0, 256, A_HMIDDLE, A_TOP, 1);
- sprintf(str, "TUX x %d", tux.lives);
+ sprintf(str, "TUX x %d", player_status.lives);
white_text->drawf(str, 0, 288, A_HMIDDLE, A_TOP, 1);
flipscreen();
break;
case SDLK_l:
if(debug_mode)
- --tux.lives;
+ --player_status.lives;
break;
case SDLK_s:
if(debug_mode)
/* No more lives!? */
- if (tux.lives < 0)
+ if (player_status.lives < 0)
{
if(st_gl_mode != ST_GL_TEST)
drawendscreen();
{
process_options_menu();
}
- else if(current_menu == save_game_menu )
- {
- process_save_game_menu();
- }
else if(current_menu == load_game_menu )
{
process_load_game_menu();
void
GameSession::drawstatus()
{
- Player& tux = *world->get_tux();
char str[60];
sprintf(str, "%d", player_status.score);
gold_text->draw(str, screen->h + 60, 40, 1);
}
- for(int i= 0; i < tux.lives; ++i)
+ for(int i= 0; i < player_status.lives; ++i)
{
tux_life->draw(565+(18*i),20);
}
sprintf(str, "SCORE: %d", player_status.score);
gold_text->drawf(str, 0, 224, A_HMIDDLE, A_TOP, 1);
- sprintf(str, "DISTROS: %d", player_status.distros);
+ sprintf(str, "COINS: %d", player_status.distros);
gold_text->drawf(str, 0, 256, A_HMIDDLE, A_TOP, 1);
flipscreen();
wait_for_event(event,2000,5000,true);
}
-void
-GameSession::savegame(int)
-{
-#if 0
- char savefile[1024];
- FILE* fi;
- unsigned int ui;
-
- sprintf(savefile,"%s/slot%d.save",st_save_dir,slot);
-
- fi = fopen(savefile, "wb");
-
- if (fi == NULL)
- {
- fprintf(stderr, "Warning: I could not open the slot file ");
- }
- else
- {
- fputs(level_subset, fi);
- fputs("\n", fi);
- fwrite(&level,sizeof(int),1,fi);
- fwrite(&score,sizeof(int),1,fi);
- fwrite(&distros,sizeof(int),1,fi);
- fwrite(&scroll_x,sizeof(float),1,fi);
- //FIXME:fwrite(&tux,sizeof(Player),1,fi);
- //FIXME:timer_fwrite(&tux.invincible_timer,fi);
- //FIXME:timer_fwrite(&tux.skidding_timer,fi);
- //FIXME:timer_fwrite(&tux.safe_timer,fi);
- //FIXME:timer_fwrite(&tux.frame_timer,fi);
- timer_fwrite(&time_left,fi);
- ui = st_get_ticks();
- fwrite(&ui,sizeof(int),1,fi);
- }
- fclose(fi);
-#endif
-}
-
-void
-GameSession::loadgame(int)
-{
-#if 0
- char savefile[1024];
- char str[100];
- FILE* fi;
- unsigned int ui;
-
- sprintf(savefile,"%s/slot%d.save",st_save_dir,slot);
-
- fi = fopen(savefile, "rb");
-
- if (fi == NULL)
- {
- fprintf(stderr, "Warning: I could not open the slot file ");
-
- }
- else
- {
- fgets(str, 100, fi);
- strcpy(level_subset, str);
- level_subset[strlen(level_subset)-1] = '\0';
- fread(&level,sizeof(int),1,fi);
-
- world->set_defaults();
- world->get_level()->cleanup();
- world->arrays_free();
- world->get_level()->free_gfx();
- world->get_level()->free_song();
-
- if(world->get_level()->load(level_subset,level) != 0)
- exit(1);
-
- world->activate_bad_guys();
- world->activate_particle_systems();
- world->get_level()->load_gfx();
- world->get_level()->load_song();
-
- levelintro();
- update_time = st_get_ticks();
-
- fread(&score, sizeof(int),1,fi);
- fread(&distros, sizeof(int),1,fi);
- fread(&scroll_x,sizeof(float),1,fi);
- //FIXME:fread(&tux, sizeof(Player), 1, fi);
- //FIXME:timer_fread(&tux.invincible_timer,fi);
- //FIXME:timer_fread(&tux.skidding_timer,fi);
- //FIXME:timer_fread(&tux.safe_timer,fi);
- //FIXME:timer_fread(&tux.frame_timer,fi);
- timer_fread(&time_left,fi);
- fread(&ui,sizeof(int),1,fi);
- fclose(fi);
- }
-#endif
-}
-
std::string slotinfo(int slot)
{
FILE* fi;
Level* get_level() { return world->get_level(); }
World* get_world() { return world; }
- void savegame(int slot);
- void loadgame(int slot);
-
static GameSession* current() { return current_; }
private:
static GameSession* current_;
frame_main = 0;
frame_ = 0;
- lives = 3;
- score = 0;
- distros = 0;
-
+
player_input_init(&input);
keymap.jump = SDLK_UP;
}
/* Enough distros for a One-up? */
- if (distros >= DISTROS_LIFEUP)
+ if (player_status.distros >= DISTROS_LIFEUP)
{
- distros = distros - DISTROS_LIFEUP;
- if(lives < MAX_LIVES)
- lives++;
+ player_status.distros = player_status.distros - DISTROS_LIFEUP;
+ if(player_status.lives < MAX_LIVES)
+ ++player_status.lives;
/*We want to hear the sound even, if MAX_LIVES is reached*/
play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER);
}
}
}
- if(dying)
- gold_text->drawf("Penguins can fly !:",0,0,A_HMIDDLE,A_VMIDDLE,1);
-
if (debug_mode)
fillrect(base.x - scroll_x, base.y, 32, 32, 75,75,75, 150);
}
{
/* He died :^( */
- --lives;
+ --player_status.lives;
remove_powerups();
dying = DYING_NOT;
}
{
public:
player_keymap_type keymap;
- int lives;
- int score;
- int distros;
player_input_type input;
bool got_coffee;
PlayerStatus player_status;
+PlayerStatus::PlayerStatus()
+ : score(0),
+ distros(0),
+ lives(3)
+{
+}
+
// FIXME: Move this into a view class
float scroll_x;
{
int score;
int distros;
+ int lives;
+
int next_level;
int score_multiplier;
+
+ PlayerStatus();
};
extern PlayerStatus player_status;
#include "gameloop.h"
#include "configfile.h"
#include "scene.h"
+#include "worldmap.h"
#ifdef WIN32
#define mkdir(dir, mode) mkdir(dir)
}
}
-void process_save_game_menu()
-{
- int slot = save_game_menu->check();
- if (slot != -1)
- GameSession::current()->savegame(slot - 1);
-}
-
bool process_load_game_menu()
{
int slot = load_game_menu->check();
if (tmp.length() == strlen("Slot X - Free"))
{ // Slot is free, so start a new game
- GameSession session("default", 1, ST_GL_PLAY);
- session.run();
-
+ worldmap_run();
+
show_menu = true;
Menu::set_current(main_menu);
}
else
{
puts("Warning: Loading games isn't supported at the moment");
-#if 0
- // Slot contains a level, so load it
- if (game_started)
- {
- GameSession session("default",slot - 1,ST_GL_LOAD_GAME);
- session.run();
-
- show_menu = true;
- Menu::set_current(main_menu);
- }
- else
- {
- //loadgame(slot - 1);
- }
-#endif
}
st_pause_ticks_stop();
return true;
void st_abort(const std::string& reason, const std::string& details);
void process_options_menu(void);
-void process_save_game_menu();
-
/** Return true if the gameloop() was entered, false otherwise */
bool process_load_game_menu();
}
else if (kind == UPGRADE_1UP)
{
- if(pplayer->lives < MAX_LIVES) {
- pplayer->lives++;
+ if(player_status.lives < MAX_LIVES) {
+ player_status.lives++;
play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER);
}
}
Text(const std::string& file, int kind, int w, int h);
~Text();
- void draw(const char* text, int x, int y, int shadowsize, int update = NO_UPDATE);
+ void draw(const char* text, int x, int y, int shadowsize = 1, int update = NO_UPDATE);
void draw_chars(Surface* pchars, const char* text, int x, int y, int update = NO_UPDATE);
void drawf(const char* text, int x, int y, TextHAlign halign, TextVAlign valign, int shadowsize, int update = NO_UPDATE);
- void draw_align(const char* text, int x, int y, TextHAlign halign, TextVAlign valign, int shadowsize, int update = NO_UPDATE);
+ void draw_align(const char* text, int x, int y, TextHAlign halign, TextVAlign valign, int shadowsize = 1, int update = NO_UPDATE);
void erasetext(const char * text, int x, int y, Surface* surf, int update, int shadowsize);
void erasecenteredtext(const char * text, int y, Surface* surf, int update, int shadowsize);
};
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <iostream>
+#include <fstream>
#include <vector>
#include <assert.h>
#include "globals.h"
{
Level level;
LispReader reader(lisp_cdr(element));
+ level.solved = false;
reader.read_string("name", &level.name);
reader.read_int("x", &level.x);
reader.read_int("y", &level.y);
{
std::cout << "Enter the current level: " << i->name << std::endl;;
halt_music();
- GameSession session(datadir + "levels/default/" + i->name,
+ GameSession session(datadir + "levels/" + i->name,
1, ST_GL_LOAD_LEVEL_FILE);
session.run();
+
+ if (1) // FIXME: insert exit status checker here
+ i->solved = true;
+
play_music(song, 1);
+ show_menu = 0;
+ menu_reset();
+ savegame(std::string(st_save_dir) + "/slot1.stsg");
return;
}
}
}
tux->draw(offset);
+ draw_status();
+}
+
+void
+WorldMap::draw_status()
+{
+ char str[80];
+ sprintf(str, "%d", player_status.score);
+ white_text->draw("SCORE", 0, 0);
+ gold_text->draw(str, 96, 0);
+
+ sprintf(str, "%d", player_status.distros);
+ white_text->draw_align("COINS", 320-64, 0, A_LEFT, A_TOP);
+ gold_text->draw_align(str, 320+64, 0, A_RIGHT, A_TOP);
+
+ white_text->draw("LIVES", 480, 0);
+ if (player_status.lives >= 5)
+ {
+ sprintf(str, "%dx", player_status.lives);
+ gold_text->draw(str, 585, 0);
+ tux_life->draw(565+(18*3), 0);
+ }
+ else
+ {
+ for(int i= 0; i < player_status.lives; ++i)
+ tux_life->draw(565+(18*i),0);
+ }
+
+ if (!tux->is_moving())
+ {
+ for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
+ {
+ if (i->x == tux->get_tile_pos().x &&
+ i->y == tux->get_tile_pos().y)
+ {
+ white_text->draw_align(i->name.c_str(), screen->w/2, screen->h, A_HMIDDLE, A_BOTTOM);
+ break;
+ }
+ }
+ }
}
void
WorldMap::display()
{
+ show_menu = 0;
+ menu_reset();
+
quit = false;
song = load_song(datadir + "/music/" + music);
free_music(song);
}
+void
+WorldMap::savegame(const std::string& filename)
+{
+ std::ofstream out(filename.c_str());
+
+ out << "(supertux-savegame\n"
+ << " (version 1)\n"
+ << " (lives " << player_status.lives << ")\n"
+ << " (score " << player_status.score << ")\n"
+ << " (distros " << player_status.distros << ")\n"
+ << " (tux (x " << tux->get_tile_pos().x << ") (y " << tux->get_tile_pos().y << ")\n"
+ << " (levels\n";
+
+ for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
+ {
+ if (i->solved)
+ {
+ out << " (level (name \"" << i->name << "\")\n"
+ << " (solved #t))\n";
+ }
+ }
+
+ out << " )\n"
+ << " )\n\n;; EOF ;;" << std::endl;
+}
+
} // namespace WorldMapNS
void worldmap_run()
int x;
int y;
std::string name;
+ bool solved;
};
typedef std::vector<Level> Levels;
bool enter_level;
Point offset;
+
+ void draw_status();
public:
WorldMap();
~WorldMap();
/** Check if it is possible to walk from \a pos into \a direction,
if possible, write the new position to \a new_pos */
bool path_ok(Direction direction, Point pos, Point* new_pos);
+
+ void savegame(const std::string& filename);
};
} // namespace WorldMapNS