From: Randy McShandy Date: Sat, 31 Jan 2026 01:26:42 +0000 (-0600) Subject: WIP commit X-Git-Url: http://git.mcshandy.xyz/gitweb.cgi?a=commitdiff_plain;h=97ba5d43d3d5cccc6b769a0c8d5b712dfdecf6a6;p=sumeriangame WIP commit --- diff --git a/main/assets.lua b/main/assets.lua index 84d24a3..2437b88 100644 --- a/main/assets.lua +++ b/main/assets.lua @@ -121,6 +121,8 @@ assets.store_object('Player', { properties = (PropertyFlag.Active), path = 'assets/sprites/gilgamesh.png', vec = vector.new_xy(), + update = function(self, dt) + end }) -- STI only supports images for tilesheet sources in a tilemap, not a tsx file diff --git a/main/assets/tilesets/kenney_1_bit/Tilesheet/monochrome_packed.png b/main/assets/tilesets/kenney_1_bit/Tilesheet/monochrome_packed.png index 1c33015..f6095fe 100644 Binary files a/main/assets/tilesets/kenney_1_bit/Tilesheet/monochrome_packed.png and b/main/assets/tilesets/kenney_1_bit/Tilesheet/monochrome_packed.png differ diff --git a/main/conf.lua b/main/conf.lua index 701a5fa..cae69e5 100644 --- a/main/conf.lua +++ b/main/conf.lua @@ -19,21 +19,38 @@ config.ControlType = Movement = 1, } -config.player_keymap = {} -config.player_keymap['l'] = { heading = (math.pi / 2) * -0, control = config.ControlType.Movement, } -config.player_keymap['k'] = { heading = (math.pi / 2) * -1, control = config.ControlType.Movement, } -config.player_keymap['h'] = { heading = (math.pi / 2) * -2, control = config.ControlType.Movement, } -config.player_keymap['j'] = { heading = (math.pi / 2) * -3, control = config.ControlType.Movement, } -config.player_keymap['d'] = { heading = (math.pi / 2) * -0, control = config.ControlType.Movement, } -config.player_keymap['w'] = { heading = (math.pi / 2) * -1, control = config.ControlType.Movement, } -config.player_keymap['a'] = { heading = (math.pi / 2) * -2, control = config.ControlType.Movement, } -config.player_keymap['s'] = { heading = (math.pi / 2) * -3, control = config.ControlType.Movement, } +-- I'd kind of like to keep player controls in a dedicated table that these then map into, +-- but that's probably overengineering for now. Maybe a nice move for flexibility. +-- Maybe even any keymapping here could describe the event(s) and params it should push. +-- At some point in the future, keymaps can be switched out contextually for *very* dynamic behavior, +-- like setting up menu systems. + +config.keymap = {} +config.keymap['l'] = { heading = (math.pi / 2) * -0, control = config.ControlType.Movement, } +config.keymap['k'] = { heading = (math.pi / 2) * -1, control = config.ControlType.Movement, } +config.keymap['h'] = { heading = (math.pi / 2) * -2, control = config.ControlType.Movement, } +config.keymap['j'] = { heading = (math.pi / 2) * -3, control = config.ControlType.Movement, } +config.keymap['d'] = { heading = (math.pi / 2) * -0, control = config.ControlType.Movement, } +config.keymap['w'] = { heading = (math.pi / 2) * -1, control = config.ControlType.Movement, } +config.keymap['a'] = { heading = (math.pi / 2) * -2, control = config.ControlType.Movement, } +config.keymap['s'] = { heading = (math.pi / 2) * -3, control = config.ControlType.Movement, } + +config.keymap['q'] = { + control = config.ControlType.System, + system_action = function(key) + print('Quitting') + love.event.quit() + end, +} function love.conf(t) for k,v in pairs(config.window) do t.window[k] = v end + for k,v in pairs(t.window) do + print(k,v) + end end return config diff --git a/main/main.lua b/main/main.lua index 4791cdc..92c28f0 100644 --- a/main/main.lua +++ b/main/main.lua @@ -14,31 +14,43 @@ player = nil local tx, ty function love.load() - love.graphics.setFont(assets.get_font('Cuneiform36')) - love.audio.play(assets.get_source('intro')) + print(love.graphics.getRendererInfo()) - active_map = assets.get_map('test_map_1') - for k,v in pairs(conf.player_keymap) do - v.speed = active_map.tilewidth - end + love.graphics.setFont(assets.get_font('Cuneiform36')) + love.audio.play(assets.get_source('intro')) - player = assets.get_object('Player') - player_module.init_controls(player, active_map) + active_map = assets.get_map('test_map_1') + player = assets.get_object('Player') + player_module.init_controls(player, active_map) - tx = 0 - ty = 0 + tx = 0 + ty = 0 end function love.update(dt) lovebird.update() active_map:update(dt) + player:update(dt) end -function love.keypressed(key) +function love.keyreleased(key) + for k,v in pairs(conf.keymap) do + if key == k then + if v.control == conf.ControlType.System then + v.system_action(k) + end + if v.control == conf.ControlType.Movement then + love.event.push('player_control', k, v) + end + end + end end -function love.keyreleased(key) - player:keyreleased(key) +function love.handlers.player_control(key, value) + if value.control == conf.ControlType.Movement then + player.vec.heading = value.heading + player.vec.speed = player.speed + end end function love.draw() diff --git a/main/player.lua b/main/player.lua index 9041579..96684aa 100644 --- a/main/player.lua +++ b/main/player.lua @@ -7,22 +7,24 @@ local collision = require('collision') local player_module = {} function player_module.init_controls(player_obj, active_map) + player_obj.speed = active_map.tilewidth + player_obj.keyreleased = function(self, key) if key == 'q' then love.event.quit(0) end - + for k, v in pairs(conf.player_keymap) do if key == k and (v.control == conf.ControlType.Movement) then -- Calculate target tile coordinates (current tile + direction) local current_tile_x = math.floor(self.vec.x / active_map.tilewidth) local current_tile_y = math.floor(self.vec.y / active_map.tileheight) - + -- Direction vectors for each heading local dx = math.floor(math.cos(v.heading) + 0.5) local dy = math.floor(math.sin(v.heading) + 0.5) - + local target_tile_x = current_tile_x + dx local target_tile_y = current_tile_y + dy - + if not collision.is_tile_collidable(active_map, target_tile_x + 1, target_tile_y + 1) then -- Move to target tile (convert back to world coordinates) self.vec.x = target_tile_x * active_map.tilewidth diff --git a/main/tiled/test_1.tmx b/main/tiled/test_1.tmx index 8ca1eff..493aef9 100644 --- a/main/tiled/test_1.tmx +++ b/main/tiled/test_1.tmx @@ -1,5 +1,5 @@ - + @@ -47,6 +47,6 @@ - +