Also, minor fixes/refactorings.
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 \
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}))
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};
}
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};
+}
// 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
--- /dev/null
+#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;
+ }
+}
#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
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) {
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) {
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();
static std::optional<Shader> shader;
std::vector<EndPoint> end_points;
Vector3 center;
+ Color color;
float radius;
float lifetime;
float timer;
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();
}
}
for (auto &ee : electricityEffects) {
- ee.draw(GREEN, &camera);
+ ee.draw(&camera);
}
for (auto &se : sparkEffects) {
- se.draw(GREEN);
+ se.draw();
}
// TODO DEBUG
#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;
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) {
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 {
};
std::vector<Spark> sparks;
+ Color color;
float lifetime;
float timer;
};
../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 \
../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})))