182 lines
4.9 KiB
C++
182 lines
4.9 KiB
C++
#include <iostream>
|
|
#include <raylib.h>
|
|
#include "Morault_Resources.h"
|
|
#include "Morault_Player.h"
|
|
#include "Morault_Map.h"
|
|
#include <raymath.h>
|
|
#include <rlgl.h>
|
|
|
|
#define MORAULT_MAP_RENDER_SCALE 0.1f
|
|
|
|
typedef enum {
|
|
NONE,
|
|
GAME,
|
|
EDITOR
|
|
} EngineState;
|
|
|
|
typedef enum {
|
|
NA, A, B, C
|
|
} SectorTriangleSelection;
|
|
|
|
struct EditorSelection {
|
|
int sector;
|
|
SectorTriangleSelection point;
|
|
};
|
|
int main(int argc, char** argv) {
|
|
InitWindow(1280, 720, "ProjectMorault");
|
|
SetTargetFPS(60);
|
|
SetExitKey(0);
|
|
|
|
|
|
DisableCursor();
|
|
|
|
|
|
Morault::Gameplay::Player player;
|
|
player.data.playerName = "TestPlayer0001";
|
|
player.data.hp = 100;
|
|
player.data.xp = 0;
|
|
bool gamePaused = false;
|
|
|
|
EngineState eState = GAME;
|
|
EditorSelection selection = { -1, NA };
|
|
bool inSelection = false;
|
|
Morault::Maps::Map* map = new Morault::Maps::Map();
|
|
|
|
{
|
|
using namespace Morault::Resources;
|
|
Textures(load("data/textures/test.png"));
|
|
}
|
|
|
|
|
|
Vector2 editorOffset = { 0,0 };
|
|
|
|
while (!WindowShouldClose()) {
|
|
|
|
|
|
switch(eState){
|
|
case GAME: {
|
|
if (IsKeyPressed(KEY_E)) {
|
|
eState = EDITOR;
|
|
EnableCursor();
|
|
}
|
|
player.controller.UpdatePlayerController(!gamePaused);
|
|
|
|
BeginDrawing();
|
|
ClearBackground(BLACK);
|
|
BeginMode3D(player.controller.camera);
|
|
DrawGrid(100, 10);
|
|
|
|
for (int i = 0; i < map->MapTriangles.size(); i++) {
|
|
DrawTriangle3D(
|
|
{
|
|
map->MapTriangles[i].a.x * MORAULT_MAP_RENDER_SCALE,
|
|
map->MapTriangles[i].heightFloor * MORAULT_MAP_RENDER_SCALE,
|
|
map->MapTriangles[i].a.y * MORAULT_MAP_RENDER_SCALE
|
|
},
|
|
{
|
|
map->MapTriangles[i].b.x * MORAULT_MAP_RENDER_SCALE,
|
|
map->MapTriangles[i].heightFloor * MORAULT_MAP_RENDER_SCALE,
|
|
map->MapTriangles[i].b.y * MORAULT_MAP_RENDER_SCALE
|
|
},
|
|
{
|
|
map->MapTriangles[i].c.x * MORAULT_MAP_RENDER_SCALE,
|
|
map->MapTriangles[i].heightFloor * MORAULT_MAP_RENDER_SCALE,
|
|
map->MapTriangles[i].c.y * MORAULT_MAP_RENDER_SCALE
|
|
},
|
|
RED
|
|
);
|
|
}
|
|
|
|
|
|
|
|
EndMode3D();
|
|
|
|
DrawFPS(0, 0);
|
|
EndDrawing();
|
|
} break;
|
|
case EDITOR: {
|
|
if (IsKeyPressed(KEY_E)) {
|
|
eState = GAME;
|
|
DisableCursor();
|
|
}
|
|
if (IsKeyPressed(KEY_ESCAPE)) {
|
|
inSelection = false;
|
|
}
|
|
if (IsKeyDown(KEY_LEFT_SHIFT)) {
|
|
if (IsKeyPressed(KEY_N)) {
|
|
Morault::Maps::MapTriangle tri;
|
|
tri.a = { -128, -128 };
|
|
tri.b = { 128,128 };
|
|
tri.c = { 128,-128 };
|
|
tri.floorTexture = "data/textures/test.png";
|
|
tri.heightFloor = 0;
|
|
tri.heightCeiling = 128;
|
|
tri.hasFloor = true;
|
|
tri.hasCeiling = false;
|
|
tri.wallAB = "data/textures/test.png";
|
|
tri.wallBC = "data/textures/test.png";
|
|
tri.wallCA = "data/textures/test.png";
|
|
map->MapTriangles.push_back(tri);
|
|
}
|
|
}
|
|
|
|
if (IsMouseButtonDown(MOUSE_BUTTON_MIDDLE)) editorOffset += GetMouseDelta();
|
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
|
for (int i = 0; i < map->MapTriangles.size(); i++) {
|
|
if (CheckCollisionPointCircle(GetMousePosition() - editorOffset, map->MapTriangles[i].a, 7)) {
|
|
inSelection = true;
|
|
selection = { i,A };
|
|
}
|
|
if (CheckCollisionPointCircle(GetMousePosition() - editorOffset, map->MapTriangles[i].b, 7)) {
|
|
inSelection = true;
|
|
selection = { i,B };
|
|
}
|
|
if (CheckCollisionPointCircle(GetMousePosition() - editorOffset, map->MapTriangles[i].c, 7)) {
|
|
inSelection = true;
|
|
selection = { i,C };
|
|
}
|
|
}
|
|
}
|
|
|
|
if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) {
|
|
if (inSelection) {
|
|
switch (selection.point) {
|
|
case A:
|
|
map->MapTriangles[selection.sector].a += GetMouseDelta();
|
|
break;
|
|
case B:
|
|
map->MapTriangles[selection.sector].b += GetMouseDelta();
|
|
break;
|
|
case C:
|
|
map->MapTriangles[selection.sector].c += GetMouseDelta();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
BeginDrawing();
|
|
ClearBackground(BLACK);
|
|
|
|
for (int i = 0; i < map->MapTriangles.size(); i++) {
|
|
DrawTriangleLines(map->MapTriangles[i].a + editorOffset, map->MapTriangles[i].b + editorOffset, map->MapTriangles[i].c + editorOffset, YELLOW);
|
|
DrawCircle((map->MapTriangles[i].a + editorOffset).x, (map->MapTriangles[i].a + editorOffset).y, 3, RED);
|
|
DrawCircle((map->MapTriangles[i].b + editorOffset).x, (map->MapTriangles[i].b + editorOffset).y, 3, RED);
|
|
DrawCircle((map->MapTriangles[i].c + editorOffset).x, (map->MapTriangles[i].c + editorOffset).y, 3, RED);
|
|
if(inSelection){
|
|
if (selection.sector == i && selection.point == A) DrawCircle((map->MapTriangles[i].a + editorOffset).x, (map->MapTriangles[i].a + editorOffset).y, 5, GREEN);
|
|
if (selection.sector == i && selection.point == B) DrawCircle((map->MapTriangles[i].b + editorOffset).x, (map->MapTriangles[i].b + editorOffset).y, 5, GREEN);
|
|
if (selection.sector == i && selection.point == C) DrawCircle((map->MapTriangles[i].c + editorOffset).x, (map->MapTriangles[i].c + editorOffset).y, 5, GREEN);
|
|
}
|
|
|
|
}
|
|
|
|
EndDrawing();
|
|
}break;
|
|
default:
|
|
throw std::runtime_error("what the fuck?");
|
|
}
|
|
}
|
|
|
|
|
|
CloseWindow();
|
|
} |