From 97d2fc1f3cef3c02fee36e416a8f2b5205940be2 Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Thu, 12 Mar 2026 17:00:24 -0400 Subject: show the tileset you're using --- src/objs/player.lua | 2 ++ src/objs/tilemap.lua | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/objs/player.lua b/src/objs/player.lua index c046c7c..4b75cb3 100644 --- a/src/objs/player.lua +++ b/src/objs/player.lua @@ -54,6 +54,8 @@ function player_ui_sys(_) tile = tile + 1 end im.layout() + + im.image(TILE_TEX, get_tileset_quad(tile)) im.end_window() end diff --git a/src/objs/tilemap.lua b/src/objs/tilemap.lua index 8b1ab76..f1cdd15 100644 --- a/src/objs/tilemap.lua +++ b/src/objs/tilemap.lua @@ -107,7 +107,7 @@ function rebuild_tilemap(map) end end -local TILE_TEX = get_tex("res/img/tilesets.png") +TILE_TEX = get_tex("res/img/tilesets.png") local TILE_QUAD = lg.newQuad( 0, 0, TILESIZE, TILESIZE, @@ -150,3 +150,12 @@ function remove_tile(map, x, y) map.tiledata[ID(map, x, y)] = 0 map.needs_rebuild = true end + +function get_tileset_quad(tileset) + local start_y = (tileset - 1) * 4 * TILESIZE + return lg.newQuad( + 0, start_y, + 4 * TILESIZE, 4 * TILESIZE, + TILE_TEX:getDimensions() + ) +end -- cgit v1.3-2-g0d8e From 2b3245f44fecbf2e426bb28f522a24e00662c610 Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Thu, 12 Mar 2026 18:10:06 -0400 Subject: Make the room editor un-hacked in --- main.lua | 6 +++- res/img/tilesets.png | Bin 3075 -> 2968 bytes src/objs/player.lua | 38 ------------------------- src/objs/room_editor.lua | 71 +++++++++++++++++++++++++++++++++++++++++++++++ src/objs/tilemap.lua | 4 +++ 5 files changed, 80 insertions(+), 39 deletions(-) create mode 100644 src/objs/room_editor.lua (limited to 'src') diff --git a/main.lua b/main.lua index ed1a48a..2453b53 100644 --- a/main.lua +++ b/main.lua @@ -12,7 +12,8 @@ function love.load() event_bind(scn.on_draw, "Sprite", sprite_draw_sys) event_bind(scn.on_draw, "Tilemap", tilemap_draw_sys) - event_bind(scn.on_ui, "Player", player_ui_sys) + event_bind(scn.on_update, "Room_Editor", room_editor_ui_sys) + event_bind(scn.on_ui, "Room_Editor", tile_place_sys) set_scene(scn) @@ -25,6 +26,9 @@ function love.load() scn.tilemap = tilemap set_tile(tilemap, 0, 0, 1) + + local room_editor = new_entity() + add_comp(room_editor, "Room_Editor") end function love.update(dt) diff --git a/res/img/tilesets.png b/res/img/tilesets.png index d6f4521..ddd69ba 100644 Binary files a/res/img/tilesets.png and b/res/img/tilesets.png differ diff --git a/src/objs/player.lua b/src/objs/player.lua index 4b75cb3..1e41523 100644 --- a/src/objs/player.lua +++ b/src/objs/player.lua @@ -14,49 +14,11 @@ function body_sys(ent, dt) ent.y = ent.box.y end -local tile = 1 - function player_movement_sys(player, dt) local inpx, inpy = input_direction("Left", "Right", "Up", "Down") inpx, inpy = normalize(inpx, inpy) player.vx = dlerp(player.vx, inpx * PLAYER_SPEED, 25 * dt) player.vy = dlerp(player.vy, inpy * PLAYER_SPEED, 25 * dt) - - -- Testicle stuff, remove when testising is no longer needed - if not im.has_focus() then - if is_input_pressed("Right_Click") then - local scn = get_current_scene() - assert(scn, "no scene set.") - - local mx, my = get_mouse_pos() - local tx, ty = to_tile_coords(mx, my) - set_tile(scn.tilemap, tx, ty, tile) - end - if is_input_pressed("Left_Click") then - local scn = get_current_scene() - assert(scn, "no scene set.") - - local mx, my = get_mouse_pos() - local tx, ty = to_tile_coords(mx, my) - remove_tile(scn.tilemap, tx, ty) - end - end -end - -function player_ui_sys(_) - im.begin_window("Room Editor", 120, 5, 180, 320, {}) - im.layout({0.5, 0.75, 1}) - im.text("Tile: " .. tostring(tile)) - if im.button(" - ") then - tile = math.max(tile - 1, 0) - end - if im.button("+ ") then - tile = tile + 1 - end - im.layout() - - im.image(TILE_TEX, get_tileset_quad(tile)) - im.end_window() end function new_player(x, y) diff --git a/src/objs/room_editor.lua b/src/objs/room_editor.lua new file mode 100644 index 0000000..baee368 --- /dev/null +++ b/src/objs/room_editor.lua @@ -0,0 +1,71 @@ +register_input("Next_Tileset", {{"key", "t"}}) +register_input("Prev_Tileset", {{"key", "r"}}) + +register_comp("Room_Editor", function(ent) + ent.room_editor = { + tile = 1, + } +end) + +function tile_place_sys(ent) + local room_editor = ent.room_editor + + if not im.has_focus() then + if is_input_pressed("Right_Click") then + local scn = get_current_scene() + assert(scn, "no scene set.") + + local mx, my = get_mouse_pos() + local tx, ty = to_tile_coords(mx, my) + set_tile(scn.tilemap, tx, ty, room_editor.tile) + end + if is_input_pressed("Left_Click") then + local scn = get_current_scene() + assert(scn, "no scene set.") + + local mx, my = get_mouse_pos() + local tx, ty = to_tile_coords(mx, my) + remove_tile(scn.tilemap, tx, ty) + end + end + + if is_input_just_pressed("Next_Tileset") then + room_editor.tile = math.min(room_editor.tile + 1, get_tileset_count()) + end + if is_input_just_pressed("Prev_Tileset") then + room_editor.tile = math.max(room_editor.tile - 1, 1) + end +end + +function room_editor_ui_sys(ent) + local room_editor = ent.room_editor + im.begin_window("Room Editor", 120, 5, 180, 320, {}) + -- im.layout({0.5, 0.75, 1}) + im.text("Tile: " .. tostring(room_editor.tile)) + -- if im.button(" - ") then + -- tile = math.max(tile - 1, 1) + -- end + -- if im.button("+ ") then + -- tile = tile + 1 + -- end + im.layout({0.1, 0.6, 1}) + + for tileset_id=1, get_tileset_count() do + local text = " " + if tileset_id == room_editor.tile then + text = "*" + elseif tileset_id == room_editor.tile - 1 then + text = "r" + elseif tileset_id == room_editor.tile + 1 then + text = "t" + end + im.text(text) + if im.button("select") then + room_editor.tile = tileset_id + end + im.image(TILE_TEX, get_tileset_quad(tileset_id)) + end + + im.layout() + im.end_window() +end diff --git a/src/objs/tilemap.lua b/src/objs/tilemap.lua index f1cdd15..cb29a40 100644 --- a/src/objs/tilemap.lua +++ b/src/objs/tilemap.lua @@ -159,3 +159,7 @@ function get_tileset_quad(tileset) TILE_TEX:getDimensions() ) end + +function get_tileset_count() + return TILE_TEX:getHeight() / (4 * TILESIZE) +end -- cgit v1.3-2-g0d8e From f5d00397e02fde75e3c63e9872ac5625bd961794 Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Thu, 12 Mar 2026 18:16:46 -0400 Subject: increase ui scroll speed --- src/im.lua | 2 +- src/objs/room_editor.lua | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/im.lua b/src/im.lua index 2737ed5..cb583ff 100644 --- a/src/im.lua +++ b/src/im.lua @@ -9,7 +9,7 @@ im = { text = {0.8, 0.8, 0.8}, }, padding = 1, - scroll_speed = 5, + scroll_speed = 15, slider_handle_width = 5, resize_handle_size = 5, } diff --git a/src/objs/room_editor.lua b/src/objs/room_editor.lua index baee368..70f0a86 100644 --- a/src/objs/room_editor.lua +++ b/src/objs/room_editor.lua @@ -40,14 +40,8 @@ end function room_editor_ui_sys(ent) local room_editor = ent.room_editor im.begin_window("Room Editor", 120, 5, 180, 320, {}) - -- im.layout({0.5, 0.75, 1}) im.text("Tile: " .. tostring(room_editor.tile)) - -- if im.button(" - ") then - -- tile = math.max(tile - 1, 1) - -- end - -- if im.button("+ ") then - -- tile = tile + 1 - -- end + im.separator() im.layout({0.1, 0.6, 1}) for tileset_id=1, get_tileset_count() do -- cgit v1.3-2-g0d8e From 05976abe6a620da85ad7a9f90cfa99703ed32240 Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Thu, 12 Mar 2026 18:28:55 -0400 Subject: Sprite offset --- src/objs/player.lua | 5 ++++- src/sprite.lua | 29 +++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/objs/player.lua b/src/objs/player.lua index 1e41523..58e5f3a 100644 --- a/src/objs/player.lua +++ b/src/objs/player.lua @@ -30,7 +30,10 @@ function new_player(x, y) mask = {"hard"}, }) add_comp(ent, "Player") - add_comp(ent, "Sprite", "res/img/player.ase") + add_comp(ent, "Sprite", "res/img/player.ase", { + offsetx = 0.5, + offsety = 0.5, + }) return ent end diff --git a/src/sprite.lua b/src/sprite.lua index b7a7541..6cd8ede 100644 --- a/src/sprite.lua +++ b/src/sprite.lua @@ -1,9 +1,11 @@ Sprite = {} Sprite.__index = Sprite -function Sprite.new(tex_name) +function Sprite.new(tex_name, opts) local self = setmetatable({}, Sprite) + opts = opts or {} + self.tex = get_tex(tex_name) self.anim = get_anim(tex_name) @@ -16,11 +18,25 @@ function Sprite.new(tex_name) self.width = width / self.anim.frame_count self.height = height + local offsetx = opts.offsetx or 0 + local offsety = opts.offsety or 0 + + if offsetx < 1 and offsetx > -1 then + self.offsetx = self.width * offsetx + else + self.offsetx = offsetx + end + if offsety < 1 and offsety > -1 then + self.offsety = self.height * offsety + else + self.offsety = offsety + end + return self end -register_comp("Sprite", function(ent, tex_name) - ent.sprite = Sprite.new(tex_name) +register_comp("Sprite", function(ent, tex_name, opts) + ent.sprite = Sprite.new(tex_name, opts) end) function sprite_anim_sys(ent, dt) @@ -49,5 +65,10 @@ function sprite_draw_sys(ent) sprite.width, sprite.height, sprite.tex:getDimensions() ) - lg.draw(sprite.tex, q, ent.x or 0, ent.y or 0) + lg.draw( + sprite.tex, q, + ent.x or 0, ent.y or 0, + 0, 1, 1, + sprite.offsetx, sprite.offsety + ) end -- cgit v1.3-2-g0d8e From 1943aa1b865a36cb88564573cdcca71ac3554504 Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Thu, 12 Mar 2026 18:30:51 -0400 Subject: Use rotation scale and shear components for sprite rendering --- src/sprite.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sprite.lua b/src/sprite.lua index 6cd8ede..49a7dd2 100644 --- a/src/sprite.lua +++ b/src/sprite.lua @@ -68,7 +68,9 @@ function sprite_draw_sys(ent) lg.draw( sprite.tex, q, ent.x or 0, ent.y or 0, - 0, 1, 1, - sprite.offsetx, sprite.offsety + ent.rotation or 0, + ent.scalex or ent.scale or 1, ent.scaley or ent.scale or 1, + sprite.offsetx, sprite.offsety, + ent.shearx or 0, ent.sheary or 0 ) end -- cgit v1.3-2-g0d8e From 94141331ac0365c8eaa823d0ed1e8eb928f09dc6 Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Thu, 12 Mar 2026 19:14:19 -0400 Subject: Fix coloring --- main.lua | 1 + src/sprite.lua | 1 + 2 files changed, 2 insertions(+) (limited to 'src') diff --git a/main.lua b/main.lua index 2453b53..96d6c09 100644 --- a/main.lua +++ b/main.lua @@ -57,6 +57,7 @@ function love.draw(dt) local scr_width, scr_height = lg.getDimensions() WindowScale = min(scr_width / SCR_WIDTH, scr_height / SCR_HEIGHT) + lg.setColor(1, 1, 1) lg.draw( viewport, scr_width / 2, scr_height / 2, 0, diff --git a/src/sprite.lua b/src/sprite.lua index 49a7dd2..79a38bf 100644 --- a/src/sprite.lua +++ b/src/sprite.lua @@ -65,6 +65,7 @@ function sprite_draw_sys(ent) sprite.width, sprite.height, sprite.tex:getDimensions() ) + lg.setColor(1, 1, 1) lg.draw( sprite.tex, q, ent.x or 0, ent.y or 0, -- cgit v1.3-2-g0d8e