- Passat a mini v1.3.6
This commit is contained in:
227
data/game.lua
227
data/game.lua
@@ -40,14 +40,14 @@ end
|
||||
|
||||
function playmus(song,loop)
|
||||
if not mute then
|
||||
playmusic(song,loop)
|
||||
music.play(song,loop)
|
||||
end
|
||||
end
|
||||
|
||||
function playsnd(sound,volume)
|
||||
function playsnd(snd,volume)
|
||||
if not mute then
|
||||
--print(sound)
|
||||
return playsound(sound,volume)
|
||||
return sound.play(snd,volume)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -156,17 +156,17 @@ function game_init(menu)
|
||||
game_update=update_menu
|
||||
menu_count=0
|
||||
menu_change_room=300
|
||||
menu_room=rnd(60)
|
||||
menu_room=math.random(0,59)
|
||||
playmus(audio_main_song)
|
||||
else
|
||||
game_update=update_game
|
||||
stopmusic()
|
||||
music.stop()
|
||||
end
|
||||
--fade.fadein()
|
||||
end
|
||||
|
||||
function draw_hab(hab,x,y,editing)
|
||||
camera(-x,-y)
|
||||
view.origin(x,y)
|
||||
mapa_draw(hab)
|
||||
|
||||
if not editing then
|
||||
@@ -180,19 +180,19 @@ function draw_hab(hab,x,y,editing)
|
||||
if cacau.hab==hab then cacau:draw() end
|
||||
if fireball.hab==hab then fireball:draw() end
|
||||
end
|
||||
camera(0,0)
|
||||
view.origin(0,0)
|
||||
end
|
||||
|
||||
function update_dialog()
|
||||
rectfill(16,16,112,50,12)
|
||||
rect(15,15,113,51,16)
|
||||
draw.rectf(16,16,97,35,12)
|
||||
draw.rect(15,15,99,37,16)
|
||||
text("Save the map?",20,20,2)
|
||||
text("This cannot be undone",20,27,2)
|
||||
text("(Y)es (N)o",25,40,2)
|
||||
|
||||
if btnp(KEY_N) then
|
||||
if key.press(key.N) then
|
||||
game_update=update_game
|
||||
elseif btnp(KEY_Y) then
|
||||
elseif key.press(key.Y) then
|
||||
mapa_save()
|
||||
game_update=update_game
|
||||
end
|
||||
@@ -200,63 +200,62 @@ end
|
||||
|
||||
scroll=0
|
||||
function update_game()
|
||||
cls(16)
|
||||
surf.cls(16)
|
||||
|
||||
if mode==modes.editing then
|
||||
draw_hab(abad.hab,0,0,true)
|
||||
text(abad.hab,120,1,2)
|
||||
|
||||
blit(0,64+scroll*8,128,48,0,48)
|
||||
color(3)
|
||||
draw.surf(0,64+scroll*8,128,48,0,48)
|
||||
local xx=(seltile&15)*8
|
||||
local yy=48+(seltile>>4)*8
|
||||
rect(xx,yy,xx+8,yy+8)
|
||||
text("EDIT",100,1,3)
|
||||
draw.rect(xx,yy,9,9, 3)
|
||||
text("EDIT",100,1,3)
|
||||
local hx = abad.hab%10
|
||||
local hy = math.floor(abad.hab/10)
|
||||
scroll=0
|
||||
if btnp(KEY_RIGHT) and hx<9 then
|
||||
if key.press(key.RIGHT) and hx<9 then
|
||||
abad.hab=abad.hab+1
|
||||
elseif btnp(KEY_LEFT) and hx>0 then
|
||||
elseif key.press(key.LEFT) and hx>0 then
|
||||
abad.hab=abad.hab-1
|
||||
elseif btnp(KEY_DOWN) and hy<7 then
|
||||
elseif key.press(key.DOWN) and hy<7 then
|
||||
abad.hab=abad.hab+10
|
||||
elseif btnp(KEY_UP) and hy>0 then
|
||||
elseif key.press(key.UP) and hy>0 then
|
||||
abad.hab=abad.hab-10
|
||||
elseif btnp(KEY_RETURN) then
|
||||
elseif key.press(key.RETURN) then
|
||||
mode=modes.playing
|
||||
elseif btnp(KEY_S) and (btn(KEY_LCTRL) or btn(KEY_LGUI)) then
|
||||
elseif key.press(key.S) and (key.down(key.LCTRL) or key.down(key.LGUI)) then
|
||||
game_update=update_dialog
|
||||
elseif btnp(KEY_C) then
|
||||
elseif key.press(key.C) then
|
||||
mapa_cycle_colors(abad.hab)
|
||||
elseif btnp(KEY_M) then
|
||||
elseif key.press(key.M) then
|
||||
mapa_create_minimap()
|
||||
return
|
||||
end
|
||||
if btn(KEY_TAB) then
|
||||
if key.down(key.TAB) then
|
||||
scroll=2
|
||||
end
|
||||
|
||||
local mx,my=mousex(),mousey()
|
||||
local mx,my=mouse.pos()
|
||||
if mx>>3 < 12 and my>>3 < 6 then
|
||||
text(mx>>3,100,10,2)
|
||||
text(my>>3,111,10,2)
|
||||
text((mx>>3)+(my>>3)*12,118,10,2)
|
||||
end
|
||||
if mbtn(1) then
|
||||
if mouse.down(mouse.LEFT) then
|
||||
if my>=48 then
|
||||
seltile=(mx>>3)+((my-48+(scroll*8))>>3)*16
|
||||
elseif mx<96 then
|
||||
mapa_set_tile(abad.hab,mx>>3,my>>3,seltile)
|
||||
end
|
||||
elseif mbtn(3) then
|
||||
elseif mouse.down(mouse.RIGHT) then
|
||||
if my<48 and mx<96 then
|
||||
mapa_set_tile(abad.hab,mx>>3,my>>3,256)
|
||||
end
|
||||
end
|
||||
if mx>>3 < 12 and my>>3 < 6 then
|
||||
local tx,ty=(mx>>3)<<3,(my>>3)<<3
|
||||
rect(tx,ty,tx+8,ty+8,3)
|
||||
draw.rect(tx,ty,9,9,3)
|
||||
end
|
||||
else
|
||||
if abad.hurting == 0 then
|
||||
@@ -266,15 +265,15 @@ function update_game()
|
||||
text(camera_names[current_camera],2,49,8)
|
||||
|
||||
score.draw()
|
||||
setsource(tiles)
|
||||
prnt("x"..abad.vides,114,13,2)
|
||||
rectfill(102+(abad.energia>>1),30,122,37,16)
|
||||
surf.source(tiles)
|
||||
draw.text("x"..abad.vides,114,13,2)
|
||||
draw.rectf(102+(abad.energia>>1),30,21-(abad.energia>>1),8,16)
|
||||
else
|
||||
blit(0,0,16,9,50,40,16,9,true)
|
||||
draw.surf(0,0,16,9,50,40,16,9,true)
|
||||
if abad.hurting > 40 then
|
||||
prnt("x"..abad.vides+1,63,43,3)
|
||||
draw.text("x"..abad.vides+1,63,43,3)
|
||||
elseif abad.hurting < 20 then
|
||||
prnt("x"..abad.vides,63,43,2)
|
||||
draw.text("x"..abad.vides,63,43,2)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -315,27 +314,27 @@ function update_game()
|
||||
--elseif btnp(KEY_ESCAPE) then
|
||||
-- pause()
|
||||
--end
|
||||
if btnp(KEY_ESCAPE) or padp(btnPause) then
|
||||
if key.press(key.ESCAPE) or pad.press(btnPause) then
|
||||
pause()
|
||||
end
|
||||
if abad.objects.gps~=nil then
|
||||
if btnp(KEY_1) then
|
||||
if key.press(key.N1) then
|
||||
if abad.objects.gorro==nil and abad.objects.clau_premiere==nil then current_camera=1 end
|
||||
elseif btnp(KEY_2) then
|
||||
elseif key.press(key.N2) then
|
||||
if abad.objects.peu==nil and abad.objects.clau_elalien==nil then current_camera=2 end
|
||||
elseif btnp(KEY_3) then
|
||||
elseif key.press(key.N3) then
|
||||
current_camera=3
|
||||
elseif btnp(KEY_4) then
|
||||
elseif key.press(key.N4) then
|
||||
current_camera=4
|
||||
elseif btnp(KEY_5) then
|
||||
elseif key.press(key.N5) then
|
||||
current_camera=5
|
||||
end
|
||||
if padp(btnCycle1) then
|
||||
if pad.press(btnCycle1) then
|
||||
current_camera=current_camera+1
|
||||
if current_camera==6 then current_camera=1 end
|
||||
if current_camera==1 and (abad.objects.gorro or abad.objects.clau_premiere) then current_camera=2 end
|
||||
if current_camera==2 and (abad.objects.peu or abad.objects.clau_elalien) then current_camera=3 end
|
||||
elseif padp(btnCycle2) then
|
||||
elseif pad.press(btnCycle2) then
|
||||
current_camera=current_camera-1
|
||||
if current_camera==0 then current_camera=5 end
|
||||
if current_camera==2 and (abad.objects.peu or abad.objects.clau_elalien) then current_camera=1 end
|
||||
@@ -347,9 +346,9 @@ end
|
||||
|
||||
function redraw_menu_hab()
|
||||
draw_hab(menu_room,16,41)
|
||||
rectfill(0,0,14,96,16)
|
||||
rectfill(114,0,191,96,16)
|
||||
rect(15,40,113,89,2)
|
||||
draw.rectf(0,0,15,97,16)
|
||||
draw.rectf(114,0,78,97,16)
|
||||
draw.rect(15,40,99,50,2)
|
||||
mapa_update(abad.hab,menu_room)
|
||||
|
||||
for key,actor in pairs(actors) do
|
||||
@@ -365,11 +364,11 @@ end
|
||||
function update_menu()
|
||||
menu_change_room=menu_change_room-1
|
||||
if menu_change_room==0 then
|
||||
menu_room = rnd(60)
|
||||
menu_room = math.random(0,59)
|
||||
menu_change_room=300
|
||||
end
|
||||
|
||||
cls(16)
|
||||
surf.cls(16)
|
||||
text("C A C A U S", 42, 8, 15)
|
||||
|
||||
if menu_state == 0 then
|
||||
@@ -385,7 +384,7 @@ function update_menu()
|
||||
|
||||
redraw_menu_hab()
|
||||
|
||||
if btnp(keyShoot) or btnp(KEY_SPACE) or padp(BTN_A) or padp(btnShoot) then
|
||||
if key.press(keyShoot) or key.press(key.SPACE) or pad.press(pad.A) or pad.press(btnShoot) then
|
||||
if menu_sel==0 then
|
||||
game_exit()
|
||||
game_init()
|
||||
@@ -397,130 +396,130 @@ function update_menu()
|
||||
menu_count=0
|
||||
menu_state=2
|
||||
end
|
||||
elseif btnp(keyDown) or btnp(KEY_DOWN) or padp(BTN_DOWN) or padp(btnDown) then
|
||||
elseif key.press(keyDown) or key.press(key.DOWN) or pad.press(pad.DOWN) or pad.press(btnDown) then
|
||||
menu_sel=menu_sel+1
|
||||
if menu_sel==3 then menu_sel=0 end
|
||||
elseif btnp(keyUp) or btnp(KEY_UP) or padp(BTN_UP) or padp(btnUp) then
|
||||
elseif key.press(keyUp) or key.press(key.UP) or pad.press(pad.UP) or pad.press(btnUp) then
|
||||
menu_sel=menu_sel-1
|
||||
if menu_sel==-1 then menu_sel=2 end
|
||||
elseif btnp(KEY_M) then
|
||||
elseif key.press(key.M) then
|
||||
mute = not mute
|
||||
if mute then
|
||||
stopmusic()
|
||||
music.stop()
|
||||
else
|
||||
playmus(audio_main_song)
|
||||
end
|
||||
elseif btnp(KEY_ESCAPE) or padp(btnPause) then
|
||||
quit()
|
||||
elseif key.press(key.ESCAPE) or pad.press(btnPause) then
|
||||
sys.quit()
|
||||
end
|
||||
elseif menu_state==1 then
|
||||
if btnp(KEY_ESCAPE) then
|
||||
if key.press(key.ESCAPE) then
|
||||
menu_count = 0
|
||||
menu_state = 0
|
||||
end
|
||||
if menu_count==0 then
|
||||
text("PULSA TECLA PER A AMUNT", 20, 24, 13)
|
||||
local key = btnp();
|
||||
if key ~= 0 and key~=KEY_ESCAPE then
|
||||
local k = key.press();
|
||||
if k ~= 0 and k~=key.ESCAPE then
|
||||
menu_count = 1
|
||||
keyUp=key
|
||||
setconf("keyup", keyUp)
|
||||
keyUp=k
|
||||
config.key("keyup", keyUp)
|
||||
end
|
||||
elseif menu_count==1 then
|
||||
text("PULSA TECLA PER A AVALL", 20, 24, 13)
|
||||
local key = btnp();
|
||||
if key ~= 0 and key~=KEY_ESCAPE then
|
||||
local k = key.press();
|
||||
if k ~= 0 and k~=key.ESCAPE then
|
||||
menu_count = 2
|
||||
keyDown=key
|
||||
setconf("keydown", keyDown)
|
||||
keyDown=k
|
||||
config.key("keydown", keyDown)
|
||||
end
|
||||
elseif menu_count==2 then
|
||||
text("PULSA TECLA PER A ESQUERRA", 14, 24, 13)
|
||||
local key = btnp();
|
||||
if key ~= 0 and key~=KEY_ESCAPE then
|
||||
local k = key.press();
|
||||
if k ~= 0 and k~=key.ESCAPE then
|
||||
menu_count = 3
|
||||
keyLeft=key
|
||||
setconf("keleft", keyLeft)
|
||||
keyLeft=k
|
||||
config.key("keleft", keyLeft)
|
||||
end
|
||||
elseif menu_count==3 then
|
||||
text("PULSA TECLA PER A DRETA", 20, 24, 13)
|
||||
local key = btnp();
|
||||
if key ~= 0 and key~=KEY_ESCAPE then
|
||||
local k = key.press();
|
||||
if k ~= 0 and k~=key.ESCAPE then
|
||||
menu_count = 4
|
||||
keyRight=key
|
||||
setconf("keyright", keyRight)
|
||||
keyRight=k
|
||||
config.key("keyright", keyRight)
|
||||
end
|
||||
elseif menu_count==4 then
|
||||
text("PULSA TECLA PER A BOTAR", 20, 24, 13)
|
||||
local key = btnp();
|
||||
if key ~= 0 and key~=KEY_ESCAPE then
|
||||
local k = key.press();
|
||||
if k ~= 0 and k~=key.ESCAPE then
|
||||
menu_count = 5
|
||||
keyJump=key
|
||||
setconf("keyjump", keyJump)
|
||||
keyJump=k
|
||||
config.key("keyjump", keyJump)
|
||||
end
|
||||
elseif menu_count==5 then
|
||||
text("PULSA TECLA PER A DISPAR", 18, 24, 13)
|
||||
local key = btnp();
|
||||
if key ~= 0 and key~=KEY_ESCAPE then
|
||||
local k = key.press();
|
||||
if k ~= 0 and k~=key.ESCAPE then
|
||||
menu_count = 0
|
||||
menu_state = 0
|
||||
keyShoot=key
|
||||
setconf("keyshoot", keyShoot)
|
||||
keyShoot=k
|
||||
config.key("keyshoot", keyShoot)
|
||||
end
|
||||
end
|
||||
else
|
||||
if btnp(KEY_ESCAPE) then
|
||||
if key.press(key.ESCAPE) then
|
||||
menu_count = 0
|
||||
menu_state = 0
|
||||
end
|
||||
if menu_count==0 then
|
||||
text("PULSA BOTÓ PER A AMUNT", 22, 24, 13)
|
||||
local btn = padp();
|
||||
local btn = pad.press();
|
||||
if btn ~= -1 then
|
||||
menu_count = 1
|
||||
btnUp=btn
|
||||
setconf("btnup", btnUp)
|
||||
config.key("btnup", btnUp)
|
||||
end
|
||||
elseif menu_count==1 then
|
||||
text("PULSA BOTÓ PER A AVALL", 22, 24, 13)
|
||||
local btn = padp();
|
||||
local btn = pad.press();
|
||||
if btn ~= -1 then
|
||||
menu_count = 2
|
||||
btnDown=btn
|
||||
setconf("btndown", btnDown)
|
||||
config.key("btndown", btnDown)
|
||||
end
|
||||
elseif menu_count==2 then
|
||||
text("PULSA BOTÓ PER A ESQUERRA", 16, 24, 13)
|
||||
local btn = padp();
|
||||
local btn = pad.press();
|
||||
if btn ~= -1 then
|
||||
menu_count = 3
|
||||
btnLeft=btn
|
||||
setconf("keleft", btnLeft)
|
||||
config.key("keleft", btnLeft)
|
||||
end
|
||||
elseif menu_count==3 then
|
||||
text("PULSA BOTÓ PER A DRETA", 22, 24, 13)
|
||||
local btn = padp();
|
||||
local btn = pad.press();
|
||||
if btn ~= -1 then
|
||||
menu_count = 4
|
||||
btnRight=btn
|
||||
setconf("btnright", btnRight)
|
||||
config.key("btnright", btnRight)
|
||||
end
|
||||
elseif menu_count==4 then
|
||||
text("PULSA BOTÓ PER A BOTAR", 22, 24, 13)
|
||||
local btn = padp();
|
||||
local btn = pad.press();
|
||||
if btn ~= -1 then
|
||||
menu_count = 5
|
||||
btnJump=btn
|
||||
setconf("btnjump", btnJump)
|
||||
config.key("btnjump", btnJump)
|
||||
end
|
||||
elseif menu_count==5 then
|
||||
text("PULSA BOTÓ PER A DISPAR", 20, 24, 13)
|
||||
local btn = padp();
|
||||
local btn = pad.press();
|
||||
if btn ~= -1 then
|
||||
menu_count = 0
|
||||
menu_state = 0
|
||||
btnShoot=btn
|
||||
setconf("btnshoot", btnShoot)
|
||||
config.key("btnshoot", btnShoot)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -538,40 +537,40 @@ function aabb(a, b)
|
||||
end
|
||||
|
||||
function pause()
|
||||
setsource(0)
|
||||
setdest(back)
|
||||
blit(0,0,128,96,0,0)
|
||||
setdest(0)
|
||||
setsource(tiles)
|
||||
surf.source(0)
|
||||
surf.target(back)
|
||||
draw.surf(0,0,128,96,0,0)
|
||||
surf.target(0)
|
||||
surf.source(tiles)
|
||||
pausa_option=1
|
||||
pause_old_update=game_update
|
||||
game_update=update_pause
|
||||
end
|
||||
|
||||
function update_pause()
|
||||
rectfill(16,16,112,80,16)
|
||||
rect(16,16,112,80,15)
|
||||
prnt("PAUSA",54,30,15)
|
||||
draw.rectf(16,16,97,65,16)
|
||||
draw.rect(16,16,97,65,15)
|
||||
draw.text("PAUSA",54,30,15)
|
||||
if pausa_option==1 then
|
||||
rect(28,48,100,56,13)
|
||||
draw.rect(28,48,73,9,13)
|
||||
else
|
||||
rect(28,58,100,66,13)
|
||||
draw.rect(28,58,73,9,13)
|
||||
end
|
||||
prnt("CONTINUAR",30,50,14)
|
||||
prnt("EIXIR",30,60,14)
|
||||
draw.text("CONTINUAR",30,50,14)
|
||||
draw.text("EIXIR",30,60,14)
|
||||
|
||||
if btnp(KEY_ESCAPE) then
|
||||
setsource(back)
|
||||
blit(0,0,128,96,0,0)
|
||||
setsource(tiles)
|
||||
if key.press(key.ESCAPE) then
|
||||
surf.source(back)
|
||||
draw.surf(0,0,128,96,0,0)
|
||||
surf.source(tiles)
|
||||
game_update = pause_old_update
|
||||
elseif btnp(keyDown) or btnp(keyUp) or padp(btnDown) or padp(btnUp) then
|
||||
elseif key.press(keyDown) or key.press(keyUp) or pad.press(btnDown) or pad.press(btnUp) then
|
||||
if pausa_option==1 then pausa_option=2 else pausa_option=1 end
|
||||
elseif btnp(keyShoot) or padp(btnShoot) then
|
||||
elseif key.press(keyShoot) or pad.press(btnShoot) then
|
||||
if pausa_option==1 then
|
||||
setsource(back)
|
||||
blit(0,0,128,96,0,0)
|
||||
setsource(tiles)
|
||||
surf.source(back)
|
||||
draw.surf(0,0,128,96,0,0)
|
||||
surf.source(tiles)
|
||||
game_update = pause_old_update
|
||||
else
|
||||
game_exit()
|
||||
|
||||
Reference in New Issue
Block a user