diff options
| author | LLLL Colonq <llll@colonq> | 2026-08-29 04:06:51 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2026-08-29 04:06:51 -0400 |
| commit | 761a3172bf4c15aed3836e4d1cd6f815b651b0e0 (patch) | |
| tree | cc90491529e83349d84d42a8e9982e5f0f38338e /2026/games/just__jane/include | |
| parent | 0d2d8cd897e94bd94e0b3ae7c6ce9aa580a44a0a (diff) | |
Fix
Diffstat (limited to '2026/games/just__jane/include')
| -rw-r--r-- | 2026/games/just__jane/include/clock.hpp | 24 | ||||
| -rw-r--r-- | 2026/games/just__jane/include/cut.hpp | 18 | ||||
| -rw-r--r-- | 2026/games/just__jane/include/game_loop.hpp | 14 | ||||
| -rw-r--r-- | 2026/games/just__jane/include/petal.hpp | 185 | ||||
| -rw-r--r-- | 2026/games/just__jane/include/score.hpp | 8 |
5 files changed, 249 insertions, 0 deletions
diff --git a/2026/games/just__jane/include/clock.hpp b/2026/games/just__jane/include/clock.hpp new file mode 100644 index 0000000..41bec56 --- /dev/null +++ b/2026/games/just__jane/include/clock.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include <raymath.h> + +class Clock { +private: + float radius_; + long frame_total_; + long current_frame_; + Vector2 center_position_; + +public: + Clock(float radius, Vector2 center, int total) { + radius_ = radius; + frame_total_ = total; + current_frame_ = total; + center_position_ = center; + } + + void Update(); + void Draw(); + bool TimeIsUp(); + void Reset(); +}; diff --git a/2026/games/just__jane/include/cut.hpp b/2026/games/just__jane/include/cut.hpp new file mode 100644 index 0000000..0804e86 --- /dev/null +++ b/2026/games/just__jane/include/cut.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "raylib.h" + +class Cut { +private: + Vector2 start_; + Vector2 end_; + float current_step_; + + Sound slash_; + +public: + Cut(Vector2 start, Vector2 end); + void Draw(); + void Update(); + bool its_joever = false; +}; diff --git a/2026/games/just__jane/include/game_loop.hpp b/2026/games/just__jane/include/game_loop.hpp new file mode 100644 index 0000000..d2b537c --- /dev/null +++ b/2026/games/just__jane/include/game_loop.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include <raylib.h> + +constexpr int GAME_WIDTH = 120; +constexpr int GAME_HEIGHT = 80; +constexpr int SCALE = 2; + +struct ScorePetal { + Vector2 Position; + Texture2D Texture; +}; + +void UpdateDrawFrame(); diff --git a/2026/games/just__jane/include/petal.hpp b/2026/games/just__jane/include/petal.hpp new file mode 100644 index 0000000..c85d227 --- /dev/null +++ b/2026/games/just__jane/include/petal.hpp @@ -0,0 +1,185 @@ +#pragma once + +#include "raylib.h" +#include <cstdlib> +#include <format> +#include <optional> +#include <random> + +struct PetalThing { + Texture2D texture; + bool direction; + Vector2 position; +}; + +class Petal { +private: + PetalThing thing_; + Vector2 size_; + Color color_; + std::mt19937 generator_; + std::uniform_real_distribution<float> change_direction_; + std::optional<Vector2> prev_mouse_position; + Texture2D cut_texture_; + std::vector<PetalThing> petal_things_; + long frame_count_ = 0; + Rectangle window_; + float fall_speed_; + + void update_position(PetalThing *thing) { + if (change_direction_(generator_) > 0.95) { + thing->direction = !thing->direction; + } + + float next_position = thing->direction ? thing->position.x - 2 : thing->position.x + 2; + if (next_position <= 0 - (thing->texture.width / 3.0f)) { + thing->direction = false; // we want to go right, right is false, clearly + next_position += 4; + } + + if (next_position >= window_.width - (thing->texture.width / 3.0f)) { + thing->direction = true; + next_position -= 4; + } + + thing->position.x = next_position; + + thing->position.y += fall_speed_; + } + + bool cut_internal(Vector2 start, Vector2 end) { + Rectangle rect = { + .x = thing_.position.x - 2, + .y = thing_.position.y - 2, + .width = size_.x + 4, + .height = size_.y + 4, + }; + + if (CheckCollisionPointRec(start, rect)) { + return true; + } + + if (CheckCollisionPointRec(end, rect)) { + return true; + } + + Vector2 tl = thing_.position; + Vector2 tr = {.x = rect.x + rect.width, .y = rect.y}; + Vector2 bl = {.x = rect.x, .y = rect.y + rect.height}; + Vector2 br = {.x = rect.x + rect.width, .y = rect.y + rect.height}; + + Vector2 collision_point; + + if (CheckCollisionLines(start, end, tl, tr, &collision_point)) { + return true; + } + + if (CheckCollisionLines(start, end, tl, bl, &collision_point)) { + return true; + } + + if (CheckCollisionLines(start, end, bl, br, &collision_point)) { + return true; + } + + if (CheckCollisionLines(start, end, br, tr, &collision_point)) { + return true; + } + + return false; + } + +public: + ~Petal() = default; + Petal(Rectangle window, unsigned seed) : window_(window) { + generator_ = std::mt19937(seed); + std::uniform_int_distribution<int> speed(0, 80); + std::uniform_int_distribution<int> x(0, window_.width); + auto pedal_thing = std::uniform_int_distribution<int>(0, 2); + int pedal = pedal_thing(generator_); + std::string file_path = std::format("assets/pedals/{}.png", pedal); + cut_texture_ = LoadTexture("assets/pedals/cut_pedal.png"); + thing_.texture = LoadTexture(file_path.c_str()); + thing_.position.x = x(generator_); + thing_.position.y = -thing_.texture.height; + size_ = {(float)thing_.texture.width, (float)thing_.texture.height}; + color_ = {0xFF, 0xFF, 0xFF, 0xFF}; + fall_speed_ = speed(generator_) / 100.0f; + } + + Petal(Rectangle window, Vector2 position, int p, float speed = 0.6) : window_(window) { + std::random_device rd; + generator_ = std::mt19937(rd()); + change_direction_ = std::uniform_real_distribution<float>(); + thing_.position = position; + thing_.texture = LoadTexture(std::format("assets/pedals/{}.png", p).c_str()); + cut_texture_ = LoadTexture("assets/pedals/cut_pedal.png"); + size_ = {(float)thing_.texture.width, (float)thing_.texture.height}; + fall_speed_ = speed; + color_ = {0xFF, 0xFF, 0xFF, 0xFF}; + } + + bool IsCut = false; + + void Cut() { + IsCut = true; + petal_things_.push_back( + PetalThing{ + .texture = cut_texture_, + .direction = true, + .position = Vector2{thing_.position.x - 1, thing_.position.y - 1}}); + + petal_things_.push_back( + PetalThing{ + .texture = cut_texture_, + .direction = false, + .position = Vector2{thing_.position.x + 1, thing_.position.y - 1}}); + + petal_things_.push_back( + PetalThing{ + .texture = cut_texture_, + .direction = true, + .position = Vector2{thing_.position.x - 1, thing_.position.y + 1}}); + + petal_things_.push_back( + PetalThing{ + .texture = cut_texture_, + .direction = false, + .position = Vector2{thing_.position.x + 1, thing_.position.y + 1}}); + } + + void Cut(Vector2 start, Vector2 end) { + + if (cut_internal(start, end)) { + Cut(); + } + } + + void Update() { + frame_count_ += 1; + if (frame_count_ % 2 != 0) { + return; + } + + if (IsCut) { + for (PetalThing &thing : petal_things_) { + update_position(&thing); + } + + } else { + update_position(&thing_); + } + } + + void Draw() { + if (IsCut) { + for (auto petal : petal_things_) { + DrawTextureEx(petal.texture, petal.position, 0, 1, color_); + } + } else { + DrawTextureEx(thing_.texture, thing_.position, 0, 1, color_); + } + } + + Vector2 GetPosition() { return thing_.position; } +}; diff --git a/2026/games/just__jane/include/score.hpp b/2026/games/just__jane/include/score.hpp new file mode 100644 index 0000000..20424ba --- /dev/null +++ b/2026/games/just__jane/include/score.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include <cstring> +#include <emscripten/fetch.h> + +void on_success(emscripten_fetch_t *fetch); +void on_error(emscripten_fetch_t *fetch); +void post_score(int score); |
