Compare commits

..

12 Commits

Author SHA1 Message Date
Lusty Lion of the Land of the Crimson Fawn 7e86da7806 Merge pull request 'I dont fucking know how to solve this shit i hate git' (#3) from bizcochito/Mothback:master into master
Reviewed-on: https://git.fai.su/lustlion/Mothback/pulls/3
2022-01-18 20:20:34 +00:00
bizcochito a183dac913 merge 2022-01-18 21:12:13 +01:00
bizcochito 69ceec024b Merge branch 'master' of https://git.fai.su/bizcochito/Mothback 2022-01-18 21:11:13 +01:00
bizcochito 2b48358ce7 merge 2022-01-18 21:11:11 +01:00
bizcochito ecebca515c merge 2022-01-18 21:09:33 +01:00
bizcochito 9995123c81 Merge branch 'master' of https://git.fai.su/bizcochito/Mothback 2022-01-18 21:09:06 +01:00
bizcochito 33ade34886 Merge https://git.fai.su/lustlion/Mothback 2022-01-18 21:08:58 +01:00
bizcochito 0fa50c3324 Merge https://git.fai.su/lustlion/Mothback 2022-01-18 21:06:21 +01:00
bizcochito a42cf7953f Merge branch 'master' of https://git.fai.su/bizcochito/Mothback 2022-01-18 20:47:57 +01:00
bizcochito da8b9004b4 Made keybind editing "backend" 2022-01-18 20:47:55 +01:00
bizcochito e8477e8750 Update 'main.lua' 2022-01-18 19:45:57 +00:00
bizcochito f021446439 Made keybind editing "backend" 2022-01-18 18:46:41 +01:00
3 changed files with 189 additions and 162 deletions

View File

@ -73,16 +73,16 @@ function Player:Smart()
if math.abs(self.vel.x) < self.zeroSpeed then self.vel.x = 0 end if math.abs(self.vel.x) < self.zeroSpeed then self.vel.x = 0 end
if keybind:Check(keybind.moveLeft) then if Keybind:Check(Keybind.move.left) then
self.move_x = -self.moveSpeed self.move_x = -self.moveSpeed
elseif keybind:Check(keybind.moveRight) then elseif Keybind:Check(Keybind.move.right) then
self.move_x = self.moveSpeed self.move_x = self.moveSpeed
else else
self.move_x = 0 self.move_x = 0
end end
self.vel.x = self.vel.x self.vel.x = self.vel.x
if keybind:Check(keybind.moveJump) then if Keybind:Check(Keybind.move.jump) then
if self.isOnGround then if self.isOnGround then
self.vel.y = -self.jumpImpulse self.vel.y = -self.jumpImpulse
end end
@ -90,18 +90,18 @@ function Player:Smart()
end end
self.dashCooldownTimer = math.max(0,self.dashCooldownTimer - current_dt) self.dashCooldownTimer = math.max(0,self.dashCooldownTimer - current_dt)
if keybind:Check(keybind.moveDash) then if Keybind:Check(Keybind.move.dash) then
if self.dashCooldownTimer == 0 if self.dashCooldownTimer == 0
and not self.isDashing and not self.isDashing
and self.dashCount > 0 then and self.dashCount > 0 then
self.dashCount = self.dashCount - 1 self.dashCount = self.dashCount - 1
self.isDashing = true self.isDashing = true
local vertical = 0 local vertical = 0
if keybind:Check(keybind.moveDown) then vertical = vertical + 1 end if Keybind:Check(Keybind.move.down) then vertical = vertical + 1 end
if keybind:Check(keybind.moveUp) then vertical = vertical - 1 end if Keybind:Check(Keybind.move.up) then vertical = vertical - 1 end
local horizontal = 0 local horizontal = 0
if keybind:Check(keybind.moveRight) then horizontal = horizontal + 1 end if Keybind:Check(Keybind.move.right) then horizontal = horizontal + 1 end
if keybind:Check(keybind.moveLeft) then horizontal = horizontal - 1 end if Keybind:Check(Keybind.move.left) then horizontal = horizontal - 1 end
if horizontal == 0 and vertical == 0 then if horizontal == 0 and vertical == 0 then
horizontal = self.sprite_flip.x horizontal = self.sprite_flip.x

View File

@ -1,7 +1,9 @@
keybind = {} Keybind = {}
Keybind.move = {}
Keybind.menu = {}
function keybind:Check(key) function Keybind:Check(action)
for _, keyname in pairs(key) do for _, keyname in pairs(action) do
if type(keyname) == "string" then if type(keyname) == "string" then
if love.keyboard.isDown(keyname) then return true end if love.keyboard.isDown(keyname) then return true end
else else
@ -11,11 +13,36 @@ function keybind:Check(key)
return false return false
end end
function Keybind:Colision(cat, key)
for _, action in pairs(cat) do
for _, keyname in pairs(action) do
if key == keyname then return true end
end
end
return false
end
keybind.moveLeft = {"left", "a"} function Keybind:Add(action, key)
keybind.moveRight = {"right", "d"} table.insert(action, key)
keybind.moveUp = {"up", "w"} end
keybind.moveDown = {"down", "s"}
keybind.moveJump = {"z", "space"} function Keybind:Change(action, position, key)
keybind.moveAttack = {"x", 1} action[position] = key
keybind.moveDash = {"c", 2} end
function Keybind:Remove(action)
action = {}
end
function Keybind:Default()
Keybind.move.left = {"left", "a"}
Keybind.move.right = {"right", "d"}
Keybind.move.up = {"up", "w"}
Keybind.move.down = {"down", "s"}
Keybind.move.jump = {"z", "space"}
Keybind.move.attack = {"x", 1}
Keybind.move.dash = {"c", 2}
end
-- Set default values at start
Keybind:Default()

288
main.lua
View File

@ -1,144 +1,144 @@
function love.load() function love.load()
arrow = 0 arrow = 0
do_pause = false do_pause = false
debug = false debug = false
debug_collision = false debug_collision = false
editor_mode = false editor_mode = false
textScale = 1 textScale = 1
fps_count = 0 fps_count = 0
fps_second = 0 fps_second = 0
fps_draw = 0 fps_draw = 0
fps_total = 0 fps_total = 0
love.graphics.setColor(1,1,1) love.graphics.setColor(1,1,1)
love.keyboard.setKeyRepeat(true) love.keyboard.setKeyRepeat(true)
love.graphics.setDefaultFilter("nearest") -- good pixel love.graphics.setDefaultFilter("nearest") -- good pixel
game = { game = {
scale = 2, scale = 2,
width = love.graphics.getWidth(), width = love.graphics.getWidth(),
height = love.graphics.getHeight(), height = love.graphics.getHeight(),
paused = false paused = false
} }
require "data/scripts" require "data/scripts"
Canvas = { Canvas = {
Darkness = CreateDarkness() Darkness = CreateDarkness()
} }
love.graphics.setCanvas(Canvas.Darkness) love.graphics.setCanvas(Canvas.Darkness)
SetDarkness() SetDarkness()
love.graphics.setCanvas() love.graphics.setCanvas()
Camera.width = game.width Camera.width = game.width
Camera.height = game.height Camera.height = game.height
levelList = {"level1","2","3","ewae","tileset"} levelList = {"level1","2","3","ewae","tileset"}
levelNum = 1 levelNum = 1
currLevel = levelList[levelNum] currLevel = levelList[levelNum]
LoadedEntities = {} LoadedEntities = {}
LevelLoadTiles() LevelLoadTiles()
main_Player = Player:New(75,50) main_Player = Player:New(75,50)
table.insert(LoadedEntities,main_Player) table.insert(LoadedEntities,main_Player)
table.insert(LoadedEntities,Kupo:New(100,150)) table.insert(LoadedEntities,Kupo:New(100,150))
table.insert(LoadedEntities,Kupo:New(300,150)) table.insert(LoadedEntities,Kupo:New(300,150))
table.insert(LoadedEntities,Decoration:New(200,89,animation.decoration.candelabra,80)) table.insert(LoadedEntities,Decoration:New(200,89,animation.decoration.candelabra,80))
table.insert(LoadedEntities,Fairy:New(200,88)) table.insert(LoadedEntities,Fairy:New(200,88))
gravity = 0.2 gravity = 0.2
end end
function love.update(dt) function love.update(dt)
-- fps counter -- fps counter
if fps_second >= 1 then if fps_second >= 1 then
fps_second = fps_second - 1 fps_second = fps_second - 1
fps_draw = fps_count fps_draw = fps_count
fps_count = 0 fps_count = 0
fps_total = fps_total + 1 fps_total = fps_total + 1
end end
fps_second = fps_second + dt fps_second = fps_second + dt
fps_count = fps_count + 1 fps_count = fps_count + 1
current_dt = dt current_dt = dt
if editor_mode then if editor_mode then
stepEditor() stepEditor()
else else
stepGame() stepGame()
end end
end end
function love.wheelmoved(_, y) function love.wheelmoved(_, y)
if editor_mode then if editor_mode then
if palette then if palette then
p_scroll = p_scroll + y or 0 p_scroll = p_scroll + y or 0
else else
local oscale = game.scale local oscale = game.scale
game.scale = math.max(0.1,game.scale + y/16) game.scale = math.max(0.1,game.scale + y/16)
end end
end end
end end
function love.keypressed(key) function love.keypressed(key)
if key == "escape" then if key == "escape" then
if do_pause then if do_pause then
do_pause = false do_pause = false
else else
pausepage = 1 pausepage = 1
do_pause = true do_pause = true
end end
end end
if key == "f1" then if key == "f1" then
if debug then if debug then
debug = false debug = false
debug_collision = true debug_collision = true
elseif debug_collision then elseif debug_collision then
debug_collision = false debug_collision = false
else else
debug = true debug = true
end end
end end
if key == "f2" then if key == "f2" then
if editor_mode then if editor_mode then
else else
main_Player.pos.x, main_Player.pos.y = 16,-10 main_Player.pos.x, main_Player.pos.y = 16,-10
end end
end end
if key == "f3" then if key == "f3" then
LoadLevel() LoadLevel()
end end
if key == "f4" then if key == "f4" then
if editor_mode then if editor_mode then
editor_mode = false editor_mode = false
else else
editor_mode = true editor_mode = true
end end
end end
end end
function love.draw() function love.draw()
if game.width ~= love.graphics.getWidth() or game.height ~= love.graphics.getHeight() then if game.width ~= love.graphics.getWidth() or game.height ~= love.graphics.getHeight() then
game.width = love.graphics.getWidth() game.width = love.graphics.getWidth()
game.height = love.graphics.getHeight() game.height = love.graphics.getHeight()
game_resize = true game_resize = true
else else
game_resize = false game_resize = false
end end
if editor_mode then if editor_mode then
drawEditor() drawEditor()
else else
drawGame() drawGame()
end end
love.graphics.print(arrow,10,40) love.graphics.print(arrow,10,40)
end end