aboutsummaryrefslogtreecommitdiff
path: root/tests/graphics.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/graphics.lua')
-rw-r--r--tests/graphics.lua93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/graphics.lua b/tests/graphics.lua
new file mode 100644
index 0000000..0f337df
--- /dev/null
+++ b/tests/graphics.lua
@@ -0,0 +1,93 @@
1math.randomseed(os.time())
2
3test_button_square = { x = 400, y = 400 }
4test_button_color = color.RED
5test_button_speed = 200
6
7test_images_asset1 = load_image("tests/icons/icon_1.png")
8
9open_window(800, 800, "Sample Window")
10set_fps(60)
11
12function test_api()
13 draw_rect(100, 100, 300, 200, color.YELLOW)
14 draw_text("Label text", 10, 10, 20, color.VIOLET)
15 draw_line(400, 10, 500, 100, color.RED)
16 draw_circle(500, 500, 100, color.BLUE)
17 draw_ellipse(200, 500, 100, 50, color.BLUE)
18 draw_triangle(20, 20, 100, 20, 50, 100, color.BLUE)
19 draw_text(string.format("fps: %d", get_fps()), 10, 30, 20, color.VIOLET)
20 draw_text(string.format("dt: %.3f", get_dt()), 10, 50, 20, color.VIOLET)
21end
22
23function get_random_color()
24 local keys = {}
25 for k in pairs(color) do
26 table.insert(keys, k) -- Collect all keys
27 end
28 local randomKey = keys[math.random(1, #keys)] -- Select a random key
29 return color[randomKey] -- Return the corresponding color
30end
31
32function test_buttons()
33 -- Testing button presses.
34 if button_pressed(button.PAD_UP) then
35 draw_text("Pad Up", 10, 10, 20, color.VIOLET)
36 end
37
38 if button_pressed(button.PAD_DOWN) then
39 draw_text("Pad Down", 10, 40, 20, color.VIOLET)
40 end
41
42 if button_pressed(button.PAD_LEFT) then
43 draw_text("Pad Left", 10, 70, 20, color.VIOLET)
44 end
45
46 if button_pressed(button.PAD_RIGHT) then
47 draw_text("Pad Right", 10, 100, 20, color.VIOLET)
48 end
49
50 if button_pressed(button.A) then
51 draw_text("A", 150, 10, 20, color.VIOLET)
52 end
53
54 if button_pressed(button.B) then
55 draw_text("B", 150, 40, 20, color.VIOLET)
56 end
57
58 if button_pressed(button.X) then
59 draw_text("X", 150, 70, 20, color.VIOLET)
60 end
61
62 if button_pressed(button.Y) then
63 draw_text("Y", 150, 100, 20, color.VIOLET)
64 end
65
66 -- Moving square left and right.
67 if button_pressed(button.PAD_LEFT) then
68 test_button_square.x = test_button_square.x - (test_button_speed * get_dt())
69 end
70
71 if button_pressed(button.PAD_RIGHT) then
72 test_button_square.x = test_button_square.x + (test_button_speed * get_dt())
73 end
74
75 if button_pressed(button.A) then
76 test_button_color = get_random_color()
77 end
78
79 draw_rect(test_button_square.x, test_button_square.y, 50, 50, test_button_color)
80end
81
82while window_running() do
83 begin_drawing()
84 clear_window(color.BLACK)
85
86 -- test_api()
87 -- test_buttons()
88
89 draw_info()
90 end_drawing()
91end
92
93close_window()