physic.set_velocity_y(0);
set_state(STATE_SQUISHED);
set_group(COLGROUP_MOVING_ONLY_STATIC);
- global_stats.add_points(BADGUYS_KILLED_STAT, 1);
+ Sector::current()->get_level()->stats.add_points(BADGUYS_KILLED_STAT, 1);
player.bounce(*this);
}
BadGuy::kill_fall()
{
sound_manager->play("sounds/fall.wav", get_pos());
- global_stats.add_points(BADGUYS_KILLED_STAT, 1);
+ Sector::current()->get_level()->stats.add_points(BADGUYS_KILLED_STAT, 1);
physic.set_velocity_y(0);
physic.enable_gravity(true);
set_state(STATE_FALLING);
level.reset(new Level);
level->load(levelfile);
- global_stats.reset();
- global_stats.set_total_points(COINS_COLLECTED_STAT, level->get_total_coins());
- global_stats.set_total_points(BADGUYS_KILLED_STAT, level->get_total_badguys());
+ level->stats.reset();
+ level->stats.set_total_points(COINS_COLLECTED_STAT, level->get_total_coins());
+ level->stats.set_total_points(BADGUYS_KILLED_STAT, level->get_total_badguys());
// get time
int time = 0;
time += int(lt->get_level_time());
}
}
- global_stats.set_total_points(TIME_NEEDED_STAT, (time == 0) ? -1 : time);
+ level->stats.set_total_points(TIME_NEEDED_STAT, (time == 0) ? -1 : time);
if (fromBeginning) reset_sector="";
if(reset_sector != "") {
if(win) {
if(WorldMap::current())
- WorldMap::current()->finished_level(levelfile);
+ WorldMap::current()->finished_level(level.get());
}
main_loop->exit_screen();
}
}
}
- global_stats.set_points(TIME_NEEDED_STAT, (tottime == 0 ? -1 : (tottime-remtime)));
+ level->stats.set_points(TIME_NEEDED_STAT, (tottime == 0 ? -1 : (tottime-remtime)));
if(sequencename == "fireworks") {
currentsector->add_object(new Fireworks());
// draw level stats while end_sequence is running
if (end_sequence) {
- global_stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop.get());
+ level->stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop.get());
}
}
} else if(token == "author") {
iter.value()->get(author);
} else if(token == "sector") {
- Sector* sector = new Sector;
+ Sector* sector = new Sector(this);
sector->parse(*(iter.lisp()));
add_sector(sector);
} else {
reader.get("name", name);
reader.get("author", author);
- Sector* sector = new Sector;
+ Sector* sector = new Sector(this);
sector->parse_old_format(reader);
add_sector(sector);
}
#include <vector>
#include <string>
+#include "statistics.hpp"
class Sector;
std::string author;
typedef std::vector<Sector*> Sectors;
Sectors sectors;
+ Statistics stats;
public:
Level();
{
Sector::current()->player->get_status()->add_coins(1);
Sector::current()->add_object(new BouncyCoin(get_pos()));
- global_stats.add_points(COINS_COLLECTED_STAT, 1);
+ Sector::current()->get_level()->stats.add_points(COINS_COLLECTED_STAT, 1);
remove_me();
}
bool Sector::show_collrects = false;
bool Sector::draw_solids_only = false;
-Sector::Sector()
- : currentmusic(LEVEL_MUSIC), gravity(10),
+Sector::Sector(Level* parent)
+ : level(parent), currentmusic(LEVEL_MUSIC), gravity(10),
player(0), solids(0), camera(0)
{
add_object(new Player(player_status));
delete *i;
}
+Level*
+Sector::get_level()
+{
+ return level;
+}
+
GameObject*
Sector::parse_object(const std::string& name, const lisp::Lisp& reader)
{
#include "script_manager.hpp"
#include "math/vector.hpp"
#include "video/drawing_context.hpp"
+#include "level.hpp"
namespace lisp {
class Lisp;
class Sector
{
public:
- Sector();
+ Sector(Level* parent);
~Sector();
+ /// get parent level
+ Level* get_level();
+
/// read sector from lisp file
void parse(const lisp::Lisp& lisp);
void parse_old_format(const lisp::Lisp& lisp);
typedef std::vector<SpawnPoint*> SpawnPoints;
private:
+ Level* level; /**< Parent level containing this sector */
uint32_t collision_tile_attributes(const Rect& dest) const;
void before_object_remove(GameObject* object);
#include "main.hpp"
#include "statistics.hpp"
-Statistics global_stats;
-
std::string
stat_name_to_string(int stat_enum)
{
int display_stat;
};
-extern Statistics global_stats;
-
#endif /*SUPERTUX_STATISTICS_H*/
#include <stddef.h>
#include <physfs.h>
-#include "level.hpp"
+#include "worldmap/level.hpp"
#include "sprite/sprite_manager.hpp"
#include "sprite/sprite.hpp"
#include "video/drawing_context.hpp"
namespace WorldMapNS
{
-Level::Level(const std::string& basedir, const lisp::Lisp* lisp)
+LevelTile::LevelTile(const std::string& basedir, const lisp::Lisp* lisp)
: solved(false), auto_path(true)
{
lisp->get("x", pos.x);
}
}
-Level::~Level()
+LevelTile::~LevelTile()
{
}
void
-Level::draw(DrawingContext& context)
+LevelTile::draw(DrawingContext& context)
{
sprite->draw(context, pos*32 + Vector(16, 16), LAYER_OBJECTS - 1);
}
void
-Level::update(float )
+LevelTile::update(float )
{
}
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#ifndef __WORLDMAP_LEVEL_HPP__
-#define __WORLDMAP_LEVEL_HPP__
+#ifndef __LEVEL_TILE_HPP__
+#define __LEVEL_TILE_HPP__
#include <memory>
#include <string>
namespace WorldMapNS
{
-class Level : public GameObject
+class LevelTile : public GameObject
{
public:
- Level(const std::string& basedir, const lisp::Lisp* lisp);
- virtual ~Level();
+ LevelTile(const std::string& basedir, const lisp::Lisp* lisp);
+ virtual ~LevelTile();
virtual void draw(DrawingContext& context);
virtual void update(float elapsed_time);
#include "video/drawing_context.hpp"
#include "player_status.hpp"
#include "worldmap.hpp"
-#include "level.hpp"
+#include "worldmap/level.hpp"
#include "special_tile.hpp"
#include "sprite_change.hpp"
#include "control/joystickkeyboardcontroller.hpp"
if (input_direction == D_NONE)
return;
- Level* level = worldmap->at_level();
+ LevelTile* level = worldmap->at_level();
// We got a new direction, so lets start walking when possible
Vector next_tile;
SpawnPoint* sp = new SpawnPoint(iter.lisp());
spawn_points.push_back(sp);
} else if(iter.item() == "level") {
- Level* level = new Level(levels_path, iter.lisp());
+ LevelTile* level = new LevelTile(levels_path, iter.lisp());
levels.push_back(level);
game_objects.push_back(level);
} else if(iter.item() == "special-tile") {
}
void
-WorldMap::get_level_title(Level& level)
+WorldMap::get_level_title(LevelTile& level)
{
/** get special_tile's title */
level.title = "<no title>";
void WorldMap::calculate_total_stats()
{
total_stats.reset();
- for(Levels::iterator i = levels.begin(); i != levels.end(); ++i) {
- Level* level = *i;
+ for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
+ LevelTile* level = *i;
if (level->solved) {
total_stats += level->statistics;
}
}
void
-WorldMap::finished_level(const std::string& filename)
+WorldMap::finished_level(Level* gamelevel)
{
- // TODO calculate level from filename?
- (void) filename;
- Level* level = at_level();
+ // TODO use Level* parameter here?
+ LevelTile* level = at_level();
bool old_level_state = level->solved;
level->solved = true;
level->sprite->set_action("solved");
// deal with statistics
- level->statistics.merge(global_stats);
+ level->statistics.merge(gamelevel->stats);
calculate_total_stats();
save_state();
}
/* Check level action */
- Level* level = at_level();
+ LevelTile* level = at_level();
if (!level) {
log_warning << "No level to enter at: " << tux->get_tile_pos().x << ", " << tux->get_tile_pos().y << std::endl;
return;
return solids->get_tile((int) p.x, (int) p.y);
}
-Level*
+LevelTile*
WorldMap::at_level()
{
- for(Levels::iterator i = levels.begin(); i != levels.end(); ++i) {
- Level* level = *i;
+ for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
+ LevelTile* level = *i;
if (level->pos == tux->get_tile_pos())
return level;
}
player_status->draw(context);
if (!tux->is_moving()) {
- for(Levels::iterator i = levels.begin(); i != levels.end(); ++i) {
- Level* level = *i;
+ for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
+ LevelTile* level = *i;
if (level->pos == tux->get_tile_pos()) {
if(level->title == "")
sq_pushstring(vm, "levels", -1);
sq_newtable(vm);
- for(Levels::iterator i = levels.begin(); i != levels.end(); ++i) {
- Level* level = *i;
+ for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
+ LevelTile* level = *i;
if (level->solved) {
sq_pushstring(vm, level->name.c_str(), -1);
if(SQ_FAILED(sq_get(vm, -2)))
throw Scripting::SquirrelError(vm, "Couldn't get levels");
- for(Levels::iterator i = levels.begin(); i != levels.end(); ++i) {
- Level* level = *i;
+ for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
+ LevelTile* level = *i;
sq_pushstring(vm, level->name.c_str(), -1);
if(SQ_SUCCEEDED(sq_get(vm, -2))) {
level->solved = read_bool(vm, "solved");
WorldMap::solved_level_count()
{
size_t count = 0;
- for(Levels::iterator i = levels.begin(); i != levels.end(); ++i) {
- Level* level = *i;
+ for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
+ LevelTile* level = *i;
if(level->solved)
count++;
#include "tile_manager.hpp"
#include "game_object.hpp"
#include "console.hpp"
+#include "../level.hpp"
class Sprite;
class Menu;
namespace WorldMapNS {
class Tux;
-class Level;
+class LevelTile;
class SpecialTile;
class SpriteChange;
typedef std::vector<SpecialTile*> SpecialTiles;
SpecialTiles special_tiles;
- typedef std::vector<Level*> Levels;
- Levels levels;
+ typedef std::vector<LevelTile*> LevelTiles;
+ LevelTiles levels;
typedef std::vector<SpriteChange*> SpriteChanges;
SpriteChanges sprite_changes;
typedef std::vector<SpawnPoint*> SpawnPoints;
* gets called from the GameSession when a level has been successfully
* finished
*/
- void finished_level(const std::string& filename);
+ void finished_level(Level* level);
- Level* at_level();
+ LevelTile* at_level();
SpecialTile* at_special_tile();
SpriteChange* at_sprite_change(const Vector& pos);
{ return name; }
private:
- void get_level_title(Level& level);
+ void get_level_title(LevelTile& level);
void draw_status(DrawingContext& context);
void calculate_total_stats();