wires
This commit is contained in:
+4
-3
@@ -31,21 +31,22 @@ void DrawButton(Button *button, Cube *cube)
|
||||
},
|
||||
});
|
||||
|
||||
Color color;
|
||||
if (pressed)
|
||||
{
|
||||
button->height = MIN(cube->position.y - cube->edge / 2.0f + 0.01f, 0.1f);
|
||||
button->color = GREEN;
|
||||
color = button->colorEnabled;
|
||||
button->pressed = true;
|
||||
cube->minY = cube->edge / 2.0f + 0.02f;
|
||||
}
|
||||
else
|
||||
{
|
||||
button->height = MIN(0.1f, button->height + 0.01f);
|
||||
button->color = PINK;
|
||||
color = button->colorDisabled;
|
||||
button->pressed = false;
|
||||
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);
|
||||
}
|
||||
|
||||
+2
-1
@@ -8,7 +8,8 @@ typedef struct
|
||||
Vector3 position;
|
||||
float length;
|
||||
float height;
|
||||
Color color;
|
||||
Color colorEnabled;
|
||||
Color colorDisabled;
|
||||
Color wiresColor;
|
||||
bool pressed;
|
||||
} Button;
|
||||
|
||||
+45
-20
@@ -3,34 +3,58 @@
|
||||
#include "player.h"
|
||||
#include "raylib.h"
|
||||
#include "screen.h"
|
||||
#include "wire.h"
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
Button button = {
|
||||
.position = (Vector3){0.0f, 0.0f, -5.0f},
|
||||
.length = 1.0f,
|
||||
.height = 0.1f,
|
||||
.color = PINK,
|
||||
.wiresColor = BLACK,
|
||||
.pressed = false,
|
||||
};
|
||||
|
||||
Cube cube = {
|
||||
.initialized = false,
|
||||
.position = (Vector3){0.0f, 0.5f, 0.0f},
|
||||
.minY = 0.4f + 0.01f,
|
||||
.edge = 0.8f,
|
||||
.color = RED,
|
||||
.wiresColor = BLACK,
|
||||
.grabbed = false,
|
||||
};
|
||||
static bool level_started = false;
|
||||
|
||||
void DrawLevel00(Player *player)
|
||||
{
|
||||
if (!cube.initialized)
|
||||
static Button button = {
|
||||
.position = (Vector3){0.0f, 0.0f, -5.0f},
|
||||
.length = 1.0f,
|
||||
.height = 0.1f,
|
||||
.colorEnabled = GREEN,
|
||||
.colorDisabled = RED,
|
||||
.wiresColor = BLACK,
|
||||
.pressed = false,
|
||||
};
|
||||
|
||||
static Wire wire = {
|
||||
.power = &button,
|
||||
.colorEnabled = GREEN,
|
||||
.colorDisabled = BLACK,
|
||||
};
|
||||
|
||||
static Cube cube = {
|
||||
.position = (Vector3){0.0f, 0.5f, 0.0f},
|
||||
.minY = 0.4f + 0.01f,
|
||||
.edge = 0.8f,
|
||||
.color = RED,
|
||||
.wiresColor = BLACK,
|
||||
.grabbed = false,
|
||||
};
|
||||
|
||||
if (!level_started)
|
||||
{
|
||||
level_started = true;
|
||||
|
||||
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;
|
||||
@@ -56,4 +80,5 @@ void DrawLevel00(Player *player)
|
||||
|
||||
MyDrawCube(&cube); // Draw a cube
|
||||
DrawButton(&button, &cube); // Draw a button
|
||||
DrawWire(&wire); // Draw a wire
|
||||
}
|
||||
|
||||
+36
@@ -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
@@ -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
|
||||
Reference in New Issue
Block a user