]> git.seodisparate.com - jumpartifact.com_demo_0/commitdiff
Impl. randomized effect colors on walker hack
authorStephen Seo <seo.disparate@gmail.com>
Thu, 31 Aug 2023 06:26:24 +0000 (15:26 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 31 Aug 2023 06:26:24 +0000 (15:26 +0900)
Also, minor fixes/refactorings.

Makefile
src/3d_helpers.cc
src/3d_helpers.h
src/common_constants.cc [new file with mode: 0644]
src/common_constants.h
src/electricity_effect.cc
src/electricity_effect.h
src/screen_trunner.cc
src/spark_effect.cc
src/spark_effect.h
wasm_build/Makefile

index ea698392e8a863247bb7f4faa4e3ac658f49b8cf..4cc8afcc71310252a9a8c7178bc6cf33c439196d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,8 @@ SOURCES = \
                src/surface_triangle.cc \
                src/screen_walker_hack.cc \
                src/electricity_effect.cc \
-               src/spark_effect.cc
+               src/spark_effect.cc \
+               src/common_constants.cc
 
 HEADERS = \
                src/game.h \
@@ -35,7 +36,8 @@ HEADERS = \
                src/surface_triangle.h \
                src/screen_walker_hack.h \
                src/electricity_effect.h \
-               src/spark_effect.h
+               src/spark_effect.h \
+               src/common_constants.h
 
 OBJECTS = $(addprefix ${OBJDIR}/,$(subst .cc,.cc.o,${SOURCES}))
 
index 4057a95b83921c58731bcf1173485cbea4589f76..14d0b5650f49be985e9accda4a336d25d5cf3c2f 100644 (file)
@@ -196,11 +196,11 @@ std::array<Vector3, 4> get_quad_from_start_end(Vector3 start, Vector3 end,
   return quad;
 }
 
-Vector3 operator+(const Vector3 &a, const Vector3 &b) {
+Vector3 operator+(Vector3 a, Vector3 b) {
   return Vector3{a.x + b.x, a.y + b.y, a.z + b.z};
 }
 
-Vector3 operator-(const Vector3 &a, const Vector3 &b) {
+Vector3 operator-(Vector3 a, Vector3 b) {
   return Vector3{a.x - b.x, a.y - b.y, a.z - b.z};
 }
 
@@ -211,3 +211,7 @@ Vector3 operator*(Vector3 vec3, float factor) {
 Vector3 operator*(Matrix mat, Vector3 vec3) {
   return Vector3Transform(vec3, mat);
 }
+
+Vector4 operator*(Vector4 a, Vector4 b) {
+  return Vector4{a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w};
+}
index e0f0190a93bd8c4ffa243b663b0e29346b6ae76d..1a6be9463c402cfddc8beaf64337cdeda7ea2c0e 100644 (file)
@@ -50,11 +50,13 @@ extern std::array<Vector3, 4> get_quad_from_start_end(Vector3 start,
 // weirdness regarding column-major matrices.
 // extern Vector4 operator*(const Matrix &m, const Vector4 &v);
 
-extern Vector3 operator+(const Vector3 &a, const Vector3 &b);
-extern Vector3 operator-(const Vector3 &a, const Vector3 &b);
+extern Vector3 operator+(Vector3 a, Vector3 b);
+extern Vector3 operator-(Vector3 a, Vector3 b);
 
 extern Vector3 operator*(Vector3 vec3, float factor);
 
 extern Vector3 operator*(Matrix mat, Vector3 vec3);
 
+extern Vector4 operator*(Vector4 a, Vector4 b);
+
 #endif
diff --git a/src/common_constants.cc b/src/common_constants.cc
new file mode 100644 (file)
index 0000000..16d2f3a
--- /dev/null
@@ -0,0 +1,41 @@
+#include "common_constants.h"
+
+// third-party includes.
+#include <raylib.h>
+
+// local includes.
+#include "ems.h"
+
+NeonColor get_random_neon_color() {
+  return (NeonColor)(call_js_get_random() * (float)NeonColor::NEON_COLOR_SIZE);
+}
+
+void set_color_from_neon_color(NeonColor nc, Color *c_out) {
+  if (!c_out) {
+    return;
+  }
+
+  switch (nc) {
+    case NeonColor::NEON_COLOR_RED:
+      *c_out = Color{255, 0, 0, 255};
+      break;
+    case NeonColor::NEON_COLOR_GREEN:
+      *c_out = Color{0, 255, 0, 255};
+      break;
+    case NeonColor::NEON_COLOR_BLUE:
+      *c_out = Color{0, 0, 255, 255};
+      break;
+    case NeonColor::NEON_COLOR_CYAN:
+      *c_out = Color{0, 255, 255, 255};
+      break;
+    case NeonColor::NEON_COLOR_YELLOW:
+      *c_out = Color{255, 255, 0, 255};
+      break;
+    case NeonColor::NEON_COLOR_MAGENTA:
+      *c_out = Color{255, 0, 255, 255};
+      break;
+    default:
+      *c_out = Color{255, 255, 255, 255};
+      break;
+  }
+}
index 47e0c0f07ad18057c0082ee1c72ee8912884b3e0..574a1e46824376db0bd00e4c53e51340b696635d 100644 (file)
@@ -1,10 +1,26 @@
 #ifndef JUMPARTIFACT_DOT_COM_DEMO_0_COMMON_CONSTANTS_H_
 #define JUMPARTIFACT_DOT_COM_DEMO_0_COMMON_CONSTANTS_H_
 
+// Forward declaration.
+struct Color;
+
 constexpr unsigned int SURFACE_UNIT_WIDTH = 51;
 constexpr unsigned int SURFACE_UNIT_HEIGHT = 51;
 
 constexpr float SURFACE_X_OFFSET = (float)SURFACE_UNIT_WIDTH / 2.0F - 0.5F;
 constexpr float SURFACE_Y_OFFSET = (float)SURFACE_UNIT_HEIGHT / 2.0F - 0.5F;
 
+enum class NeonColor {
+  NEON_COLOR_RED = 0,
+  NEON_COLOR_GREEN,
+  NEON_COLOR_BLUE,
+  NEON_COLOR_CYAN,
+  NEON_COLOR_YELLOW,
+  NEON_COLOR_MAGENTA,
+  NEON_COLOR_SIZE
+};
+
+extern NeonColor get_random_neon_color();
+extern void set_color_from_neon_color(NeonColor nc, Color *c_out);
+
 #endif
index c03daa2106bf843649e388d336719425cba670c0..5b0ed59dc6bb0ba0a7179ca5c233cf93c167bebb 100644 (file)
 std::optional<Shader> ElectricityEffect::shader = std::nullopt;
 
 ElectricityEffect::ElectricityEffect(Vector3 center, float radius,
-                                     int line_count, float lifetime)
+                                     int line_count, float lifetime,
+                                     Color color)
     : end_points(),
       center(center),
+      color(color),
       radius(radius),
       lifetime(lifetime),
       timer(0.0F) {
@@ -113,7 +115,7 @@ bool ElectricityEffect::update(float dt) {
   return timer >= lifetime;
 }
 
-void ElectricityEffect::draw(Color color, Camera *camera) {
+void ElectricityEffect::draw(Camera *camera) {
   float ratio = timer < lifetime ? (1.0F - timer / lifetime) : 0.0F;
 
   for (const auto &end_point : end_points) {
index 2f3b6deacdb46e6161bc7d8bf4f969db7fba0931..aecc3222e0661c82c4367e142e078380978fec13 100644 (file)
@@ -17,12 +17,12 @@ constexpr float QUAD_MOVE_RATE = 0.05F;
 class ElectricityEffect {
  public:
   ElectricityEffect(Vector3 center, float radius, int line_count,
-                    float lifetime);
+                    float lifetime, Color color);
 
   /// Returns true if lifetime ended.
   bool update(float dt);
   /// Assumes draw mode is active.
-  void draw(Color color, Camera *camera);
+  void draw(Camera *camera);
 
   static Shader get_shader();
   static void cleanup_shader();
@@ -39,6 +39,7 @@ class ElectricityEffect {
   static std::optional<Shader> shader;
   std::vector<EndPoint> end_points;
   Vector3 center;
+  Color color;
   float radius;
   float lifetime;
   float timer;
index bb6e6258e6b2eccedb0cad435150bd1214191871..975d36b695c522faf8680d54f17f70f21fac10a3 100644 (file)
@@ -108,15 +108,17 @@ bool TRunnerScreen::update(float dt, bool is_resized) {
   if (flags.test(1)) {
     if (walker_hack_success && controlled_walker_idx.has_value()) {
       walkers[controlled_walker_idx.value()].set_player_controlled(true);
+      Color color;
+      set_color_from_neon_color(get_random_neon_color(), &color);
       electricityEffects.push_back(ElectricityEffect(
           walkers[controlled_walker_idx.value()].get_body_pos(),
           ELECTRICITY_EFFECT_RADIUS, ELECTRICITY_EFFECT_LINE_COUNT,
-          ELECTRICITY_EFFECT_LIFETIME));
+          ELECTRICITY_EFFECT_LIFETIME, color));
 
       sparkEffects.push_back(
           SparkEffect(SPARK_EFFECT_SPARK_COUNT, SPARK_EFFECT_LIFETIME,
                       walkers[controlled_walker_idx.value()].get_body_pos(),
-                      SPARK_EFFECT_XZ_VARIANCE, SPARK_EFFECT_RADIUS));
+                      SPARK_EFFECT_XZ_VARIANCE, SPARK_EFFECT_RADIUS, color));
     } else {
       controlled_walker_idx.reset();
     }
@@ -372,11 +374,11 @@ bool TRunnerScreen::draw(RenderTexture *render_texture) {
   }
 
   for (auto &ee : electricityEffects) {
-    ee.draw(GREEN, &camera);
+    ee.draw(&camera);
   }
 
   for (auto &se : sparkEffects) {
-    se.draw(GREEN);
+    se.draw();
   }
 
   // TODO DEBUG
index b747e3b7ca9b4420262b106abace140e50f90986..d60133dc494b8f7f99581134702417d1e1c200a8 100644 (file)
@@ -5,8 +5,8 @@
 #include "ems.h"
 
 SparkEffect::SparkEffect(int count, float lifetime, Vector3 pos,
-                         float pos_xz_variance, float radius)
-    : sparks(), lifetime(lifetime), timer(0.0F) {
+                         float pos_xz_variance, float radius, Color color)
+    : sparks(), color(color), lifetime(lifetime), timer(0.0F) {
   sparks.reserve(count);
 
   Vector3 above_pos = pos;
@@ -36,7 +36,7 @@ bool SparkEffect::update(float dt) {
   return timer > lifetime;
 }
 
-void SparkEffect::draw(Color color) {
+void SparkEffect::draw() {
   float ratio = timer < lifetime ? (1.0F - timer / lifetime) : 0.0F;
 
   for (const auto &spark : sparks) {
index 0dde24a3e96be6be8b700146d4e2cb6b67814e3f..430cf7a7afab7d138d0cc68e9b36bb39e40e58fb 100644 (file)
@@ -15,13 +15,13 @@ constexpr float SPARK_ACC_RATE = 8.0F;
 class SparkEffect {
  public:
   SparkEffect(int count, float lifetime, Vector3 pos, float pos_xz_variance,
-              float radius);
+              float radius, Color color);
 
   /// Returns true if end of lifetime.
   bool update(float dt);
 
   /// Assumes draw mode is active when called.
-  void draw(Color color);
+  void draw();
 
  private:
   struct Spark {
@@ -29,6 +29,7 @@ class SparkEffect {
   };
 
   std::vector<Spark> sparks;
+  Color color;
   float lifetime;
   float timer;
 };
index 0af63c64743afd03b3143aa63c47ed01e1da9998..37f6cfac4a4f6f34a21d4a473207ea91f0d24e9b 100644 (file)
@@ -19,7 +19,8 @@ SOURCES = \
                ../src/surface_triangle.cc \
                ../src/screen_walker_hack.cc \
                ../src/electricity_effect.cc \
-               ../src/spark_effect.cc
+               ../src/spark_effect.cc \
+               ../src/common_constants.cc
 
 HEADERS = \
                ../src/ems.h \
@@ -32,7 +33,8 @@ HEADERS = \
                ../src/surface_triangle.h \
                ../src/screen_walker_hack.h \
                ../src/electricity_effect.h \
-               ../src/spark_effect.h
+               ../src/spark_effect.h \
+               ../src/common_constants.h
 
 OBJECTS = $(addprefix ${OBJDIR}/,$(subst ..,PREVDIR,$(subst .cc,.cc.o,${SOURCES})))