mirror of https://git.sr.ht/~kikoodx/sle
Level drawing and new arguments + README update
This commit is contained in:
parent
246287b466
commit
5d3b1bfd01
|
@ -8,13 +8,15 @@ include_directories(include)
|
|||
|
||||
set(SOURCES
|
||||
src/main.c
|
||||
src/level.c)
|
||||
src/level.c
|
||||
src/draw.c
|
||||
)
|
||||
|
||||
set(FLAGS
|
||||
-Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum
|
||||
-Wunreachable-code -Wstrict-prototypes -Wmissing-prototypes
|
||||
-Wold-style-definition -Werror-implicit-function-declaration
|
||||
-g -Os)
|
||||
-Os)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCES} ${SOURCES_RAYLIB})
|
||||
|
||||
|
|
6
README
6
README
|
@ -15,6 +15,12 @@ $ mkdir sle/build && cd sle/build
|
|||
$ cmake ..
|
||||
$ make
|
||||
|
||||
RUN
|
||||
===
|
||||
$ <SLE binary path> <tileset> <KBLE level to open>
|
||||
Example:
|
||||
$ build/sle assets/tileset.png sample.kble
|
||||
|
||||
LICENSE
|
||||
=======
|
||||
Copyright (C) 2021 KikooDX <kikoodx@paranoici.org>
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
|
@ -1,8 +1,11 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#pragma once
|
||||
|
||||
static const int window_width = 396;
|
||||
static const int window_height = 224;
|
||||
static const int draw_offset_x = -2;
|
||||
static const int draw_offset_y = -8;
|
||||
static const int tile_width = 16;
|
||||
static const int tile_height = 16;
|
||||
static const int target_fps = 60;
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
#pragma once
|
||||
|
||||
#include "level.h"
|
||||
#include <raylib.h>
|
||||
|
||||
void level_draw(struct Level level, Texture2D tileset);
|
|
@ -1,6 +1,5 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef unsigned int tile_t;
|
||||
|
|
BIN
sample.kble
BIN
sample.kble
Binary file not shown.
|
@ -0,0 +1,29 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "conf.h"
|
||||
#include "level.h"
|
||||
#include <raylib.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void level_draw(struct Level level, Texture2D tileset)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
for (x = 0; x < level.width; x += 1) {
|
||||
for (y = 0; y < level.height; y += 1) {
|
||||
const int tile =
|
||||
level.data[x + y * level.width];
|
||||
Rectangle tile_rect = {
|
||||
(int)(tile % tileset.width) * tile_width,
|
||||
(int)(tile / tileset.width) * tile_width,
|
||||
tile_width, tile_height};
|
||||
Vector2 tile_pos = {
|
||||
x * tile_width + draw_offset_x,
|
||||
y * tile_height + draw_offset_y};
|
||||
if (tile)
|
||||
DrawTextureRec(tileset, tile_rect,
|
||||
tile_pos, WHITE);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +1,11 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "level.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "level.h"
|
||||
|
||||
static const int kble_fmt_version = 0;
|
||||
|
||||
static char read_byte(FILE *file);
|
||||
|
|
31
src/main.c
31
src/main.c
|
@ -1,23 +1,19 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "conf.h"
|
||||
#include "draw.h"
|
||||
#include "level.h"
|
||||
#include <assert.h>
|
||||
#include <raylib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "conf.h"
|
||||
#include "level.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct Level level;
|
||||
level.data = NULL;
|
||||
|
||||
/* initialize raylib */
|
||||
InitWindow(window_width, window_height, "SLE");
|
||||
SetTargetFPS(target_fps);
|
||||
|
||||
/* check for argument count */
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "ERROR: expected 2 arguments, got %d\n",
|
||||
|
@ -25,8 +21,25 @@ int main(int argc, char **argv)
|
|||
return EXIT_FAILURE;
|
||||
};
|
||||
|
||||
/* initialize raylib */
|
||||
InitWindow(window_width, window_height, "SLE");
|
||||
SetTargetFPS(target_fps);
|
||||
/* load textures */
|
||||
const Texture2D tileset = LoadTexture(argv[1]);
|
||||
assert(tileset.width > 0);
|
||||
|
||||
/* load level */
|
||||
level_read(&level, argv[1]);
|
||||
level_read(&level, argv[2]);
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
/* draw */
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(BLACK);
|
||||
level_draw(level, tileset);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
/* save level */
|
||||
level_write(level, argv[2]);
|
||||
|
@ -34,8 +47,6 @@ int main(int argc, char **argv)
|
|||
/* deinit */
|
||||
level_free(&level);
|
||||
|
||||
for (;;) {}
|
||||
|
||||
CloseWindow();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
Loading…
Reference in New Issue