From 20d195c12b017fda166b241c07eff11a71f2f63f Mon Sep 17 00:00:00 2001 From: Entarno54 Date: Fri, 30 May 2025 09:14:00 +0700 Subject: [PATCH] Added settings and fixed some stuff --- characters/tankman.json | 2 +- modules/states/playstate.lua | 20 ++++++++++++++++---- modules/types.lua | 2 +- modules/types/character.lua | 1 + settings.json | 5 +++++ 5 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 settings.json diff --git a/characters/tankman.json b/characters/tankman.json index cb35878..92505d6 100644 --- a/characters/tankman.json +++ b/characters/tankman.json @@ -136,7 +136,7 @@ 225 ], "camera_position": [ - -500, + -900, -20 ], "sing_duration": 4, diff --git a/modules/states/playstate.lua b/modules/states/playstate.lua index ef10e87..055a4bc 100644 --- a/modules/states/playstate.lua +++ b/modules/states/playstate.lua @@ -64,6 +64,8 @@ return function(songName, songDifficulty) local receptors = { } + local keyBinds = {} + local function checkNote(dir) if pressed[dir] or holded[dir] then pressed[dir] = false @@ -131,25 +133,25 @@ return function(songName, songDifficulty) myTypes.updateSprites(dt) - if love.keyboard.isDown("a") then + if love.keyboard.isDown(keyBinds[1]) then checkNote(1) else holded[1] = false pressed[1] = false end - if love.keyboard.isDown("s") then + if love.keyboard.isDown(keyBinds[2]) then checkNote(2) else holded[2] = false pressed[2] = false end - if love.keyboard.isDown("up") then + if love.keyboard.isDown(keyBinds[3]) then checkNote(3) else holded[3] = false pressed[3] = false end - if love.keyboard.isDown("right") then + if love.keyboard.isDown(keyBinds[4]) then checkNote(4) else holded[4] = false @@ -271,12 +273,22 @@ return function(songName, songDifficulty) myTypes.cameraTarget = myTypes.Vector2() + local settings = json.parse(files.read_file("settings.json")) + if not settings then + error("Failed to load settings") + end + + keyBinds = settings.Keybinds + end function state.finish() inst:play() voices:play() + while not inst:isPlaying() do + end --waiting till the song actually plays. + elapsed = 0 playing = true diff --git a/modules/types.lua b/modules/types.lua index db63c95..902fb93 100644 --- a/modules/types.lua +++ b/modules/types.lua @@ -169,7 +169,7 @@ function module.drawSprites() love.graphics.draw(sprite.image, quad.quad, (sprite.position.x + (sprite.position.x - quad.offset.x - sprite.extraOffset.x) + cameraOffset.x), (sprite.position.y + (sprite.position.y - quad.offset.y - sprite.extraOffset.y) + cameraOffset.y), 0, quad.resize.x * (sprite.flipX and -1 or 1), quad.resize.y) ::continue:: -- Point itself end - + for index, rect in next, Rects do if not rect.animation then goto continue end diff --git a/modules/types/character.lua b/modules/types/character.lua index e920809..f61175c 100644 --- a/modules/types/character.lua +++ b/modules/types/character.lua @@ -9,6 +9,7 @@ CharacterClass.__index = CharacterClass function CharacterClass:PlayAnimation(name) local animName = self.animations[name] + local reOffset = self.flipX and -1 or 1 if self.animInfo[name].random then self.sprite:PlayAnimation(animName..string.format("%s ", math.random(self.animInfo[name].random[1], self.animInfo[name].random[2])), self.animInfo[name].fps) self.sprite.extraOffset = module.myTypes.Vector2(self.animInfo[name].offsets[1] - self.stagePosition.x, self.animInfo[name].offsets[2] - self.stagePosition.y) diff --git a/settings.json b/settings.json new file mode 100644 index 0000000..4015627 --- /dev/null +++ b/settings.json @@ -0,0 +1,5 @@ +{ + "Keybinds": [ + "d", "f", "j", "k" + ] +} \ No newline at end of file