Impl. randomized effect colors on walker hack
All checks were successful
Build and Publish WASM version of demo / Build-And-Deploy (push) Successful in 26s

Also, minor fixes/refactorings.
This commit is contained in:
Stephen Seo 2023-08-31 15:26:24 +09:00
parent 247fc8c74b
commit 3c944d6f8e
11 changed files with 94 additions and 21 deletions

View file

@ -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}))

View 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};
}

View 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

41
src/common_constants.cc Normal file
View file

@ -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;
}
}

View 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

View file

@ -33,9 +33,11 @@
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) {

View 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;

View 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

View 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) {

View 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;
};

View 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})))