diff options
Diffstat (limited to 'tests/graphics.lua')
| -rw-r--r-- | tests/graphics.lua | 132 |
1 files changed, 0 insertions, 132 deletions
diff --git a/tests/graphics.lua b/tests/graphics.lua deleted file mode 100644 index 1322101..0000000 --- a/tests/graphics.lua +++ /dev/null | |||
| @@ -1,132 +0,0 @@ | |||
| 1 | math.randomseed(os.time()) | ||
| 2 | |||
| 3 | test_button_square = { x = 400, y = 400 } | ||
| 4 | test_button_color = color.RED | ||
| 5 | test_button_speed = 200 | ||
| 6 | |||
| 7 | test_camera_position = { x = 0, y = 0 } | ||
| 8 | test_camera_speed = 200 | ||
| 9 | |||
| 10 | test_images_asset1 = load_image("tests/icons/icon_1.png") | ||
| 11 | |||
| 12 | open_window(800, 800, "Sample Window") | ||
| 13 | set_fps(60) | ||
| 14 | |||
| 15 | function test_api() | ||
| 16 | draw_rect(100, 100, 300, 200, color.YELLOW) | ||
| 17 | draw_text("Label text", 10, 10, 20, color.VIOLET) | ||
| 18 | draw_line(400, 10, 500, 100, color.RED) | ||
| 19 | draw_circle(500, 500, 100, color.BLUE) | ||
| 20 | draw_ellipse(200, 500, 100, 50, color.BLUE) | ||
| 21 | draw_triangle(20, 20, 100, 20, 50, 100, color.BLUE) | ||
| 22 | draw_text(string.format("fps: %d", get_fps()), 10, 30, 20, color.VIOLET) | ||
| 23 | draw_text(string.format("dt: %.3f", get_dt()), 10, 50, 20, color.VIOLET) | ||
| 24 | end | ||
| 25 | |||
| 26 | function get_random_color() | ||
| 27 | local keys = {} | ||
| 28 | for k in pairs(color) do | ||
| 29 | table.insert(keys, k) -- Collect all keys | ||
| 30 | end | ||
| 31 | local randomKey = keys[math.random(1, #keys)] -- Select a random key | ||
| 32 | return color[randomKey] -- Return the corresponding color | ||
| 33 | end | ||
| 34 | |||
| 35 | function test_buttons() | ||
| 36 | -- Testing button presses. | ||
| 37 | if button_down(button.PAD_UP) then | ||
| 38 | draw_text("Pad Up", 10, 10, 20, color.VIOLET) | ||
| 39 | end | ||
| 40 | |||
| 41 | if button_down(button.PAD_DOWN) then | ||
| 42 | draw_text("Pad Down", 10, 40, 20, color.VIOLET) | ||
| 43 | end | ||
| 44 | |||
| 45 | if button_down(button.PAD_LEFT) then | ||
| 46 | draw_text("Pad Left", 10, 70, 20, color.VIOLET) | ||
| 47 | end | ||
| 48 | |||
| 49 | if button_down(button.PAD_RIGHT) then | ||
| 50 | draw_text("Pad Right", 10, 100, 20, color.VIOLET) | ||
| 51 | end | ||
| 52 | |||
| 53 | if button_down(button.A) then | ||
| 54 | draw_text("A", 150, 10, 20, color.VIOLET) | ||
| 55 | end | ||
| 56 | |||
| 57 | if button_down(button.B) then | ||
| 58 | draw_text("B", 150, 40, 20, color.VIOLET) | ||
| 59 | end | ||
| 60 | |||
| 61 | if button_down(button.X) then | ||
| 62 | draw_text("X", 150, 70, 20, color.VIOLET) | ||
| 63 | end | ||
| 64 | |||
| 65 | if button_down(button.Y) then | ||
| 66 | draw_text("Y", 150, 100, 20, color.VIOLET) | ||
| 67 | end | ||
| 68 | |||
| 69 | -- Moving square around. | ||
| 70 | if button_down(button.PAD_UP) then | ||
| 71 | test_button_square.y = test_button_square.y - (test_button_speed * get_dt()) | ||
| 72 | end | ||
| 73 | |||
| 74 | if button_down(button.PAD_DOWN) then | ||
| 75 | test_button_square.y = test_button_square.y + (test_button_speed * get_dt()) | ||
| 76 | end | ||
| 77 | |||
| 78 | if button_down(button.PAD_LEFT) then | ||
| 79 | test_button_square.x = test_button_square.x - (test_button_speed * get_dt()) | ||
| 80 | end | ||
| 81 | |||
| 82 | if button_down(button.PAD_RIGHT) then | ||
| 83 | test_button_square.x = test_button_square.x + (test_button_speed * get_dt()) | ||
| 84 | end | ||
| 85 | |||
| 86 | if button_pressed(button.A) then | ||
| 87 | test_button_color = get_random_color() | ||
| 88 | end | ||
| 89 | |||
| 90 | draw_rect(test_button_square.x, test_button_square.y, 50, 50, test_button_color) | ||
| 91 | end | ||
| 92 | |||
| 93 | function test_camera() | ||
| 94 | if button_down(button.PAD_UP) then | ||
| 95 | test_camera_position.y = test_camera_position.y - (test_camera_speed * get_dt()) | ||
| 96 | end | ||
| 97 | |||
| 98 | if button_down(button.PAD_DOWN) then | ||
| 99 | test_camera_position.y = test_camera_position.y + (test_camera_speed * get_dt()) | ||
| 100 | end | ||
| 101 | |||
| 102 | if button_down(button.PAD_LEFT) then | ||
| 103 | test_camera_position.x = test_camera_position.x - (test_camera_speed * get_dt()) | ||
| 104 | end | ||
| 105 | |||
| 106 | if button_down(button.PAD_RIGHT) then | ||
| 107 | test_camera_position.x = test_camera_position.x + (test_camera_speed * get_dt()) | ||
| 108 | end | ||
| 109 | |||
| 110 | -- Using camera | ||
| 111 | move_camera(test_camera_position.x, test_camera_position.y) | ||
| 112 | |||
| 113 | start_camera() | ||
| 114 | draw_rect(0, 0, 300, 200, color.YELLOW) | ||
| 115 | stop_camera() | ||
| 116 | |||
| 117 | draw_text("This text doesn't move!", 10, 10, 20, color.VIOLET) | ||
| 118 | end | ||
| 119 | |||
| 120 | while window_running() do | ||
| 121 | start_drawing() | ||
| 122 | clear_window(color.BLACK) | ||
| 123 | |||
| 124 | -- test_api() | ||
| 125 | -- test_buttons() | ||
| 126 | -- test_camera() | ||
| 127 | |||
| 128 | draw_info() | ||
| 129 | stop_drawing() | ||
| 130 | end | ||
| 131 | |||
| 132 | close_window() | ||
