From 3950a3b2fa78b7a928c0437d98105d79c13a922f Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Sun, 8 Mar 2026 18:32:14 -0400 Subject: add util functions; add resources --- main.lua | 4 +-- res/img/bullet.png | Bin 0 -> 114 bytes res/img/carrabasset_big_trunk.png | Bin 0 -> 389 bytes res/img/carrabasset_vines_0.png | Bin 0 -> 715 bytes res/img/carrabasset_vines_1.png | Bin 0 -> 512 bytes res/img/carrabasset_vines_2.png | Bin 0 -> 631 bytes res/img/carrabassett_big_bush_0.png | Bin 0 -> 645 bytes res/img/carrabassett_props.png | Bin 0 -> 5165 bytes res/img/carrabassett_small_bush_0.png | Bin 0 -> 435 bytes res/img/carrabassett_small_trunk.png | Bin 0 -> 284 bytes res/img/dash_pickup.png | Bin 0 -> 133 bytes res/img/double_jump_pickup.png | Bin 0 -> 134 bytes res/img/hugbug.ase | Bin 0 -> 1369 bytes res/img/lamp_post_0.png | Bin 0 -> 382 bytes res/img/muntik.ase | Bin 0 -> 908 bytes res/img/pistol.png | Bin 0 -> 122 bytes res/img/player.ase | Bin 0 -> 5279 bytes res/img/small_lamp.png | Bin 0 -> 164 bytes res/img/tilesets.png | Bin 0 -> 2904 bytes res/img/windchimes_0.png | Bin 0 -> 196 bytes res/img/windchimes_1.png | Bin 0 -> 250 bytes src/init.lua | 2 +- src/utils.lua | 55 ++++++++++++++++++++++++++++++++++ 23 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 res/img/bullet.png create mode 100644 res/img/carrabasset_big_trunk.png create mode 100644 res/img/carrabasset_vines_0.png create mode 100644 res/img/carrabasset_vines_1.png create mode 100644 res/img/carrabasset_vines_2.png create mode 100644 res/img/carrabassett_big_bush_0.png create mode 100644 res/img/carrabassett_props.png create mode 100644 res/img/carrabassett_small_bush_0.png create mode 100644 res/img/carrabassett_small_trunk.png create mode 100644 res/img/dash_pickup.png create mode 100644 res/img/double_jump_pickup.png create mode 100644 res/img/hugbug.ase create mode 100644 res/img/lamp_post_0.png create mode 100644 res/img/muntik.ase create mode 100644 res/img/pistol.png create mode 100644 res/img/player.ase create mode 100644 res/img/small_lamp.png create mode 100644 res/img/tilesets.png create mode 100644 res/img/windchimes_0.png create mode 100644 res/img/windchimes_1.png diff --git a/main.lua b/main.lua index 36294c2..2b23b5b 100644 --- a/main.lua +++ b/main.lua @@ -24,7 +24,7 @@ end function love.draw(dt) lg.origin() - lg.setCanvas(Viewport) + lg.setCanvas(viewport) lg.clear() local scn = get_current_scene() @@ -38,7 +38,7 @@ function love.draw(dt) WindowScale = min(scr_width/SCR_WIDTH, scr_height/SCR_HEIGHT) lg.draw( - Viewport, + viewport, scr_width/2, scr_height/2, 0, WindowScale, WindowScale, SCR_WIDTH/2, SCR_HEIGHT/2) diff --git a/res/img/bullet.png b/res/img/bullet.png new file mode 100644 index 0000000..99d2828 Binary files /dev/null and b/res/img/bullet.png differ diff --git a/res/img/carrabasset_big_trunk.png b/res/img/carrabasset_big_trunk.png new file mode 100644 index 0000000..689fdf6 Binary files /dev/null and b/res/img/carrabasset_big_trunk.png differ diff --git a/res/img/carrabasset_vines_0.png b/res/img/carrabasset_vines_0.png new file mode 100644 index 0000000..97e2482 Binary files /dev/null and b/res/img/carrabasset_vines_0.png differ diff --git a/res/img/carrabasset_vines_1.png b/res/img/carrabasset_vines_1.png new file mode 100644 index 0000000..e2116d2 Binary files /dev/null and b/res/img/carrabasset_vines_1.png differ diff --git a/res/img/carrabasset_vines_2.png b/res/img/carrabasset_vines_2.png new file mode 100644 index 0000000..2a43b05 Binary files /dev/null and b/res/img/carrabasset_vines_2.png differ diff --git a/res/img/carrabassett_big_bush_0.png b/res/img/carrabassett_big_bush_0.png new file mode 100644 index 0000000..fc11931 Binary files /dev/null and b/res/img/carrabassett_big_bush_0.png differ diff --git a/res/img/carrabassett_props.png b/res/img/carrabassett_props.png new file mode 100644 index 0000000..5b28a5b Binary files /dev/null and b/res/img/carrabassett_props.png differ diff --git a/res/img/carrabassett_small_bush_0.png b/res/img/carrabassett_small_bush_0.png new file mode 100644 index 0000000..dc926e4 Binary files /dev/null and b/res/img/carrabassett_small_bush_0.png differ diff --git a/res/img/carrabassett_small_trunk.png b/res/img/carrabassett_small_trunk.png new file mode 100644 index 0000000..bfef5d5 Binary files /dev/null and b/res/img/carrabassett_small_trunk.png differ diff --git a/res/img/dash_pickup.png b/res/img/dash_pickup.png new file mode 100644 index 0000000..758b70a Binary files /dev/null and b/res/img/dash_pickup.png differ diff --git a/res/img/double_jump_pickup.png b/res/img/double_jump_pickup.png new file mode 100644 index 0000000..c0ed3f8 Binary files /dev/null and b/res/img/double_jump_pickup.png differ diff --git a/res/img/hugbug.ase b/res/img/hugbug.ase new file mode 100644 index 0000000..78cbb8e Binary files /dev/null and b/res/img/hugbug.ase differ diff --git a/res/img/lamp_post_0.png b/res/img/lamp_post_0.png new file mode 100644 index 0000000..8b6a9ba Binary files /dev/null and b/res/img/lamp_post_0.png differ diff --git a/res/img/muntik.ase b/res/img/muntik.ase new file mode 100644 index 0000000..83ff0e7 Binary files /dev/null and b/res/img/muntik.ase differ diff --git a/res/img/pistol.png b/res/img/pistol.png new file mode 100644 index 0000000..5b3942e Binary files /dev/null and b/res/img/pistol.png differ diff --git a/res/img/player.ase b/res/img/player.ase new file mode 100644 index 0000000..72f999f Binary files /dev/null and b/res/img/player.ase differ diff --git a/res/img/small_lamp.png b/res/img/small_lamp.png new file mode 100644 index 0000000..120a22d Binary files /dev/null and b/res/img/small_lamp.png differ diff --git a/res/img/tilesets.png b/res/img/tilesets.png new file mode 100644 index 0000000..4a431fe Binary files /dev/null and b/res/img/tilesets.png differ diff --git a/res/img/windchimes_0.png b/res/img/windchimes_0.png new file mode 100644 index 0000000..9e1ba66 Binary files /dev/null and b/res/img/windchimes_0.png differ diff --git a/res/img/windchimes_1.png b/res/img/windchimes_1.png new file mode 100644 index 0000000..892a768 Binary files /dev/null and b/res/img/windchimes_1.png differ diff --git a/src/init.lua b/src/init.lua index c18f175..fd13bcb 100644 --- a/src/init.lua +++ b/src/init.lua @@ -35,7 +35,7 @@ end function main_init() lg.setDefaultFilter("nearest", "nearest") - Viewport = lg.newCanvas(SCR_WIDTH, SCR_HEIGHT) + viewport = lg.newCanvas(SCR_WIDTH, SCR_HEIGHT) load_textures_from() diff --git a/src/utils.lua b/src/utils.lua index c3e4bea..b2186cc 100644 --- a/src/utils.lua +++ b/src/utils.lua @@ -37,3 +37,58 @@ function dist(x1, y1, x2, y2) local dy = y1 - y2 return (dx*dx + dy*dy)^0.5 end + +mathx = {} + +mathx.tau = math.pi * 2 + +function mathx.sign(x) + if x == 0 then + return 0 + end + return x < 0 and -1 or 1 +end + +function round(x) + return math.floor(x + 0.5) +end + +function clamp(a, min, max) + return math.min(max, math.max(a, min)) +end + +function snap(x, step) + return math.floor(x / step) * step +end + +function frac(x) + return x - math.floor(x) +end + +local function angle_diff(a, b) + local diff = (b - a) % (math.pi * 2) + return (2 * diff) % (math.pi * 2) - diff +end + +function lerp_angle(a, b, t) + return a + angle_diff(a, b) * (1 - 0.5^t) +end + +function dot(x, y, xx, yy) + return x*xx + y*yy +end + +function vec_sqlen(x, y) + return x*x + y*y +end + +function vec_len(x, y) + return math.sqrt(x*x + y*y) +end + +function rotate_vec(x, y, r) + local angle = math.atan2(y, x) + r + local len = mathx.vec_len(x, y) + return math.cos(angle) * len, math.sin(angle) * len +end + -- cgit v1.3-2-g0d8e