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
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
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()
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
<?xml version="1.0" encoding="UTF-8"?>
-<map version="1.10" tiledversion="1.11.2" orientation="orthogonal" renderorder="right-down" width="30" height="20" tilewidth="16" tileheight="16" infinite="0" nextlayerid="5" nextobjectid="10">
+<map version="1.10" tiledversion="1.11.2" orientation="orthogonal" renderorder="right-down" width="30" height="20" tilewidth="16" tileheight="16" infinite="0" nextlayerid="5" nextobjectid="11">
<editorsettings>
<export target="test_1.lua" format="lua"/>
</editorsettings>
</data>
</layer>
<objectgroup id="2" name="Object Layer 1">
- <object id="2" name="Player" gid="515" x="48" y="160" width="16" height="16"/>
+ <object id="2" name="Player" gid="1593" x="48" y="160" width="16" height="16"/>
</objectgroup>
</map>