diff --git a/src/door.c b/src/door.c new file mode 100644 index 0000000..e4f157e --- /dev/null +++ b/src/door.c @@ -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); +} diff --git a/src/door.h b/src/door.h new file mode 100644 index 0000000..3edb1c9 --- /dev/null +++ b/src/door.h @@ -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 diff --git a/src/level00.c b/src/level00.c index b4d8382..7042ad9 100644 --- a/src/level00.c +++ b/src/level00.c @@ -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); } diff --git a/src/player.h b/src/player.h index eb3baaf..c5f879c 100644 --- a/src/player.h +++ b/src/player.h @@ -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 diff --git a/src/screen.h b/src/screen.h index 26eed10..ea22235 100644 --- a/src/screen.h +++ b/src/screen.h @@ -8,4 +8,4 @@ void DrawLevel00(Player *player); -#endif +#endif // SCREEN_H diff --git a/src/wire.c b/src/wire.c index 1b8f12e..e53852f 100644 --- a/src/wire.c +++ b/src/wire.c @@ -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) { diff --git a/src/wire.h b/src/wire.h index ffe02d4..75663dc 100644 --- a/src/wire.h +++ b/src/wire.h @@ -2,6 +2,7 @@ #define WIRE_H #include "button.h" +#include "door.h" #include "raylib.h" #include @@ -18,6 +19,7 @@ typedef struct typedef struct { Button *power; + Door *door; WireNode *nodes; size_t nodes_count; size_t nodes_capasity;