aboutsummaryrefslogtreecommitdiff
path: root/src/objs
diff options
context:
space:
mode:
authorne_mene <[email protected]>2026-03-13 17:54:17 +0100
committerne_mene <[email protected]>2026-03-13 17:54:17 +0100
commitb47490aea2f63d881a2cc69a326b03abae1a46c0 (patch)
tree2f25d7d56fb495bdbc5a2f24fc7776c9f7e87bdd /src/objs
parentbc52ad3e36ecb0918eca17ea68a0dc54852a3392 (diff)
parent94141331ac0365c8eaa823d0ed1e8eb928f09dc6 (diff)
stupid merge that i hate
Diffstat (limited to 'src/objs')
-rw-r--r--src/objs/player.lua41
-rw-r--r--src/objs/room_editor.lua65
-rw-r--r--src/objs/tilemap.lua15
3 files changed, 83 insertions, 38 deletions
diff --git a/src/objs/player.lua b/src/objs/player.lua
index 82c5ed5..ec04204 100644
--- a/src/objs/player.lua
+++ b/src/objs/player.lua
@@ -14,47 +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.end_window()
end
function new_player(x, y)
@@ -66,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/objs/room_editor.lua b/src/objs/room_editor.lua
new file mode 100644
index 0000000..70f0a86
--- /dev/null
+++ b/src/objs/room_editor.lua
@@ -0,0 +1,65 @@
+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.text("Tile: " .. tostring(room_editor.tile))
+ im.separator()
+ 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 7904a19..834a770 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,
@@ -157,3 +157,16 @@ 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
+
+function get_tileset_count()
+ return TILE_TEX:getHeight() / (4 * TILESIZE)
+end