summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2025-08-09 02:56:49 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2025-08-09 02:56:49 +0200
commitb6197cc1c5ca7632a604f354f8a2d7274b25f308 (patch)
tree64c12976d0d11e71360359b2ba05ca4feacef937
parent7e927d46915646c7c219f6a57df5569bee9d78f8 (diff)
downloadbidi-b6197cc1c5ca7632a604f354f8a2d7274b25f308.tar.gz
Fixed button definitions and refactor
-rw-r--r--.vimrc2
-rw-r--r--tests/graphics.lua (renamed from examples/graphics.lua)35
-rw-r--r--tests/icons/icon_1.png (renamed from examples/icons/icon_1.png)bin352069 -> 352069 bytes
-rw-r--r--tests/icons/icon_2.png (renamed from examples/icons/icon_2.png)bin455412 -> 455412 bytes
-rw-r--r--tests/json.lua (renamed from examples/json.lua)2
-rw-r--r--tests/test.json (renamed from examples/test.json)0
6 files changed, 35 insertions, 4 deletions
diff --git a/.vimrc b/.vimrc
index 46cc038..7bd9554 100644
--- a/.vimrc
+++ b/.vimrc
@@ -2,7 +2,7 @@ set makeprg=make
set errorformat=%f:%l:%c:\ %m
let g:gdb_executable = 'bidi'
-let g:gdb_arguments = '-r examples/graphics.lua'
+let g:gdb_arguments = '-r tests/graphics.lua'
nnoremap <leader>m :call LocalMake()<CR>
nnoremap <leader>r :execute '!./' . g:gdb_executable . ' ' . g:gdb_arguments<CR>
diff --git a/examples/graphics.lua b/tests/graphics.lua
index 6c1f8e4..0f337df 100644
--- a/examples/graphics.lua
+++ b/tests/graphics.lua
@@ -1,4 +1,10 @@
-asset1 = load_image("examples/icons/armor_3.png")
+math.randomseed(os.time())
+
+test_button_square = { x = 400, y = 400 }
+test_button_color = color.RED
+test_button_speed = 200
+
+test_images_asset1 = load_image("tests/icons/icon_1.png")
open_window(800, 800, "Sample Window")
set_fps(60)
@@ -14,7 +20,17 @@ function test_api()
draw_text(string.format("dt: %.3f", get_dt()), 10, 50, 20, color.VIOLET)
end
+function get_random_color()
+ local keys = {}
+ for k in pairs(color) do
+ table.insert(keys, k) -- Collect all keys
+ end
+ local randomKey = keys[math.random(1, #keys)] -- Select a random key
+ return color[randomKey] -- Return the corresponding color
+end
+
function test_buttons()
+ -- Testing button presses.
if button_pressed(button.PAD_UP) then
draw_text("Pad Up", 10, 10, 20, color.VIOLET)
end
@@ -46,6 +62,21 @@ function test_buttons()
if button_pressed(button.Y) then
draw_text("Y", 150, 100, 20, color.VIOLET)
end
+
+ -- Moving square left and right.
+ if button_pressed(button.PAD_LEFT) then
+ test_button_square.x = test_button_square.x - (test_button_speed * get_dt())
+ end
+
+ if button_pressed(button.PAD_RIGHT) then
+ test_button_square.x = test_button_square.x + (test_button_speed * get_dt())
+ end
+
+ if button_pressed(button.A) then
+ test_button_color = get_random_color()
+ end
+
+ draw_rect(test_button_square.x, test_button_square.y, 50, 50, test_button_color)
end
while window_running() do
@@ -53,7 +84,7 @@ while window_running() do
clear_window(color.BLACK)
-- test_api()
- test_buttons()
+ -- test_buttons()
draw_info()
end_drawing()
diff --git a/examples/icons/icon_1.png b/tests/icons/icon_1.png
index 4785224..4785224 100644
--- a/examples/icons/icon_1.png
+++ b/tests/icons/icon_1.png
Binary files differ
diff --git a/examples/icons/icon_2.png b/tests/icons/icon_2.png
index c19d642..c19d642 100644
--- a/examples/icons/icon_2.png
+++ b/tests/icons/icon_2.png
Binary files differ
diff --git a/examples/json.lua b/tests/json.lua
index 17a1930..a659889 100644
--- a/examples/json.lua
+++ b/tests/json.lua
@@ -1,4 +1,4 @@
-local file = io.open("examples/test.json", "r")
+local file = io.open("tests/test.json", "r")
local content = file:read("*a")
file:close()
diff --git a/examples/test.json b/tests/test.json
index 4bd3e38..4bd3e38 100644
--- a/examples/test.json
+++ b/tests/test.json