This commit is contained in:
speckitor
2026-07-07 18:18:43 +07:00
parent f3c71085be
commit ef2f6d004c
5 changed files with 119 additions and 24 deletions
+4 -3
View File
@@ -31,21 +31,22 @@ void DrawButton(Button *button, Cube *cube)
}, },
}); });
Color color;
if (pressed) if (pressed)
{ {
button->height = MIN(cube->position.y - cube->edge / 2.0f + 0.01f, 0.1f); button->height = MIN(cube->position.y - cube->edge / 2.0f + 0.01f, 0.1f);
button->color = GREEN; color = button->colorEnabled;
button->pressed = true; button->pressed = true;
cube->minY = cube->edge / 2.0f + 0.02f; cube->minY = cube->edge / 2.0f + 0.02f;
} }
else else
{ {
button->height = MIN(0.1f, button->height + 0.01f); button->height = MIN(0.1f, button->height + 0.01f);
button->color = PINK; color = button->colorDisabled;
button->pressed = false; button->pressed = false;
cube->minY = cube->edge / 2.0f + 0.01f; cube->minY = cube->edge / 2.0f + 0.01f;
} }
DrawCube(button->position, button->length, button->height, button->length, button->color); DrawCube(button->position, button->length, button->height, button->length, color);
DrawCubeWires(button->position, button->length, button->height, button->length, button->wiresColor); DrawCubeWires(button->position, button->length, button->height, button->length, button->wiresColor);
} }
+2 -1
View File
@@ -8,7 +8,8 @@ typedef struct
Vector3 position; Vector3 position;
float length; float length;
float height; float height;
Color color; Color colorEnabled;
Color colorDisabled;
Color wiresColor; Color wiresColor;
bool pressed; bool pressed;
} Button; } Button;
+33 -8
View File
@@ -3,20 +3,31 @@
#include "player.h" #include "player.h"
#include "raylib.h" #include "raylib.h"
#include "screen.h" #include "screen.h"
#include "wire.h"
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
Button button = { static bool level_started = false;
void DrawLevel00(Player *player)
{
static Button button = {
.position = (Vector3){0.0f, 0.0f, -5.0f}, .position = (Vector3){0.0f, 0.0f, -5.0f},
.length = 1.0f, .length = 1.0f,
.height = 0.1f, .height = 0.1f,
.color = PINK, .colorEnabled = GREEN,
.colorDisabled = RED,
.wiresColor = BLACK, .wiresColor = BLACK,
.pressed = false, .pressed = false,
}; };
Cube cube = { static Wire wire = {
.initialized = false, .power = &button,
.colorEnabled = GREEN,
.colorDisabled = BLACK,
};
static Cube cube = {
.position = (Vector3){0.0f, 0.5f, 0.0f}, .position = (Vector3){0.0f, 0.5f, 0.0f},
.minY = 0.4f + 0.01f, .minY = 0.4f + 0.01f,
.edge = 0.8f, .edge = 0.8f,
@@ -25,12 +36,25 @@ Cube cube = {
.grabbed = false, .grabbed = false,
}; };
void DrawLevel00(Player *player) if (!level_started)
{
if (!cube.initialized)
{ {
level_started = true;
cube.model = LoadModelFromMesh(GenMeshCube(cube.edge, cube.edge, cube.edge)); cube.model = LoadModelFromMesh(GenMeshCube(cube.edge, cube.edge, cube.edge));
cube.initialized = true;
float wireW = 0.1f;
float wireH = 0.1f;
float wireL = 5.0f;
float wireZ = button.position.z - wireL / 2.0f - button.length / 2.0f;
Vector3 wirePos = {0.0f, wireH / 2.0f, wireZ};
WireAppend(&wire, wirePos, wireW, wireH, wireL);
wireZ -= wireL / 2.0f;
wireW = 5.0f;
wireH = 0.1f;
wireL = 0.1f;
wirePos = (Vector3){wireW / 2.0f, wireH / 2.0f, wireZ};
WireAppend(&wire, wirePos, wireW, wireH, wireL);
} }
const int floorExtent = 25; const int floorExtent = 25;
@@ -56,4 +80,5 @@ void DrawLevel00(Player *player)
MyDrawCube(&cube); // Draw a cube MyDrawCube(&cube); // Draw a cube
DrawButton(&button, &cube); // Draw a button DrawButton(&button, &cube); // Draw a button
DrawWire(&wire); // Draw a wire
} }
+36
View File
@@ -0,0 +1,36 @@
#include "wire.h"
#include "raylib.h"
#include <stdlib.h>
void WireAppend(Wire *wire, Vector3 position, float width, float height, float length)
{
if (!wire->nodes)
{
wire->nodes_capasity = DEFAULT_WIRES_CAPASITY;
wire->nodes = calloc(wire->nodes_capasity, sizeof(WireNode));
}
if (wire->nodes_count == wire->nodes_capasity)
{
wire->nodes_capasity *= 1.5;
wire->nodes = realloc(wire->nodes, sizeof(WireNode) * wire->nodes_capasity);
}
WireNode *node = &wire->nodes[wire->nodes_count++];
node->position = position;
node->width = width;
node->height = height;
node->length = length;
}
void DrawWire(Wire *wire)
{
Color color = wire->power->pressed ? wire->colorEnabled : wire->colorDisabled;
WireNode *node;
for (int i = 0; i < wire->nodes_count; ++i)
{
node = &wire->nodes[i];
DrawCube(node->position, node->width, node->height, node->length, color);
}
}
+32
View File
@@ -0,0 +1,32 @@
#ifndef WIRE_H
#define WIRE_H
#include "button.h"
#include "raylib.h"
#include <stddef.h>
#define DEFAULT_WIRES_CAPASITY 4
typedef struct
{
Vector3 position;
float width;
float height;
float length;
} WireNode;
typedef struct
{
Button *power;
WireNode *nodes;
size_t nodes_count;
size_t nodes_capasity;
Color colorEnabled;
Color colorDisabled;
} Wire;
void WireAppend(Wire *wire, Vector3 position, float width, float height, float length);
void DrawWire(Wire *wire);
#endif // WIRE_H