add door
This commit is contained in:
+22
@@ -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
@@ -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
@@ -1,5 +1,6 @@
|
|||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include "cube.h"
|
#include "cube.h"
|
||||||
|
#include "door.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
@@ -21,12 +22,6 @@ void DrawLevel00(Player *player)
|
|||||||
.pressed = false,
|
.pressed = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
static Wire wire = {
|
|
||||||
.power = &button,
|
|
||||||
.colorEnabled = GREEN,
|
|
||||||
.colorDisabled = BLACK,
|
|
||||||
};
|
|
||||||
|
|
||||||
static Cube cube = {
|
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,
|
||||||
@@ -36,6 +31,25 @@ void DrawLevel00(Player *player)
|
|||||||
.grabbed = false,
|
.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)
|
if (!level_started)
|
||||||
{
|
{
|
||||||
level_started = true;
|
level_started = true;
|
||||||
@@ -81,4 +95,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
|
DrawWire(&wire); // Draw a wire
|
||||||
|
DrawDoor(&door);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -45,4 +45,4 @@ void UpdateBody(Player *player, float rot, char side, char forward, bool jump, b
|
|||||||
|
|
||||||
void UpdateGrab(Player *player, Cube *cube);
|
void UpdateGrab(Player *player, Cube *cube);
|
||||||
|
|
||||||
#endif
|
#endif // PLAYER_H
|
||||||
|
|||||||
+1
-1
@@ -8,4 +8,4 @@
|
|||||||
|
|
||||||
void DrawLevel00(Player *player);
|
void DrawLevel00(Player *player);
|
||||||
|
|
||||||
#endif
|
#endif // SCREEN_H
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ void WireAppend(Wire *wire, Vector3 position, float width, float height, float l
|
|||||||
void DrawWire(Wire *wire)
|
void DrawWire(Wire *wire)
|
||||||
{
|
{
|
||||||
Color color = wire->power->pressed ? wire->colorEnabled : wire->colorDisabled;
|
Color color = wire->power->pressed ? wire->colorEnabled : wire->colorDisabled;
|
||||||
|
wire->door->opened = wire->power->pressed;
|
||||||
WireNode *node;
|
WireNode *node;
|
||||||
for (int i = 0; i < wire->nodes_count; ++i)
|
for (int i = 0; i < wire->nodes_count; ++i)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define WIRE_H
|
#define WIRE_H
|
||||||
|
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
|
#include "door.h"
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ typedef struct
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Button *power;
|
Button *power;
|
||||||
|
Door *door;
|
||||||
WireNode *nodes;
|
WireNode *nodes;
|
||||||
size_t nodes_count;
|
size_t nodes_count;
|
||||||
size_t nodes_capasity;
|
size_t nodes_capasity;
|
||||||
|
|||||||
Reference in New Issue
Block a user