added seawell level
authorFrank DeMarco <if.self.end@gmail.com>
Sun, 6 Sep 2020 07:02:23 +0000 (03:02 -0400)
committerFrank DeMarco <if.self.end@gmail.com>
Sun, 6 Sep 2020 07:02:23 +0000 (03:02 -0400)
Sea.cpp
Sea.hpp
lib/sfw

diff --git a/Sea.cpp b/Sea.cpp
index 484a348..2eacb30 100644 (file)
--- a/Sea.cpp
+++ b/Sea.cpp
@@ -85,7 +85,7 @@ void Sea::activate()
 {
     Node::activate();
     restore_background_animation.reset();
-    root->set_gravity(4.576f);
+    root->set_gravity(4.96f);
     anemone.hide();
     // root->populate_bubbles(world_rect)
     // root->arrange_bubbles(world_rect)
@@ -945,7 +945,97 @@ void Seabed::update()
     }
 }
 
-Seawell::Seawell(Node* parent) : Sea(parent) {}
+Seawell::Seawell(Node* parent) : Sea(parent)
+{
+    world_box = {{0, 0}, {1170, 405}};
+    floors.emplace_back(this, 1270, 345);
+    corals.reserve(6);
+    for (int ii = 0; ii < 6; ii++)
+    {
+        corals.emplace_back(this, "euplectella-aspergillum");
+    }
+    cans.reserve(3);
+    cans.emplace_back(this, true, true);
+    cans.emplace_back(this);
+    cans.emplace_back(this, false, true);
+    jellyfish.reserve(2);
+    jellyfish.emplace_back(this, glm::vec2(42, 30), -1);
+    jellyfish.emplace_back(this, glm::vec2(42, 30), -1);
+    clownfish_start = {1060, 185};
+    recycle_start = {140, 80};
+}
+
+void Seawell::load()
+{
+    Sea::load();
+    floors[0].move({-50, 0});
+    float world_bottom = world_box.get_bottom();
+    corals[0].move({32, world_bottom + 36 - corals[0].get_bottom()});
+    corals[1].move({200, world_bottom + 136 - corals[1].get_bottom()});
+    corals[2].move({400, world_bottom + 36 - corals[2].get_bottom()});
+    corals[3].move({650, world_bottom + 76 - corals[3].get_bottom()});
+    corals[4].move({870, world_bottom + 176 - corals[4].get_bottom()});
+    corals[5].move({1020, world_bottom + 116 - corals[5].get_bottom()});
+    anemone_start = anemone.get_box().stamp(corals[0].get_north() - anemone.get_south()).get_nw();
+    anemone_start.y += 14;
+}
+
+void Seawell::activate()
+{
+    Sea::activate();
+    seafloor.move({0, 32});
+}
+
+void Seawell::restart()
+{
+    clownfish.set_frameset("left");
+    Sea::restart();
+    jellyfish[0].direction = 1;
+    jellyfish[0].x_range = {215, 295};
+    jellyfish[0].y_range = {170, 280};
+    jellyfish[0].set_south({jellyfish[0].x_range.x, 250});
+    jellyfish[1].direction = 1;
+    jellyfish[1].x_range = {570, 850};
+    jellyfish[1].y_range = {120, 260};
+    jellyfish[1].set_south({jellyfish[1].x_range.x, 130});
+    place_cans(
+        {corals[0].get_north() + glm::vec2(-cans[0].get_w() / 2, -12),
+         corals[2].get_north() + glm::vec2(-cans[1].get_w() / 2, -20),
+         corals[4].get_north() + glm::vec2(-cans[2].get_w() / 2, -12)});
+}
+
+void Seawell::scroll(float amount)
+{
+    Sea::scroll(amount);
+    for (Jellyfish& jelly : jellyfish)
+    {
+        jelly.x_range += glm::vec2(amount, amount);
+    }
+}
+
+void Seawell::update()
+{
+    for (Jellyfish& jelly : jellyfish)
+    {
+        x = jelly.get_south().x;
+        y = jelly.get_south().y;
+        sx = jelly.x_range.x;
+        ex = jelly.x_range.y;
+        nx = x + 5 * jelly.direction;
+        ny = std::pow(((nx - (sx + (ex - sx) / 2)) / 12), 2) + jelly.y_range.x;
+        glm::vec2 step = root->weight(Segment({x, y}, {nx, ny}).get_step(1.248));
+        jelly.move(step);
+        if (jelly.get_center_x() > sx + (ex - sx) / 2 && jelly.get_bottom() > jelly.y_range.y)
+        {
+            jelly.direction = -1;
+        }
+        else if (jelly.get_center_x() < sx + (ex - sx) / 2 && jelly.get_bottom() > jelly.y_range.y)
+        {
+            jelly.direction = 1;
+        }
+    }
+    Sea::update();
+}
 
 Seabreeze::Seabreeze(Node* parent) : Sea(parent) {}
 
@@ -1111,6 +1201,33 @@ void Jellyfish::load()
     SDL_DestroyTexture(wiggled);
 }
 
+void Jellyfish::reset()
+{
+    Sprite::reset();
+    bob_animation.reset();
+    offset = {0.0f, 0.0f};
+    bobbing_up = true;
+    moving_right = true;
+    released = true;
+}
+
+void Jellyfish::bob()
+{
+    float step = .416f;
+    move_weighted({0, step * bobbing_up});
+    offset.y += step;
+    if (offset.y >= 32.0f)
+    {
+        offset.y = 0.0f;
+        bobbing_up = !bobbing_up;
+    }
+}
+
+void Jellyfish::release()
+{
+    released = true;
+}
+
 Clownfish::Clownfish(Sea* parent) : Sprite(parent, "resource/clownfish")
 {
     int frame_count = frame_paths.size();
diff --git a/Sea.hpp b/Sea.hpp
index 70727df..e48046b 100644 (file)
--- a/Sea.hpp
+++ b/Sea.hpp
 #include "Platform.hpp"
 #include "Color.hpp"
 #include "Node.hpp"
+#include "Animation.hpp"
 
 struct Sea;
 
 struct Jellyfish : Sprite
 {
 
-    glm::vec2 frame_size;
+    glm::vec2 frame_size, offset = {0.0f, 0.0f}, x_range, y_range;
     int z_index;
     Color body_color, eye_color;
+    float direction;
+    Animation bob_animation = Animation(&Jellyfish::bob, this),
+        release_animation = Animation(&Jellyfish::release, this);
+    bool bobbing_up = true, moving_right = true, released = true;
 
     Jellyfish(Sea*, glm::vec2, int, const Color& = Color(255, 255, 255), const Color& = Color(255, 0, 0));
     void load();
+    void reset();
+    void bob();
+    void release();
 
 };
 
@@ -123,7 +131,6 @@ struct Buddi : Sprite
 };
 
 #include "Recycle.hpp"
-#include "Animation.hpp"
 
 struct Sea : Node
 {
@@ -245,7 +252,15 @@ struct Seabed : Sea
 struct Seawell : Sea
 {
 
+    glm::vec2 step;
+    float x, y, sx, ex, nx, ny;
+
     Seawell(Node*);
+    void load();
+    void activate();
+    void restart();
+    void scroll(float);
+    void update();
 
 };
 
diff --git a/lib/sfw b/lib/sfw
index 35a5acb..df8bf26 160000 (submodule)
--- a/lib/sfw
+++ b/lib/sfw
@@ -1 +1 @@
-Subproject commit 35a5acbd532bdaf03a869e6b57664a787eb51134
+Subproject commit df8bf267f02f3f9fb3e4136d97d8dcf0a9a2f26b