aboutsummaryrefslogtreecommitdiff
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.
15> download and replace them from official repositories if desired; they have 15> download and replace them from official repositories if desired; they have
16> not been tampered with. 16> not been tampered with.
17 17
18## Controller mappings
19
20```
21 Q W E I O
22 A S D J k
23```
24
25## Tools
26
27- https://hardwaretester.com/gamepad
28
18## Libraries 29## Libraries
19 30
20- https://github.com/rxi/microtar 31- https://github.com/rxi/microtar
@@ -27,3 +38,4 @@ sounds.
27- https://www.love2d.org/wiki/Main_Page 38- https://www.love2d.org/wiki/Main_Page
28- https://www.lexaloffle.com/dl/docs/pico-8_manual.html 39- https://www.lexaloffle.com/dl/docs/pico-8_manual.html
29- https://home.cs.colorado.edu/~main/bgi/doc/ 40- https://home.cs.colorado.edu/~main/bgi/doc/
41- 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 @@
1asset1 = load_image("examples/icons/armor_3.png")
2
1open_window(800, 800, "Sample Window") 3open_window(800, 800, "Sample Window")
2set_fps(60) 4set_fps(60)
3 5
4while window_running() do 6function test_api()
5 begin_drawing()
6 clear_window(color.BLACK)
7
8 draw_rect(100, 100, 300, 200, color.YELLOW) 7 draw_rect(100, 100, 300, 200, color.YELLOW)
9 draw_text("YOOOOO", 10, 10, 20, color.VIOLET) 8 draw_text("Label text", 10, 10, 20, color.VIOLET)
10
11 draw_text(string.format("fps: %d", get_fps()), 10, 30, 20, color.VIOLET)
12 draw_text(string.format("dt: %.3f", get_dt()), 10, 50, 20, color.VIOLET)
13
14 draw_line(400, 10, 500, 100, color.RED) 9 draw_line(400, 10, 500, 100, color.RED)
15 draw_circle(500, 500, 100, color.BLUE) 10 draw_circle(500, 500, 100, color.BLUE)
16 draw_ellipse(200, 500, 100, 50, color.BLUE) 11 draw_ellipse(200, 500, 100, 50, color.BLUE)
17
18 draw_triangle(20, 20, 100, 20, 50, 100, color.BLUE) 12 draw_triangle(20, 20, 100, 20, 50, 100, color.BLUE)
13 draw_text(string.format("fps: %d", get_fps()), 10, 30, 20, color.VIOLET)
14 draw_text(string.format("dt: %.3f", get_dt()), 10, 50, 20, color.VIOLET)
15end
16
17function test_buttons()
18 if button_pressed(button.PAD_UP) then
19 draw_text("Pad Up", 10, 10, 20, color.VIOLET)
20 end
21
22 if button_pressed(button.PAD_DOWN) then
23 draw_text("Pad Down", 10, 40, 20, color.VIOLET)
24 end
25
26 if button_pressed(button.PAD_LEFT) then
27 draw_text("Pad Left", 10, 70, 20, color.VIOLET)
28 end
29
30 if button_pressed(button.PAD_RIGHT) then
31 draw_text("Pad Right", 10, 100, 20, color.VIOLET)
32 end
33
34 if button_pressed(button.A) then
35 draw_text("A", 150, 10, 20, color.VIOLET)
36 end
37
38 if button_pressed(button.B) then
39 draw_text("B", 150, 40, 20, color.VIOLET)
40 end
41
42 if button_pressed(button.X) then
43 draw_text("X", 150, 70, 20, color.VIOLET)
44 end
45
46 if button_pressed(button.Y) then
47 draw_text("Y", 150, 100, 20, color.VIOLET)
48 end
49end
50
51while window_running() do
52 begin_drawing()
53 clear_window(color.BLACK)
54
55 -- test_api()
56 test_buttons()
19 57
20 draw_info() 58 draw_info()
21 end_drawing() 59 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 @@
2#include <stdarg.h> 2#include <stdarg.h>
3#include <getopt.h> 3#include <getopt.h>
4#include <stdlib.h> 4#include <stdlib.h>
5#include <time.h>
5 6
6#include "raylib.h" 7#include "raylib.h"
7#include "lua.h" 8#include "lua.h"
@@ -10,6 +11,7 @@
10 11
11#include "stdlib/json.h" 12#include "stdlib/json.h"
12#include "stdlib/color.h" 13#include "stdlib/color.h"
14#include "stdlib/button.h"
13#include "stdlib/tilemap.h" 15#include "stdlib/tilemap.h"
14 16
15#include "fonts/dejavusans_mono_bold.h" 17#include "fonts/dejavusans_mono_bold.h"
@@ -17,15 +19,35 @@
17#define VERSION "x.x" 19#define VERSION "x.x"
18#define DEBUG_LEVEL LOG_DEBUG 20#define DEBUG_LEVEL LOG_DEBUG
19#define FONT_IMPORT_SIZE 30 21#define FONT_IMPORT_SIZE 30
22#define UID_LENGTH 36
23
24typedef struct {
25 char uid[UID_LENGTH + 1];
26 const char* filepath;
27} ExternalImage;
28
29typedef struct {
30} ExternalAudio;
20 31
21typedef struct { 32typedef struct {
22 Font font; 33 Font font;
23 int font_size; 34 int font_size;
35 Camera2D camera;
36 ExternalImage *images;
37 ExternalAudio *audio;
24} Context; 38} Context;
25 39
26// Setting up global context. 40// Setting up global context.
27Context ctx = {0}; 41Context ctx = {0};
28 42
43static void generate_uid(char *uid) {
44 const char *chars = "0123456789abcdef";
45 for (size_t i = 0; i < UID_LENGTH; i++) {
46 uid[i] = chars[rand() % 16];
47 }
48 uid[UID_LENGTH + 1] = '\0';
49}
50
29static int lua_getfield_int(lua_State *L, int index, const char *key) { 51static int lua_getfield_int(lua_State *L, int index, const char *key) {
30 lua_getfield(L, index, key); 52 lua_getfield(L, index, key);
31 int val = (int)luaL_checknumber(L, -1); 53 int val = (int)luaL_checknumber(L, -1);
@@ -249,6 +271,24 @@ static int l_draw_triangle(lua_State *L) {
249 return 0; 271 return 0;
250} 272}
251 273
274static int l_button_pressed(lua_State *L) {
275 int button = luaL_checknumber(L, 1);
276 lua_pushboolean(L, IsKeyDown(button));
277 return 1;
278}
279
280static int l_load_image(lua_State *L) {
281 return 0;
282}
283
284static int l_load_audio(lua_State *L) {
285 return 0;
286}
287
288static int l_move_camera(lua_State *L) {
289 return 0;
290}
291
252static void help(const char *argv0) { 292static void help(const char *argv0) {
253 printf("Usage: %s [options]\n" 293 printf("Usage: %s [options]\n"
254 "\nAvailable options:\n" 294 "\nAvailable options:\n"
@@ -265,6 +305,8 @@ static void version(const char *argv0) {
265} 305}
266 306
267int main(int argc, char *argv[]) { 307int main(int argc, char *argv[]) {
308 srand(time(NULL));
309
268 TraceLogLevel debug_level = LOG_WARNING; 310 TraceLogLevel debug_level = LOG_WARNING;
269 const char *run_file = NULL; 311 const char *run_file = NULL;
270 312
@@ -308,6 +350,12 @@ int main(int argc, char *argv[]) {
308 lua_State *L = luaL_newstate(); 350 lua_State *L = luaL_newstate();
309 luaL_openlibs(L); 351 luaL_openlibs(L);
310 352
353 // Loading embeded modules into Lua state.
354 if (!load_embedded_module(L, json, json_len, "json")) return 1;
355 if (!load_embedded_module(L, color, color_len, "color")) return 1;
356 if (!load_embedded_module(L, button, button_len, "button")) return 1;
357 if (!load_embedded_module(L, tilemap, tilemap_len, "tilemap")) return 1;
358
311 // Registring Raylib mappings. 359 // Registring Raylib mappings.
312 lua_register(L, "open_window", l_open_window); 360 lua_register(L, "open_window", l_open_window);
313 lua_register(L, "close_window", l_close_window); 361 lua_register(L, "close_window", l_close_window);
@@ -326,11 +374,10 @@ int main(int argc, char *argv[]) {
326 lua_register(L, "draw_circle", l_draw_circle); 374 lua_register(L, "draw_circle", l_draw_circle);
327 lua_register(L, "draw_ellipse", l_draw_ellipse); 375 lua_register(L, "draw_ellipse", l_draw_ellipse);
328 lua_register(L, "draw_triangle", l_draw_triangle); 376 lua_register(L, "draw_triangle", l_draw_triangle);
329 377 lua_register(L, "load_image", l_load_image);
330 // Loading embeded modules into Lua state. 378 lua_register(L, "load_audio", l_load_audio);
331 if (!load_embedded_module(L, json, json_len, "json")) return 1; 379 lua_register(L, "move_camera", l_move_camera);
332 if (!load_embedded_module(L, color, color_len, "color")) return 1; 380 lua_register(L, "button_pressed", l_button_pressed);
333 if (!load_embedded_module(L, tilemap, tilemap_len, "tilemap")) return 1;
334 381
335 // Interpreting and running input file Lua script. 382 // Interpreting and running input file Lua script.
336 if (luaL_loadfile(L, run_file) || lua_pcall(L, 0, 0, 0)) { 383 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 @@
1local button = {}
2
3button.PAD_UP = 87 -- Key: W
4button.PAD_DOWN = 83 -- Key: S
5button.PAD_LEFT = 65 -- Key: A
6button.PAD_RIGHT = 68 -- Key: D
7
8button.A = 76 -- Key: L
9button.B = 80 -- Key: P
10button.X = 75 -- Key: K
11button.Y = 79 -- Key: O
12
13return button