editMap
This commit is contained in:
parent
21e81f471d
commit
294c5e8e8a
@ -1,13 +1,13 @@
|
|||||||
10 25
|
10 15
|
||||||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||||
|
0 0 0 0 0 0 0 3 0 0 0 0 0 0 0
|
||||||
|
0 0 0 0 0 0 3 3 3 0 0 0 0 0 0
|
||||||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||||
|
0 0 0 0 0 0 3 0 0 0 0 0 0 0 0
|
||||||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
0 0 0 0 0 0 0 3 0 0 0 0 0 0 0
|
||||||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
0 0 0 0 3 0 0 3 3 0 0 0 0 0 0
|
||||||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
0 0 0 0 3 0 0 0 3 0 0 0 0 0 0
|
||||||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
0 0 0 0 3 3 3 0 0 0 3 0 0 0 0
|
||||||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
0 0 25 37
|
||||||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
3 3 3
|
||||||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
|
||||||
0 0 9 34
|
|
||||||
3 4 2
|
|
||||||
|
@ -3,18 +3,20 @@
|
|||||||
#include <iso646.h>
|
#include <iso646.h>
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
|
#include "resource_dir.h"
|
||||||
|
|
||||||
#define RAYGUI_IMPLEMENTATION
|
#define RAYGUI_IMPLEMENTATION
|
||||||
#include "raygui.h"
|
#include "raygui.h"
|
||||||
|
|
||||||
#include "resource_dir.h"
|
|
||||||
|
|
||||||
#define M 10
|
#define M 10
|
||||||
#define N 15
|
#define N 15
|
||||||
#define HEIGHT 50
|
#define HEIGHT 50
|
||||||
#define WIDTH 50
|
#define WIDTH 50
|
||||||
#define VOFFSET 50
|
#define VOFFSET 50
|
||||||
|
|
||||||
|
#define FWIDTH (float)WIDTH
|
||||||
|
#define FHEIGHT (float)HEIGHT
|
||||||
|
|
||||||
#define PUREBLUE (Color) { 0, 0, 255, 255 }
|
#define PUREBLUE (Color) { 0, 0, 255, 255 }
|
||||||
#define BLACKGRAY (Color) {30, 30, 30, 255}
|
#define BLACKGRAY (Color) {30, 30, 30, 255}
|
||||||
#define VSGRAY (Color) {78, 201, 176, 255}
|
#define VSGRAY (Color) {78, 201, 176, 255}
|
||||||
@ -137,11 +139,11 @@ void doMidashand() {
|
|||||||
|
|
||||||
bool netToggle = false;
|
bool netToggle = false;
|
||||||
void drawNet() {
|
void drawNet() {
|
||||||
for (int i = 0; i <= N * WIDTH; i = i + WIDTH) {
|
for (int i = 0; i <= N * WIDTH; i += WIDTH) {
|
||||||
DrawLine(i, 0, i, M * HEIGHT, BLACK);
|
DrawLine(i, 0, i, M * HEIGHT, BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i <= M * HEIGHT; i = i + HEIGHT) {
|
for (int i = 0; i <= M * HEIGHT; i += HEIGHT) {
|
||||||
DrawLine(0, i, N * WIDTH, i, BLACK);
|
DrawLine(0, i, N * WIDTH, i, BLACK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -256,9 +258,58 @@ void load() {
|
|||||||
fclose(fin);
|
fclose(fin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool editMap = 0;
|
||||||
void handleKeys() {
|
void handleKeys() {
|
||||||
|
|
||||||
|
/*if (IsKeyPressedRepeat(KEY_W)) movePlayer(up);
|
||||||
|
if (IsKeyPressedRepeat(KEY_S)) movePlayer(down);
|
||||||
|
if (IsKeyPressedRepeat(KEY_D)) movePlayer(right);
|
||||||
|
if (IsKeyPressedRepeat(KEY_A)) movePlayer(left);*/
|
||||||
|
|
||||||
int key;
|
int key;
|
||||||
while (key = GetKeyPressed()) {
|
while (key = GetKeyPressed()) {
|
||||||
|
if (not editMap) {
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case KEY_W:
|
||||||
|
movePlayer(up);
|
||||||
|
break;
|
||||||
|
case KEY_S:
|
||||||
|
movePlayer(down);
|
||||||
|
break;
|
||||||
|
case KEY_D:
|
||||||
|
movePlayer(right);
|
||||||
|
break;
|
||||||
|
case KEY_A:
|
||||||
|
movePlayer(left);
|
||||||
|
break;
|
||||||
|
case KEY_ONE:
|
||||||
|
stomp(1);
|
||||||
|
break;
|
||||||
|
case KEY_TWO:
|
||||||
|
stomp(2);
|
||||||
|
break;
|
||||||
|
case KEY_Z:
|
||||||
|
deathbeam(right);
|
||||||
|
break;
|
||||||
|
case KEY_M:
|
||||||
|
doMidashand();
|
||||||
|
break;
|
||||||
|
case KEY_LEFT:
|
||||||
|
putElement(left, selected_element);
|
||||||
|
break;
|
||||||
|
case KEY_RIGHT:
|
||||||
|
putElement(right, selected_element);
|
||||||
|
break;
|
||||||
|
case KEY_UP:
|
||||||
|
putElement(up, selected_element);
|
||||||
|
break;
|
||||||
|
case KEY_DOWN:
|
||||||
|
putElement(down, selected_element);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case KEY_F5:
|
case KEY_F5:
|
||||||
@ -270,52 +321,18 @@ void handleKeys() {
|
|||||||
case KEY_SPACE:
|
case KEY_SPACE:
|
||||||
netToggle = !netToggle;
|
netToggle = !netToggle;
|
||||||
break;
|
break;
|
||||||
case KEY_W:
|
case KEY_ENTER:
|
||||||
movePlayer(up);
|
editMap = !editMap;
|
||||||
break;
|
|
||||||
case KEY_S:
|
|
||||||
movePlayer(down);
|
|
||||||
break;
|
|
||||||
case KEY_D:
|
|
||||||
movePlayer(right);
|
|
||||||
break;
|
|
||||||
case KEY_A:
|
|
||||||
movePlayer(left);
|
|
||||||
break;
|
|
||||||
case KEY_ONE:
|
|
||||||
stomp(1);
|
|
||||||
break;
|
|
||||||
case KEY_TWO:
|
|
||||||
stomp(2);
|
|
||||||
break;
|
|
||||||
case KEY_Z:
|
|
||||||
deathbeam(right);
|
|
||||||
break;
|
|
||||||
case KEY_M:
|
|
||||||
doMidashand();
|
|
||||||
break;
|
break;
|
||||||
case KEY_G:
|
case KEY_G:
|
||||||
if (selected_element == gold) selected_element = wall;
|
if (selected_element == gold) selected_element = wall;
|
||||||
else selected_element = gold;
|
else selected_element = gold;
|
||||||
break;
|
break;
|
||||||
case KEY_LEFT:
|
|
||||||
putElement(left, selected_element);
|
|
||||||
break;
|
|
||||||
case KEY_RIGHT:
|
|
||||||
putElement(right, selected_element);
|
|
||||||
break;
|
|
||||||
case KEY_UP:
|
|
||||||
putElement(up, selected_element);
|
|
||||||
break;
|
|
||||||
case KEY_DOWN:
|
|
||||||
putElement(down, selected_element);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CPSIZE 213
|
||||||
#define CDPSIZE 213
|
|
||||||
int main() {
|
int main() {
|
||||||
//SetConfigFlags(FLAG_WINDOW_HIGHDPI);
|
//SetConfigFlags(FLAG_WINDOW_HIGHDPI);
|
||||||
|
|
||||||
@ -325,25 +342,47 @@ int main() {
|
|||||||
|
|
||||||
SearchAndSetResourceDir("resources");
|
SearchAndSetResourceDir("resources");
|
||||||
|
|
||||||
int codepoints[CDPSIZE] = { 0 };
|
int codepoints[CPSIZE] = { 0 };
|
||||||
for (int i = 0; i < 127 - 32; i++) codepoints[i] = 32 + i; // Basic ASCII characters
|
for (int i = 0; i < 127 - 32; i++) codepoints[i] = 32 + i; // Basic ASCII characters
|
||||||
for (int i = 0; i < 118; i++) codepoints[95 + i] = 1024 + i; // Cyrillic characters
|
for (int i = 0; i < 118; i++) codepoints[95 + i] = 1024 + i; // Cyrillic characters
|
||||||
|
|
||||||
//Font InconsolataRegular = LoadFontEx("Inconsolata-Regular.ttf", 24, NULL, 0);
|
//Font InconsolataRegular = LoadFontEx("Inconsolata-Regular.ttf", 24, NULL, 0);
|
||||||
//Font InconsolataSemiBold = LoadFontEx("Inconsolata-SemiBold.ttf", 48, codepoints, 512);
|
//Font InconsolataSemiBold = LoadFontEx("Inconsolata-SemiBold.ttf", 48, codepoints, 512);
|
||||||
Font InconsolataBold = LoadFontEx("Inconsolata-LGC-Bold.ttf", 48, codepoints, CDPSIZE);
|
Font InconsolataBold = LoadFontEx("Inconsolata-LGC-Bold.ttf", 48, codepoints, CPSIZE);
|
||||||
SetTextureFilter(InconsolataBold.texture, TEXTURE_FILTER_BILINEAR);
|
SetTextureFilter(InconsolataBold.texture, TEXTURE_FILTER_BILINEAR);
|
||||||
|
|
||||||
//GuiSetFont(InconsolataBold);
|
//GuiSetFont(InconsolataBold);
|
||||||
|
|
||||||
|
Vector2 mousePos = { 0 };
|
||||||
|
int mouseCellX = 0;
|
||||||
|
int mouseCellY = 0;
|
||||||
|
|
||||||
// game loop
|
// game loop
|
||||||
while (!WindowShouldClose()) // run the loop untill the user presses ESCAPE or presses the Close button on the window
|
while (!WindowShouldClose()) // run the loop untill the user presses ESCAPE or presses the Close button on the window
|
||||||
{
|
{
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
// Update
|
||||||
|
//------------------------------------------------------------------
|
||||||
handleKeys();
|
handleKeys();
|
||||||
|
mousePos = GetMousePosition();
|
||||||
|
|
||||||
// drawing
|
if (editMap) {
|
||||||
|
mouseCellX = (int)(Clamp(mousePos.x, 0, FWIDTH * N - 1) / WIDTH);
|
||||||
|
mouseCellY = (int)(Clamp(mousePos.y, 0, FHEIGHT * M - 1) / HEIGHT);
|
||||||
|
|
||||||
|
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) and not(mouseCellX == player_x and mouseCellY == player_y)) {
|
||||||
|
map[mouseCellY][mouseCellX] = selected_element;
|
||||||
|
}
|
||||||
|
else if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) {
|
||||||
|
map[mouseCellY][mouseCellX] = empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
// Draw
|
||||||
|
//------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
// Setup the back buffer for drawing (clear color and depth buffers)
|
// Setup the back buffer for drawing (clear color and depth buffers)
|
||||||
ClearBackground(WHITE);
|
ClearBackground(WHITE);
|
||||||
|
|
||||||
@ -351,10 +390,31 @@ int main() {
|
|||||||
drawPlayer();
|
drawPlayer();
|
||||||
drawBottomBar(InconsolataBold, 24);
|
drawBottomBar(InconsolataBold, 24);
|
||||||
|
|
||||||
|
if (editMap) {
|
||||||
|
Rectangle rec = {
|
||||||
|
mouseCellX * FWIDTH,
|
||||||
|
mouseCellY * FHEIGHT,
|
||||||
|
FWIDTH, FHEIGHT
|
||||||
|
};
|
||||||
|
|
||||||
|
Color color = { 0, 0, 0, 255 };
|
||||||
|
if (mouseCellX == player_x and mouseCellY == player_y) {
|
||||||
|
color.r = 255;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
color.g = 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawRectangleLinesEx(rec, 2, color);
|
||||||
|
}
|
||||||
|
|
||||||
if (netToggle) {
|
if (netToggle) {
|
||||||
drawNet();
|
drawNet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// show mouse position
|
||||||
|
//DrawText(TextFormat("%.1f %.1f", mousePos.x, mousePos.y), 5, M * HEIGHT - 30, 30, ORANGE);
|
||||||
|
|
||||||
// show FPS and frametime
|
// show FPS and frametime
|
||||||
//DrawText(TextFormat("%2d FPS", GetFPS()), 0, 0, 34, ORANGE);
|
//DrawText(TextFormat("%2d FPS", GetFPS()), 0, 0, 34, ORANGE);
|
||||||
//DrawText(TextFormat("%4f ms", GetFrameTime()), 0, 34, 34, BEIGE);
|
//DrawText(TextFormat("%4f ms", GetFrameTime()), 0, 34, 34, BEIGE);
|
||||||
|
Loading…
Reference in New Issue
Block a user