## Add lots of dependencies to compiler switches
+SET(Boost_ADDITIONAL_VERSIONS "1.41" "1.41.0")
FIND_PACKAGE(Boost REQUIRED)
-INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
+INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIR})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
FIND_PACKAGE(SDL REQUIRED)
OPTION(WERROR "Stop on first compiler warning" OFF)
OPTION(WARNINGS "Enable long list of warnings for compiler to check" ON)
IF(CMAKE_COMPILER_IS_GNUCC)
- SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
- SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
- SET(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_DEBUG} -pg")
- SET(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_DEBUG} -pg")
- SET(CMAKE_LD_FLAGS_PROFILE "${CMAKE_LD_FLAGS_DEBUG} -pg")
+ SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g" CACHE STRING "Debug flags")
+ SET(CMAKE_C_FLAGS_DEBUG "-O0 -g" CACHE STRING "Debug flags")
+ SET(CMAKE_CXX_FLAGS_PROFILE "-pg" CACHE STRING "Profile flags")
+ SET(CMAKE_C_FLAGS_PROFILE "-pg" CACHE STRING "Profile flags")
+ SET(CMAKE_LD_FLAGS_PROFILE "-lgmon" CACHE STRING "Profile flags")
ADD_DEFINITIONS(-Wall -Wextra -funit-at-a-time)
IF(WERROR)
ADD_DEFINITIONS(-Werror)
ENDIF(WERROR)
IF(WARNINGS)
ADD_DEFINITIONS(-fdiagnostics-show-option -pedantic -Wno-long-long -Wcast-align -Wdisabled-optimization -Winit-self -Winvalid-pch -Wlogical-op -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wredundant-decls -Wstack-protector)
- SET(CMAKE_CXX_FLAGS "-Weffc++ -Wabi -Wctor-dtor-privacy -Wstrict-null-sentinel ${CMAKE_CXX_FLAGS}")
+ SET(CMAKE_CXX_FLAGS "-Weffc++ -Wabi -Wctor-dtor-privacy -Wstrict-null-sentinel" CACHE STRING "CXX Flags")
# -ansi fails in MinGW
# still left: -Wold-style-cast -Wpadded -Wconversion -Wundef -Wsign-conversion -Wshadow -Winline -Wunsafe-loop-optimizations -Wfloat-equal -Wswitch-default -Wswitch-enum -Wcast-qual -Wsign-promo -Woverloaded-virtual -Wmissing-format-attribute -Wstrict-overflow=5 -Wformat=2
ENDIF(WARNINGS)
(hitbox 2 3 31.8 31.8)
(mirror-action "left"))
- (action (name "falling-left")
- (hitbox 2 3 31.8 31.8)
- (images "snowsnail_flip1.png"
- "snowsnail_flip2.png"
- "snowsnail_flip3.png"
- "snowsnail_flip4.png"
- "snowsnail_flip5.png"
- "snowsnail_flip6.png"
- "snowsnail_flip7.png"
- ))
-
- (action (name "falling-right")
- (hitbox 2 3 31.8 31.8)
- (mirror-action "falling-left"))
-
(action (name "flat-left")
+ (anim-fps 64.0)
(hitbox 2 3 31.8 31.8)
- (images "snowsnail_flip1.png"
- "snowsnail_flip2.png"
- "snowsnail_flip3.png"
- "snowsnail_flip4.png"
- "snowsnail_flip5.png"
- "snowsnail_flip6.png"
- "snowsnail_flip7.png"
+ (images
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip5.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip6.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip7.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip1.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip2.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip3.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
+"snowsnail_flip4.png"
))
(action (name "flat-right")
(hitbox 2 3 31.8 31.8)
- (mirror-action "falling-left")))
+ (mirror-action "flat-left")))
{
}
+ virtual void set_relative(bool )
+ {
+ }
+
virtual void set_gain(float )
{
}
{
}
- virtual void set_rollof_factor(float )
- {
- }
-
private:
bool is_playing;
};
}
void
+OpenALSoundSource::set_relative(bool relative)
+{
+ alSourcei(source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
+}
+
+void
OpenALSoundSource::set_position(const Vector& position)
{
alSource3f(source, AL_POSITION, position.x, position.y, 0);
alSourcef(source, AL_REFERENCE_DISTANCE, distance);
}
-void
-OpenALSoundSource::set_rollof_factor(float factor)
-{
- alSourcef(source, AL_ROLLOFF_FACTOR, factor);
-}
-
/* EOF */
virtual void update();
virtual void set_looping(bool looping);
+ virtual void set_relative(bool relative);
virtual void set_gain(float gain);
virtual void set_pitch(float pitch);
virtual void set_position(const Vector& position);
virtual void set_velocity(const Vector& position);
virtual void set_reference_distance(float distance);
- virtual void set_rollof_factor(float factor);
protected:
friend class SoundManager;
OpenALSoundSource*
SoundManager::intern_create_sound_source(const std::string& filename)
{
- if(!sound_enabled)
- throw std::runtime_error("sound disabled");
+ assert(sound_enabled);
std::auto_ptr<OpenALSoundSource> source (new OpenALSoundSource());
std::auto_ptr<OpenALSoundSource> source
(intern_create_sound_source(filename));
- if(pos == Vector(-1, -1)) {
- source->set_rollof_factor(0);
+ if(pos.x < 0 || pos.y < 0) {
+ source->set_relative(true);
} else {
source->set_position(pos);
}
try {
std::auto_ptr<StreamSoundSource> newmusic (new StreamSoundSource());
- alSourcef(newmusic->source, AL_ROLLOFF_FACTOR, 0);
newmusic->set_sound_file(load_sound_file(filename));
newmusic->set_looping(true);
+ newmusic->set_relative(true);
if(fade)
newmusic->set_fading(StreamSoundSource::FadingOn, .5f);
newmusic->play();
virtual bool playing() = 0;
virtual void set_looping(bool looping) = 0;
+ virtual void set_relative(bool relative) = 0;
/// Set volume (0.0 is silent, 1.0 is normal)
virtual void set_gain(float gain) = 0;
virtual void set_pitch(float pitch) = 0;
virtual void set_position(const Vector& position) = 0;
- virtual void set_velocity(const Vector& position) = 0;
+ virtual void set_velocity(const Vector& velocity) = 0;
virtual void set_reference_distance(float distance) = 0;
- virtual void set_rollof_factor(float factor) = 0;
};
#endif
Snail::Snail(const Reader& reader) :
WalkingBadguy(reader, "images/creatures/snail/snail.sprite", "left", "right"),
state(STATE_NORMAL),
- flat_timer(),
kicked_delay_timer(),
squishcount(0)
{
Snail::Snail(const Vector& pos, Direction d) :
WalkingBadguy(pos, d, "images/creatures/snail/snail.sprite", "left", "right"),
state(STATE_NORMAL),
- flat_timer(),
kicked_delay_timer(),
squishcount(0)
{
Snail::be_flat()
{
state = STATE_FLAT;
- sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
- sprite->set_fps(64);
+ sprite->set_action(dir == LEFT ? "flat-left" : "flat-right", 1);
physic.set_velocity_x(0);
physic.set_velocity_y(0);
-
- flat_timer.start(4);
}
void
Snail::be_kicked()
{
state = STATE_KICKED_DELAY;
- sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
- sprite->set_fps(64);
+ sprite->set_action(dir == LEFT ? "flat-left" : "flat-right", 1);
physic.set_velocity_x(0);
physic.set_velocity_y(0);
case STATE_NORMAL:
WalkingBadguy::active_update(elapsed_time);
- break;
+ return;
case STATE_FLAT:
- if (flat_timer.started()) {
- sprite->set_fps(64 - 15 * flat_timer.get_timegone());
- }
- if (flat_timer.check()) {
+ if (sprite->animation_done()) {
be_normal();
}
- BadGuy::active_update(elapsed_time);
break;
case STATE_KICKED_DELAY:
physic.set_velocity_y(KICKSPEED_Y);
state = STATE_KICKED;
}
- BadGuy::active_update(elapsed_time);
break;
case STATE_KICKED:
physic.set_velocity_x(physic.get_velocity_x() * pow(0.99, elapsed_time/0.02));
- if (fabsf(physic.get_velocity_x()) < walk_speed) be_normal();
- BadGuy::active_update(elapsed_time);
+ if (sprite->animation_done() || (fabsf(physic.get_velocity_x()) < walk_speed)) be_normal();
break;
}
+
+ BadGuy::active_update(elapsed_time);
}
void
Snail::collision_solid(const CollisionHit& hit)
{
- update_on_ground_flag(hit);
-
switch (state) {
case STATE_NORMAL:
WalkingBadguy::collision_solid(hit);
- break;
- case STATE_FLAT:
- if(hit.top || hit.bottom) {
- physic.set_velocity_y(0);
- }
- if(hit.left || hit.right) {
- }
- break;
- case STATE_KICKED_DELAY:
- if(hit.top || hit.bottom) {
- physic.set_velocity_y(0);
- }
- if(hit.left || hit.right) {
- physic.set_velocity_x(0);
- }
- break;
+ return;
case STATE_KICKED:
- if(hit.top || hit.bottom) {
- physic.set_velocity_y(0);
- }
if(hit.left || hit.right) {
sound_manager->play("sounds/iceblock_bump.wav", get_pos());
dir = (dir == LEFT) ? RIGHT : LEFT;
sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
- physic.set_velocity_x(-physic.get_velocity_x()*0.75);
- if (fabsf(physic.get_velocity_x()) < walk_speed) be_normal();
+ physic.set_velocity_x(-physic.get_velocity_x());
}
-
+ }
+ /* fall-through */
+ case STATE_FLAT:
+ case STATE_KICKED_DELAY:
+ if(hit.top || hit.bottom) {
+ physic.set_velocity_y(0);
}
break;
}
+ update_on_ground_flag(hit);
+
}
HitResponse
private:
State state;
- Timer flat_timer; /**< wait time until flipping right-side-up again */
Timer kicked_delay_timer; /**< wait time until switching from STATE_KICKED_DELAY to STATE_KICKED */
int squishcount;
};
if(Sector::current()->add_bullet(
get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2)
: Vector(32, bbox.get_height()/2)),
+ player_status,
physic.get_velocity_x(), dir))
shooting_timer.start(SHOOTING_TIME);
}
{
movement = pos - get_pos();
last_movement = movement;
- set_group(COLGROUP_DISABLED);
+ set_group(COLGROUP_TOUCHABLE); //needed for lanterns catching willowisps
on_ground = false;
grabbed = true;
}
if (current_alpha == 0.0) return;
context.push_transform();
- context.push_target();
- context.set_target(draw_target);
+ if(draw_target != DrawingContext::NORMAL) {
+ context.push_target();
+ context.set_target(draw_target);
+ }
if(drawing_effect != 0) context.set_drawing_effect(drawing_effect);
if(current_alpha != 1.0) context.set_alpha(current_alpha);
int tx, ty;
for(pos.x = start_x, tx = tsx; pos.x < end_x; pos.x += 32, ++tx) {
for(pos.y = start_y, ty = tsy; pos.y < end_y; pos.y += 32, ++ty) {
- if ((tx < 0) || (ty < 0)) continue;
+ if ((tx < 0) || (ty < 0) || (tiles[ty*width + tx] == 0)) continue;
const Tile* tile = tileset->get(tiles[ty*width + tx]);
assert(tile != 0);
tile->draw(context, pos, z_pos);
}
}
- context.pop_target();
+ if(draw_target != DrawingContext::NORMAL) {
+ context.pop_target();
+ }
context.pop_transform();
}
{
using namespace worldmap;
- g_screen_manager->push_screen(new WorldMap(filename));
+ if(World::current() == NULL)
+ throw std::runtime_error("Can't start WorldMap without active world.");
+
+ g_screen_manager->push_screen(new WorldMap(filename, World::current()->get_player_status()));
}
void load_level(const std::string& filename)
{
- g_screen_manager->push_screen(new GameSession(filename));
+ if(GameSession::current() == NULL)
+ throw std::runtime_error("Can't start level without active level.");
+
+ g_screen_manager->push_screen(new GameSession(filename, GameSession::current()->get_player_status()));
}
static SQInteger squirrel_read_char(SQUserPointer file)
if(action && action->name == name)
return;
- SpriteData::Action* newaction = data.get_action(name);
+ const SpriteData::Action* newaction = data.get_action(name);
if(!newaction) {
log_debug << "Action '" << name << "' not found." << std::endl;
return;
if(action && action->name == name)
return;
- SpriteData::Action* newaction = data.get_action(name);
+ const SpriteData::Action* newaction = data.get_action(name);
if(!newaction) {
log_debug << "Action '" << name << "' not found." << std::endl;
return;
}
void
-Sprite::set_fps(float new_fps)
-{
- action->fps = new_fps;
-}
-
-void
Sprite::set_angle(float a)
{
angle = a;
void set_animation_loops(int loops = -1)
{ animation_loops = loops; }
- /** Set framerate */
- void set_fps(float new_fps);
-
/* Stop animation */
void stop_animation()
{ animation_loops = 0; }
Color color;
Blend blend;
- SpriteData::Action* action;
+ const SpriteData::Action* action;
private:
Sprite(const Sprite& other);
std::string mirror_action;
lisp.get("mirror-action", mirror_action);
if(!mirror_action.empty()) {
- Action* act_tmp = get_action(mirror_action);
+ const Action* act_tmp = get_action(mirror_action);
if(act_tmp == NULL) {
throw std::runtime_error("Could not mirror action. Action not found.\n"
"Mirror actions must be defined after the real one!");
actions[action->name] = action;
}
-SpriteData::Action*
-SpriteData::get_action(std::string act)
+const SpriteData::Action*
+SpriteData::get_action(const std::string act)
{
Actions::iterator i = actions.find(act);
if(i == actions.end()) {
void parse_action(const Reader& lispreader, const std::string& basedir);
/** Get an action */
- Action* get_action(std::string act);
+ const Action* get_action(const std::string act);
Actions actions;
std::string name;
#include "util/gettext.hpp"
#include "worldmap/worldmap.hpp"
-GameSession::GameSession(const std::string& levelfile_, Statistics* statistics) :
+GameSession::GameSession(const std::string& levelfile_, PlayerStatus* player_status, Statistics* statistics) :
level(0),
statistics_backdrop(),
scripts(),
newsector(),
newspawnpoint(),
best_level_statistics(statistics),
+ player_status(player_status),
capture_demo_stream(0),
capture_file(),
playback_demo_stream(0),
class Level;
class Sector;
class Statistics;
+class PlayerStatus;
class DrawingContext;
class CodeController;
class Menu;
public Currenton<GameSession>
{
public:
- GameSession(const std::string& levelfile, Statistics* statistics = NULL);
+ GameSession(const std::string& levelfile, PlayerStatus* player_status, Statistics* statistics = NULL);
~GameSession();
void record_demo(const std::string& filename);
Level* get_current_level()
{ return level.get(); }
+ PlayerStatus* get_player_status()
+ { return player_status; }
+
void start_sequence(const std::string& sequencename);
/**
std::string newspawnpoint;
Statistics* best_level_statistics;
+ PlayerStatus* player_status;
std::ostream* capture_demo_stream;
std::string capture_file;
/** this is only set while loading a map */
extern TileSet *current_tileset;
-// global player state
-extern PlayerStatus* player_status;
-
extern SpriteManager* sprite_manager;
extern float g_game_speed;
#include "scripting/squirrel_util.hpp"
#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"
+#include "supertux/player_status.hpp"
#include "supertux/screen_manager.hpp"
#include "supertux/resources.hpp"
#include "supertux/title_screen.hpp"
timelog(0);
+ const std::auto_ptr<PlayerStatus> default_playerstatus(new PlayerStatus());
+
g_screen_manager = new ScreenManager();
+
+ init_rand();
+
if(g_config->start_level != "") {
// we have a normal path specified at commandline, not a physfs path.
// So we simply mount that path here...
if(g_config->start_level.size() > 4 &&
g_config->start_level.compare(g_config->start_level.size() - 5, 5, ".stwm") == 0) {
- init_rand();
g_screen_manager->push_screen(new worldmap::WorldMap(
- FileSystem::basename(g_config->start_level)));
+ FileSystem::basename(g_config->start_level), default_playerstatus.get()));
} else {
- init_rand();//If level uses random eg. for
- // rain particles before we do this:
std::auto_ptr<GameSession> session (
- new GameSession(FileSystem::basename(g_config->start_level)));
+ new GameSession(FileSystem::basename(g_config->start_level), default_playerstatus.get()));
g_config->random_seed =session->get_demo_random_seed(g_config->start_demo);
init_rand();//initialise generator with seed from session
g_screen_manager->push_screen(session.release());
}
} else {
- init_rand();
- g_screen_manager->push_screen(new TitleScreen());
+ g_screen_manager->push_screen(new TitleScreen(default_playerstatus.get()));
}
- //init_rand(); PAK: this call might subsume the above 3, but I'm chicken!
g_screen_manager->run(context);
} catch(std::exception& e) {
log_fatal << "Unexpected exception: " << e.what() << std::endl;
if (get_item_by_id(index).kind == MN_ACTION)
{
sound_manager->stop_music();
- GameSession* session = new GameSession(m_current_world.get_level_filename(index));
+ GameSession* session = new GameSession(m_current_world.get_level_filename(index), m_current_world.get_player_status());
g_screen_manager->push_screen(session);
}
}
class DrawingContext;
/**
- * This class memorizes player status between different game sessions (for
+ * This class keeps player status between different game sessions (for
* example when switching maps in the worldmap)
*/
class PlayerStatus
tile_manager = new TileManager();
sprite_manager = new SpriteManager();
-
- player_status = new PlayerStatus();
}
/* Free shared data: */
/* Free mouse-cursor */
delete mouse_cursor;
-
- delete player_status;
- player_status = NULL;
}
/* EOF */
#include "scripting/squirrel_util.hpp"
#include "supertux/collision.hpp"
#include "supertux/constants.hpp"
+#include "supertux/game_session.hpp"
#include "supertux/globals.hpp"
#include "supertux/level.hpp"
#include "supertux/object_factory.hpp"
+#include "supertux/player_status.hpp"
#include "supertux/spawn_point.hpp"
#include "supertux/tile.hpp"
#include "trigger/sequence_trigger.hpp"
camera(0),
effect(0)
{
- add_object(new Player(player_status, "Tux"));
+ add_object(new Player(GameSession::current()->get_player_status(), "Tux"));
add_object(new DisplayEffect("Effect"));
add_object(new TextObject("Text"));
}
bool
-Sector::add_bullet(const Vector& pos, float xm, Direction dir)
+Sector::add_bullet(const Vector& pos, const PlayerStatus* player_status, float xm, Direction dir)
{
// TODO remove this function and move these checks elsewhere...
class Sprite;
class GameObject;
class Player;
+class PlayerStatus;
class Camera;
class TileMap;
class Bullet;
void play_music(MusicType musictype);
MusicType get_music_type();
- bool add_bullet(const Vector& pos, float xm, Direction dir);
+ bool add_bullet(const Vector& pos, const PlayerStatus* player_status, float xm, Direction dir);
bool add_smoke_cloud(const Vector& pos);
/** get currently activated sector. */
void merge(const TileSet *tileset, uint32_t start, uint32_t end,
uint32_t offset);
- const Tile* get(uint32_t id) const
+ const Tile* get(const uint32_t id) const
{
assert(id < tiles.size());
Tile* tile = tiles[id];
#include <version.h>
-TitleScreen::TitleScreen() :
+TitleScreen::TitleScreen(PlayerStatus* player_status) :
main_menu(new MainMenu()),
frame(),
controller(),
titlesession()
{
controller.reset(new CodeController());
- titlesession.reset(new GameSession("levels/misc/menu.stl"));
+ titlesession.reset(new GameSession("levels/misc/menu.stl", player_status));
Player* player = titlesession->get_current_sector()->player;
player->set_controller(controller.get());
void
TitleScreen::setup()
{
- player_status->reset();
-
Sector* sector = titlesession->get_current_sector();
if(Sector::current() != sector) {
sector->play_music(LEVEL_MUSIC);
class ContribWorldMenu;
class MainMenu;
class Menu;
+class PlayerStatus;
class World;
/**
static std::string get_level_name(const std::string& levelfile);
public:
- TitleScreen();
+ TitleScreen(PlayerStatus* player_status);
virtual ~TitleScreen();
virtual void setup();
world_thread(),
title(),
description(),
+ player_status(),
hide_from_contribs(),
is_levelset()
{
+ player_status.reset(new PlayerStatus());
+
is_levelset = true;
hide_from_contribs = false;
sq_resetobject(&world_thread);
} catch(std::exception& ) {
// fallback: try to load worldmap worldmap.stwm
using namespace worldmap;
- g_screen_manager->push_screen(new WorldMap(basedir + "worldmap.stwm"));
+ g_screen_manager->push_screen(new WorldMap(basedir + "worldmap.stwm", get_player_status()));
}
}
#include <string>
#include <vector>
+class PlayerStatus;
+
class World
{
public:
const std::string& get_level_filename(unsigned int i) const;
const std::string& get_basedir() const;
const std::string& get_title() const;
+ /** returns player status */
+ PlayerStatus* get_player_status() const { return player_status.get(); }
+
void run();
HSQOBJECT world_thread;
std::string title;
std::string description;
+ std::auto_ptr<PlayerStatus> player_status;
public:
bool hide_from_contribs;
void
Tux::draw(DrawingContext& context)
{
- switch (player_status->bonus) {
+ switch (worldmap->get_player_status()->bonus) {
case GROWUP_BONUS:
sprite->set_action(moving ? "large-walking" : "large-stop");
break;
WorldMap* WorldMap::current_ = NULL;
-WorldMap::WorldMap(const std::string& filename, const std::string& force_spawnpoint) :
+WorldMap::WorldMap(const std::string& filename, PlayerStatus* player_status, const std::string& force_spawnpoint) :
tux(0),
+ player_status(player_status),
tileset(NULL),
free_tileset(false),
worldmap_menu(),
WorldMap::change(const std::string& filename, const std::string& force_spawnpoint)
{
g_screen_manager->exit_screen();
- g_screen_manager->push_screen(new WorldMap(filename, force_spawnpoint));
+ g_screen_manager->push_screen(new WorldMap(filename, player_status, force_spawnpoint));
}
void
// update state and savegame
save_state();
- g_screen_manager->push_screen(new GameSession(levelfile, &level->statistics),
+ g_screen_manager->push_screen(new GameSession(levelfile, player_status, &level->statistics),
new ShrinkFade(shrinkpos, 1.0f));
in_level = true;
} catch(std::exception& e) {
class Menu;
class GameObject;
class TileMap;
+class PlayerStatus;
namespace worldmap {
Tux* tux;
+ PlayerStatus* player_status;
+
TileSet *tileset;
bool free_tileset;
bool panning;
public:
- WorldMap(const std::string& filename, const std::string& force_spawnpoint = "");
+ WorldMap(const std::string& filename, PlayerStatus* player_status, const std::string& force_spawnpoint = "");
~WorldMap();
void add_object(GameObject* object);
/** returns current Tux incarnation */
Tux* get_tux() { return tux; }
+ /** returns player status */
+ PlayerStatus* get_player_status() { return player_status; }
+
LevelTile* at_level();
SpecialTile* at_special_tile();
SpriteChange* at_sprite_change(const Vector& pos);