#include <SDL_image.h>
#include <physfs.h>
-#include "title.h"
-#include "video/screen.h"
-#include "video/surface.h"
-#include "gui/menu.h"
-#include "timer.h"
-#include "lisp/lisp.h"
-#include "lisp/parser.h"
-#include "level.h"
-#include "level_subset.h"
-#include "game_session.h"
-#include "worldmap.h"
-#include "leveleditor.h"
-#include "player_status.h"
-#include "tile.h"
-#include "sector.h"
-#include "object/tilemap.h"
-#include "object/camera.h"
-#include "object/player.h"
-#include "resources.h"
-#include "gettext.h"
-#include "misc.h"
-#include "textscroller.h"
-#include "file_system.h"
-#include "control/joystickkeyboardcontroller.h"
-#include "control/codecontroller.h"
-#include "main.h"
+#include "title.hpp"
+#include "video/screen.hpp"
+#include "video/surface.hpp"
+#include "audio/sound_manager.hpp"
+#include "gui/menu.hpp"
+#include "timer.hpp"
+#include "lisp/lisp.hpp"
+#include "lisp/parser.hpp"
+#include "level.hpp"
+#include "level_subset.hpp"
+#include "game_session.hpp"
+#include "worldmap.hpp"
+#include "player_status.hpp"
+#include "tile.hpp"
+#include "sector.hpp"
+#include "object/tilemap.hpp"
+#include "object/camera.hpp"
+#include "object/player.hpp"
+#include "resources.hpp"
+#include "gettext.hpp"
+#include "misc.hpp"
+#include "textscroller.hpp"
+#include "file_system.hpp"
+#include "control/joystickkeyboardcontroller.hpp"
+#include "control/codecontroller.hpp"
+#include "main.hpp"
+#include "exceptions.hpp"
+#include "msg.hpp"
static Surface* bkg_title;
static Surface* logo;
//static Surface* img_choose_subset;
-static bool walking;
-static Timer random_timer;
-
static int frame;
static GameSession* titlesession;
*/
void resume_demo()
{
- player_status.reset();
+ player_status->reset();
titlesession->get_current_sector()->activate("main");
titlesession->set_current();
void update_load_save_game_menu(Menu* menu)
{
- printf("update loadsavemenu.\n");
+ msg_debug("update loadsavemenu");
for(int i = 1; i < 6; ++i) {
MenuItem& item = menu->get_item_by_id(i);
item.kind = MN_ACTION;
contrib_subsets.push_back(subset.release());
} catch(std::exception& e) {
#ifdef DEBUG
- std::cerr << "Couldn't parse levelset info for '"
- << *it << "': " << e.what() << "\n";
+ msg_warning("Couldn't parse levelset info for '"
+ << *it << "': " << e.what() << "");
#endif
}
}
level->get("name", name);
return name;
} catch(std::exception& e) {
- std::cerr << "Problem getting name of '" << filename << "'.\n";
+ msg_warning("Problem getting name of '" << filename << "'.");
return "";
}
}
if(subset.has_worldmap) {
WorldMapNS::WorldMap worldmap;
worldmap.set_map_filename(subset.get_worldmap_filename());
+ sound_manager->stop_music();
// some fading
fadeout(256);
int index = contrib_subset_menu->check();
if (index != -1) {
if (contrib_subset_menu->get_item_by_id(index).kind == MN_ACTION) {
+ sound_manager->stop_music();
GameSession session(
current_contrib_subset->get_level_filename(index), ST_GL_PLAY);
session.run();
- player_status.reset();
+ player_status->reset();
Menu::set_current(main_menu);
resume_demo();
}
void draw_demo(float elapsed_time)
{
+ static Timer randomWaitTimer;
+ static Timer jumpPushTimer;
+ static Timer jumpRecoverTimer;
static float last_tux_x_pos = -1;
static float last_tux_y_pos = -1;
+
Sector* sector = titlesession->get_current_sector();
Player* tux = sector->player;
controller->update();
controller->press(Controller::RIGHT);
+
+ // Determine how far we moved since last frame
+ float dx = fabsf(last_tux_x_pos - tux->get_pos().x);
+ float dy = fabsf(last_tux_y_pos - tux->get_pos().y);
+
+ // Calculate space to check for obstacles
+ Rect lookahead = Rect(tux->get_bbox());
+ lookahead.move(Vector(lookahead.get_width()*2,0));
- if(random_timer.check() ||
- (walking && fabsf(last_tux_x_pos - tux->get_pos().x)) < .1) {
- walking = false;
- } else {
- if(!walking && fabsf(tux->get_pos().y - last_tux_y_pos) < .1) {
- random_timer.start(float(rand() % 3000 + 3000) / 1000.);
- walking = true;
- }
+ // Check if we should press the jump button
+ bool randomJump = !randomWaitTimer.started();
+ bool mayJump = !jumpRecoverTimer.started();
+ bool notMoving = (dx+dy < 0.1);
+ bool pathBlocked = !sector->is_free_space(lookahead);
+ if ((notMoving || pathBlocked || randomJump) && mayJump) {
+ float jumpDuration = float(rand() % 200 + 500) / 1000.0;
+ jumpPushTimer.start(jumpDuration);
+ jumpRecoverTimer.start(jumpDuration+0.1);
+ randomWaitTimer.start(float(rand() % 3000 + 3000) / 1000.0);
}
- if(!walking)
- controller->press(Controller::JUMP);
+
+ // Keep jump button pressed
+ if (jumpPushTimer.started()) controller->press(Controller::JUMP);
+
+ // Remember last position, so we can determine if we moved
last_tux_x_pos = tux->get_pos().x;
last_tux_y_pos = tux->get_pos().y;
/* --- TITLE SCREEN --- */
void title()
{
- walking = true;
//LevelEditor* leveleditor;
- MusicRef credits_music;
controller = new CodeController();
titlesession = new GameSession("levels/misc/menu.stl", ST_GL_DEMO_GAME);
/* Load images: */
- bkg_title = new Surface("images/background/arctis.jpg", false);
- logo = new Surface("images/engine/menu/logo.png", true);
- //img_choose_subset = new Surface("images/status/choose-level-subset.png", true);
+ bkg_title = new Surface("images/background/arctis.jpg");
+ logo = new Surface("images/engine/menu/logo.png");
+ //img_choose_subset = new Surface("images/status/choose-level-subset.png");
titlesession->get_current_sector()->activate("main");
titlesession->set_current();
/* --- Main title loop: --- */
frame = 0;
- random_timer.start(float(rand() % 2000 + 2000) / 1000.0);
-
Uint32 lastticks = SDL_GetTicks();
Menu::set_current(main_menu);
// Calculate the movement-factor
Uint32 ticks = SDL_GetTicks();
float elapsed_time = float(ticks - lastticks) / 1000.;
- global_time += elapsed_time;
+ game_time += elapsed_time;
lastticks = ticks;
// 40fps is minimum
if(elapsed_time > .04)
}
main_controller->process_event(event);
if (event.type == SDL_QUIT)
- throw std::runtime_error("Received window close");
+ throw graceful_shutdown();
}
/* Draw the background: */
draw_demo(elapsed_time);
if (Menu::current() == main_menu)
- context.draw_surface(logo, Vector(SCREEN_WIDTH/2 - logo->w/2, 30),
+ context.draw_surface(logo, Vector(SCREEN_WIDTH/2 - logo->get_width()/2, 30),
LAYER_FOREGROUND1+1);
context.draw_text(white_small_text, " SuperTux " PACKAGE_VERSION "\n",
Vector(0, SCREEN_HEIGHT - 50), LEFT_ALLIGN, LAYER_FOREGROUND1);
context.draw_text(white_small_text,
_(
-"Copyright (c) 2005 SuperTux Devel Team\n"
+"Copyright (c) 2006 SuperTux Devel Team\n"
"This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to\n"
"redistribute it under certain conditions; see the file COPYING for details.\n"
),
// Contrib Menu
generate_contrib_menu();
break;
-#if 0
- case MNID_LEVELEDITOR: {
- LevelEdtiro* leveleditor = new LevelEditor();
- leveleditor->run();
- delete leveleditor;
- Menu::set_current(main_menu);
- resume_demo();
- break;
- }
-#endif
case MNID_CREDITS:
+ sound_manager->stop_music();
fadeout(500);
- credits_music = sound_manager->load_music(
- "/music/credits.ogg");
- sound_manager->play_music(credits_music);
+ sound_manager->play_music("music/credits.ogg");
display_text_file("credits.txt");
+ sound_manager->stop_music();
fadeout(500);
Menu::set_current(main_menu);
break;
if(confirm_dialog(bkg_title, str.c_str())) {
str = "save/slot" + stream.str() + ".stsg";
- printf("Removing: %s\n",str.c_str());
+ msg_debug("Removing: " << str);
PHYSFS_delete(str.c_str());
}
}
context.do_drawing();
+ sound_manager->update();
//frame_rate.update();