This commit is contained in:
2026-07-08 13:43:18 +03:00
parent ef2f6d004c
commit 6fbcfdbb01
7 changed files with 70 additions and 9 deletions
+22
View File
@@ -0,0 +1,22 @@
#include "door.h"
#include "raylib.h"
void DrawDoor(Door *door)
{
float movStep = door->opened ? door->movStep : -door->movStep;
Vector3 posEnd = door->opened ? door->positionOpened : door->positionClosed;
if (door->position.x != posEnd.x)
{
door->position.x += movStep;
}
if (door->position.y != posEnd.y)
{
door->position.y += movStep;
}
if (door->position.z != posEnd.z)
{
door->position.z += movStep;
}
DrawCube(door->position, door->width, door->height, door->length, door->color);
DrawCubeWires(door->position, door->width, door->height, door->length, door->wiresColor);
}
+22
View File
@@ -0,0 +1,22 @@
#ifndef DOOR_H
#define DOOR_H
#include "raylib.h"
typedef struct
{
Vector3 position;
const Vector3 positionClosed;
const Vector3 positionOpened;
Color color;
Color wiresColor;
float width;
float height;
float length;
float movStep;
bool opened;
} Door;
void DrawDoor(Door *door);
#endif // DOOR_H
+21 -6
View File
@@ -1,5 +1,6 @@
#include "button.h"
#include "cube.h"
#include "door.h"
#include "player.h"
#include "raylib.h"
#include "screen.h"
@@ -21,12 +22,6 @@ void DrawLevel00(Player *player)
.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,
@@ -36,6 +31,25 @@ void DrawLevel00(Player *player)
.grabbed = false,
};
static Door door = {
.position = (Vector3){5.0f, 2.5f, -15.0f},
.positionClosed = (Vector3){5.0f, 2.5f, -15.0f},
.positionOpened = (Vector3){5.0f, 2.5f, -5.0f},
.width = 1.0f,
.height = 5.0f,
.length = 10.0f,
.color = RED,
.wiresColor = BLACK,
.movStep = 1.0f,
};
static Wire wire = {
.power = &button,
.door = &door,
.colorEnabled = GREEN,
.colorDisabled = BLACK,
};
if (!level_started)
{
level_started = true;
@@ -81,4 +95,5 @@ void DrawLevel00(Player *player)
MyDrawCube(&cube); // Draw a cube
DrawButton(&button, &cube); // Draw a button
DrawWire(&wire); // Draw a wire
DrawDoor(&door);
}
+1 -1
View File
@@ -45,4 +45,4 @@ void UpdateBody(Player *player, float rot, char side, char forward, bool jump, b
void UpdateGrab(Player *player, Cube *cube);
#endif
#endif // PLAYER_H
+1 -1
View File
@@ -8,4 +8,4 @@
void DrawLevel00(Player *player);
#endif
#endif // SCREEN_H
+1 -1
View File
@@ -26,7 +26,7 @@ void WireAppend(Wire *wire, Vector3 position, float width, float height, float l
void DrawWire(Wire *wire)
{
Color color = wire->power->pressed ? wire->colorEnabled : wire->colorDisabled;
wire->door->opened = wire->power->pressed;
WireNode *node;
for (int i = 0; i < wire->nodes_count; ++i)
{
+2
View File
@@ -2,6 +2,7 @@
#define WIRE_H
#include "button.h"
#include "door.h"
#include "raylib.h"
#include <stddef.h>
@@ -18,6 +19,7 @@ typedef struct
typedef struct
{
Button *power;
Door *door;
WireNode *nodes;
size_t nodes_count;
size_t nodes_capasity;