X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fsector.cpp;h=1420d7f422c17a0aa165dbb873487c0462a4f0ce;hb=35fa5542fadf1848919363620c7a76b04150c283;hp=a108e3065cb43f21dc7924a841d10d7e9a634c3e;hpb=c5cbd36c2e01d8c807c8c931ca44fb7c1b48ad18;p=supertux.git diff --git a/src/sector.cpp b/src/sector.cpp index a108e3065..1420d7f42 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"; @@ -85,6 +87,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"; @@ -96,7 +102,7 @@ Sector::parse(LispReader& lispreader) } else if(token == "background") { background = new Background(reader); add_object(background); - } else if(token == "playerspawn") { + } else if(token == "spawn-points") { SpawnPoint* sp = new SpawnPoint; reader.read_string("name", sp->name); reader.read_float("x", sp->pos.x); @@ -155,6 +161,7 @@ Sector::parse_old_format(LispReader& reader) reader.read_string("background", backgroundimage); float bgspeed = .5; reader.read_float("bkgd_speed", bgspeed); + bgspeed /= 100; Color bkgd_top, bkgd_bottom; int r = 0, g = 0, b = 128; @@ -182,6 +189,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") @@ -227,7 +241,27 @@ Sector::parse_old_format(LispReader& reader) add_object(tilemap); } - // TODO read resetpoints + // read reset-points (now spawn-points) + { + lisp_object_t* cur = 0; + if(reader.read_lisp("reset-points", cur)) { + while(!lisp_nil_p(cur)) { + lisp_object_t* data = lisp_car(cur); + LispReader reader(lisp_cdr(data)); + + Vector sp_pos; + if(reader.read_float("x", sp_pos.x) && reader.read_float("y", sp_pos.y)) + { + SpawnPoint* sp = new SpawnPoint; + sp->name = "main"; + sp->pos = sp_pos; + spawnpoints.push_back(sp); + } + + cur = lisp_cdr(cur); + } + } + } // read objects { @@ -271,11 +305,11 @@ Sector::write(LispWriter& writer) for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end(); ++i) { SpawnPoint* spawn = *i; - writer.start_list("playerspawn"); + writer.start_list("spawn-points"); writer.write_string("name", spawn->name); writer.write_float("x", spawn->pos.x); writer.write_float("y", spawn->pos.y); - writer.end_list("playerspawn"); + writer.end_list("spawn-points"); } // write objects @@ -362,6 +396,22 @@ Sector::activate(const std::string& spawnpoint) camera->reset(Vector(player->base.x, player->base.y)); } +Vector +Sector::get_best_spawn_point(Vector pos) +{ +Vector best_reset_point = Vector(-1,-1); + +for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end(); + ++i) { + if((*i)->name != "main") + continue; + if((*i)->pos.x > best_reset_point.x && (*i)->pos.x < pos.x) + best_reset_point = (*i)->pos; + } + +return best_reset_point; +} + void Sector::action(float elapsed_time) { @@ -423,7 +473,19 @@ Sector::update_game_objects() std::remove(flying_platforms.begin(), flying_platforms.end(), flying_platform), flying_platforms.end()); } - + SmokeCloud* smoke_cloud = dynamic_cast (*i); + if(smoke_cloud) { + smoke_clouds.erase( + std::remove(smoke_clouds.begin(), smoke_clouds.end(), smoke_cloud), + smoke_clouds.end()); + } + Particles* particle = dynamic_cast (*i); + if(particle) { + particles.erase( + std::remove(particles.begin(), particles.end(), particle), + particles.end()); + } + delete *i; i = gameobjects.erase(i); } else { @@ -454,6 +516,12 @@ Sector::update_game_objects() = dynamic_cast (*i); if(interactive_object) interactive_objects.push_back(interactive_object); + SmokeCloud* smoke_cloud = dynamic_cast (*i); + if(smoke_cloud) + smoke_clouds.push_back(smoke_cloud); + Particles* particle = dynamic_cast (*i); + if(particle) + particles.push_back(particle); gameobjects.push_back(*i); } @@ -598,9 +666,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 @@ -633,10 +701,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; } @@ -668,12 +738,32 @@ 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; } +bool +Sector::add_smoke_cloud(const Vector& pos) +{ + add_object(new SmokeCloud(pos)); + return true; +} + +bool +Sector::add_particles(const Vector& epicenter, const Vector& velocity, const Vector& acceleration, int number, Color color, int size, int life_time) +{ + add_object(new Particles(epicenter, velocity, acceleration, number, color, size, life_time)); + 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) @@ -710,9 +800,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; } @@ -728,7 +819,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; } @@ -766,7 +857,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; @@ -787,7 +879,7 @@ Sector::tryemptybox(const Vector& pos, Direction col_side) break; case 3: // Add a golden herring - add_upgrade(Vector(posx, posy), col_side, UPGRADE_HERRING); + add_upgrade(Vector(posx, posy), col_side, UPGRADE_STAR); break; case 4: // Add a 1up extra @@ -824,14 +916,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++; } @@ -910,3 +1003,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; +}