added seaking level
authorFrank DeMarco <if.self.end@gmail.com>
Mon, 7 Sep 2020 08:12:20 +0000 (04:12 -0400)
committerFrank DeMarco <if.self.end@gmail.com>
Mon, 7 Sep 2020 08:12:20 +0000 (04:12 -0400)
Sea.cpp
Sea.hpp
config.json
lib/sfw

diff --git a/Sea.cpp b/Sea.cpp
index 09de522..30b9e1f 100644 (file)
--- a/Sea.cpp
+++ b/Sea.cpp
@@ -1332,9 +1332,228 @@ void Searupt::update()
     }
 }
 
-Seasqueeze::Seasqueeze(Node* parent) : Sea(parent) {}
+Seasqueeze::Seasqueeze(Node* parent) : Sea(parent)
+{
+    world_box = {{0, 0}, {1600, 405}};
+    jellyfish.reserve(7);
+    jellyfish.emplace_back(this, glm::vec2(40, 20), -1);
+    jellyfish.emplace_back(this, glm::vec2(65, 80), -1);
+    jellyfish.emplace_back(this, glm::vec2(40, 40), -1);
+    jellyfish.emplace_back(this, glm::vec2(40, 40), -1);
+    jellyfish.emplace_back(this, glm::vec2(80, 30), -1);
+    jellyfish.emplace_back(this, glm::vec2(32, 48), -1);
+    jellyfish.emplace_back(this, glm::vec2(32, 48), -1);
+    floors.reserve(3);
+    floors.emplace_back(this, 300, 200, true);
+    floors.emplace_back(this, 530, 120, true);
+    floors.emplace_back(this, 200, 17, true);
+    corals.reserve(4);
+    corals.emplace_back(this, "paragorgia-arborea");
+    corals.emplace_back(this, "diploria-labyrinthiformis", glm::vec2(10, -50));
+    corals.emplace_back(this, "paragorgia-arborea");
+    corals.emplace_back(this, "acropora-latistella");
+    cans.reserve(6);
+    cans.emplace_back(this, true);
+    cans.emplace_back(this, false, true);
+    cans.emplace_back(this, true);
+    cans.emplace_back(this, true);
+    cans.emplace_back(this, true, true);
+    cans.emplace_back(this);
+    recycle_start = {410, 70};
+    anemone_start = {80, 80};
+    shift_jellyfish_animation.play();
+}
+
+void Seasqueeze::load()
+{
+    Sea::load();
+    floors[1].move({1070, 0});
+    floors[2].move({550, 0});
+    corals[0].set_sw({85, floors[0].get_top()});
+    corals[1].set_sw(floors[1].get_nw() + glm::vec2(5, 0));
+    corals[2].set_sw(floors[1].get_nw() + glm::vec2(355, 0));
+    corals[3].set_sw(floors[2].get_nw() - glm::vec2(85, 0));
+    clownfish_start = corals[2].get_north();
+}
+
+void Seasqueeze::activate()
+{
+    Sea::activate();
+    seafloor.set_bottom(get_window_box().get_bottom());
+}
+
+void Seasqueeze::restart()
+{
+    clownfish.set_frameset("left");
+    jellyfish_moving_right = true;
+    jellyfish_offset_x = 0;
+    Sea::restart();
+    place_cans({{20, 30}, {252, 130}, {0, 0}, {0, 0}});
+    jellyfish[0].set_nw({20, 10});
+    jellyfish[1].set_nw({230, 50});
+    jellyfish[2].set_nw(corals[3].get_nw() + glm::vec2(-10, 200));
+    jellyfish[3].set_nw(corals[3].get_nw() + glm::vec2(190, 200));
+    jellyfish[4].set_nw(corals[3].get_nw() + glm::vec2(90, -90));
+    can_angle = 0;
+}
+
+void Seasqueeze::shift_jellyfish()
+{
+    float speed = 2.0f * .416;
+    glm::vec2 step;
+    for (int ii = 2; ii < 5; ii++)
+    {
+        step = root->weight({speed * (jellyfish_moving_right ? 1 : -1), 0});
+        jellyfish[ii].move(step);
+        jellyfish_offset_x += std::abs(step.x);
+        if (jellyfish_offset_x >= 380)
+        {
+            jellyfish_offset_x = 0;
+            jellyfish_moving_right = !jellyfish_moving_right;
+        }
+        cans[ii].set_north(jellyfish[ii].get_south());
+    }
+}
+
+void Seasqueeze::update()
+{
+    if (is_active())
+    {
+        shift_jellyfish_animation.update();
+        glm::vec2 point = sfw::get_point_on_circle({1400, 220}, 120, can_angle);
+        point += glm::vec2(world_box.get_left(), 0);
+        cans[5].set_center(point);
+        jellyfish[5].set_center(cans[5].get_center() + glm::vec2(-60, 0));
+        jellyfish[6].set_center(cans[5].get_center() + glm::vec2(60, 0));
+        can_angle += root->weight(0.02618f * .416);
+        Sea::update();
+    }
+}
+
+Seaking::Seaking(Node* parent) : Sea(parent)
+{
+    world_box = {{0, 0}, {1600, 405}};
+    jellyfish.reserve(2);
+    jellyfish.emplace_back(this, glm::vec2(48, 48), -1);
+    jellyfish.emplace_back(this, glm::vec2(250, 270), 0);
+    floors.reserve(4);
+    floors.emplace_back(this, 1600, 17, true);
+    floors.emplace_back(this, 520, 200);
+    floors.emplace_back(this, 320, 150);
+    floors.emplace_back(this, 220, 240);
+    corals.reserve(5);
+    corals.emplace_back(this, "dendrogyra-cylindrus", glm::vec2(-150, -10));
+    corals.emplace_back(this, "paragorgia-arborea");
+    corals.emplace_back(this, "cycloseris-patelliformis", glm::vec2(-15, 0));
+    corals.emplace_back(this, "acropora-latistella");
+    corals.emplace_back(this, "cycloseris-patelliformis", glm::vec2(15, 0));
+    cans.reserve(6);
+    cans.emplace_back(this, true);
+    cans.emplace_back(this, true, true);
+    cans.emplace_back(this, true);
+    cans.emplace_back(this);
+    cans.emplace_back(this, true, true);
+    cans.emplace_back(this, true);
+}
+
+void Seaking::load()
+{
+    Sea::load();
+    floors[2].move({900, 0});
+    floors[3].set_right(world_box.get_right());
+    corals[0].set_sw(floors[1].get_nw() + glm::vec2(20, 0));
+    corals[1].set_sw(floors[0].get_nw() + glm::vec2(360, 0));
+    corals[2].set_sw(floors[0].get_nw() + glm::vec2(570, 0));
+    corals[3].set_sw(floors[2].get_nw() + glm::vec2(-20, 0));
+    corals[4].set_sw(floors[3].get_nw() + glm::vec2(40, 0));
+    clownfish_start = corals[3].get_center() + glm::vec2(0, 30);
+    recycle_start = floors[1].get_nw() + glm::vec2(405, -recycle.get_h() - 16);
+    anemone_start = corals[0].get_nw() + glm::vec2(171, 75);
+}
+
+void Seaking::restart()
+{
+    clownfish.set_frameset("right");
+    Sea::restart();
+    place_cans({{28, 54}, {190, 126}, {595, 320}, {900, 75}, {1360, 368}, {1540, 52}});
+    jellyfish[1].set_se(world_box.get_se() + glm::vec2(20, 50));
+    jellyfish[0].set_ne(world_box.get_sw());
+    launch_animation.reset();
+    launch();
+}
+
+void Seaking::launch()
+{
+    glm::vec2 j = get_world_coordinates(jellyfish[1], LAUNCH_OFFSET);
+    glm::vec2 p = get_world_coordinates(root->get_selected_scientist());
+    tx = p.x;
+    k = std::max(0.0f, p.y - 100 + LAUNCH_OFFSET.y);
+    while (true)
+    {
+        a = (j.y - k) / std::pow(j.x - tx, 2);
+        if (a * std::pow(p.x - tx, 2) + k >= p.y)
+        {
+            break;
+        }
+        if (j.x > p.x)
+        {
+            tx += 1;
+        }
+        else
+        {
+            tx -= 1;
+        }
+    }
+}
 
-Seaking::Seaking(Node* parent) : Sea(parent) {}
+void Seaking::update()
+{
+    if (is_active())
+    {
+        launch_animation.update();
+        Sea::update();
+        Jellyfish &bomb = jellyfish[0], &boss = jellyfish[1];
+        if (bomb.get_top() >= get_window_box().get_bottom())
+        {
+            bomb.set_center(boss.get_center() + LAUNCH_OFFSET);
+            launch_animation.play_once(2000.0f);
+        }
+        if (!launch_animation.is_playing())
+        {
+            glm::vec2 g = get_world_coordinates(bomb);
+            glm::vec2 n = g;
+            float distance = 0.0f;
+            while (distance < root->weight(12 * .416))
+            {
+                if (tx <= get_world_coordinates(boss, LAUNCH_OFFSET).x)
+                {
+                    n.x -= root->weight(.5);
+                }
+                else
+                {
+                    n.x += root->weight(.5);
+                }
+                n.y = a * std::pow(n.x - tx, 2) + k;
+                distance += glm::distance(n, g);
+                g = n;
+            }
+            bomb.set_center(n + world_box.get_nw());
+        }
+        if (bomb.collide(boss))
+        {
+            bomb.z_index = 0;
+        }
+        else
+        {
+            bomb.z_index = -1;
+        }
+    }
+}
+
+glm::vec2 Seaking::get_world_coordinates(const Sprite& sprite, const glm::vec2& offset)
+{
+    return sprite.get_center() + offset - world_box.get_nw();
+}
 
 Seagarden::Seagarden(Node* parent) : Sea(parent) {}
 
diff --git a/Sea.hpp b/Sea.hpp
index 02da24d..ea7f96d 100644 (file)
--- a/Sea.hpp
+++ b/Sea.hpp
@@ -304,14 +304,32 @@ struct Searupt : Sea
 struct Seasqueeze : Sea
 {
 
+    Animation shift_jellyfish_animation = Animation(&Seasqueeze::shift_jellyfish, this);
+    bool jellyfish_moving_right;
+    float jellyfish_offset_x, can_angle;
+
     Seasqueeze(Node*);
+    void load();
+    void activate();
+    void restart();
+    void shift_jellyfish();
+    void update();
 
 };
 
 struct Seaking : Sea
 {
 
+    const glm::vec2 LAUNCH_OFFSET = {-80, -80};
+    Animation launch_animation = Animation(&Seaking::launch, this);
+    float tx, k, a;
+
     Seaking(Node*);
+    void load();
+    void restart();
+    void launch();
+    void update();
+    glm::vec2 get_world_coordinates(const Sprite&, const glm::vec2& = {0, 0});
 
 };
 
index bc027cf..697006d 100644 (file)
@@ -2,7 +2,7 @@
     "display":
     {
         "dimensions": [720, 405],
-        "framerate": 30,
+        "framerate": 60,
         "title": "B.U.D.D.I.",
         "debug": false,
         "render-test-spacing": 2,
diff --git a/lib/sfw b/lib/sfw
index 9d97c35..7d00cda 160000 (submodule)
--- a/lib/sfw
+++ b/lib/sfw
@@ -1 +1 @@
-Subproject commit 9d97c3539df03486d877bd05e56203ca3e37b040
+Subproject commit 7d00cda9bbba770f9714bd0514d560faed950cab