X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=sidebyside;f=src%2Fsector.cpp;h=4cde141967339ab83157baebf95a6242dc6c90f2;hb=377b24b9da20a23487cec26c1193097d5c0c0cbc;hp=3d0f3e55a3b9c5aa7ae2a788c1b67ca51433106e;hpb=de51923531f5ddc3a793f3cd8c11f9a78e5f4897;p=supertux.git diff --git a/src/sector.cpp b/src/sector.cpp index 3d0f3e55a..4cde14196 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -40,11 +40,13 @@ #include "resources.h" #include "interactive_object.h" #include "door.h" +#include "statistics.h" Sector* Sector::_current = 0; Sector::Sector() - : gravity(10), player(0), solids(0), background(0), camera(0), + : end_sequence_animation_type(NONE_ENDSEQ_ANIM), + gravity(10), player(0), solids(0), background(0), camera(0), currentmusic(LEVEL_MUSIC) { song_title = "Mortimers_chipdisko.mod"; @@ -66,6 +68,23 @@ Sector::~Sector() _current = 0; } +Sector *Sector::create(const std::string& name, size_t width, size_t height) +{ + Sector *sector = new Sector; + sector->name = name; + TileMap *background = new TileMap(LAYER_BACKGROUNDTILES, false, width, height); + TileMap *interactive = new TileMap(LAYER_TILES, true, width, height); + TileMap *foreground = new TileMap(LAYER_FOREGROUNDTILES, false, width, height); + sector->add_object(background); + sector->add_object(interactive); + sector->add_object(foreground); + sector->solids = interactive; + sector->camera = new Camera(sector); + sector->add_object(sector->camera); + sector->update_game_objects(); + return sector; +} + void Sector::parse(LispReader& lispreader) { @@ -85,6 +104,10 @@ Sector::parse(LispReader& lispreader) } else if(token == "music") { song_title = lisp_string(data); load_music(); + } else if(token == "end-sequence-animation") { + std::string end_seq_anim = lisp_string(data); + if(end_seq_anim == "fireworks") + end_sequence_animation_type = FIREWORKS_ENDSEQ_ANIM; } else if(token == "camera") { if(camera) { std::cerr << "Warning: More than 1 camera defined in sector.\n"; @@ -183,6 +206,13 @@ Sector::parse_old_format(LispReader& reader) add_object(background); } + std::string end_seq_anim; + reader.read_string("end-sequence-animation", end_seq_anim); + if(end_seq_anim == "fireworks") + end_sequence_animation_type = FIREWORKS_ENDSEQ_ANIM; +// else +// end_sequence_animation = NONE_ENDSEQ_ANIM; + std::string particlesystem; reader.read_string("particle_system", particlesystem); if(particlesystem == "clouds") @@ -653,9 +683,9 @@ Sector::collision_handler() void Sector::add_score(const Vector& pos, int s) { - player_status.score += s; + global_stats.add_points(SCORE_STAT, s); - add_object(new FloatingScore(pos, s)); + add_object(new FloatingText(pos, s)); } void @@ -688,10 +718,12 @@ Sector::add_bouncy_brick(const Vector& pos) } BadGuy* -Sector::add_bad_guy(float x, float y, BadGuyKind kind) +Sector::add_bad_guy(float x, float y, BadGuyKind kind, bool activate) { BadGuy* badguy = new BadGuy(kind, x, y); add_object(badguy); + if(activate) + badguy->activate(LEFT); return badguy; } @@ -723,7 +755,7 @@ Sector::add_bullet(const Vector& pos, float xm, Direction dir) else throw std::runtime_error("wrong bullet type."); add_object(new_bullet); - + SoundManager::get()->play_sound(IDToSound(SND_SHOOT)); return true; @@ -737,12 +769,18 @@ Sector::add_smoke_cloud(const Vector& pos) } bool -Sector::add_particles(const Vector& epicenter, int number, Color color, int size, float velocity, int life_time) +Sector::add_particles(const Vector& epicenter, int min_angle, int max_angle, const Vector& initial_velocity, const Vector& acceleration, int number, Color color, int size, int life_time, int drawing_layer) { - add_object(new Particles(epicenter, number, color, size, velocity, life_time)); + add_object(new Particles(epicenter, min_angle, max_angle, initial_velocity, acceleration, number, color, size, life_time, drawing_layer)); return true; } +void +Sector::add_floating_text(const Vector& pos, const std::string& text) +{ + add_object(new FloatingText(pos, text)); +} + /* Break a brick: */ bool Sector::trybreakbrick(const Vector& pos, bool small) @@ -779,9 +817,10 @@ Sector::trybreakbrick(const Vector& pos, bool small) counting_distros = false; solids->change_at(pos, tile->next_tile); } - + SoundManager::get()->play_sound(IDToSound(SND_DISTRO)); - player_status.score = player_status.score + SCORE_DISTRO; + global_stats.add_points(SCORE_STAT, SCORE_DISTRO); + global_stats.add_points(COINS_COLLECTED_STAT, 1); player_status.distros++; return true; } @@ -797,7 +836,7 @@ Sector::trybreakbrick(const Vector& pos, bool small) /* Get some score: */ SoundManager::get()->play_sound(IDToSound(SND_BRICK)); - player_status.score = player_status.score + SCORE_BRICK; + global_stats.add_points(SCORE_STAT, SCORE_BRICK); return true; } @@ -835,7 +874,8 @@ Sector::tryemptybox(const Vector& pos, Direction col_side) case 1: // Box with a distro! add_bouncy_distro(Vector(posx, posy)); SoundManager::get()->play_sound(IDToSound(SND_DISTRO)); - player_status.score = player_status.score + SCORE_DISTRO; + global_stats.add_points(SCORE_STAT, SCORE_DISTRO); + global_stats.add_points(COINS_COLLECTED_STAT, 1); player_status.distros++; break; @@ -893,14 +933,15 @@ Sector::trygrabdistro(const Vector& pos, int bounciness) solids->change_at(pos, tile->next_tile); SoundManager::get()->play_sound(IDToSound(SND_DISTRO)); - + if (bounciness == BOUNCE) { add_bouncy_distro(Vector(((int)(pos.x + 1) / 32) * 32, (int)(pos.y / 32) * 32)); } - player_status.score = player_status.score + SCORE_DISTRO; + global_stats.add_points(SCORE_STAT, SCORE_DISTRO); + global_stats.add_points(COINS_COLLECTED_STAT, 1); player_status.distros++; } @@ -979,3 +1020,16 @@ Sector::get_music_type() { return currentmusic; } + +int +Sector::get_total_badguys() +{ + int total_badguys = 0; + for(GameObjects::iterator i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i) + { + BadGuy* badguy = dynamic_cast (*i); + if(badguy) + total_badguys++; + } + return total_badguys; +}