[NEW] Implementada pausa

[FIX] Corregit un segon arranc de partida
[NEW] Afegida controller:keypressed
This commit is contained in:
2026-05-15 23:05:26 +02:00
parent d732269d49
commit 2e9883e622
5 changed files with 172 additions and 1 deletions
+88
View File
@@ -59,6 +59,8 @@ function controller:check(action)
elseif action=="jump" then
result = key.down(keyJump) or pad.down(btnJump)
elseif action=="shoot" then
-- No gaste key.press perque no vull "metralleta"
-- s'obliga a alçar la pulsació
result = key.down(keyShoot) or pad.down(btnShoot)
if result then
if self.keysdown[keyShoot] then
@@ -92,4 +94,90 @@ function controller:key_release(keyid)
return true
end
return false
end
function controller:onKeyUp(action)
local resultKey = false
local resultPad = false
local keyDown = false
local buttDown = false
local keyid = nil
local buttid = nil
action = string.upper(action)
if action=="UP" then
keyid = keyUp
buttid = btnUp
elseif action=="DOWN" then
keyid = keyDown
buttid = btnDown
elseif action=="LEFT" then
keyid = keyLeft
buttid = btnLeft
elseif action=="RIGHT" then
keyid = keyRight
buttid = btnRight
elseif action=="JUMP" then
keyid = keyJump
buttid = btnJump
elseif action=="SHOOT" then
keyid = keyShoot
buttid = btnShoot
elseif action=="ESC" then
keyid = key
buttid = btn
end
if keyid~=nil then resultKey = key.down(keyid) end
if buttid~=nil then resultButt = pad.down(buttid) end
result = resultKey or resultPad
if result then
if keyid~=nil then keyDown = self.keysdown[keyid] end
if buttid~=nil then buttDown = self.keysdown[buttid] end
result = true
if keyDown or buttDown then result = false end
-- self.keysdown[keyid] = true
if keyid~=nil then self.keysdown[keyid]=true end
if buttid~=nil then self.keysdown[buttid]=true end
else
-- self.keysdown[keyid] = false
if keyid~=nil then self.keysdown[keyid]=false end
if buttid~=nil then self.keysdown[buttid]=false end
end
return result
end
function controller:keypressed(action)
action = string.upper(action)
if action=="UP" then
keyid = keyUp
buttid = btnUp
elseif action=="DOWN" then
keyid = keyDown
buttid = btnDown
elseif action=="LEFT" then
keyid = keyLeft
buttid = btnLeft
elseif action=="RIGHT" then
keyid = keyRight
buttid = btnRight
elseif action=="JUMP" then
keyid = keyJump
buttid = btnJump
elseif action=="SHOOT" then
keyid = keyShoot
buttid = btnShoot
elseif action=="ESC" then
keyid = key.ESCAPE
buttid = btnPause
end
return key.press(keyid) or pad.press(buttid)
end
+6
View File
@@ -122,6 +122,8 @@ function game_exit()
end
function game_init(menu)
stage= 1
stage_loaded = 0
-- print("GAME INIT")
actors={}
@@ -282,6 +284,10 @@ function update_game()
score.draw()
if controller:check("ESC") then
states:executar("pause", true)
end
if DEBUG then
special_keys()
debug_info()
+1
View File
@@ -17,6 +17,7 @@ require "game"
require "opcions"
require "opcions_input"
require "point"
require "pause"
require "fps"
--require "menu"
+1 -1
View File
@@ -77,7 +77,7 @@ function opcions_input_update()
if input_type==controller.input.kb then
local k = key.press()
if k ~= 0 and k~=key.ESCAPE then
print(k..", "..curr_key.name..", "..curr_key.code)
-- print(k..", "..curr_key.name..", "..curr_key.code)
config_key(curr_key, k)
menu_opt = menu_opt+1
end
+76
View File
@@ -0,0 +1,76 @@
local menu_count = 0
local pausa_option= 1
function pause_init()
-- surf.target(0)
-- surf.cls(16)
menu_count = 1
states:next()
end
function pause_draw()
draw.rectf(32,32,194,130,16)
draw.rect(32,32,194,130,15)
draw.text("PAUSA",108,40,15)
menu_count=menu_count+1
local parpadeig=false
if menu_count>=20 then
parpadeig=true
if menu_count>40 then menu_count=0 end
end
draw.rect(56,66+(20*(pausa_option-1)),146,18,14)
if (not parpadeig) then draw.rect(56,66+(20*(pausa_option-1)),146,18,13) end
draw.text("CONTINUAR",60,70,14)
draw.text("MUSICA:",60,90,14)
if music.enabled() then
draw.text("SI",182,90,15)
else
draw.text("NO",182,90,15)
end
draw.text("SÓ:",60,110,14)
if sound.enabled() then
draw.text("SI",182,110,15)
else
draw.text("NO",182,110,15)
end
draw.text("EIXIR",60,130,14)
end
function pause_update_logic()
if controller:keypressed("down") then
pausa_option = pausa_option + 1
if pausa_option == 5 then pausa_option = 1 end
elseif controller:keypressed("up") then
pausa_option = pausa_option - 1
if pausa_option == 0 then pausa_option = 4 end
elseif controller:keypressed("shoot") then
if pausa_option==1 then
states:next()
elseif pausa_option==2 then
music.enabled(not music.enabled())
elseif pausa_option==3 then
sound.enabled(not sound.enabled())
else
states:executar("title", false)
end
end
end
function pause_update()
if key.press(key.ESCAPE) then
states:next()
return
end
pause_update_logic()
pause_draw()
end
function pause_end()
states:finish()
end
states:registrar("pause", { pause_init, pause_update, pause_end } )