summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md12
-rw-r--r--examples/graphics.lua58
-rw-r--r--examples/icons/icon_1.pngbin0 -> 352069 bytes
-rw-r--r--examples/icons/icon_2.pngbin0 -> 455412 bytes
-rw-r--r--main.c57
-rw-r--r--stdlib/button.lua13
6 files changed, 125 insertions, 15 deletions
diff --git a/README.md b/README.md
index e2bf699..79102ec 100644
--- a/README.md
+++ b/README.md
@@ -15,6 +15,17 @@ sounds.
> download and replace them from official repositories if desired; they have
> not been tampered with.
+## Controller mappings
+
+```
+ Q W E I O
+ A S D J k
+```
+
+## Tools
+
+- https://hardwaretester.com/gamepad
+
## Libraries
- https://github.com/rxi/microtar
@@ -27,3 +38,4 @@ sounds.
- https://www.love2d.org/wiki/Main_Page
- https://www.lexaloffle.com/dl/docs/pico-8_manual.html
- https://home.cs.colorado.edu/~main/bgi/doc/
+- https://opengameart.org/content/free-rpg-skill-icons-for-crafter-blacksmith-and-gnome
diff --git a/examples/graphics.lua b/examples/graphics.lua
index c6b30a5..6c1f8e4 100644
--- a/examples/graphics.lua
+++ b/examples/graphics.lua
@@ -1,21 +1,59 @@
+asset1 = load_image("examples/icons/armor_3.png")
+
open_window(800, 800, "Sample Window")
set_fps(60)
-while window_running() do
- begin_drawing()
- clear_window(color.BLACK)
-
+function test_api()
draw_rect(100, 100, 300, 200, color.YELLOW)
- draw_text("YOOOOO", 10, 10, 20, color.VIOLET)
-
- draw_text(string.format("fps: %d", get_fps()), 10, 30, 20, color.VIOLET)
- draw_text(string.format("dt: %.3f", get_dt()), 10, 50, 20, color.VIOLET)
-
+ draw_text("Label text", 10, 10, 20, color.VIOLET)
draw_line(400, 10, 500, 100, color.RED)
draw_circle(500, 500, 100, color.BLUE)
draw_ellipse(200, 500, 100, 50, color.BLUE)
-
draw_triangle(20, 20, 100, 20, 50, 100, color.BLUE)
+ draw_text(string.format("fps: %d", get_fps()), 10, 30, 20, color.VIOLET)
+ draw_text(string.format("dt: %.3f", get_dt()), 10, 50, 20, color.VIOLET)
+end
+
+function test_buttons()
+ if button_pressed(button.PAD_UP) then
+ draw_text("Pad Up", 10, 10, 20, color.VIOLET)
+ end
+
+ if button_pressed(button.PAD_DOWN) then
+ draw_text("Pad Down", 10, 40, 20, color.VIOLET)
+ end
+
+ if button_pressed(button.PAD_LEFT) then
+ draw_text("Pad Left", 10, 70, 20, color.VIOLET)
+ end
+
+ if button_pressed(button.PAD_RIGHT) then
+ draw_text("Pad Right", 10, 100, 20, color.VIOLET)
+ end
+
+ if button_pressed(button.A) then
+ draw_text("A", 150, 10, 20, color.VIOLET)
+ end
+
+ if button_pressed(button.B) then
+ draw_text("B", 150, 40, 20, color.VIOLET)
+ end
+
+ if button_pressed(button.X) then
+ draw_text("X", 150, 70, 20, color.VIOLET)
+ end
+
+ if button_pressed(button.Y) then
+ draw_text("Y", 150, 100, 20, color.VIOLET)
+ end
+end
+
+while window_running() do
+ begin_drawing()
+ clear_window(color.BLACK)
+
+ -- test_api()
+ test_buttons()
draw_info()
end_drawing()
diff --git a/examples/icons/icon_1.png b/examples/icons/icon_1.png
new file mode 100644
index 0000000..4785224
--- /dev/null
+++ b/examples/icons/icon_1.png
Binary files differ
diff --git a/examples/icons/icon_2.png b/examples/icons/icon_2.png
new file mode 100644
index 0000000..c19d642
--- /dev/null
+++ b/examples/icons/icon_2.png
Binary files differ
diff --git a/main.c b/main.c
index a57280f..67f3520 100644
--- a/main.c
+++ b/main.c
@@ -2,6 +2,7 @@
#include <stdarg.h>
#include <getopt.h>
#include <stdlib.h>
+#include <time.h>
#include "raylib.h"
#include "lua.h"
@@ -10,6 +11,7 @@
#include "stdlib/json.h"
#include "stdlib/color.h"
+#include "stdlib/button.h"
#include "stdlib/tilemap.h"
#include "fonts/dejavusans_mono_bold.h"
@@ -17,15 +19,35 @@
#define VERSION "x.x"
#define DEBUG_LEVEL LOG_DEBUG
#define FONT_IMPORT_SIZE 30
+#define UID_LENGTH 36
+
+typedef struct {
+ char uid[UID_LENGTH + 1];
+ const char* filepath;
+} ExternalImage;
+
+typedef struct {
+} ExternalAudio;
typedef struct {
Font font;
int font_size;
+ Camera2D camera;
+ ExternalImage *images;
+ ExternalAudio *audio;
} Context;
// Setting up global context.
Context ctx = {0};
+static void generate_uid(char *uid) {
+ const char *chars = "0123456789abcdef";
+ for (size_t i = 0; i < UID_LENGTH; i++) {
+ uid[i] = chars[rand() % 16];
+ }
+ uid[UID_LENGTH + 1] = '\0';
+}
+
static int lua_getfield_int(lua_State *L, int index, const char *key) {
lua_getfield(L, index, key);
int val = (int)luaL_checknumber(L, -1);
@@ -249,6 +271,24 @@ static int l_draw_triangle(lua_State *L) {
return 0;
}
+static int l_button_pressed(lua_State *L) {
+ int button = luaL_checknumber(L, 1);
+ lua_pushboolean(L, IsKeyDown(button));
+ return 1;
+}
+
+static int l_load_image(lua_State *L) {
+ return 0;
+}
+
+static int l_load_audio(lua_State *L) {
+ return 0;
+}
+
+static int l_move_camera(lua_State *L) {
+ return 0;
+}
+
static void help(const char *argv0) {
printf("Usage: %s [options]\n"
"\nAvailable options:\n"
@@ -265,6 +305,8 @@ static void version(const char *argv0) {
}
int main(int argc, char *argv[]) {
+ srand(time(NULL));
+
TraceLogLevel debug_level = LOG_WARNING;
const char *run_file = NULL;
@@ -308,6 +350,12 @@ int main(int argc, char *argv[]) {
lua_State *L = luaL_newstate();
luaL_openlibs(L);
+ // Loading embeded modules into Lua state.
+ if (!load_embedded_module(L, json, json_len, "json")) return 1;
+ if (!load_embedded_module(L, color, color_len, "color")) return 1;
+ if (!load_embedded_module(L, button, button_len, "button")) return 1;
+ if (!load_embedded_module(L, tilemap, tilemap_len, "tilemap")) return 1;
+
// Registring Raylib mappings.
lua_register(L, "open_window", l_open_window);
lua_register(L, "close_window", l_close_window);
@@ -326,11 +374,10 @@ int main(int argc, char *argv[]) {
lua_register(L, "draw_circle", l_draw_circle);
lua_register(L, "draw_ellipse", l_draw_ellipse);
lua_register(L, "draw_triangle", l_draw_triangle);
-
- // Loading embeded modules into Lua state.
- if (!load_embedded_module(L, json, json_len, "json")) return 1;
- if (!load_embedded_module(L, color, color_len, "color")) return 1;
- if (!load_embedded_module(L, tilemap, tilemap_len, "tilemap")) return 1;
+ lua_register(L, "load_image", l_load_image);
+ lua_register(L, "load_audio", l_load_audio);
+ lua_register(L, "move_camera", l_move_camera);
+ lua_register(L, "button_pressed", l_button_pressed);
// Interpreting and running input file Lua script.
if (luaL_loadfile(L, run_file) || lua_pcall(L, 0, 0, 0)) {
diff --git a/stdlib/button.lua b/stdlib/button.lua
new file mode 100644
index 0000000..7a656e0
--- /dev/null
+++ b/stdlib/button.lua
@@ -0,0 +1,13 @@
+local button = {}
+
+button.PAD_UP = 87 -- Key: W
+button.PAD_DOWN = 83 -- Key: S
+button.PAD_LEFT = 65 -- Key: A
+button.PAD_RIGHT = 68 -- Key: D
+
+button.A = 76 -- Key: L
+button.B = 80 -- Key: P
+button.X = 75 -- Key: K
+button.Y = 79 -- Key: O
+
+return button