Compare commits

..

94 Commits

Author SHA1 Message Date
cb16e0ea63 [NEW] Batvió
[NEW] tiles2.gif
2026-05-04 21:54:43 +02:00
61bf843799 [FIX] Canviat el mode de detecció de les escales 2026-05-03 20:38:00 +02:00
7f0f065e8b [FIX] Incidencia #3 parcialment resolta ('tembleque')
[NEW] La manera de pujar y baixar les escales ha canviat
2026-05-03 20:14:25 +02:00
7faf7049fd [NEW] Zombies amb mes d'1 de vida
[NEW] Afegits nous 'monstruitos' en la casa de Batman
2026-05-03 00:26:24 +02:00
e59be0c33f [FIX] Posició dels tiles d'aranya animats 2026-05-02 23:22:28 +02:00
c9f3aabfaa [NEW] Mes tiles d'aranya animats 2026-05-02 23:13:46 +02:00
526eb88fd7 [NEW] Tile de la aranya animat 2026-05-02 22:52:56 +02:00
7eb8162621 [NEW] Afegida una capa al mapa per a fer coses especials 2026-05-02 22:01:44 +02:00
a4f7d78457 [FIX] Canviada la poció a 'objecte' 2026-05-02 20:47:20 +02:00
2cb75fc184 [Fix] Sprite de la botella de vida modificat 2026-05-02 00:20:36 +02:00
b7c84163a0 [Fix] Arreglos menors. Jugable 2026-05-01 23:57:21 +02:00
40c874ec57 [NEW] Botella de vida 2026-05-01 23:21:19 +02:00
3f83b7254b [FIX] Canviat el diàleg del boss 2026-05-01 22:17:18 +02:00
cc3b1f02cd [NEW] Afegit 'bocadillo' per a elalien 2026-05-01 22:02:38 +02:00
5eb4256e8f [FIX] Afegit run a trigger (mes lògic que com estava abans) 2026-05-01 21:59:03 +02:00
f071c4b359 [FIX] Requreix mini 1.5.2 2026-05-01 21:49:04 +02:00
20646e9c64 [FIX] Incidencia #9 resolta 2026-05-01 18:16:01 +02:00
bbcb6cc667 [FIX] Incidencies #4 y #6 resoltes 2026-05-01 17:32:04 +02:00
17ad156896 [FIX] Tiles del logo modificats 2026-05-01 15:21:28 +02:00
301247003c [FIX] Bol i escena del bol 2026-05-01 12:47:29 +02:00
1143b5d83e [Fix] Eliminada la última posició per al peu perque no se fer-ho d'altra forma 2026-05-01 08:48:03 +02:00
dfd0fe41db [NEW] Posició nova per al peu - prova 2026-05-01 08:45:00 +02:00
df30835830 [NEW] Porta final funcionant
[FIX] Una posició del peu
2026-05-01 00:35:55 +02:00
8e3117d5bc [NEW] Escena habitació de Batman funcionant 2026-04-30 23:42:49 +02:00
dff88be17a [FIX] Peu corregit en l'inventari 2026-04-30 23:32:09 +02:00
030a5ef69e [NEW] Peu funcionant 2026-04-30 23:14:46 +02:00
cb525845ac [NEW] Elalien en marxa 2026-04-30 22:55:02 +02:00
8b758af0e7 [NEW] Premiere també camina 2026-04-26 22:03:45 +02:00
90fd942d84 [NEW] Moguts els dialegs a trigger per event 2026-04-26 19:57:53 +02:00
ca4169f2f1 [FIX] Modificada l'estructura de trigger_event per a incorporar funcions init i update 2026-04-26 11:36:57 +02:00
6b6f6e6721 [NEW] Triggers per event 2026-04-25 12:45:19 +02:00
311e5ff6f8 [WIP] Treballant en el jefe. Preparant l'achuda 2026-04-23 21:33:39 +02:00
ea19c43865 [NEW] Dialeg funcionant. 2026-04-22 22:31:32 +02:00
a811ece34f [WIP] Dialeg. dialeg:draw() 2026-04-21 22:11:38 +02:00
75898372f9 [FIX] Tile de peu pudent 2026-04-20 22:16:50 +02:00
e152df913c [WIP] Dialeg 2026-04-20 22:08:02 +02:00
a4f989eb02 [WIP] Afegit un grapaet mes de monstruacos per a donar-li interes a la cosa 2026-04-19 16:15:23 +02:00
5622392f41 [WIP] Treballant en el jefe. Implementant chase i avoid 2026-04-19 15:56:33 +02:00
dab08a0f17 [WIP] Treballant en el jefe. Per fi torna a ser jugable! Ara a pels detalls 2026-04-18 18:45:58 +02:00
8f65666a06 [WIP] Treballant en el jefe. Tram final 2026-04-18 01:51:00 +02:00
5843953b7b [WIP] Treballant en el jefe. Super! 2026-04-17 23:49:16 +02:00
1b3aa47d9e [WIP] Treballant en el jefe. Pattern recovery 2026-04-17 21:57:00 +02:00
82e00e04d1 [WIP] Treballant en el jefe. Per fi! Ja comença a funcionar de nou 2026-04-17 21:22:03 +02:00
956603b99c [WIP] Treballant en el jefe. Pareix que se va aclarint, pareix 2026-04-16 22:27:13 +02:00
1b812127e2 [WIP] Treballant en el jefe. La que s'està liant... 2026-04-15 23:31:19 +02:00
0c9c31dca2 [WIP] Treballant en el jefe. Separat el 'motor' de moviment per patró 2026-04-14 23:41:34 +02:00
d477988d10 [WIP] Treballant en el jefe. Almenys ja no explota, algo es algo 2026-04-13 22:32:07 +02:00
a43173a940 [WIP] Treballant en el jefe. Organitzant codi (Ha deixat de funcionar quasi tot)
[FIX] Els warps reutilitzats mantenien l'estat anterior
[NEW] Funcio distancia(a, b)
2026-04-12 23:06:20 +02:00
f26d43a97d [WIP] Treballant en el jefe. Super power done! 2026-04-12 14:00:25 +02:00
91db8e40be [WIP] Treballant en el jefe. Super al 50% 2026-04-11 23:22:50 +02:00
2af80b121f [WIP] Treballant en el jefe. Barra d'energia 2026-04-11 18:07:43 +02:00
6497f02f3c [WIP] Treballant en el jefe. Dispar complet 2026-04-11 14:49:57 +02:00
acbf262ee3 [WIP] Treballant en el jefe. Moviment per patró assegurat 2026-04-11 14:09:26 +02:00
2e4453ecdb [WIP] Treballant en el jefe. Dispar al 50% 2026-04-11 12:18:27 +02:00
d5dc2aba5f [WIP] Treballant en el jefe. 'chase' i 'away' 2026-04-11 11:56:57 +02:00
f5f9f3d3dc [WIP] Treballant en el jefe. Arreglos de codi 2026-04-11 11:34:04 +02:00
6da507378f [WIP] Treballant en el jefe. Pattern mode modificacions menors 2026-04-11 02:57:23 +02:00
d4ef8ba551 [WIP] Treballant en el jefe. Pattern mode funcionant 2026-04-11 02:32:55 +02:00
568b531d4b [WIP] Treballant en el jefe. 2026-04-10 20:41:00 +02:00
87e2a134a8 [WIP] Treballant en el jefe. Recuperar informació de l'entorn 2026-04-09 23:12:17 +02:00
0a682b2440 [WIP] Lluita contra jefe. 2026-04-08 23:04:23 +02:00
cbf265fe4d [WIP] Continue treballant en el jefe 2026-04-07 22:32:59 +02:00
f93c9b6c55 [WIP] Lluita contra jefes.
+ Redisseny de mapa
+ Ajustada la vista abans del combat i fixada en la vertical
[NEW] Objecte point
2026-04-06 23:30:53 +02:00
a481d3798b [WIP] Lluita contra jefes. El cacaus ja li impacten 2026-04-06 02:15:19 +02:00
6ac7a811d9 [WIP] Lluita contra jefes. Casi implementat se serebro de la bestia 2026-04-06 01:58:49 +02:00
aaf5c0fb47 [WIP] Lluita contra jefes. Càrrega de fase redefinida 2026-04-05 20:03:59 +02:00
5aa9dd5051 [WIP] Lluita contra jefes. Eliminats actors de la zona de combat 2026-04-05 17:32:08 +02:00
4c2c8dc84f [NEW] Switchs i triggers dependents enllaçats
[NEW] Visió remota al obrir-se una porta
2026-04-05 16:17:24 +02:00
679e22f7fd [NEW] Estructura de triggers ampliada per a soportar switchs
[NEW] Switchs convertits a triggers
2026-04-05 13:28:01 +02:00
1624afc849 [FIX] Afegit mood a escenes 2026-04-05 00:45:09 +02:00
82ca7cb2b5 [NEW] Afegit sistema de mood per a l'abad 2026-04-05 00:33:21 +02:00
b2cb8698b4 [WIP] Lluita contra jefes
-- El viewport ja es fixa i es solta
-- L'escenari ja se modifica i se restaura
2026-04-04 22:00:51 +02:00
9bb372a70b [WIP] Lluita contra jefes 2026-04-04 20:45:14 +02:00
205586cc77 [WIP] Afegint codi per a múltiples fases
[NEW] Quan cau la gota canvia la imatge. Ja no cauen peres XD
[FIX] El foc feia mal des de massa alt
2026-04-04 17:00:43 +02:00
d5896466cf [WIP] Afegint codi per a múltiples fases 2026-04-04 13:30:53 +02:00
e4fe812e4a [NEW] Veu de l'imp
[NEW] Afegits cacaus desapareguts en la intro
2026-04-04 12:55:33 +02:00
42b4638567 [NEW] Llibre de tècniques
[NEW] Escena llibre
[NEW] El abad dispara en l'aire
2026-04-04 11:41:54 +02:00
73122ebb78 - [NEW] Música per a l'imp
- [NEW] Escena amb l'imp
- [FIX] scenes.lua - La música pot arrancar en qualsevol escena
2026-04-04 00:58:03 +02:00
9ab8c80a56 [NEW] Afegits mini sprites de gorro, peu i clau
[NEW] Afegit JAILGAMES al títol
2026-04-03 23:14:44 +02:00
6fd1d2d49c - Premiere i gorro actius
- Canviat l'sprite de Premiere
2026-04-03 22:29:25 +02:00
5a385ef1a8 Triggers en marxa 2026-04-03 21:37:39 +02:00
8b516a6a26 [WIP] Triggers
- Algo de neteja de codi
2026-04-03 20:09:30 +02:00
de395abb06 [NEW] Controller.lua - Gestiona tot lo relatiu al teclat i gamepad
[NEW] opcions_input.lua - Pantalla de definició de tecles per a teclat i pad
- Modificat el abad per a que use controller
2026-04-03 19:33:51 +02:00
ca0393046e [FIX] Sistema de navegació entre pantalles (flow)
- Optimitzat el logo. Ara necessita menys memòria aprofitant les funcions de paleta
2026-04-03 15:29:44 +02:00
2564c54b3e - [NEW] draw_shiny_rect()
- [WIP] Menú d'opcions
2026-04-03 01:08:20 +02:00
d45c2fe011 - El foc ja fa mal
- El abad ja no es invencible si entra en col·lisió infinita
2026-04-02 22:14:21 +02:00
fc9ed7614e - Primer 'redo' de part del codi
- Afegida la pantalla de titol
2026-04-02 21:46:43 +02:00
56807c2285 Escenes funcionant.
Altres correccions menors.
2026-04-01 21:58:41 +02:00
205a98bf17 Zombies interdimensionals done! 2026-03-31 21:31:16 +02:00
1708be71a8 Cacos interdimensionals done! 2026-03-31 21:03:58 +02:00
c9a4313e04 [WIP] Enviant als cacos a altra dimensió
[NEW] Tile per a warping
2026-03-30 21:46:30 +02:00
9e9a60b733 Sprite del Caco modificat 2026-03-29 21:44:59 +02:00
2986f69e2c [WIP] Començant en el forat negre 2026-03-29 21:33:54 +02:00
8d84cdbda1 El monstruitos ja fan pupa 2026-03-29 19:32:13 +02:00
53 changed files with 7002 additions and 807 deletions

3
.gitignore vendored
View File

@@ -2,6 +2,9 @@
release/*
*.exe
*.dll
*.xcf
desktop.ini
mini
mini_debug
data-old
backups

View File

@@ -1,5 +1,3 @@
-- TO DO: Afegir un contador per a saber quan de temps está parat el abad per a traure al Imp
keysdown = {}
-- local arcade_config = require("arcade_config")
cw = arcade_config.character_width
ch = arcade_config.character_height
@@ -31,6 +29,7 @@ end
function abad_init()
abad={ name="abad",
id="abad",
x=40, y=24,
w=32, h=32,
flip=false,
@@ -45,9 +44,11 @@ function abad_init()
step=0,
mustep=1,
stairs_flip=false,
stairs_moves=0, --contador de moviments dins de les escales
draw=abad.draw,
hurting=0,
update=nil,
save_update=nil,
jumpfwd=false,
step_length=1,
vmove_space=1,
@@ -63,7 +64,8 @@ function abad_init()
anim={0,1,0,2},
bb={x=8,y=0,w=16,h=32},
safe={hab=10,x=40,y=24},
move=abad.move }
move=abad.move,
mood="normal"}
abad.update=abad_state_normal
abad.objects={}
end
@@ -75,24 +77,58 @@ function abad:move( x, y )
self.hab = hab
end
function abad_add_mood(abad_x, spr_off_x, abad_y, spr_off_y, flip, mood)
flip = flip or false
mood = mood or "normal"
if flip then
abad_x = abad_x-15+4
end
if mood~="normal" then
if mood=="sorpresa" then
draw.surf(240,0,11,4,abad_x+16-spr_off_x,abad_y+5-spr_off_y,11,4,flip)
elseif mood=="enfadat" then
draw.surf(240,4,11,4,abad_x+16-spr_off_x,abad_y+5-spr_off_y,11,4,flip)
elseif mood=="interessant" then
draw.surf(240,8,11,4,abad_x+16-spr_off_x,abad_y+5-spr_off_y,11,4,flip)
end
end
end
function abad:draw()
local flip = abad.flip
if abad.update==abad_state_stairs then
flip=abad.stairs_flip
-- flip=(((abad.x>>1)+(abad.y>>1))%2)==0
if ((abad.x+abad.y)%12)==0 then abad.stairs_flip=not abad.stairs_flip end
local msg = "-- "..abad.x.." "..abad.y
if flip then msg = "FLIP"..abad.x.." "..abad.y end
msg_print(0,35,msg,true)
end
if (abad.respawning==0) or (math.floor(abad.respawning/15)%2==0) then
local x, y = viewp:screen_coords(self.x, self.y)
draw.surf(abad.frame*cw,0,cw,ch,x,y,cw,ch,flip)
if abad.update==abad_state_stairs then
-- flip=abad.stairs_flip
-- -- flip=(((abad.x>>1)+(abad.y>>1))%2)==0
if math.abs(abad.stairs_moves-(abad.x+abad.y))>12 then
abad.stairs_moves = abad.x+abad.y
abad.flip = not abad.flip
end
flip = abad.flip
-- if ((abad.x+abad.y)%12)==0 then
-- abad.stairs_flip=not abad.stairs_flip
-- end
-- local msg = "-- "..abad.x.." "..abad.y
-- if flip then msg = "FLIP"..abad.x.." "..abad.y end
-- -- msg_print(0,35,msg,true)
end
if (abad.respawning==0) or (math.floor(abad.respawning/15)%2==0) then
draw.surf(abad.frame*abad.w,0,abad.w,abad.h,x,y,abad.w,abad.h,flip)
-- caminant, parat, disparant o saltant
if abad.frame<=3 or abad.frame==6 then
abad_add_mood(x,0,y,0,flip,abad.mood)
end
end
if abad.respawning > 0 then
abad.respawning=abad.respawning-1
end
draw.rect(x+abad.bb.x,y+abad.bb.y,abad.bb.w,abad.bb.h,3)
end
function abad_make_safe( force )
@@ -105,8 +141,15 @@ function abad_make_safe( force )
end
end
function abad_heal(howmuch)
abad.energia = abad.energia + howmuch
if abad.energia>abad.max_energia then
abad.energia = abad.max_energia
end
end
function abad_hurt(howmuch)
howmuch = 0
if abad.hurting == 0 and abad.respawning==0 then
sound.play(audio_abad_hit)
abad.energia=abad.energia-howmuch
@@ -136,6 +179,7 @@ function abad_hurt(howmuch)
surf.cls(3)
end
end
if abad.respawning==0 then abad.respawning = 120 end
end
function abad_do_jump ( jumpfwd )
@@ -154,6 +198,7 @@ end
function abad_shot_cacau ()
if cacau:available(abad.cacau_num_shots, abad.cacau_type_shot) then
sound.play(audio_abad_shot)
abad.save_update=abad.update
abad.update=abad_state_fire
abad.wait=0
-- cacau.init(abad.hab,abad.x+8,abad.y+8,abad.flip)
@@ -174,20 +219,30 @@ function abad_jump()
local not_block_tile = tile1_hit_type ~= tiletype.block and tile2_hit_type ~= tiletype.block
local switch_tile = tile1_hit_type == tiletype.switch or tile2_hit_type == tiletype.switch
-- print("JUMP > "..x1_check..", "..x2_check..", "..y_check)
-- print("T1= "..tile1_hit_type.." / T2= "..tile2_hit_type)
-- print("T1= "..tile1_hit_type.." / T2= "..tile2_hit_type.." / SW= "..tiletype.switch)
-- local msg = "BLOCK TILE HITTED"
-- if not_block_tile then msg="not block" end
-- print(msg)
-- Fer l'acció que correspon
if not_block_tile then
--if switch_tile then
-- local xx= x2_check
-- local yy= y_check
-- -- Executar el switch
-- if tile1_hit_type == tiletype.switch then
-- xx= x1_check
-- end
-- switches.start(xx, yy)
--else
-- abad.y=abad.y-vspace
--end
if switch_tile then
local xx= x2_check
local yy= y_check
-- Executar el switch
if tile1_hit_type == tiletype.switch then
xx= x1_check
-- Si la posició actual no es dins del tile, avançar per a colisionar
if (arc_check_tile(x1_check, abad.y)~= tiletype.switch and
arc_check_tile(x2_check, abad.y)~= tiletype.switch)
then
abad.y=abad.y-vspace
end
switches.start(xx, yy)
else
abad.y=abad.y-vspace
end
@@ -221,11 +276,11 @@ function abad_jump()
if abad.jump_in_half_block>0 then
abad.y=abad.y-vspace
abad.jump_in_half_block = abad.jump_in_half_block-1
abad.jump_in_half_block_used = true
end
end
end
abad.jump_height = abad.jump_height+1
abad.jump_in_half_block_used = true
end
function abad_land ()
@@ -253,29 +308,88 @@ function abad_land ()
return can_land
end
function abad_in_stairs(next_x, next_y)
next_x = next_x or 0
next_y = next_y or 0
-- local x1_check = abad.x+abad.bb.x+next_x
-- local x2_check = abad.x+abad.bb.x+abad.bb.w+next_x
-- local y1_check = abad.y+next_y
-- local y2_check = abad.y+abad.bb.h+next_y
--
-- if arc_check_tile(x1_check, y1_check)==tiletype.stair or
-- arc_check_tile(x2_check, y1_check)==tiletype.stair or
-- arc_check_tile(x1_check, y2_check)==tiletype.stair or
-- arc_check_tile(x2_check, y2_check)==tiletype.stair
-- then
-- return true
-- end
local x1_check = abad.x+(abad.w/2)+next_x
local y1_check = abad.y+next_y
local y2_check = abad.y+abad.bb.h+next_y
if arc_check_tile(x1_check, y1_check)==tiletype.stair or
arc_check_tile(x1_check, y2_check)==tiletype.stair
then
return true
end
return false
end
function abad_in_floor(next_x, next_y)
local x1_check = abad.x+abad.bb.x+next_x
local x2_check = abad.x+abad.bb.x+abad.bb.w+next_x
local y2_check = abad.y+abad.bb.h+next_y
if arc_check_tile(x1_check, y2_check)==tiletype.block or
arc_check_tile(x2_check, y2_check)==tiletype.block
then
return true
end
return false
end
function abad_advance()
local step_length=abad.step_length; --lo que avança l'abad cada pas
local limit=tiletype.block
if abad.update~=abad_state_walking then limit=tiletype.half end
if abad.update~=abad_state_walking then
limit=tiletype.half
end
local x_check = abad.x+abad.bb.x+abad.bb.w+step_length
if abad.flip then
step_length = -step_length
x_check = abad.x+abad.bb.x+step_length
end
local y_check = abad.y+abad.bb.h-4
-- local y_check = abad.y+abad.bb.h-4
local y_check = abad.y+abad.bb.h-1
if arc_check_tile(x_check, y_check)<limit then
abad.x=abad.x+step_length
end
if arc_check_tile(x_check,y_check)==tiletype.stair then
abad.update=abad_state_stairs
elseif abad.update==abad_state_stairs then
-- if arc_check_tile(x_check,y_check)==tiletype.stair then
-- print("STAIRS "..math.random(50))
-- if abad.update~=abad_state_stairs and controller:check("up")
-- then
-- print("UPDATE STAIRS")
-- abad.update=abad_state_stairs
-- end
-- elseif abad.update==abad_state_stairs then
-- abad.update=abad_state_normal
-- abad.frame=0
-- end
if not abad_in_stairs() and
abad.update==abad_state_stairs
then
abad.update=abad_state_normal
abad.frame=0
end
local hab,xx, yy = coords.world_to_tile(abad.x, abad.y)
abad.hab = hab
end
@@ -294,9 +408,10 @@ function abad_state_normal()
end
if abad.falling>0 then
if abad.falling>(abad.max_jump_height<<1) then
-- numero de pisos caiguts * 2
local damage = math.floor(abad.falling/(mapa_room_rows*arcade_config.tiles_height))*2
local altura_piso = (mapa_room_rows*arcade_config.tiles_height)
local pisos_caiguts = math.floor(abad.falling/altura_piso)
local damage = pisos_caiguts*2
if damage>0 then
if damage>abad.energia then damage=abad.energia end
abad_hurt(damage)
end
@@ -305,34 +420,29 @@ function abad_state_normal()
abad_make_safe()
if key.down(keyRight) or pad.down(btnRight) then
if controller:check("right") then
abad.update=abad_state_walking
abad.flip=false
elseif key.down(keyLeft) or pad.down(btnLeft) then
elseif controller:check("up") and abad_in_stairs() then
abad.update=abad_state_stairs
elseif controller:check("left") then
abad.update=abad_state_walking
abad.flip=true
elseif key.down(keyJump) or pad.down(btnJump) then
elseif controller:check("jump") then
abad_do_jump()
elseif key.down(keyDown) or pad.down(btnDown) then
elseif controller:check("down") then
if abad_in_stairs() then
abad.update=abad_state_stairs
else
abad.update=abad_state_crouch
end
--elseif btn(KEY_Z) then
-- abad.respawning=240
elseif key_release(keyShoot) or pad.down(btnShoot) and cacau.hab==-1 then
elseif controller:check("shoot") then
abad_shot_cacau()
end
end
function key_release(keyid)
-- if keysdown[keyid] then print("Pressed "..keyid) end
if key.down(keyid) then
keysdown[keyid] = true
elseif keysdown[keyid] then
keysdown[keyid] = false
return true
end
return false
end
function abad_state_crouch()
abad.bb.y=8
abad.bb.h=24
@@ -341,7 +451,7 @@ function abad_state_crouch()
abad.step=0
abad.jumpfwd=false
abad.jump_height=0
if not (key.down(keyDown) or pad.down(btnDown)) then
if not controller:check("down") then
abad.update=abad_state_normal
abad.bb.y=0
abad.bb.h=32
@@ -355,10 +465,17 @@ function abad_state_fire()
if abad.wait==6 then
abad.wait=0
if abad.save_update==nil then
abad.update=abad_state_normal
else
abad.update=abad.save_update
abad.save_update=nil
end
end
if abad.save_update~=nil and abad.save_update~=abad_state_normal then abad_advance() end
end
function abad_state_walking()
-- Limitar la velocitat de moviment
abad.wait=abad.wait+1
@@ -391,19 +508,19 @@ function abad_state_walking()
abad_make_safe()
-- Gestionar accions mentre es camina
if key.down(keyJump) or pad.down(btnJump) then
if controller:check("jump") then
abad_do_jump(true); -- jumping forward
return
elseif key.down(keyDown) or pad.down(btnDown) then
elseif controller:check("down") then
abad.update=abad_state_crouch
elseif key.down(keyShoot) or pad.down(btnShoot) and cacau.hab==-1 then
elseif controller:check("shoot") then
abad_shot_cacau()
end
-- "Flipar" a l'Abad
if key.down(keyRight) or pad.down(btnRight) then
if controller:check("right") then
abad.flip=false
elseif key.down(keyLeft) or pad.down(btnLeft) then
elseif controller:check("left") then
abad.flip=true
elseif abad.wait==0 then
abad.update=abad_state_normal
@@ -429,6 +546,10 @@ function abad_state_jumping()
if abad.jumpfwd then abad_advance() end
if abad.objects.llibre and controller:check("shoot") then
abad_shot_cacau()
end
end
function abad_state_falling()
@@ -465,37 +586,55 @@ function abad_state_falling()
abad.jump_height = abad.jump_height-1
abad.falling=abad.falling+1
if abad.jumpfwd then abad_advance() end
if abad.objects.llibre and controller:check("shoot") then
abad_shot_cacau()
end
end
function abad_state_stairs()
abad.frame=4
abad.wait=abad.wait+1
local moved = false
local x1_check = abad.x+abad.bb.x
local x2_check = abad.x+abad.bb.x+abad.bb.w-1
local y_check = abad.y+abad.bb.h-1
--local x1_check = abad.x+abad.bb.x
--local x2_check = abad.x+abad.bb.x+abad.bb.w-1
--local y_check = abad.y+abad.bb.h
if key.down(keyRight) or pad.down(btnRight) then
if controller:check("right") then
abad.flip=false
abad_advance()
if abad.wait==6 then sound.play(audio_low) end
elseif key.down(keyLeft) or pad.down(btnLeft) then
moved = true
elseif controller:check("left") then
abad.flip=true
abad_advance()
if abad.wait==6 then sound.play(audio_low) end
elseif key.down(keyUp) or pad.down(btnUp) then
if arc_check_tile(x1_check,y_check)==tiletype.stair and
arc_check_tile(x2_check,y_check)==tiletype.stair then
moved = true
elseif controller:check("up") then
--y_check = y_check - 1
--if arc_check_tile(x1_check,y_check)==tiletype.stair and
-- arc_check_tile(x2_check,y_check)==tiletype.stair then
-- abad.y=abad.y-1
-- if abad.wait==6 then sound.play(audio_low) end
--end
if abad_in_stairs(0,-1) then
abad.y=abad.y-1
if abad.wait==6 then sound.play(audio_low) end
moved = true
end
elseif key.down(keyDown) or pad.down(btnDown) then
if arc_check_tile(x1_check,y_check)==tiletype.stair and
arc_check_tile(x2_check,y_check)==tiletype.stair then
elseif controller:check("down") then
-- y_check = y_check + 1
-- if arc_check_tile(x1_check,y_check)==tiletype.stair and
-- arc_check_tile(x2_check,y_check)==tiletype.stair then
-- abad.y=abad.y+1
-- if abad.wait==6 then sound.play(audio_low) end
-- end
if abad_in_stairs(0,1) and not abad_in_floor(0,0) then
abad.y=abad.y+1
if abad.wait==6 then sound.play(audio_low) end
moved = true
else
--abad.update=abad_state_normal
end
end
if moved and abad.wait==6 then sound.play(audio_low) end
if abad.wait==6 then abad.wait=0 end
end

View File

@@ -2,7 +2,7 @@ local arcade_config = {
org_resolucion = { width = 128, height = 96 },
resolucion = { width = 256, height = 192 },
surface = { width = 256, height = 192 },
logo_sf = { width = 144, height = 20 },
--logo_sf = { width = 144, height = 20 },
sprite_size = { w = 32, h = 32 },
escala = 1.0,
org2arc_escala = 2.0,

View File

@@ -4,6 +4,7 @@ audio_song_premiere="mus_prem.ogg"
audio_song_elalien="mus_alie.ogg"
audio_life_lost="mus_life.ogg"
audio_game_over="mus_over.ogg"
audio_song_imp="mus_imp.ogg"
audio_final=audio_main_song
audio_abad_jump="snd_ajmp.wav"
@@ -18,3 +19,4 @@ audio_text_abad="snd_txta.wav"
audio_text_premiere="snd_txtp.wav"
audio_text_elalien="snd_txte.wav"
audio_text_batman="snd_txtb.wav"
audio_text_imp="snd_txtb.wav"

71
data/bar_meter.lua Normal file
View File

@@ -0,0 +1,71 @@
bar_meter={}
function bar_meter.new(scr_x, scr_y, width, height, _value, _max_value, _actor, _color_ok, _color_warn, _color_danger)
_color_ok = _color_ok or 10; -- verd
_color_warn = _color_warn or 8; -- groc
_color_danger = _color_danger or 3; -- roig
return {
x = scr_x,
y = scr_y,
w = width,
h = height,
value = _value,
max_value = _max_value,
draw=bar_meter.draw,
actor=_actor,
color_ok = _color_ok,
color_warn = _color_warn,
color_danger = _color_danger,
}
end
function bar_meter:draw()
if self.actor~=nil and not empty_table(self.actor) then
self.value=self.actor.energia
self.max_value=self.actor.max_energia
end
-- local x = 0
-- local y = 2
-- local w = 6
-- local h = 7
local x = self.x
local y = self.y
local w = self.w
local h = self.h
-- borde blau
draw.hline(x+1, y, x+w-1, 15)
draw.hline(x+1, y+h, x+w-1, 15)
draw.vline(x , y+1, y+h-1, 15)
draw.vline(x+w, y+1, y+h-1, 15)
draw.rectf(x+1, y+1, w-1, h-1, 16 ); -- fons negre
if self.value>self.max_value/2 then
-- 50%
color = self.color_ok
elseif self.value>self.max_value/3 then
-- 33%
color = self.color_warn
else
color = self.color_danger
end
local lifebar_w = w-3
local segment_w = lifebar_w/self.max_value
local life_w = math.floor(lifebar_w*(self.value/self.max_value))
-- if self.value==self.max_value then curr_width=curr_width-2 end
if self.value>0 then
-- barra de vida
draw.rectf( x+2, y+2, life_w, h-3, color );
-- segments
for n_segment=1,self.value-1 do
x_segment = math.floor((x+2)+segment_w*n_segment)
-- if n_segment==self.max_value then
-- x_segment=x+w-2
-- end
draw.vline( x_segment, y+2, y+h-2, 16)
end
-- draw.vline( x+2+segment_w*n_segment, y+2, y+h-2, 16)
end
end

254
data/batman.lua Normal file
View File

@@ -0,0 +1,254 @@
local arcade_config = require("arcade_config")
o2aX = arcade_config.org2arc_escala
cxr = arcade_config.character_per_row-1
cxr2 = arcade_config.character_per_row_base2
cw = arcade_config.character_width
ch = arcade_config.character_height
batman={hab=5,x=24,y=24,flip=true,goup=true,frame=8,stairscooldown=0,stepscooldown=0,stepsremember=0,wait=0,step=0,anim={24,25,24,26},bb={x=4,y=0,w=8,h=16},scene_intro=false,scene_object=false}
function batman.init()
batman.hit=batman.hit
batman.update=batman.update_normal
batman.draw=batman.draw
local habs={5,9,46,36,18}
batman.hab=habs[1+math.random(0,#habs-1)]
batman.x=24
batman.y=24
end
function batman.draw()
local flip=batman.flip
if batman.update==batman.update_stairs then
flip=(((batman.x>>1)+(batman.y>>1))%2)==0
end
-- draw.surf((batman.frame&7)*16,(batman.frame>>3)*16,16,16,batman.x,batman.y,16,16,flip)
draw.surf((batman.frame&7)*cw,(batman.frame>>cxr2)*ch,cw,ch,batman.x*o2aX,batman.y*o2aX,cw,ch,flip)
end
function batman.hit()
if abad.objects.bol~=nil then
batman.endgame=true
-- Start end of the game
start_scene(scenes.final)
end
end
function batman.update_normal()
batman.wait=batman.wait+1
if batman.wait>=6 then
batman.wait=0
if batman.stairscooldown>0 then batman.stairscooldown=batman.stairscooldown-1 end
batman.step=(batman.step+1)%4
if batman.stepscooldown>0 then batman.stepscooldown=batman.stepscooldown-1 end
batman.frame=batman.anim[batman.step+1]
local inc=12 if batman.flip then inc=2 end
if not batman.flip and batman.x==84 then
batman.hab=batman.hab+1
batman.x=-4
elseif check_tile(batman.hab,batman.x+inc,batman.y+14)==tiletype.nonpc then
--if rnd(10)<8 then
batman.update=batman.update_jumping
batman.step=0
--else
-- batman.flip=not batman.flip
--end
elseif check_tile(batman.hab,batman.x+inc,batman.y+14)<tiletype.half then
if batman.flip then
batman.x=batman.x-2
else
batman.x=batman.x+2
end
if batman.x<-4 then
batman.hab=batman.hab-1
batman.x=84
end
elseif check_tile(batman.hab,batman.x+inc,batman.y+6)<tiletype.half then
local r=math.random(0,1)
if check_tile(batman.hab,batman.x+inc,batman.y+14)==tiletype.block then r=0 end
if batman.stepscooldown>0 and check_tile(batman.hab,batman.x+inc,batman.y+14)==tiletype.half then r=batman.stepsremember end
if r==0 then
batman.update=batman.update_jumping
batman.step=0
else
if batman.flip then
batman.x=batman.x-2
else
batman.x=batman.x+2
end
if batman.x<-4 then
batman.hab=batman.hab-1
batman.x=84
end
end
if batman.stepscooldown==0 then
batman.stepscooldown=30
batman.stepsremember=r
end
else
--if check_tile(batman.hab,batman.x+4,batman.y+16)==tiletype.void and ((batman.x+4)&7==0 or check_tile(batman.hab,batman.x+12,batman.y+16)==tiletype.void) then
--batman.update=batman.update_falling
--else
batman.flip=not batman.flip
--end
end
if batman.stairscooldown==0 and
check_tile(batman.hab,batman.x+6,batman.y+8)==tiletype.stair and
check_tile(batman.hab,batman.x+14,batman.y+8)==tiletype.stair then
if math.random(0,9)<8 then
batman.update=batman.update_stairs
if check_tile(batman.hab,batman.x+4,batman.y+16)==tiletype.block then
batman.goup=true
else
batman.goup=false
end
--batman.goup=rnd(2)==0 and true or false
else
batman.stairscooldown=50
end
elseif batman.update==batman.update_stairs then
batman.stairscooldown=50
batman.update=batman.update_normal
batman.frame=24
end
if check_tile(batman.hab,batman.x+4,batman.y+16)==tiletype.void and ((batman.x+4)&7==0 or check_tile(batman.hab,batman.x+12,batman.y+16)==tiletype.void) then
local option=math.random(0,1)
if batman.stairscooldown>0 then option=0 end
if option==0 then
batman.update=batman.update_falling
else
batman.update=batman.update_jumping
batman.step=0
batman.wait=0
--else
-- batman.flip=not batman.flip
end
end
if batman.hab==abad.hab then
if aabb(abad,batman) then
abad_hurt(40)
end
end
end
end
function batman.update_jumping()
batman.frame=25
batman.wait=batman.wait+1
if batman.wait>=6 then
batman.wait=0
local inc=12 if batman.flip then inc=2 end
if not batman.flip and batman.x==84 then
batman.hab=batman.hab+1
batman.x=-4
elseif check_tile(batman.hab,batman.x+inc,batman.y+14)<tiletype.half then
if batman.flip then
batman.x=batman.x-2
else
batman.x=batman.x+2
end
if batman.x<-4 then
batman.hab=batman.hab-1
batman.x=84
end
end
if batman.step<6 then
if batman.y>0 then
if check_tile(batman.hab,batman.x+4,batman.y-2)~=tiletype.block then
if (batman.x+4)&7==0 or check_tile(batman.hab,batman.x+12,batman.y-2)~=tiletype.block then
batman.y=batman.y-2
end
end
else
batman.hab=batman.hab-10
batman.y=32
end
elseif batman.step>6 then
batman.update=batman.update_falling
end
batman.step=batman.step+1
end
end
function batman.update_falling()
batman.frame=25
batman.wait=batman.wait+1
if batman.wait>=6 then
batman.wait=0
local inc=12 if batman.flip then inc=2 end
if not batman.flip and batman.x==84 then
batman.hab=batman.hab+1
batman.x=-4
elseif check_tile(batman.hab,batman.x+inc,batman.y+14)<tiletype.half then
if batman.flip then
batman.x=batman.x-2
else
batman.x=batman.x+2
end
if batman.x<-4 then
batman.hab=batman.hab-1
batman.x=84
end
end
if batman.y<32 then
if (batman.y+16)&7==0 and (check_tile(batman.hab,batman.x+4,batman.y+16)>=tiletype.half or ((batman.x+4)&7~=0 and check_tile(batman.hab,batman.x+12,batman.y+16)>=tiletype.half)) then
batman.update=batman.update_normal
return
end
batman.y=batman.y+2
else
batman.hab=batman.hab+10
batman.y=0
end
end
end
function batman.update_stairs()
batman.frame=27
batman.wait=batman.wait+1
if batman.wait>=6 then
batman.wait=0
if batman.goup then
if batman.y>0 then
if check_tile(batman.hab,batman.x+4,batman.y+8)==tiletype.stair or (batman.x+4)&7~=0 and check_tile(batman.hab,batman.x+12,batman.y+8)==tiletype.stair then
batman.y=batman.y-2
else
batman.update=batman.update_normal
if math.random(0,2)>0 then batman.flip=not batman.flip end
batman.stairscooldown=50
end
else
batman.hab=batman.hab-10
batman.y=32
end
else
if batman.y<32 then
if check_tile(batman.hab,batman.x+4,batman.y+16)==tiletype.stair or (batman.x+4)&7~=0 and check_tile(batman.hab,batman.x+12,batman.y+16)==tiletype.stair then
batman.y=batman.y+2
else
batman.update=batman.update_normal
if math.random(0,2)>0 then batman.flip=not batman.flip end
batman.stairscooldown=50
end
else
batman.hab=batman.hab+10
batman.y=0
end
end
end
end

53
data/batvio.lua Normal file
View File

@@ -0,0 +1,53 @@
-- 0,80 -> 112,112
batvio={
name="batvio",
hab=7,
x=7,
y=2,
w=112,
h=32,
flip=true,
frame=0,
wait=0,
step=0,
energy=_energy,
max_energy = _energy,
hit=zombie.hit,
update=zombie.update_normal,
draw=zombie.draw,
jumpfwd=false,
anim={},
bb={x=16,y=3,w=80,h=29},
can_warp=false,
warping=false,
shrink=1,
d_shrink=1,
angle=0,
d_angle=15,
dying=false,
death_time=40,
enabled=true,
disable_reason="",
enabled=true,
}
function batvio.init()
local world_x, world_y = coords.room_to_world(batvio.hab,batvio.x,batvio.y)
batvio.x=world_x
batvio.y=world_y
end
function batvio.draw()
local curr_sf = surf.source()
surf.source(tiles2)
local scr_x, scr_y = viewp:screen_coords( batvio.x, batvio.y )
draw.surf(0,80,batvio.w,batvio.h,scr_x,scr_y,batvio.w,batvio.h,batvio.flip)
surf.source(curr_sf)
end
function batvio.hit()
end
function batvio.update()
end

View File

@@ -6,7 +6,14 @@ bol_gif_col = 14
bol_gif_row = 3
-- bol={hab=39,x=28,y=25,w=32,h=16,bb={x=0,y=0,w=16,h=8}}
bol={hab=39,x=4,y=3,w=32,h=16,bb={x=0,y=0,w=16,h=8}}
bol={
hab=39,
x=4, y=3,
w=32,h=16,
bb={x=0,y=0,w=16,h=8},
furtat = false,
scene_trobat = false,
}
function bol.init()
local world_x, world_y = coords.room_to_world(bol.hab,bol.x,bol.y)
@@ -26,7 +33,20 @@ function bol.draw()
local x = bol_gif_col*tw
local y = toff+bol_gif_row*th
local scr_x, scr_y = viewp:screen_coords( bol.x, bol.y )
if bol.furtat then
pal.trans(0)
pal.subpal(1,0)
pal.subpal(2,0)
pal.subpal(5,0)
pal.subpal(6,2)
pal.subpal(16,2)
end
draw.surf(x,y,bol.w,bol.h,scr_x,scr_y,bol.w,bol.h)
pal.subpal(1)
pal.subpal(2)
pal.subpal(5)
pal.subpal(6)
pal.subpal(16)
end
function bol.update()
@@ -37,4 +57,16 @@ function bol.update()
-- remove_actor(bol)
-- end
-- end
local ah,ax,ay = coords.world_to_tile(abad.x, abad.y)
local bh,bx,by = coords.world_to_tile(bol.x, bol.y)
if bh ==ah then
if ay==by and not bol.scene_trobat then
-- abad.objects.bol=true
start_scene(scenes.bol_trobat)
bol.scene_trobat = true
-- remove_actor(bol)
-- crear el trigger per a disparar el final de fase
table.insert( actors, trigger.new(8,4,3,triggers.escena_stage1_ending,"stage1 ending","TR09") )
end
end
end

View File

@@ -1,5 +1,3 @@
local arcade_config = require("arcade_config")
o2aX = arcade_config.org2arc_escala
cxr2 = arcade_config.character_per_row_base2
cw = arcade_config.character_width
ch = arcade_config.character_height
@@ -18,25 +16,56 @@ function caco.new(_hab,_x,_y,_flip)
frame=19,
wait=0,
step=0,
can_warp=true,
warping=false,
shrink=1,
d_shrink=1,
angle=0,
d_angle=15,
hit=caco.hit,
update=caco.update_normal,
draw=caco.draw,
jumpfwd=false,
dying=false,
death_time=40,
anim={19,19,20,21},
bb={x=4,y=4,w=24,h=16} }
bb={x=4,y=4,w=24,h=16},
enabled= true,
disable_reason="" }
end
function caco:draw()
if not self.enabled then return end
-- if self.frame>0 then draw.surf((self.frame&7)*16,(self.frame>>3)*16,16,16,self.x,self.y,16,16,self.flip) end
-- if self.frame>0 then draw.surf((self.frame&7)*cw,(self.frame>>cxr2)*ch,cw,ch,self.x*o2aX,self.y*o2aX,cw,ch,self.flip) end
if self.warping then
-- local shrink_w = self.w*self.shrink
-- local shrink_h = self.h*self.shrink
-- local offset_x = math.floor((self.w-shrink_w)/2)
-- local offset_y = math.floor((self.h-shrink_h)/2)
-- local scr_x, scr_y = viewp:screen_coords( self.x+offset_x, self.y+offset_y )
-- shrink_w = math.floor(shrink_w)
-- shrink_h = math.floor(shrink_h)
--
-- if shrink_w>0 and shrink_h>0 then
-- draw.surfrot((self.frame&7)*cw, (self.frame>>cxr2)*ch,
-- cw, ch,
-- scr_x, scr_y,
-- self.angle,
-- shrink_w, shrink_h,
-- self.flip)
-- end
actor_warp_draw(self)
else
if self.frame>0 then
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
draw.surf((self.frame&7)*cw, (self.frame>>cxr2)*ch, cw, ch, scr_x, scr_y, cw, ch, self.flip)
end
end
end
function caco:update_normal()
if not self.enabled then return end
self.wait=self.wait+1
if self.wait==6 then
@@ -73,6 +102,11 @@ function caco:update_normal()
self.flip=not self.flip
end
if viewp:inside(self.x, self.y, self.w, self.h) then
if collision(abad,self) then
abad_hurt(1)
end
end
-- if self.hab==abad.hab then
-- if aabb(abad,self) then
@@ -86,26 +120,81 @@ function caco:update_normal()
end
function caco:update_hit()
if not self.enabled then return end
local step_time = self.death_time
if self.can_warp then
step_time = self.death_time/3; -- warp, wait, appear
end
self.wait=self.wait+1
if self.wait==6 then
if self.wait>=6 then
self.wait=0
self.step=self.step+1
if self.step<40 then
if self.can_warp then
-- -- warp, wait, respawn
-- if self.warping then
-- if self.step<self.death_time then
-- self.shrink=self.shrink-self.d_shrink
-- self.angle=self.angle+self.d_angle
-- if self.angle>=360 then self.angle = self.angle % 360 end
-- if self.shrink<=0 then
-- self.shrink=1
-- self.d_shrink=1
-- self.angle=0
-- self.d_angle=1
-- self.warping = false
-- self.frame = -1
-- self.step = 0
-- end
-- end
-- elseif self.step<self.death_time/2 then
-- self.frame = -1
-- elseif self.step<self.death_time then
-- if self.step%2==0 then
-- self.frame=21
-- else
-- self.frame=-1
-- end
-- elseif self.step>=self.death_time then
-- self.frame=19
-- self.step=0
-- self.wait=0
-- self.update=caco.update_normal
-- self.dying = false
-- end
actor_warp_update(self)
else
if self.step<self.death_time then
if self.step%2==0 then
self.frame=21
-- self.frame=21
self.frame=self.anim[#self.anim]
else
self.frame=-1
end
elseif self.step>=40 then
self.frame=19
elseif self.step>=self.death_time then
-- self.frame=19
self.frame=self.anim[1]
self.step=0
self.wait=0
self.update=caco.update_normal
self.dying = false
end
end
end
end
function caco:hit()
if not self.enabled then return end
self.update=caco.update_hit
if self.can_warp then self.warping=true end
self.shrink=1
self.angle=0
self.dying=true
-- calcular velocitat per al warp
local warp_time = self.death_time/3
self.d_angle = 720 / warp_time; -- 720 = 2 voltes
self.d_shrink = self.shrink / warp_time
end

83
data/controller.lua Normal file
View File

@@ -0,0 +1,83 @@
controller = {
input = { kb=0, pad=1 },
keysdown = {},
kb_keys= { {name="up", code="keyup"},
{name="down", code="keydow"},
{name="left", code="keyleft"},
{name="right",code="keyright"},
{name="jump", code="keyjump"},
{name="shoot",code="keyshoot"}},
pad_keys= { {name="up", code="btnup"},
{name="down", code="btndown"},
{name="left", code="keleft"},
{name="right",code="btnright"},
{name="jump", code="btnjump"},
{name="shoot",code="btnshoot"},
{name="next", code="btncycle1"},
{name="prev", code="btncycle2"},
{name="pause",code="btnpause"}}
}
function controller:init()
-- Configuració dels input
keyUp = tonumber(config.key("keyup")) or key.UP
keyDown = tonumber(config.key("keydown")) or key.DOWN
keyLeft = tonumber(config.key("keyleft")) or key.LEFT
keyRight = tonumber(config.key("keyright")) or key.RIGHT
keyJump = tonumber(config.key("keyjump")) or key.UP
keyShoot = tonumber(config.key("keyshoot")) or key.SPACE
btnUp = tonumber(config.key("btnup")) or pad.UP
btnDown = tonumber(config.key("btndown")) or pad.DOWN
btnLeft = tonumber(config.key("btnleft")) or pad.LEFT
btnRight = tonumber(config.key("btnright")) or pad.RIGHT
btnJump = tonumber(config.key("btnjump")) or pad.B
btnShoot = tonumber(config.key("btnshoot")) or pad.A
btnCycle1 = tonumber(config.key("btncycle1")) or pad.RIGHTSHOULDER
btnCycle2 = tonumber(config.key("btncycle2")) or pad.LEFTSHOULDER
btnPause = tonumber(config.key("btnpause")) or pad.START
end
function controller:define(code, key_code)
config.key(code, key_code)
-- To do: comprovar que es un code valid
return true
end
function controller:check(action)
local result = false
if action=="up" then
result = key.down(keyUp) or pad.down(btnUp)
elseif action=="down" then
result = key.down(keyDown) or pad.down(btnDown)
elseif action=="left" then
result = key.down(keyLeft) or pad.down(btnLeft)
elseif action=="right" then
result = key.down(keyRight) or pad.down(btnRight)
elseif action=="jump" then
result = key.down(keyJump) or pad.down(btnJump)
elseif action=="shoot" then
-- result = key.down(keyShoot) or pad.down(btnShoot)
result = self:key_release(keyShoot) or self:key_release(btnShoot)
elseif action=="ESC" then
result = key.press(key.ESCAPE) or pad.press(btnPause)
end
return result
end
function controller:key_release(keyid)
if keyid==nil then
print("INVALID KEY")
return
end
-- if keysdown[keyid] then print("Pressed "..keyid) end
if key.down(keyid) or pad.down(keyid) then
self.keysdown[keyid] = true
elseif self.keysdown[keyid]
then
self.keysdown[keyid] = false
return true
end
return false
end

View File

@@ -86,6 +86,18 @@ function coords.room_to_coord ( room, center )
return x, y
end
function coords.room_to_mini_tile( room, x, y )
-- room=room-1
x=x-1
y=y-1
local tx = room % coords.ROOMS_PER_FLOOR -- columna de l'habitació
tx = tx * coords.ROOM_COLS+x
local ty = math.floor(room / coords.ROOMS_PER_FLOOR) -- fila de l'habitació
ty = ty * coords.ROOM_ROWS+y
return tx, ty
end
-- local TILE_W = arcade_config.tiles_width
-- local TILE_H = arcade_config.tiles_height
-- local ROOM_COLS = mapa_room_cols

76
data/dialeg.lua Normal file
View File

@@ -0,0 +1,76 @@
dialeg={
list = {},
}
-- dialegs = {}
-- function dialeg.update()
-- for i,d in ipairs(dialegs) do
-- if distancia(d.actor1, d.actor2, d.direccio)<=d.distancia and d.enabled then
-- dialeg.new(d.text, d.actor1)
-- d.enabled=false
-- end
-- end
-- end
-- function dialeg.new( _text, _actor )
-- print(_text)
-- table.insert(
-- dialeg.list,
-- {
-- actor= _actor,
-- text=_text,
-- time = 120,
-- w = math.floor(4.6*#_text),
-- h = 20,
-- } )
-- end
function dialeg.draw( )
local i = 1
while i <= #dialeg.list do
local d = dialeg.list[i]
if d.time>0 and d.actor then
if viewp:inside(d.actor.x, d.actor.y, d.actor.w, d.actor.h) then
local x = 0
local y = 0
y = d.actor.y-20
if d.actor.flip then
x = d.actor.x-d.w
else
x = d.actor.x+d.actor.w
end
x, y = viewp:screen_coords( x, y )
draw.rrectf(x, y, d.w, d.h, 5, 2)
if d.actor.flip then
draw.line(x+d.w, y+d.h-1+5, x+d.w-20, y+d.h-1, 2)
draw.line(x+d.w, y+d.h-1+5, x+d.w-18, y+d.h-1, 2)
draw.line(x+d.w, y+d.h-1+5, x+d.w-14, y+d.h-1, 2)
draw.line(x+d.w, y+d.h-1+5, x+d.w-12, y+d.h-1, 2)
else
draw.line(x, y+d.h-1+5, x+20, y+d.h-1, 2)
draw.line(x, y+d.h-1+5, x+18, y+d.h-1, 2)
draw.line(x, y+d.h-1+5, x+14, y+d.h-1, 2)
draw.line(x, y+d.h-1+5, x+12, y+d.h-1, 2)
end
local font_curr = font.current()
font.current(font_default)
draw.text(d.text, x+5,y+7, 16)
font.current(font_curr)
d.time = d.time-1
end
i = i + 1
else
table.remove(dialeg.list, i)
end
end
end
return dialeg

View File

@@ -13,6 +13,7 @@ elalien={name="elalien",
flip=true,
goup=true,
frame=8,
parpadeig=false,
stairscooldown=0,
wait=0,
step=0,
@@ -23,7 +24,7 @@ elalien={name="elalien",
function elalien.init()
-- elalien.x=24
elalien.x=3
elalien.x=9
-- elalien.y=24
elalien.y=3
elalien.w=32
@@ -37,7 +38,8 @@ function elalien.init()
elalien.scene_intro=false
elalien.scene_object=false
local habs={66,56,59,53}
elalien.hab=habs[1+math.random(0,3)]
-- elalien.hab=habs[1+math.random(0,3)]
elalien.hab=56
local world_x, world_y = coords.room_to_world(elalien.hab,elalien.x,elalien.y)
elalien.x=world_x
@@ -49,24 +51,82 @@ function elalien.draw()
if elalien.update==elalien.update_stairs then
flip=(((elalien.x>>1)+(elalien.y>>1))%2)==0
end
-- draw.surf((elalien.frame&7)*cw,(elalien.frame>>cxr2)*ch,cw,ch,elalien.x*o2aX,elalien.y*o2aX,cw,ch,flip)
local xoff0 = 18
local xoff1 = 19
local xoff2 = 20
local xoff3 = 21
-- draw.surf((elalien.frame&7)*cw,(elalien.frame>>cxr2)*ch,cw,ch,elalien.x*o2aX,elalien.y*o2aX,cw,ch,flip)
local scr_x, scr_y = viewp:screen_coords( elalien.x, elalien.y )
if elalien.update == elalien.update_stay then
draw.surf(0,32,elalien.w,elalien.h,scr_x,scr_y,elalien.w,elalien.h,flip)
if elalien.parpadeig then
if elalien.flip then
xoff0 = 13
xoff1 = 12
xoff2 = 11
xoff3 = 10
end
if elalien.step==0 then
draw.line(scr_x+xoff0, scr_y+6, scr_x+xoff0, scr_y+11, 11)
draw.pixel(scr_x+xoff1, scr_y+11, 11)
draw.pixel(scr_x+xoff1, scr_y+7, 11)
elseif elalien.step<3 then
draw.line(scr_x+xoff0, scr_y+6, scr_x+xoff0, scr_y+11, 11)
draw.line(scr_x+xoff1, scr_y+7, scr_x+xoff1, scr_y+11, 11)
draw.line(scr_x+xoff2, scr_y+8, scr_x+xoff2, scr_y+11, 11)
draw.line(scr_x+xoff3, scr_y+8, scr_x+xoff3, scr_y+11, 11)
elseif elalien.step==3 then
draw.line(scr_x+xoff0, scr_y+6, scr_x+xoff0, scr_y+11, 11)
draw.line(scr_x+xoff1, scr_y+7, scr_x+xoff1, scr_y+11, 11)
draw.line(scr_x+xoff2, scr_y+8, scr_x+xoff2, scr_y+11, 11)
draw.line(scr_x+xoff3, scr_y+8, scr_x+xoff3, scr_y+11, 11)
elalien.parpadeig = false
end
end
else
local x = (elalien.frame&7)*cw
local y = (elalien.frame>>cxr2)*ch
draw.surf(x,y,cw,ch,scr_x,scr_y,elalien.w,elalien.h,flip)
end
end
function elalien.hit()
end
function elalien.update_stay()
elalien.wait=elalien.wait+1
if elalien.wait==6 then
if elalien.wait==18 then
elalien.wait=0
elalien.step=(elalien.step+1)%4
elalien.frame=elalien.anim[elalien.step+1]
if elalien.step==0 and not elalien.parpadeig then
if math.random(5)==5 then elalien.parpadeig = true end
end
-- elalien.frame=elalien.anim[elalien.step+1]
end
if elalien.hab==abad.hab then
if collision(abad,elalien) then
if not elalien.scene_intro then
if abad.objects.peu~=nil then
start_scene(scenes.elalien_intro_peu)
elalien.scene_object=true
abad.objects.clau_elalien=true
abad.objects.peu=nil
else
start_scene(scenes.elalien_intro)
end
elalien.scene_intro=true
elseif not elalien.scene_object and abad.objects.peu~=nil then
start_scene(scenes.elalien_peu)
elalien.scene_object=true
abad.objects.clau_elalien=true
abad.objects.peu=nil
end
end
end
end

124
data/fireball.lua Normal file
View File

@@ -0,0 +1,124 @@
fireball={
hab=-1,
x=0, y=0,
w=6, h=6,
wait=0,
flip=false,
step_length=3,
power=1,
size=1,
bb={x=0,y=0,w=4,h=4},
x1=0,
y1=0,
step_length_x=1,
step_length_y=1,
}
function fireball.init(_hab,_x,_y,_flip, _off_x, _off_y, _power)
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
_power = _power or 1
if fireball.hab ~= -1 then return end
_off_x = _off_x or 0
_off_y = _off_y or 0
fireball.hab=_hab
fireball.x= world_x+_off_x
fireball.y= world_y+_off_y
fireball.flip=_flip
fireball.power=_power
fireball.size=1
fireball.w = 6
fireball.h = 6
fireball.bb = {x=0,y=0,w=4,h=4}
end
function fireball.draw()
if fireball.hab == -1 then return end
local scr_x, scr_y = viewp:screen_coords( fireball.x, fireball.y )
draw.circf(scr_x,scr_y,8*fireball.size,16)
draw.circf(scr_x,scr_y,6*fireball.size,3)
draw.circf(scr_x,scr_y,2*fireball.size,8)
-- draw.rect(scr_x-5*fireball.size,scr_y-5*fireball.size,5*fireball.size*2,5*fireball.size*2,2)
end
function fireball.update()
if fireball.power==2 and fireball.power>fireball.size then
fireball.wait = fireball.wait + 1
fireball.x1=abad.x+abad.bb.x+(abad.bb.w//2)
fireball.y1=abad.y+(abad.bb.h/2)
if abad.x<fireball.x then
fireball.step_length_x = -1
else
fireball.step_length_x = 1
end
if abad.y<fireball.y then
fireball.step_length_y = -1
else
fireball.step_length_y = 1
end
if fireball.wait==6 then
fireball.size = fireball.size+0.1
fireball.wait = 0
end
local dx = math.abs(fireball.x-fireball.x1)
local dy = math.abs(fireball.y-fireball.y1)
if dx<dy then
if dy~=0 then
fireball.step_length_x = fireball.step_length_x*(dx/dy)*2
fireball.step_length_y = fireball.step_length_y*2
end
else
if dx~=0 then
fireball.step_length_x = fireball.step_length_x*2
fireball.step_length_y = fireball.step_length_y*(dy/dx)*2
end
end
fireball.w=6*fireball.size
fireball.h=fireball.w
fireball.bb = {x=0,y=0,w=4*fireball.size,h=4*fireball.size}
return
end
if fireball.hab == -1 then return end
-- fireball.wait=fireball.wait+1
--if fireball.wait==3 then
fireball.wait=0
--if viewp:inside(fireball.x, fireball.y, fireball.w, fireball.h)==false then
-- fireball.hab=-1
-- return
--end
if fireball.power==1 then
if arc_check_tile(fireball.x,fireball.y)<tiletype.block then
if fireball.flip then
fireball.x=fireball.x-fireball.step_length
else
fireball.x=fireball.x+fireball.step_length
end
else
fireball.hab=-1
return
end
elseif fireball.power==2 then
fireball.x = fireball.x+fireball.step_length_x
fireball.y = fireball.y+fireball.step_length_y
end
if viewp:inside(fireball.x, fireball.y, fireball.w, fireball.h) then
if collision(fireball,abad) then
if fireball.power==1 and abad.update~=abad_state_crouch then
abad_hurt(1)
fireball.hab=-1
elseif fireball.power==2 then
abad_hurt(2)
fireball.hab=-1
end
end
else
fireball.hab=-1
end
--end
end

110
data/flow.lua Normal file
View File

@@ -0,0 +1,110 @@
-- flow={
-- level=1,
-- step={0},
-- actiu="",
-- pila={},
-- paths={ {flow_safe} },
-- registre={}
-- -- sub_path_enable = false,
-- -- sub_step = 0,
-- -- sub_path={}
-- }
-- function flow:print()
-- print("> STEP= "..self.step.." / "..#self.path)
-- if self.sub_path_enable then
-- print("> SUB_PATH_ENABLE= TRUE")
-- else
-- print("> SUB_PATH_ENABLE= FALSE")
-- end
-- print("> SUB_STEP= "..self.sub_step.." / "..#self.sub_path)
-- print("")
-- end
flow={
registre={}, -- {nom {ptr (a l'estat actual), path (llista de funcions ordenada)} ...}
actiu = "", -- nom del registre actiu
stack = {}, -- guarda els canvis de registre per a poder tornar a l'estat anterior
safe_show = false
}
function flow:safe()
if not flow.safe_show then
print("[FLOW] No hi ha res en la pila")
flow.safe_show = true
end
end
function flow:registrar(nom, _path)
self.registre[nom]= {ptr=0, path=_path}
end
function flow:borrar(nom)
self.registre[nom].ptr=0
self.registre[nom].path=nil
end
function flow:executar(nom, stacking)
-- print("FLOW EXEC "..nom)
if stacking then
table.insert(self.stack, self.actiu)
-- print(" APILAT "..self.actiu.."!")
end
self.actiu=nom
self.registre[self.actiu].ptr=0
self:next()
end
-- function flow:next()
-- local ptr = self.registre[self.actiu].ptr
-- local steps = #self.registre[self.actiu].path
-- print("FLOW_NEXT= "..self.actiu..", "..ptr..", "..steps)
-- if ptr+1>steps then
-- self.actiu = table.remove(self.stack)
-- if self.actiu==nil then
-- -- no queda res en la pila
-- self.actiu="flow"
-- self.registre[self.actiu].ptr = 1
-- else
-- -- ultim element afegit a la pila
-- -- No se fa cap acció lo que implica que se restaura l'estat en el
-- -- que s'estava abans de l'ultima cridada
-- end
-- else
-- self.registre[self.actiu].ptr = ptr+1
-- end
--
-- game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
-- return self.actiu, self.registre[self.actiu].ptr
-- end
function flow:next()
local ptr = self.registre[self.actiu].ptr
local steps = #self.registre[self.actiu].path
-- print("FLOW_NEXT= "..self.actiu..", "..ptr..", "..steps)
if ptr+1>steps then
self:finish()
else
self.registre[self.actiu].ptr = ptr+1
game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
end
return self.actiu, self.registre[self.actiu].ptr
end
function flow:finish()
self.actiu = table.remove(self.stack)
if self.actiu==nil then
-- no queda res en la pila
self.actiu="flow"
self.registre[self.actiu].ptr = 1
else
-- ultim element afegit a la pila
-- No se fa cap acció lo que implica que se restaura l'estat en el
-- que s'estava abans de l'ultima cridada
end
game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
end
flow:registrar("flow",{flow.safe})

View File

@@ -1,5 +1,5 @@
title=Cacaus Arcade
config=cacaus_arcade
title=Cacaus Arcade Redo
config=cacaus_arcade_redo
width=256
height=192
zoom=3

View File

@@ -1,16 +1,34 @@
viewport= require("viewport")
require "abad"
require "cacau"
require "caco"
require "zombie"
require "gota"
require "bol"
require "llibre"
require "gorro"
require "gps"
require "peu"
require "premiere"
require "elalien"
require "bol"
require "gota"
require "invisible"
require "caco"
require "zombie"
require "score"
-- require "switches"
require "trigger"
require "imp3"
require "fireball"
require "bar_meter"
require "stage1"
require "remote_view"
require "dialeg"
require "trigger_event"
require "batman"
require "health_potion"
require "tiles_layer2"
require "batvio"
local DEBUG = false
local tile_w = arcade_config.tiles_width
local tile_h = arcade_config.tiles_height
@@ -19,190 +37,145 @@ local res_h = arcade_config.resolucion.height
local view_tile_id = false
local view_checking_tile = false
local stage= 1
local stage_loaded = 0
stage_update = foo
stage_draw_back = foo
stage_draw_middle = foo
stage_draw_front = foo
viewp = viewport.new(arcade_config.resolucion.width, arcade_config.resolucion.height)
viewp:position(0,0)
function foo()
print("foo")
end
function actor_warp_draw(actor)
local shrink_w = actor.w*actor.shrink
local shrink_h = actor.h*actor.shrink
local offset_x = math.floor((actor.w-shrink_w)/2)
local offset_y = math.floor((actor.h-shrink_h)/2)
local scr_x, scr_y = viewp:screen_coords( actor.x+offset_x, actor.y+offset_y )
shrink_w = math.floor(shrink_w)
shrink_h = math.floor(shrink_h)
if shrink_w>0 and shrink_h>0 then
draw.surfrot((actor.frame&7)*cw, (actor.frame>>cxr2)*ch,
cw, ch,
scr_x, scr_y,
actor.angle,
shrink_w, shrink_h,
actor.flip)
end
end
function actor_warp_update(actor)
-- warp, wait, respawn
if actor.warping then
if actor.step<actor.death_time then
actor.shrink=actor.shrink-actor.d_shrink
actor.angle=actor.angle+actor.d_angle
if actor.angle>=360 then actor.angle = actor.angle % 360 end
if actor.shrink<=0 then
actor.shrink=1
actor.d_shrink=1
actor.angle=0
actor.d_angle=1
actor.warping = false
actor.frame = -1
actor.step = 0
if actor.energy~=nil then
actor.energy = actor.max_energy
end
end
end
elseif actor.step<actor.death_time/2 then
actor.frame = -1
elseif actor.step<actor.death_time then
if actor.step%2==0 then
actor.frame=actor.anim[#actor.anim]
else
actor.frame=-1
end
elseif actor.step>=actor.death_time then
actor.frame=actor.anim[1]
actor.step=0
actor.wait=0
if actor.name=="caco" then
actor.update=caco.update_normal
elseif actor.name=="zombie" then
actor.update=zombie.update_normal
end
actor.dying = false
end
end
actors={}
function game_exit()
-- mapa_restore_backup()
actors={}
-- cameras={}
end
function game_init(menu)
-- print("GAME INIT")
actors={}
abad_init()
table.insert(actors,abad)
gps.init()
table.insert(actors,gps)
gorro.init()
table.insert(actors,gorro)
peu.init()
table.insert(actors,peu)
premiere.init()
table.insert(actors,premiere)
elalien.init()
table.insert(actors,elalien)
bol.init()
table.insert(actors,bol)
table.insert( actors, gota.new(70,5,1,20) )
table.insert( actors, gota.new(70,9,1,30) )
table.insert( actors, gota.new(63,5,1,25,2,-7) )
table.insert( actors, gota.new(63,9,1,20,0,-8) )
table.insert( actors, gota.new(64,3,1,10,0,-6) )
table.insert( actors, gota.new(64,6,1,25,-1,-5) )
table.insert( actors, gota.new(65,7,1,10,0,-7) )
table.insert( actors, gota.new(65,8,1,25,0,-7) )
table.insert( actors, gota.new(66,3,1,10,0,-7) )
table.insert( actors, gota.new(66,4,1,15,0,-7) )
table.insert( actors, gota.new(77,2,1,30,-5,-7) )
table.insert( actors, gota.new(77,9,1,25,-5,-7) )
table.insert( actors, caco.new(13,3,2,true ) )
table.insert( actors, caco.new(17,3,2,false) )
table.insert( actors, caco.new(20,3,2,false) )
table.insert( actors, caco.new(26,3,2,false) )
table.insert( actors, caco.new(37,3,2,false) )
table.insert( actors, caco.new(41,3,2,false) )
table.insert( actors, caco.new(50,3,2,false) )
table.insert( actors, caco.new(57,3,2,false) )
table.insert( actors, caco.new(61,3,2,false) )
table.insert( actors, zombie.new(2, 3, 3,false) )
table.insert( actors, zombie.new(28, 3, 3,false) )
table.insert( actors, zombie.new(32, 3, 3,false) )
table.insert( actors, zombie.new(44, 3, 3,false) )
table.insert( actors, zombie.new(46, 3, 3,false) )
table.insert( actors, zombie.new(54, 3, 3,false) )
table.insert( actors, zombie.new(68, 3, 3,false) )
table.insert( actors, zombie.new(73, 3, 3,false) )
score.create()
local abad_x, abad_y = coords.room_to_world ( 10, 4, 3 )
-- local abad_x, abad_y = arc_mapa_get_coords ( 77, 3, 2 )
abad:move(abad_x, abad_y)
abad_make_safe( true )
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
game_update=update_game
-- game_update=update_game
flow:next()
end
function render_map( sf_map, sf_tiles, x, y )
function render_map( sf_map, sf_tiles, x, y, target )
target = target or 0
map.surf(sf_map)
map.cell(16, 16)
surf.source(sf_tiles)
surf.target(0)
surf.target(target)
view.origin(-x,-y)
map.draw()
view.origin(0,0)
end
function update_game()
surf.target(0)
surf.cls(16)
-- surf.target(logo)
-- surf.cls(16)
-- draw.text("UPDATE_GAME",0,0,15)
-- surf.source(logo)
-- draw.surf(0,0,36,5,56,70,arcade_config.logo_sf.width,arcade_config.logo_sf.height)
--- if abad.hurting == 0 then
--- draw_hab(abad.hab,0,0)
--- --text(abad.hab,1,1,2)
--- draw_hab(cameras[current_camera].hab,0,48)
--- -- text(camera_names[current_camera],2*o2aX,49*o2aX,8)
--- arc_textB(camera_names[current_camera],2*o2aX,49*o2aX,8)
---
--- score.draw()
--- surf.source(tiles)
--- -- draw.text("x"..abad.vides,114*o2aX,13*o2aX,2)
--- arc_text("x"..abad.vides,114*o2aX,13*o2aX,2)
--- draw.rectf((102+(abad.energia>>1))*o2aX,30*o2aX,(21-(abad.energia>>1))*o2aX,8*o2aX,16)
--- else
--- draw.surf(0,0,16*o2aX,9*o2aX,50*o2aX,40*o2aX,16*o2aX,9*o2aX,true)
--- if abad.hurting > 40 then
--- -- draw.text("x"..abad.vides+1,63*o2aX,43*o2aX,3)
--- arc_text("x"..abad.vides+1,63*o2aX,43*o2aX,3)
--- elseif abad.hurting < 20 then
--- -- draw.text("x"..abad.vides,63*o2aX,43*o2aX,2)
--- arc_text("x"..abad.vides,63*o2aX,43*o2aX,2)
--- end
--- end
---
--- mapa_update(abad.hab,cameras[current_camera].hab)
--local vp_x, vp_y = viewp:position()
--if key.down(keyRight) then
-- if vp_x+1<=(tile_w*mapa_room_cols*(mapa_rooms_per_piso))-(res_w) then vp_x = vp_x+1 end
--elseif key.down(keyLeft) then
-- if vp_x>0 then vp_x = vp_x-1 end
--elseif key.down(keyUp) then
-- if vp_y>0 then vp_y = vp_y -1 end
--elseif key.down(keyDown) then
-- if vp_y+1<=(tile_h*mapa_room_rows*mapa_pisos)-(res_h) then vp_y = vp_y+1 end
--end
if key.press(key.N1) then
local hab = abad.hab-1
if hab<0 then hab=0 end
local hab_x = 4
local hab_y = 3
local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y)
abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end
if key.press(key.N2) then
local hab = abad.hab+1
if hab<0 then hab=0 end
local hab_x = 4
local hab_y = 3
local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y)
abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end
if key.press(key.N0) then
local abad_x, abad_y = coords.room_to_world ( 24, 1, 3 )
print(abad_x..", "..abad_y)
abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end
arc_mapa_update()
for key,actor in pairs(actors) do
actor:update()
--if actor.hab==cacau.hab and actor~=abad then
-- if aabb(actor,cacau) then
-- if actor.hit~=nil then
-- actor:hit()
-- cacau.hab=-1
-- end
-- end
--end
if viewp:inside(actor.x, actor.y, actor.w, actor.h) and actor~=abad then
for _, cacau_shot in pairs(cacau.shots()) do
if cacau_shot.alive and collision(actor,cacau_shot) then
if actor.hit ~= nil then
actor:hit()
cacau:kill(cacau_shot)
end
function load_stage()
local stage_init = stages["stage"..stage.."_init"]
if stage_init then
stage_init()
stage_loaded = stage
print("Stage "..stage.." loaded")
else
print("No se ha cargado la fase "..stage)
end
end
function load_boss_stage()
local stage_boss = stages["stage"..stage.."_boss"]
if stage_boss and not scene_running and not stages.loaded_boss then
stage_update = stages["stage"..stage.."_update"]
stage_draw_back = stages["stage"..stage.."_draw_back"]
stage_draw_middle = stages["stage"..stage.."_draw_middle"]
stage_draw_front = stages["stage"..stage.."_draw_front"]
stage_boss_end = stages["stage"..stage.."_boss_end"]
stage_boss()
print("Stage "..stage.." Boss loaded")
else
print("No se ha cargado la fase "..stage)
end
end
cacau.update()
switches.update()
function viewport_update()
-- Moure el viewport
local vp_x = viewp.x
local vp_y = viewp.y
--viewp:position(vp_x, vp_y)
local vp_center_offset_x = (viewp.width >> 1)
local vp_center_offset_y = (viewp.height >> 1)
@@ -214,23 +187,296 @@ function update_game()
if vp_y < 0 then vp_y = 0 end
viewp:position(vp_x, vp_y)
render_map(sf_mapa, tiles, vp_x, vp_y)
end
function world_update()
-- Actualitzar moviment del mapa (ex: tiles animats)
arc_mapa_update()
tiles_layer2.update()
-- Moure a tots
for key,actor in pairs(actors) do
actor:update()
-- Comprovar dispars contra "monstres"
if viewp:inside(actor.x, actor.y, actor.w, actor.h) and actor~=abad then
for _, cacau_shot in pairs(cacau.shots()) do
-- if collision(actor,cacau_shot) then print("COLLISION") end
-- if actor.enabled then print(actor.name) else print("NOT "..actor.name) end
-- if cacau_shot.alive then print("CACAU") end
if actor.enabled and cacau_shot.alive and collision(actor,cacau_shot) then
if actor.hit ~= nil and not actor.dying then
actor:hit()
if actor.can_warp then warp.open(actor) end
cacau:kill(cacau_shot)
end
end
end
end
end
if stages.boss_loaded then
stage_update()
else
-- print("NO BOSS")
end
-- Actualizar el que queda
cacau.update()
-- switches.update()
warp.update_all()
trigger_event.update()
end
function world_draw()
-- Pintar la finestra del mon
render_map(sf_mapa, tiles, viewp.x, viewp.y)
tiles_layer2.draw()
if stages.boss_loaded then stage_draw_back() end
-- pintar warps
for key,warp in pairs(warp.warp_list) do
if viewp:inside(warp.x, warp.y, warp.w, warp.h) then
warp:draw()
end
end
--pintar actors
for key,actor in pairs(actors) do
if viewp:inside(actor.x, actor.y, actor.w, actor.h) then
actor:draw()
end
end
dialeg.draw()
if stages.boss_loaded then stage_draw_middle() end
cacau:draw()
if stages.boss_loaded then stage_draw_front() end
remote_view_draw()
end
function update_game()
if stage~=stage_loaded then load_stage() end
if stages.boss_ready and not stages.boss_loaded then
load_boss_stage()
end
if stages.boss_ready and stages.boss_finished then
stage_boss_end()
stage_update = nil
stage_draw_back = nil
stage_draw_middle = nil
stage_draw_front = nil
stage_boss_end = nil
end
surf.target(0)
surf.cls(16)
world_update()
viewport_update()
world_draw()
score.draw()
fps_print()
special_keys()
debug_info()
if DEBUG then
end
end
function pause()
print("pause()")
-- 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()
draw.rectf(16,16,97,65,16)
draw.rect(16,16,97,65,15)
draw.text("PAUSA",54,20,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(28,33+(10*(pausa_option-1)),73,9,14)
if (not parpadeig) then draw.rect(28,33+(10*(pausa_option-1)),73,9,13) end
--draw.rect(28,33+(10*(pausa_option-1)),73,9,13)
draw.text("CONTINUAR",30,35,14)
draw.text("MUSICA:",30,45,14)
if music.enabled() then
draw.text("SI",91,45,15)
else
draw.text("NO",91,45,15)
end
draw.text("SÓ:",30,55,14)
if sound.enabled() then
draw.text("SI",91,55,15)
else
draw.text("NO",91,55,15)
end
draw.text("EIXIR",30,65,14)
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 key.press(keyDown) or pad.press(btnDown) then
pausa_option = pausa_option + 1
if pausa_option == 5 then pausa_option = 1 end
elseif key.press(keyUp) or pad.press(btnUp) then
pausa_option = pausa_option - 1
if pausa_option == 0 then pausa_option = 4 end
elseif key.press(keyShoot) or pad.press(btnShoot) then
if pausa_option==1 then
surf.source(back)
draw.surf(0,0,128,96,0,0)
surf.source(tiles)
game_update = pause_old_update
elseif pausa_option==2 then
music.enabled(not music.enabled())
elseif pausa_option==3 then
sound.enabled(not sound.enabled())
else
game_exit()
game_init(true)
end
end
end
function print_analisis_field ( field )
local field_state=" "
if boss.analisis[field] then field_state="X" end
print(" [ "..field_state.." ] "..field)
end
function print_analisis()
print("--------------------------------------------")
print_analisis_field("can_chase_abad")
print_analisis_field("can_climb")
print_analisis_field("can_shot")
print_analisis_field("can_super")
print_analisis_field("can_go_altar")
print_analisis_field("falling")
print_analisis_field("going_to_fall")
print_analisis_field("target_reached")
print("X= "..boss.x..", OX= "..boss.x_old)
print(" ")
end
function special_keys()
if key.press(key.A) then
boss.x_old = boss.x
boss.x = boss.x-1
print_analisis()
end
if key.press(key.S) then
boss.y_old = boss.y
boss.y = boss.y+1
print_analisis()
end
if key.press(key.D) then
-- boss.x_old = boss.x
-- boss.x = boss.x+1
-- print_analisis()
dialeg.new( "Hola mundo!", abad )
end
if key.press(key.F) then
-- boss.x_old = boss.x
-- boss.x = boss.x+1
-- print_analisis()
dialeg.new( "Ma cuando arribo a casa", premiere )
end
if key.press(key.W) then
boss.y_old = boss.y
boss.y = boss.y-1
print_analisis()
end
if key.press(key.W) then
boss.y_old = boss.y
boss.y = boss.y-1
print_analisis()
end
if key.press(key.F) then
boss._pause = not boss._pause
end
if key.press(key.N1) then
-- abad prev room
local hab = abad.hab-1
if hab<0 then hab=0 end
local hab_x = 4
local hab_y = 3
local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y)
abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end
if key.press(key.N2) then
-- abad next room
local hab = abad.hab+1
if hab<0 then hab=0 end
local hab_x = 4
local hab_y = 3
local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y)
abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end
if key.press(key.N8) then
-- local abad_x, abad_y = coords.room_to_world ( 31, 8, 3 )
-- print(abad_x..", "..abad_y)
-- abad:move(abad_x, abad_y)
-- local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
imp.mode="away"
imp.mode_cooldown = 60000
print("away")
end
if key.press(key.N9) then
-- mapa_restore_backup()
-- set_actors_enabled_by_room(true, "boss", 44, 55)
-- viewp:free_move()
imp.mode="chase"
imp.mode_cooldown = 60000
print("chase")
end
if key.press(key.N0) then
-- abad go to room
-- local abad_x, abad_y = coords.room_to_world ( 34, 3, 3 )
-- print(abad_x..", "..abad_y)
-- abad:move(abad_x, abad_y)
-- local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
imp.init()
end
end
function debug_info()
-- fps_print()
-- if true then return end
font.current(font_default)
-- viewp:print()
-- msg_print(0,14,"ABAD= "..abad.x..", "..abad.y, true)
-- msg_print(0,21,"VIEW= "..vp_x..", "..vp_y, true)
-- local hab, xx, yy = coords.world_to_tile(abad.x, abad.y)
-- msg_print(0,28,hab.." ( "..xx..", "..yy.." )", true)
-- msg_print(0,21,"VIEW= "..viewp.x..", "..viewp.y, true)
local hab, xx, yy = coords.world_to_tile(abad.x, abad.y)
msg_print(0,28,hab.." ( "..xx..", "..yy.." )", true)
-- msg_print(0,35,hab.." ( "..xx..", "..yy.." )", true)
-- msg_print(0,42," JH= "..abad.jump_height,true)
@@ -270,12 +516,7 @@ function update_game()
-- end
-- msg_print(abad.x, abad.y-8,msg)
-- end
font.current(font_sf)
end
function collision(a, b)
return (a.x+a.bb.x+a.bb.w >= b.x+b.bb.x)
and (a.x+a.bb.x <= b.x+b.bb.x+b.bb.w)
and (a.y+a.bb.y+a.bb.h >= b.y+b.bb.y)
and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h)
end
flow:registrar("game", {game_init, update_game} )

View File

@@ -1,8 +1,3 @@
o2aX = arcade_config.org2arc_escala
cxr = arcade_config.character_per_row-1
cxr2 = arcade_config.character_per_row_base2
cw = arcade_config.character_width
ch = arcade_config.character_height
-- posició en el gif
gorro_gif_col = 6
gorro_gif_row = 2
@@ -10,10 +5,9 @@ gorro_gif_row = 2
gorro={name="gorro",hab=5,x=6,y=3,w=32,h=32,bb={x=0,y=0,w=16,h=16}}
function gorro.init()
local habs={{60,5},{4,5},{34,4},{62,7},{75,4}}
local habs={{4,5},{12,10},{21,11},{34,4},{43,1}}
local r=1+math.random(0,#habs-1)
gorro.hab=habs[r][1]
-- gorro.x=habs[r][2]*8
gorro.x=habs[r][2]
local world_x, world_y = coords.room_to_world(gorro.hab,gorro.x,gorro.y)
@@ -24,28 +18,23 @@ function gorro.init()
end
function gorro.draw()
-- draw.surf(96,32,16,16,gorro.x,gorro.y,16,16)
-- local x = gorro_gif_col*cw
-- local y = gorro_gif_row*ch
-- draw.surf(x,y,cw,ch,gorro.x*o2aX,gorro.y*o2aX,cw,ch)
local x = gorro_gif_col*cw
local y = gorro_gif_row*ch
local x = gorro_gif_col*gorro.w
local y = gorro_gif_row*gorro.h
local scr_x, scr_y = viewp:screen_coords( gorro.x, gorro.y )
draw.surf(x,y,gorro.w,gorro.h,scr_x,scr_y,gorro.w,gorro.h)
end
function gorro.update()
-- if gorro.hab==abad.hab then
-- if aabb(abad,gorro) then
-- abad.objects.gorro=true
-- if premiere.scene_intro then
-- start_scene(scenes.gorro_trobat)
-- else
-- start_scene(scenes.gorro_trobat_nointro)
-- end
-- if abad.objects.gps~=nil then current_camera=3 end
-- remove_actor(gorro)
-- end
-- end
if gorro.hab==abad.hab then
if collision(abad,gorro) then
abad.objects.gorro=true
if premiere.scene_intro then
start_scene(scenes.gorro_trobat)
else
start_scene(scenes.gorro_trobat_nointro)
end
-- if abad.objects.gps~=nil then current_camera=3 end
remove_actor(gorro)
end
end
end

View File

@@ -34,10 +34,13 @@ function gota.new(_hab,_x,_y,_freq,_x_offset, _y_offset)
update=gota.update_normal,
draw=gota.draw_normal,
draw_drop= gota.draw_drop,
bb={x=4,y=0,w=8,h=12}}
bb={x=4,y=0,w=8,h=12},
enabled= true,
disable_reason="" }
end
function gota:draw_normal()
if not self.enabled then return end
local x = gota_gif_col*cw
local y = gota_gif_row*ch
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
@@ -48,6 +51,7 @@ function gota:draw_normal()
end
function gota:update_normal()
if not self.enabled then return end
self.wait=self.wait+1
if self.wait==18 then
@@ -69,11 +73,24 @@ function gota:update_normal()
self.dy=-4
self.dy=-2
if self.hab==abad.hab then sound.play(audio_low) end
else
self.draw=gota.draw_falling
end
else
--self.flip=not self.flip
end
if viewp:inside(self.x, self.y, self.w, self.h) then
if collision(abad,self) then
abad_hurt(1)
self.update=gota.update_splash
self.draw=gota.draw_splash
self.cx=self.x+2
self.dx=0
self.dy=-4
end
end
-- if self.hab==abad.hab then
-- if aabb(abad,self) then
-- abad_hurt(1)
@@ -90,13 +107,23 @@ end
function gota:hit()
end
function gota:draw_falling()
if not self.enabled then return end
local gota_x, gota_y = viewp:screen_coords( self.x, self.y )
draw.circf( gota_x+4, gota_y+12, 4, 16)
draw.circf( gota_x+5, gota_y+13, 3, 11)
draw.pixel( gota_x+3, gota_y+13, 2)
end
function gota:draw_drop( x, y )
if not self.enabled then return end
splash_x, splash_y = viewp:screen_coords( x, y )
draw.circf( splash_x, splash_y, 2, 16)
draw.circf( splash_x, splash_y, 1, 11)
end
function gota:draw_splash()
if not self.enabled then return end
local splash_L1_x = (self.cx-self.dx)
local splash_L2_x = (self.cx-(self.dx/2))
local splash_R1_x = (self.cx+self.dx)
@@ -111,6 +138,7 @@ function gota:draw_splash()
end
function gota:update_splash()
if not self.enabled then return end
self.dx=self.dx-1
self.dy=self.dy+0.25
self.x=self.cx+self.dx

75
data/health_potion.lua Normal file
View File

@@ -0,0 +1,75 @@
health_potion_gif_x = 192
health_potion_gif_y = 128
health_potion={}
function health_potion.new(_hab, _x, _y, _y_speed, _max_height, _heal)
_raising = false
if _max_height>0 then _raising=true end
return {
name="health_potion",
hab = _hab,
x = _x, y = _y,
w = 16, h = 16,
vx=0, vy=0,
y_speed = _y_speed,
max_height = _max_height,
heal = _heal,
raising = _raising,
enabled=true,
wait = 0,
bb={x=4,y=0,w=9,h=16},
update=health_potion.update,
draw=health_potion.draw,
}
end
function health_potion:draw()
if not self.enabled then return end
local x = health_potion_gif_x
local y = health_potion_gif_y
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
if self.heal==1 then
pal.subpal(3,11)
elseif self.heal==2 then
pal.subpal(3,8)
end
draw.surf(x,y,self.w,self.h,scr_x,scr_y,self.w,self.h)
pal.subpal(3)
-- draw.rect(scr_x+health_potion.bb.x,scr_y+health_potion.bb.y,health_potion.bb.w,health_potion.bb.h,3)
end
function health_potion:update()
if not self.enabled then return end
if self.raising and self.y_speed>0 then
self.y_speed = -self.y_speed
elseif not self.raising and self.y_speed<0 then
self.y_speed = -self.y_speed
end
local x2_check = self.x+self.bb.x+self.bb.w
local x1_check = self.x+self.bb.x
local y_check = self.y+self.bb.h+self.y_speed
if true then
self.wait=0
self.max_height = self.max_height+self.y_speed
self.y = self.y+self.y_speed
if self.max_height==0 then self.raising=false end
end
self.wait=self.wait+1
local tile1_hit_type= arc_check_tile(x1_check, y_check )
local tile2_hit_type= arc_check_tile(x2_check, y_check)
local block_tile = tile1_hit_type == tiletype.block or tile2_hit_type == tiletype.block
if block_tile then self.y_speed=0 end
self.hab = coords.world_to_tile(self.x, self.y)
if self.hab==abad.hab then
if collision(abad,self) then
abad_heal(self.heal)
self.enabled = false
remove_actor(self)
end
end
end

383
data/helpers.lua Normal file
View File

@@ -0,0 +1,383 @@
local shine_step = 1
local shine_wait = 0
local shine_pos = 0
local map_backup = {}
local actors_backup = {}
function distancia(a, b, hv)
local dx = (a.x-b.x)
local dy = (a.y-b.y)
local r = 0
if hv==nil then
r = math.sqrt(dx*dx+dy*dy)
elseif hv=="h" then
if math.abs(dy)<=16 then r=dx else r=999999 end
elseif hv=="v" then
if math.abs(dx)<=16 then r=dy else r=999999 end
end
return math.abs(r)
end
function in_table(tabla, valor)
for _, v in ipairs(tabla) do
if v == valor then return true end
end
return false
end
function table_key (tabla, valor)
for k, v in pairs(tabla) do
if v==valor then return k end
end
return 0
end
function collision(a, b)
return (a.x+a.bb.x+a.bb.w > b.x+b.bb.x)
and (a.x+a.bb.x < b.x+b.bb.x+b.bb.w)
and (a.y+a.bb.y+a.bb.h > b.y+b.bb.y)
and (a.y+a.bb.y < b.y+b.bb.y+b.bb.h)
end
function half_collision(a, b)
return ((a.x+a.bb.x+a.bb.w >= b.x+b.bb.x)
and (a.x+a.bb.x <= b.x+b.bb.x+b.bb.w) )
or ((a.y+a.bb.y+a.bb.h >= b.y+b.bb.y)
and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h))
end
function v_collision(a, b)
return ((a.x+a.bb.x+a.bb.w >= b.x+b.bb.x)
and (a.x+a.bb.x <= b.x+b.bb.x+b.bb.w) )
end
function h_collision(a, b)
return ((a.y+a.bb.y+a.bb.h >= b.y+b.bb.y)
and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h))
end
function remove_actor(actor)
for index, value in pairs(actors) do
if value == actor then
table.remove(actors,index)
end
end
end
function set_actors_enabled_by_room(_enabled, _reason, room0, room1)
-- print("set_actors_enabled_by_room")
-- print(" hab_list")
room1 = room1 or room0
local rw=(room1-room0)%mapa_rooms_per_piso
local hab_list = {}
y = room0
while y<=room1 do
for x=y, y+rw do
hab_list[x]=true
-- print(" "..x)
end
y = y+mapa_rooms_per_piso
end
for index, actor in pairs(actors) do
if hab_list[actor.hab] and actor~=abad then
-- if actor.name then print(" "..actor.name) end
-- if actor.disable_reason then print(" "..actor.disable_reason) end
-- if actor.enabled then print("ENABLED") end
if not _enabled then
-- print("DISABLE ACTORS")
-- disable
if actor.enabled then
-- Si el actor està actiu -> deshabilitar amb motiu
actor.enabled=_enabled
actor.disable_reason = _reason
-- print("-> ".._reason)
end
else
-- enable
if actor.disable_reason and actor.disable_reason==_reason then
-- Si l'actor te un motiu per haver estat deshabilitat -> habilitar i borrar motiu
actor.enabled=_enabled
actor.disable_reason = ""
else
-- Habilitar l'actor si no te atribut disable_reason
actor.enabled=_enabled
end
end
end
end
end
function disable_actor_by_id( remove_set )
local id_list = {}
local ok = false
-- Construir llista per a eliminar
if type(remove_set) == "string" then
id_list[remove_set] = true
ok = true
elseif type(remove_set) == "table" then
for _, v in ipairs(remove_set) do
ok = true
id_list[v] = true
end
end
-- eliminar
if ok then
for index, actor in pairs(actors) do
if id_list[actor.id] then
-- actors[index]=nil
actor.enabled=false
end
end
end
end
function draw_shiny_rect(x, y, w, h, color, shine_color)
draw.rect(x,y,w,h,color)
local shine_w= 18
-- Convertir el rectangle en una linea en checkpoints
local p0 = 0
local p1 = p0+w-1
local p2 = p1+h
local p3 = p2+w
local p4 = p3+h
-- Punt inicial y final de la recta del brillo
local s0 = shine_step
local s1 = s0+shine_w
local y0 = 0
if s0==p4 then
shine_step=0
draw.line(x, y, x+shine_w, y, shine_color)
elseif s0<p1 then
if s1<p1 then
draw.line(x+s0, y, x+s1, y, shine_color)
elseif s1<p2 then
segment = s1-p1
draw.line(x+s0, y, x+w-1, y, shine_color)
draw.line(x+w-1, y, x+w-1, y+segment, shine_color)
end
elseif s0<p2 then
if s1<p2 then
segment = shine_w
x0 = x+w-1
y0= y+(s0-p1)-1
draw.line(x0, y0, x0, y0+segment, shine_color)
elseif s1<p3 then
segment = s1-p2
x0= x+w-1-segment
y0= y+h-1
draw.line(x0, y0, x0+segment, y0, shine_color)
segment = p2-s0-1
x0= x+w-1
y0= y+(s0-p1)
draw.line(x0, y0, x0, y0+segment, shine_color)
end
elseif s0<p3 then
if s1<p3 then
segment=shine_w
x0 = x+w-1-(s1-p2)
y0 = y+h-1
draw.line(x0, y0, x0+shine_w, y0, shine_color)
elseif s1<p4 then
segment = s1-p3
y0 = y+h-1
draw.line(x,y0,x,y0-segment,shine_color)
segment = p3-s0
y0 = y+h-1
draw.line(x,y0,x+segment,y0,shine_color)
end
elseif s0<p4 then
if s1<p4 then
segment = shine_w
y0 = y+p4-s1
draw.line(x,y0,x,y0+segment,shine_color)
else
segment = s1-p4
draw.line(x,y,x+segment,y,shine_color)
segment = p4-s0
draw.line(x,y,x,y+segment,shine_color)
end
end
shine_step = shine_step+1
end
function arc_text(str, x, y, col)
font.current(font_sf)
draw.text(str,x,y,col)
end
function arc_textB(str, x, y, col)
font.current(font_sf)
-- Crear el borde negre
draw.text(str, x-1, y-1, 16)
draw.text(str, x , y-1, 16)
draw.text(str, x+1, y-1, 16)
draw.text(str, x-1, y, 16)
draw.text(str, x+1, y, 16)
draw.text(str, x-1, y+1, 16)
draw.text(str, x , y+1, 16)
draw.text(str, x+1, y+1, 16)
-- Escriure la cadena
draw.text(str,x,y,col)
end
function editor_to_map_tile(editor_tile)
local result = 0
if editor_tile<256 then result = editor_tile + arcade_config.tiles_offset end
return result
end
function map_to_editor_tile(map_tile)
local result = map_tile - arcade_config.tiles_offset
if map_tile==0 then result = 256 end
return result
end
function mapa_backup(tx,ty,tile)
table.insert(map_backup,{x=tx,y=ty,val=tile})
end
function mapa_restore_backup()
for i = 1, #map_backup do
local e = map_backup[i]
map.tile(e.x, e.y, e.val)
end
map_backup = {}
end
function load_tilemap( sf_mapa, replace_map )
local mapa_tw, mapa_th = surf.size(sf_mapa)
local nrooms = mapa_rooms_per_piso*mapa_pisos
local x = 0
local y = 0
local yroom = 0
local xroom = 0
map.surf(sf_mapa)
if replace_map==nil then
for ty=0,mapa_th-1 do
if y == mapa_room_rows then
yroom = yroom + mapa_rooms_per_piso
y = 0
end
xroom = yroom
for tx=0,mapa_tw-1 do
local tile=editor_to_map_tile(mapa[1+xroom][1+x+y*mapa_room_cols])
map.tile(tx, ty, tile)
x = x + 1
if x == mapa_room_cols then
x = 0
xroom = xroom + 1
end
end
y = y +1
end
else
local mapa_x0, mapa_y0 = coords.room_to_mini_tile( replace_map.r0.r, replace_map.r0.x, replace_map.r0.y )
local mapa_x1, mapa_y1 = coords.room_to_mini_tile( replace_map.r1.r, replace_map.r1.x, replace_map.r1.y )
local replace_rooms_per_piso = ((replace_map.r1.r-replace_map.r0.r)+1)%mapa_rooms_per_piso
-- print(mapa_x0..", "..mapa_y0)
-- print(mapa_x1..", "..mapa_y1)
-- print(mapa_x1-mapa_x0..", "..mapa_y1-mapa_y0)
-- print(replace_rooms_per_piso)
y = 0
for ty=mapa_y0,mapa_y1 do --24 -> 41 = 17 (18)
if y == mapa_room_rows then
yroom = yroom + replace_rooms_per_piso
y = 0
end
xroom = yroom
for tx=mapa_x0, mapa_x1 do -- 36 -> 59 = 23 (24)
-- print("ROOM= "..xroom.." ( "..x..", "..y.." ) <= "..(1+xroom)..", "..(1+x+y*mapa_room_cols))
-- print(replace_map.map[1+xroom][1+x+y*mapa_room_cols])
local tile=editor_to_map_tile(replace_map.map[1+xroom][1+x+y*mapa_room_cols])
mapa_backup(tx, ty, map.tile(tx,ty))
map.tile(tx, ty, tile)
x = x + 1
if x == mapa_room_cols then
x = 0
xroom = xroom + 1
end
end
y = y +1
end
end
end
-- DEBUG
-- Imprime cualquier valor, incluyendo tablas anidadas
function dump(value, indent)
indent = indent or ""
if type(value) ~= "table" then
return tostring(value)
end
local parts = {"{"}
for k, v in pairs(value) do
local key = (type(k) == "string") and k or "["..tostring(k).."]"
table.insert(parts,
string.format("%s %s = %s,",
indent, key, dump(v, indent.." ")))
end
table.insert(parts, indent.."}")
return table.concat(parts, "\n")
end
function msg_print(x, y, msg, direct_print )
local scr_x, scr_y
direct_print = direct_print or false
if direct_print then
scr_x = x
scr_y = y
else
scr_x, scr_y = viewp:screen_coords(x, y)
end
draw.rectf(scr_x,scr_y,64,8,16)
draw.text(msg,scr_x+1,scr_y+1,2)
end
function view_coord(x, y, w, h, color)
local scr_x, scr_y = viewp:screen_coords(x, y)
draw.rect(scr_x, scr_y, w, h, color)
end
function debug.write_tile(x, y, yplus, print_type, align )
local scr_x, scr_y = viewp:screen_coords(x, y)
local hab, xx, yy = coords.world_to_tile(x, y)
yplus = yplus or 0
print_type = print_type or false
align = align or "R"
local txt_offset = -7
if align=="R" then txt_offset = -14
elseif align=="L" then txt_offset = 0
end
draw.rectf(scr_x+txt_offset,scr_y+yplus,14,7,16)
-- local msg = mapa_get_tile(hab,xx,yy)
local msg = arc_get_tile(x,y)
if print_type then
msg = msg.." "..arc_check_tile(x, y)
end
draw.text(msg,scr_x+txt_offset+1,scr_y+1+yplus,2)
end
function empty_table(t)
for _ in pairs(t) do
return false
end
return true
end

879
data/imp3-functions.lua Normal file
View File

@@ -0,0 +1,879 @@
-- function imp:_moure( foo, name )
-- -- name = name or "anonymous"
-- -- if not foo then
-- -- print_dbg(name.." not found")
-- -- else
-- -- print_dbg(name)
-- -- end
-- self.moure = foo
-- end
function noop ()
end
-------------------------------
--
-------------------------------
function imp:reduce_timers()
if self.mood=="stop" then return end
if DEBUG_FN_NAME then print_dbg("reduce_timers") end
for key, val in pairs(self.timers) do
local is_locked = string.sub(key, -7) == "_locked"
if not is_locked then
self.timers[key] = val - 1
if (val-1)<0 then self.timers[key] = 0 end
end
end
if self.invencible and self.invencible_time >0 then
self.invencible_time = self.invencible_time - 1
else
self.invencible = false
end
end
-------------------------------
--
-------------------------------
function imp:reset_timer( timer )
if self.mood == "stop" then return end
if DEBUG_FN_NAME then print_dbg("reduce_timers") end
local time = 0
if timer=="mood" then time = 150
elseif timer=="target" then time = 350
elseif timer=="shot" then time = 100
elseif timer=="super" then time = 600
elseif timer=="super_wait" then time = 200
elseif timer=="flip_wait" then time = 50
end
if time > 0 then self.timers[timer] = time end
end
-------------------------------
--
-------------------------------
function imp:analyze_env() --OK
if self.mood=="stop" then return end
if DEBUG_FN_NAME then print_dbg("analyze_env") end
-- Distancia fins a l'abad
local r = distancia(self,abad)
self.analisis.can_chase_abad = false
if r<=100 then
self.analisis.can_chase_abad=true
end
-- Els dos punts de cintura per a saber si es pot escalar
local x1_check = self.x+self.bb.x
local x2_check = self.x+self.bb.x+self.bb.w
local y_check = self.y+self.bb.h-4
local tile_type1, tile_code1= arc_check_tile(x1_check,y_check)
local tile_type2, tile_code2= arc_check_tile(x2_check,y_check)
self.analisis.can_climb = false
if tile_type1~=tiletype.void or tile_type2~=tiletype.void then
self.analisis.can_climb = true
end
-- Abad a tir
self.analisis.can_shot = false
if h_collision(self,abad) then self.analisis.can_shot=true end
-- Super preparat
self.analisis.can_super = false
if self.timers.super<=0 then self.analisis.can_super=true end
-- Acces a la zona central (només si el super està preparat)
x1_check = self.x+self.bb.x
x2_check = self.x+self.bb.x+self.bb.w
y_check = self.y+self.bb.h+8
self.analisis.can_go_altar = false
hab1, tx1, ty1 = coords.world_to_tile(x1_check, y_check)
hab2, tx2, ty2 = coords.world_to_tile(x2_check, y_check)
if (hab1==44 and tx1==6 and ty1==4) or (hab2==44 and tx2==7 and ty2==4)
or (hab1==45 and tx1==7 and ty1==3) or (hab2==45 and tx2==8 and ty2==3)then
if self.analisis.can_super then self.analisis.can_go_altar = true end
end
-- Caiguent
self.analisis.falling = false
local tile_type1, tile_code1= arc_check_tile(x1_check,y_check)
local tile_type2, tile_code2= arc_check_tile(x2_check,y_check)
if tile_type1==tiletype.void and tile_type2==tiletype.void then
self.analisis.falling = true
end
-- Cau al següent moviment?
self.analisis.going_to_fall = false
if not self.analisis.falling then
local step_length = self.step_length
-- default movent-se cap a la dreta
x1_check = self.x+self.bb.x+(self.bb.w/2)
x2_check = self.x+self.bb.x+self.bb.w
if self.x_old>self.x then
-- movent-se cap a l'esquerra
step_length = -step_length
x1_check = self.x+self.bb.x
x2_check = x1_check+(self.bb.w/2)
elseif self.x_old==self.x then
-- quet
step_length = 0
x1_check = self.x+self.bb.x
x2_check = self.x+self.bb.x+self.bb.w
end
local tile_type1, tile_code1= arc_check_tile(x1_check+step_length,y_check)
local tile_type2, tile_code2= arc_check_tile(x2_check+step_length,y_check)
if tile_type1==tiletype.void and tile_type2==tiletype.void then
self.analisis.going_to_fall = true
end
end
-- Ha arribat a destí
self.analisis.target_reached = false
if not empty_table(self.pattern:target_node()) then
-- Target reached
if self.pattern:in_target(self) then self.analisis.target_reached=true end
end
end
function imp:update_action_events()
if self.analisis.going_to_fall then
self:add_action_event("prefall")
end
if self.analisis.falling then
self:add_action_event("falling")
end
if self.analisis.target_reached then
self:add_action_event("target")
end
if self.analisis.can_go_altar then
self:add_action_event("super_ready")
end
if self.x_old>self.x then
self:add_action_event("left")
end
if self.x_old<self.x then
self:add_action_event("right")
end
end
function imp:check_action_event ( event )
for _, v in ipairs(self.action_event) do
-- print_dbg(v)
if v == event then return true end
end
return false
end
function imp:add_action_event ( event )
table.insert(self.action_event, event)
end
-------------------------------
--
-------------------------------
function imp:choose_action() -- antic imp:move
if DEBUG_FN_NAME then print_dbg("choose_action "..self.mood.." / ".."stop") end
-- if self.mood=="stop" then return self.mood end
-- Si no te ganes de fer res, no moure
if self.mood=="stop" then return self.actions.no_action end
local next_action = self:next_action()
if self.analisis.target_reached and next_action=="super" then
self.add_action_event("super ready")
-- next_action = self:next_action()
-- self:super()
end
if self.old_action~=next_action then
self.old_action=next_action
end
self.action = next_action
return next_action
end
-------------------------------
-- imp.controller_input()
--
-- Traduir a una entrada de pad
-------------------------------
function imp:controller_input()
if DEBUG_FN_NAME then print_dbg("controller_input") end
if (self.action == self.actions.right or
self.action == self.actions.left) then
if self.moure == imp.state_normal or self.moure == imp.state_walking then
self.moure=imp.state_walking
end
elseif (self.action == self.actions.jump) then
if self.moure == imp.state_normal or self.moure == imp.state_walking then
self:jump()
end
elseif (self.action == self.actions.jumpfwd) then
if self.moure == imp.state_normal or self.moure == imp.state_walking then
self:jump(true)
end
elseif (self.action == self.actions.shot) then
self:shot()
elseif (self.action == self.actions.super) then
self:super()
end
self.old_action = self.action
self.action = self.actions.no_action
end
-------------------------------
--
-------------------------------
function imp:fight() -- OK
if DEBUG_FN_NAME then print_dbg("fight") end
self:create_hot_points()
self:load_pattern_paths()
local node = 6
local path = {target=6, actions={{action="right",event="target"}}}
self.pattern:add_manual_target ( node, path )
-- self.pattern.recovery = imp.pattern_recovery
self.shot_target = abad
self.mood=self.moods.chase
self:pattern_movement()
self.moure = imp.state_normal
self.stucked = {x=0, y=0, t=0 }
end
-------------------------------
--
-------------------------------
function imp:shot(actor)
if DEBUG_FN_NAME then print("shot") end
self:do_flip(abad)
-- print_dbg("FIREBALL!!")
local flip = false
local x_ini = self.x+self.bb.x+self.bb.w+4
if self.x>abad.x then
flip=true
x_ini = self.x-4
end
local hab, tx, ty, off_x, off_y = coords.world_to_tile(x_ini,self.y+(self.h/4))
fireball.init(hab, tx, ty, flip, off_x, off_y)
sound.play(audio_hit)
self:reset_timer("shot")
end
-------------------------------
--
-------------------------------
function imp:create_hot_points() --OK
self.pattern.node[1] = point.new(44, 6, 3, 0, 0,"P1")
self.pattern.node[2] = point.new(45, 7, 3, 0, 0,"P2")
self.pattern.node[3] = point.new(44,12, 5, 8, 0,"P3")
self.pattern.node[4] = point.new(54, 5, 4, 0, 0,"P4")
self.pattern.node[5] = point.new(54,12, 4, 8, 0,"P5")
self.pattern.node[6] = point.new(55, 8, 4, 0, 0,"P6")
self.pattern.node[7] = point.new(55, 8, 0, 0, 0,"P7")
self.pattern.node[8] = point.new(54, 5, 0, 0, 0,"P8")
self.pattern.node[9] = point.new(54, 9, 1, 0, 0,"P9")
self.pattern.node[10] = point.new(55, 4, 1, 0, 0,"P10")
-- self.hot_points[11] = abad
-- self.hot_points[11] = point.new(45, 1, 5, 8, 0,"altar-R")
-- self.hot_points[12] = point.new(44,11, 5, 0, 0,"altar-L")
end
-------------------------------
--
-------------------------------
function imp:load_pattern_paths() --OK
self.pattern.path[1] = {
{target=3, actions= {{action="right" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="target"}}},
{target=4, actions= {{action="" , event="land"},
{action="right" , event="land"},
{action="left" , event="target"}}},
{target=4, actions= {{action="right" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="target"}}},
{target=10, actions= {{action="right" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="target"}}},
{target=6, actions= {{action="right" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="target"}}},
{target=5, actions= {{action="right" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="land"},
{action="left" , event="target"}}},
{target=5, actions= {{action="right" , event="target"}}}
}
self.pattern.path[2] = {
{target=3, actions= {{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="target"}}},
{target=6, actions= {{action="" , event="land"},
{action="left" , event="land"},
{action="right" , event="target"}}},
{target=6, actions= {{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="target"}}},
{target=6, actions= {{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="land"},
{action="right" , event="target"}}},
{target=6, actions= {{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="land"},
{action="left" , event="land"},
{action="right" , event="target"}}},
{target=9, actions= {{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="target"}}},
{target=4, actions= {{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="target"}}},
{target=5, actions= {{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="land"},
{action="right" , event="target"}}},
{target=5, actions= {{action="left" , event="target"}}}
}
self.pattern.path[3] = {
{target=1, actions={{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="prefall"},
{action="jump" , event="target"}}},
{target=2, actions={{action="right" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="prefall"},
{action="jump" , event="target"}}},
{target=4, actions={{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="land"},
{action="left" , event="target"}}},
{target=5, actions={{action="left" , event="land"},
{action="right" , event="target"}}},
{target=6, actions={{action="left" , event="land"},
{action="right" , event="target"}}}
}
self.pattern.path[4] = {
{target=1, actions={{action="jump" , event="target"}}},
{target=5, actions={{action="right", event="target"}}},
{target=6, actions={{action="right", event="target"}}},
{target=8, actions={{action="jump" , event="target"}}},
}
self.pattern.path[5] = {
{target=4, actions={{action="left" , event="target"}}},
{target=6, actions={{action="right", event="target"}}}
}
self.pattern.path[6] = {
{target=2, actions={{action="jump", event="target"}}},
{target=5, actions={{action="left", event="target"}}},
{target=7, actions={{action="jump", event="target"}}},
{target=4, actions={{action="left", event="target"}}}
}
self.pattern.path[7] = {
{target=5, actions={{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="target"}}},
{target=10,actions={{action="" , event="land"},
{action="left" , event="land"},
{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="target"}}},
{target=2, actions={{action="jump" , event="target"}}},
{target=6, actions={{action="" , event="land"},
{action="left" , event="land"},
{action="left" , event="land"},
{action="right", event="target"}}},
}
self.pattern.path[8] = {
{target=5, actions={{action="right" , event="prefall"},
{action="jumpfwd" , event="land"},
{action="right" , event="target"}}},
{target=9, actions={{action="" , event="land"},
{action="right" , event="land"},
{action="jumpfwd" , event="land"},
{action="right" , event="target"}}},
{target=1, actions={{action="jump" , event="target"}}}
}
self.pattern.path[9] = {
{target=6, actions={{action="right" , event="target"}}},
{target=5, actions={{action="right" , event="target"}}},
{target=1, actions={{action="left" , event="prefall"},
{action="jumpfwd" , event="land"},
{action="left" , event="prefall"},
{action="jump" , event="target"}}},
{target=4, actions={{action="left" , event="target"}}}
}
self.pattern.path[10] = {
{target=5, actions={{action="left" , event="target"}}},
{target=2, actions={{action="right" , event="prefall"},
{action="jumpfwd" , event="land"},
{action="right" , event="prefall"},
{action="jump" , event="target"}}},
{target=6, actions={{action="right" , event="target"}}},
{target=6, actions={{action="left" , event="land"},
{action="right" , event = "target"}}}
}
self.pattern.path[11] = {
{target=4, actions={{action="left", event="target"}}}
}
self.pattern.path[12] = {
{target=6, actions={{action="right", event="target"}}}
}
end
-------------------------------------------------------------------
-- // PATTERN MOVEMENT
function imp:pattern_movement() --OK
if DEBUG_FN_NAME then print_dbg("pattern_movement") end
self.move_type = self.move_types.pattern
-- print("Pattern")
end
function imp:pattern_recovery() -- OK
-- print("Pattern recovery")
self:pattern_movement() -- Canviar a moviment per patró
-- Situar-se en el mapa respecte als punts de recuperació (els tres punts del pis)
local x_after_4 = false
local x_after_5 = false
local x_after_6 = false
local y_upper_4 = false
local y_upper_5 = false
local y_upper_6 = false
if self.pattern.node[4].x<self.x then x_after_4 = true end
if self.pattern.node[5].x<self.x then x_after_5 = true end
if self.pattern.node[6].x<self.x then x_after_6 = true end
-- Comparar en el punt dels peus
if self.pattern.node[4].y>self.y+self.h then y_upper_4 = true end
if self.pattern.node[5].y>self.y+self.h then y_upper_5 = true end
if self.pattern.node[6].y>self.y+self.h then y_upper_6 = true end
local node = 0
local path = {}
-- Seleccionar les instruccions segons la posicio
if not y_upper_5 then
-- target 5
node = 5
if not x_after_5 then
-- right target
path = {target=5, actions={{action="right",event="target"}}}
else
-- left target
path = {target=5, actions={{action="left",event="target"}}}
end
else
if x_after_5 then
--target 4
node = 4
-- left target
path = {target=4, actions={{action="left",event="target"}}}
else
--target 6
node = 6
-- right target
path = {target=6, actions={{action="right",event="target"}}}
end
end
self.pattern:add_manual_target ( node, path )
-- Tornar l'acció a fer
-- return self.actions[self.path.actions[1].action]
end
-------------------------------------------------------------------
-- // ACTION
function imp:next_action()
local next_action = self.actions.no_action
-- Si el blanc està a tir disparar
if self.timers.shot<=0 and
h_collision(self, self.shot_target) and
not self.invencible then
next_action = "shot"
end
-- anar a fer el super
if self.timers.super<=0 then
self.pattern:set_target_mode(PATTERN_CHASE,self.pattern.node[1])
else
self.pattern:set_target_mode(self.mood,abad)
end
-- fer el super
if self.timers.super<=0 and self:check_action_event("super_ready") then
if self.x<self.pattern.node[3].x then
local node = 3
local path = {target=3, actions= {{action="jumpfwd", event="land"},
{action="right" , event="target"},
{action="super" , event="super"}}}
self.pattern:add_manual_target(node, path)
end
end
-- Resta d'accions
if next_action==self.actions.no_action then
if self.timers.target<=0 or self.stucked.t>=self.timers.stucked_locked then
self:pattern_recovery()
self:reset_timer("target")
end
if self.move_type==self.move_types.free then
-- FREE
-- next_action = self:free_next_action()
elseif self.move_type==self.move_types.pattern then
-- PATTERN
local action_event_done = self:check_action_event(self.pattern:event())
-- local str_aev = ""
-- for k,v in pairs(self.action_event) do str_aev=str_aev..", "..v end
if action_event_done then
next_action=self.pattern:next_action()
-- print_dbg("NEXT ACTION "..next_action)
else
next_action=self.pattern:action()
-- print_dbg("HOLD ACTION "..next_action)
end
elseif self.move_type==self.move_types.super then
-- SUPER
--
next_action = "no_action"
end
end
self.action_event = {}
-- next_action es text, traduir
return self.actions[next_action]
end
function imp:jump ( jumpfwd )
if DEBUG_FN_NAME then print_dbg("") end
-- Inicialització de fer el salt
jumpfwd = jumpfwd or false
self.jump_height = 0
-- self.step=0
self:_step(0,"jump")
self.jumpfwd=jumpfwd
self.moure = imp.state_jumping
end
function imp:state_jumping()
if self.mood=="stop" then return self.mood end
if DEBUG_FN_NAME then print_dbg("state_jumping") end
-- ??
self.wait=self.wait+1
self.wait=0
self.next_frame=imp.jumping_next_frame
-- Pujar o caure
if self.jump_height<self.max_jump_height then
-- Comprovar que pasa en l'aire
self:do_jump()
else
-- Canviar a mode caure
self.moure = imp.state_falling
end
-- self.step=self.step+1
self:_step(self.step+1,"state_jumping")
-- cap endavant?
if self.jumpfwd then self:advance() end
end
function imp:do_jump()
if DEBUG_FN_NAME then print_dbg("jump") end
local vspace = self.vmove_space
-- Els dos punts de dalt del personatge
local x1_check = self.x+self.bb.x
local x2_check = self.x+self.bb.x+self.bb.w
local y_check = self.y-vspace; -- posicio de dalt
-- Comprovar on està pegant
local tile1_hit_type= arc_check_tile(x1_check, y_check )
local tile2_hit_type= arc_check_tile(x2_check, y_check)
local not_block_tile = tile1_hit_type ~= tiletype.block and tile2_hit_type ~= tiletype.block
-- Fer l'acció que correspon
if not_block_tile then
-- Ascendir
self.old_y = self.y
self.y=self.y-vspace
else
-- Si es un bloc permetre gastar l'espai no pintat
local tile1_hit = arc_get_tile(x1_check, y_check )
local tile2_hit = arc_get_tile(x2_check, y_check)
local half_block1 = mapa_is_half_block_tile(map_to_editor_tile(tile1_hit))
local half_block2 = mapa_is_half_block_tile(map_to_editor_tile(tile2_hit))
local full_block1 = tile1_hit_type == tiletype.block and not half_block1
local full_block2 = tile2_hit_type == tiletype.block and not half_block2
local full_block = full_block1 and full_block2
local half_block = half_block1 or half_block2
-- Si ninguno dels tiles tocats es un block complet
-- i almenys un dels tiles tocats es mig tile
-- permetre continuar en el salt
if not full_block and half_block then
if self.jump_in_half_block==0 and not self.jump_in_half_block_used then
self.jump_in_half_block = arcade_config.tiles_height / 2
end
if self.jump_in_half_block>0 then
self.old_y = self.y
self.y=self.y-vspace
self.jump_in_half_block = self.jump_in_half_block-1
self.jump_in_half_block_used = true
end
end
end
-- Registrar el desplaçament
self.jump_height = self.jump_height+vspace
end
function imp:advance()
if DEBUG_FN_NAME then print_dbg("advance") end
local limit=tiletype.block
if self.moure~=imp.state_walking then limit=tiletype.half end
local step_length=self.step_length; --lo que avança el imp cada pas
local x_check = 0
local y_check = self.y+self.bb.h-1
if (self.old_action == self.actions.right or
self.old_action == self.actions.left) then
-- orientació des de control
if self.old_action == self.actions.left then
step_length = -step_length
x_check = self.x+self.bb.x
else
x_check = self.x+self.bb.x+self.bb.w
end
x_check = x_check + step_length
else
-- detectar orientacio des del movimentl
if self.x_old>self.x then
step_length = -step_length
x_check = self.x+self.bb.x
else
x_check = self.x+self.bb.x+self.bb.w
end
x_check = x_check + step_length
end
if arc_check_tile(x_check, y_check)<limit then
self.x_old = self.x
self.x=self.x+step_length
end
local hab,xx, yy = coords.world_to_tile(self.x, self.y)
self.hab = hab
end
function imp:state_falling()
if DEBUG_FN_NAME then print_dbg("state_falling") end
-- self.frame=30
self.wait=self.wait+1
self.next_frame=imp.falling_next_frame
-- Si toca terra canviar el mode
if self:land() then
self.moure = imp.state_normal
self.jumpfwd = false
return
end
-- Seguir caiguent
self.old_y = self.y
self.y=self.y+1
self.jump_height = self.jump_height-1
self.falling=self.falling+1
-- Caiguent cap endavant?
if self.jumpfwd then self:advance() end
end
function imp:land ()
if DEBUG_FN_NAME then print_dbg("land") end
-- Els dos punts de baix de l'abad
local x1_check = self.x+self.bb.x
local x2_check = self.x+self.bb.x+self.bb.w
local y_check = self.y+self.bb.h
-- Comprovar on està aterrant
local tile1_hit= arc_check_tile(x1_check, y_check )
local tile2_hit= arc_check_tile(x2_check, y_check)
local floor_tile = tile1_hit>=tiletype.half or tile2_hit>=tiletype.half
-- Encara que siga un tile de piso s'ha de comprovar que
-- la y es un múltiple de l'alt dels tiles
local over_tile = (y_check & 0xF) == 0
local can_land = floor_tile and over_tile
if can_land then
self.jump_in_half_block_used = false
self.jump_height = 0
self:add_action_event("land")
end
-- if can_land then print_dbg ("LANDED") end
return can_land
end
function imp:state_walking()
if self.mood=="stop" then return end
if DEBUG_FN_NAME then print("state_walking") end
-- Limitar la velocitat de moviment
self.wait=self.wait+1
-- Funció de selecció de frame
self.next_frame = imp.walking_next_frame
-- Comprovar dos punts de contacte del personatge en el piso a vore si cau
local x1_check = self.x+self.bb.x
local x2_check = x1_check+self.bb.w
local y_check = self.y+self.bb.h; -- base del personatge
local tile1 = arc_check_tile(x1_check,y_check)
local tile2 = arc_check_tile(x2_check,y_check)
if tile1==tiletype.void and tile2==tiletype.void then
-- si no hi ha piso, caure
self.moure = imp.state_falling
return
end
self:advance()
end
function imp:state_normal()
if DEBUG_FN_NAME then print_dbg("state_normal") end
self.frame=28
self.wait=0
-- self.step=0
self:_step(0,"state_normal")
self.jumpfwd=false
self.jump_height = 0
self.next_frame=imp.staying_next_frame
end
-- imp.next_frame()
function imp:walking_next_frame()
-- Selecció de frame
if self.wait>=6 then
self.wait=0
-- self.step=(self.step+1)%4
self:_step((self.step+1)%4,"walking_next_frame")
self.frame=self.anim[self.step+1]
end
-- Orientar
self:do_flip()
-- Aguantar el flip
if self.timers.flip_wait<=0 then
if self.mood==self.moods.chase then
self:do_flip(abad)
else
self:do_flip(self.pattern:target_node())
end
end
end
function imp:jumping_next_frame()
self.frame=30
end
function imp:falling_next_frame()
self.frame=30
end
function imp:staying_next_frame()
self.frame=28
end
-- function imp:super_next_frame()
-- self.frame=11
-- end
function imp:do_flip( actor )
actor = actor or self.pattern:target_node()
-- enllaçat a actor
if actor.x<self.x then
self.flip=true
else
self.flip=false
end
self:reset_timer("flip_wait")
end
function imp:super()
if DEBUG_FN_NAME then print("super()") end
self:super_movement()
self.invencible = true
self.moure = imp.state_super
self:reset_timer("super_wait")
end
function imp:state_super()
if DEBUG_FN_NAME then print("state_super") end
-- self.super_wait = self.super_wait -1
local wait = self.timers.super_wait
if self.zoom<1.75 and wait>100 then
if wait%4==0 then self.zoom=self.zoom+0.1 end
elseif not self.super_fired and self.zoom>=1.75 and wait>100 then
local x_ini = self.x+self.bb.x+self.bb.w+4
local hab, tx, ty, off_x, off_y = coords.world_to_tile(x_ini,self.y+(self.h/2))
fireball.init(hab, tx, ty, false, off_x, off_y, 2)
self.super_fired = true
elseif self.zoom>1 and wait<=100 then
if wait%4==0 then self.zoom=self.zoom-0.1 end
end
if wait == 0 then
self.moure = imp.super_end
end
end
function imp:super_end()
self.zoom = 1
self.invencible = false
self.super_fired = false
self.moure = imp.state_normal
self:reset_timer("mood")
self:reset_timer("super")
self:reset_timer("super_wait")
self:pattern_movement()
self:pattern_recovery()
end
function imp:super_movement()
if DEBUG_FN_NAME then print("super_movement") end
self.move_type = self.move_types.super
end
function imp:choose_mood()
if self.mood=="stop" then return end
if self.timers.mood<=0 then
self.mood=self.moods[math.random(2+(math.random(2)-1))+1] -- chase o avoid o aleatoriament neutral
self:reset_timer("mood")
print(self.mood)
end
end

279
data/imp3.lua Normal file
View File

@@ -0,0 +1,279 @@
function print_dbg(...)
-- level = 2 → el llamador de imprimir_con_contexto
local info = debug.getinfo(2, "n")
local nombre = info.name or "<anónima>"
print("[" .. nombre .. "]", ...)
end
hab1 = 1
tx1 = 1
ty1 = 1
hab2 = 1
tx2 = 1
ty2 = 1
require "pattern"
imp = {}
DEBUG_FN_NAME = false
function imp.new(_hab,_x,_y)
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
return {
name="imp",
hab=_hab,
x=world_x, y=world_y,
x_old = 0, y_old = 0,
w=32, h=32,
bb={x=8,y=0,w=16,h=32},
flip=true,
frame=28,
anim={28,29,28,30}, -- seqüencia de frames
wait=0,
step=0,
moods={"stop",PATTERN_CHASE, PATTERN_AVOID, PATTERN_RANDOM }, -- deu coincidir en els modes de pattern
mood="stop", --anterior fight_mode
timers={mood=150,target=350, shot=100, super=2000, super_wait=200, flip_wait=50, stucked_locked=50}, --anterior *_cooldown
move_types={free=0, pattern=1, super=2},
move_type=1, -- anterior movement_type
actions={no_action=0, up=1, down=2, left=4, right=8, jump=16, shot=32, super=64, jumpfwd=128},
pattern= pattern.new(),
analisis = {}, -- memoria per a guardar el resultat de l'analisis
step_length=1,
energia=21,
max_energia=21,
jump_height=0,
max_jump_height=24,
vmove_space = 1,
falling = 0,
action_event = {},
action = 0,
old_action = 0,
stucked = {x=0, y=0, t=0 },
invencible = false,
zoom = 1,
super_pal={[13]=13,[14]=14,[15]=15},
super_fired = false,
can_warp = false,
invencible_time = 0,
disappear_time=40,
disappearing = false,
--
moure = noop,
draw=imp.draw,
update=imp.update_normal,
reduce_timers = imp.reduce_timers,
reset_timer = imp.reset_timer,
analyze_env = imp.analyze_env,
choose_action = imp.choose_action,
controller_input = imp.controller_input,
fight = imp.fight,
create_hot_points = imp.create_hot_points,
load_pattern_paths = imp.load_pattern_paths,
pattern_movement = imp.pattern_movement,
next_action = imp.next_action,
do_jump = imp.do_jump,
jump = imp.jump,
advance = imp.advance,
land = imp.land,
next_frame = imp.staying_next_frame,
do_flip = imp.do_flip,
update_action_events = imp.update_action_events,
check_action_event = imp.check_action_event,
add_action_event = imp.add_action_event,
shot = imp.shot,
pattern_recovery = imp.pattern_recovery,
super = imp.super,
super_movement = imp.super_movement,
hit = imp.hit,
warp_update = imp.warp_update,
choose_mood = imp.choose_mood,
-- debug
_moure = imp._moure,
_pause = false,
_step = imp._step,
}
end
function imp:draw() --OK
self.pattern:draw()
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
if self.warping then
actor_warp_draw(self)
elseif self.moure==imp.state_super then
-- Modo super
-- rotar paleta
for col=13,15 do
local newc = self.super_pal[col]
if self.timers.super_wait%6 == 0 then
newc = newc+1
if newc>15 then newc=13 end
end
pal.subpal(col,newc)
self.super_pal[col]=newc
end
-- pintar
draw.surf(96, 32, self.w, self.h,
scr_x, scr_y-self.h*(self.zoom-1),
self.w*self.zoom, self.h*self.zoom,
self.flip)
-- restaurar paleta
for col=13,15 do pal.subpal(col) end
else
-- Modo normal
if self.invencible then
pal.subpal(5,1)
end
draw.surf((self.frame&7)*self.w, (self.frame>>cxr2)*self.h, self.w, self.h, scr_x, scr_y, self.w, self.h, self.flip)
pal.subpal(5)
end
-- draw.rect(scr_x+self.bb.x,scr_y+self.bb.h, self.bb.w, 8,2)
-- local wtx, wty = coords.room_to_world(hab1, tx1, ty1)
-- local scr_x, scr_y = viewp:screen_coords( wtx, wty )
-- draw.rect(scr_x, scr_y, 16, 16, 15)
-- local wtx, wty = coords.room_to_world(hab2, tx2, ty2)
-- local scr_x, scr_y = viewp:screen_coords( wtx, wty )
-- draw.rect(scr_x, scr_y, 16, 16, 13)
end
function imp:hit() -- OK
if self.energia <= 0 then return end
if DEBUG_FN_NAME then print_dbg("hit") end
if not self.invencible then
self.energia = self.energia -1
if distancia(self, abad)<50 and self.invencible_time<=0 then
self.invencible = true
self.invencible_time = 50
end
end
if self.energia==1 then self.can_warp=true end
if self.energia <= 0 then
self.energia = 0
-- self.enabled = false
if self.can_warp then self.warping=true end
self.shrink=1
self.angle=0
self.disappearing=true
-- calcular velocitat per al warp
local warp_time = self.disappear_time/3
self.d_angle = 720 / warp_time; -- 720 = 2 voltes
self.d_shrink = self.shrink / warp_time
self.update=imp.update_disappearing
end
end
function imp:_step( value, foo )
foo = foo or "anonymous"
-- print_dbg(foo)
self.step = value
end
function imp:warp_update()
-- warp, wait, respawn
if self.warping then
if self.step<self.disappear_time then
self.shrink=self.shrink-self.d_shrink
self.angle=self.angle+self.d_angle
if self.angle>=360 then self.angle = self.angle % 360 end
if self.shrink<=0 then
-- Ha desaparegut
self.shrink=1
self.d_shrink=1
self.angle=0
self.d_angle=1
self.warping = false
self.frame = -1
-- self.can_warp = false
-- self.step = 0
end
end
else
self.can_warp = false
end
end
function imp:update_disappearing()
-- print_dbg(">>>>>>>>>> update_hit")
if not self.enabled then return end
-- Que pasa quan "mor"
local step_time = self.disappear_time
if self.can_warp then
step_time = self.disappear_time/2; -- warp, wait
end
self.wait=self.wait+1
-- print(self.step)
if self.wait>=6 then
self.wait=0
-- self.step=self.step+1
self:_step(self.step+1,"update_hit")
if self.can_warp then
self:warp_update()
self.moure = self.noop
else
self.enabled = false
print("END BOSS")
stages.stage1_boss_finished()
end
end
end
function imp:update_normal()
-- print("")
-- print("TARGET TIMER= "..self.timers.target)
if not self._pause then
-- print("-------------------------------------------------")
-- if self.mood~="stop" then print("TARGET= "..self.pattern:target()) end
-- if self.mood~="stop" then print("ACT/EV= "..self.pattern:action().." / "..self.pattern:event()) end
-- if self.mood~="stop" then print("ACTIONS= "..#self.pattern:actions()) end
self:reduce_timers()
-- Ajustar mood (emocions)
self:choose_mood()
-- self:choose_target()
-- analisis
self:analyze_env()
self:update_action_events()
if self.analisis.target_reached then self:reset_timer("target") end
-- print_analisis()
-- decisio
self:choose_action()
-- local str_aev = ""
-- for k,v in pairs(self.action_event) do str_aev=str_aev..", "..v end
-- if self.mood~="stop" then print("TARGET= "..self.pattern:target().." ACTION= "..self.pattern:action().." ACTION EVENT= "..self.pattern:event().." / "..str_aev) end
-- moviment
self:controller_input()
self:moure()
-- Que no conte si està en modo Super
if self.move_type ~= self.move_types.super then
if self.stucked.x == self.x and self.stucked.y == self.y then
self.stucked.t = self.stucked.t + 1
else
self.stucked.x = self.x
self.stucked.y = self.y
self.stucked.t = 0
end
end
-- Logica per a selecció de frame
self:next_frame()
-- colisions en personatges
-- self:colisions()
end
end
require "imp3-functions"

View File

@@ -1,103 +1,102 @@
o2aX = arcade_config.org2arc_escala
local abad={x=0,y=0,w=32,h=32,dx=88,dy=48,dw=32,dh=32}
local batman={x=0,y=96,w=32,h=32,dx=164,dy=48,dw=32,dh=32}
local cacaus={x=224,y=176,w=32,h=16,dx=152,dy=64,dw=32,dh=16}
local cacaus_trans={x=192,y=176,w=16,h=8,dx=65,dy=56,dw=16,dh=8}
local marc={x=30,y=6,w=198,h=102,color=2}
local pas_porta={x=146,y=48,w=14,h=32,color=16}
local scene_x_offset = 32
local scene_y_offset = 8
intro_wait=40
intro_step=0
function intro_init()
game_update = intro_intro
intro_wait=400
surf.cls(16)
local font_default = font.current()
font.current(font_sf)
surf.target(back)
surf.cls(16)
draw.text("INTRO INIT",0,0,15)
font.current(font_default)
surf.target(0)
surf.source(back)
draw.surf(0,0,63,10,100,100,126,20)
-- surf.source(tiles)
fade.fadein()
print("INTRO INIT")
end
function intro_intro()
intro_wait=intro_wait-1
if intro_wait==0 or key.press(key.ESCAPE) or key.press(keyShoot) or pad.press(btnShoot) or pad.press(btnPause) then
intro_wait=1
game_update = intro_update
fade.fadeoutin()
end
end
function intro_update()
fps_print()
game_init(true)
fade.fadeoutin()
end
-- RESTOS DEL X2 CACAUS
function _draw_item_intro( name, flip )
local cw = arcade_config.character_width
local ch = arcade_config.character_height
if ( name == "abad" ) then
draw.surf(0,0,cw,ch,44*o2aX,24*o2aX,cw,ch,flip)
elseif (name == "batman" ) then
draw.surf(0,48*o2aX,cw,ch,82*o2aX,24*o2aX,cw,ch,flip)
elseif (name == "cacaus" ) then
draw.surf(112*o2aX,88*o2aX,cw,ch/2,76*o2aX,32*o2aX,cw,ch/2,flip)
elseif (name == "marc" ) then
draw.rect(15*o2aX,3*o2aX,99*o2aX,51*o2aX,2)
elseif (name == "pas porta" ) then
draw.rectf(73*o2aX,24*o2aX,7*o2aX,16*o2aX,16)
end
end
function _draw_escenari ()
function draw_escenari ()
surf.cls(16)
draw_item_intro("marc",false)
view.origin(16*o2aX,4*o2aX)
view.origin(scene_x_offset, scene_y_offset)
mapa_draw(10)
-- Borrar la porta del mapa
draw_item_intro("pas porta")
end
function _intro_update()
if key.press(key.ESCAPE) or pad.press(btnPause) then
game_init(true)
function draw_item_intro( name, flip, mood )
if ( name == "abad" ) then
-- abad.mood = mood or "normal"
draw.surf(abad.x, abad.y, abad.w, abad.h, abad.dx, abad.dy, abad.dw, abad.dh, flip)
abad_add_mood(abad.dx,0,abad.dy,0,flip,mood)
elseif (name == "batman" ) then
draw.surf(batman.x, batman.y, batman.w, batman.h, batman.dx, batman.dy, batman.dw, batman.dh, flip)
elseif (name == "cacaus" ) then
draw.surf(cacaus.x, cacaus.y, cacaus.w, cacaus.h, cacaus.dx, cacaus.dy, cacaus.dw, cacaus.dh, flip)
elseif (name == "cacaus trans" ) then
draw.surf(cacaus_trans.x, cacaus_trans.y, cacaus_trans.w, cacaus_trans.h, cacaus_trans.dx, cacaus_trans.dy, cacaus_trans.dw, cacaus_trans.dh, flip)
elseif (name == "marc" ) then
draw.rect(marc.x, marc.y, marc.w, marc.h, marc.color)
elseif (name == "pas porta" ) then
draw.rectf(pas_porta.x, pas_porta.y, pas_porta.w, pas_porta.h, pas_porta.color)
end
end
function intro_init()
print("INTRO_INIT")
-- game_update = intro_intro
intro_wait=400
surf.source(tiles)
surf.target(0)
surf.cls(16)
fade.fadein()
font.current(font_sf)
-- flow:add_path({intro_intro, intro_update})
flow:next()
end
function intro_intro()
intro_wait=1
-- game_update = intro_update
flow:next()
fade.fadeoutin()
end
function intro_update()
if key.press(key.ESCAPE) or pad.press(btnPause) then
-- game_init(true)
print("INTRO_UPDATE")
-- game_update = menu_init
-- game_init(true)
intro_end()
elseif key.press(key.SPACE) then
intro_wait=1
end
intro_wait=intro_wait-1
if intro_wait==0 then
-- == INTRO_01
-- STEP 0
if intro_step==0 then
draw_escenari()
draw_item_intro("abad", true)
draw_item_intro("abad", false)
view.origin(0,0)
intro_step=intro_step+1
-- STEP 1
elseif intro_step==1 then
start_scene(scenes.intro_01,58)
intro_step=intro_step+1
-- == INTRO_02
-- STEP 2
elseif intro_step==2 then
draw_escenari()
draw_item_intro("abad", false)
draw_item_intro("abad", true, "sorpresa")
draw_item_intro("cacaus trans", false)
view.origin(0,0)
intro_step=intro_step+1
-- STEP 3
elseif intro_step==3 then
start_scene(scenes.intro_02,58)
intro_step=intro_step+1
-- == INTRO_03
-- STEP 4
elseif intro_step==4 then
draw_escenari()
@@ -110,6 +109,8 @@ function _intro_update()
elseif intro_step==5 then
start_scene(scenes.intro_03,58)
intro_step=intro_step+1
-- == INTRO_04
-- STEP 6
elseif intro_step==6 then
draw_escenari()
@@ -120,12 +121,21 @@ function _intro_update()
elseif intro_step==7 then
start_scene(scenes.intro_04,58)
intro_step=intro_step+1
-- STEP 8
elseif intro_step==8 then
music.play(audio_main_song)
game_init(true)
fade.fadeoutin()
-- game_init(true)
-- game_update = menu_init
intro_end()
end
intro_wait=50
end
end
function intro_end()
print("intro_end")
fade.fadeoutin()
flow:executar("title")
end
flow:registrar("intro", {intro_init, intro_intro, intro_update})

46
data/invisible.lua Normal file
View File

@@ -0,0 +1,46 @@
invisible={}
function invisible.new(_hab,_x,_y)
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
return {hab=_hab,
x=world_x,
y=world_y,
w=16,
h=16,
wait=0,
hit=invisible.hit,
update=invisible.update,
draw=invisible.draw,
bb={x=0,y=1,w=16,h=15}}
end
function invisible:draw()
-- Es invisible, res que drawar
-- local scr_x, scr_y = viewp:screen_coords( self.x+self.bb.x, self.y+self.bb.y )
-- draw.rect(scr_x, scr_y, 16, 16, 3)
end
function invisible:update()
--self.wait=self.wait+1
--
--if self.wait==6 then
-- self.wait=0
--
-- if self.hab==abad.hab then
-- if aabb(abad,self) then
-- abad_hurt(1)
-- end
-- end
--
--end
if viewp:inside(self.x, self.y, self.w, self.h) then
if collision(abad,self) then
print("check collision")
abad_hurt(1)
end
end
end
function invisible:hit()
end

40
data/llibre.lua Normal file
View File

@@ -0,0 +1,40 @@
-- posició en el gif (tiles de 32)
llibre_gif_col = 7
llibre_gif_row = 3
llibre={name="llibre",hab=5,x=6,y=3,w=32,h=32,bb={x=0,y=0,w=32,h=32}}
function llibre.init()
-- local habs={{33,8},{13,4},{51,9},{50,4},{42,7}}
-- local r=1+math.random(0,#habs-1)
-- llibre.hab=habs[r][1]
-- llibre.x=habs[r][2]*8
-- llibre.x=habs[r][2]
llibre.hab = 41
llibre.x = 10
llibre.y = 2
local world_x, world_y = coords.room_to_world(llibre.hab,llibre.x,llibre.y)
llibre.x=world_x-4
llibre.y=world_y-3
llibre.update=llibre.update
llibre.draw=llibre.draw
end
function llibre.draw()
local x = llibre_gif_col*llibre.w
local y = llibre_gif_row*llibre.h
local scr_x, scr_y = viewp:screen_coords( llibre.x, llibre.y )
draw.surf(x,y,llibre.w,llibre.h,scr_x,scr_y,llibre.w,llibre.h)
end
function llibre.update()
if llibre.hab==abad.hab then
if collision(abad,llibre) then
abad.objects.llibre=true
remove_actor(llibre)
start_scene(scenes.llibre_trobat)
end
end
end

View File

@@ -3,7 +3,11 @@ local logo_step_wait=0
local logo_anim={}
local step1_finished = false
local brillo_y = 10
local logo_wait = 400
local logo_wait = 500
local logo_sf = 99
local font_sf = 99
local logo_sf_w = 63
local logo_sf_h = 20
function logo_anim_init ()
logo_anim={ [1] = {x0=-126, y=80, w=126, h=4, speed= 1, accel= 0.25, x1=65, delay=0},
@@ -13,43 +17,98 @@ function logo_anim_init ()
[5] = {x0=-126, y=96, w=126, h=4, speed= 1, accel= 0.25, x1=65, delay=16}}
end
function logo_config(font_surface)
font_sf = font_surface
end
function logo_init()
game_update = logo_intro
surf.cls(16)
-- print("LOGO INIT")
local font_default = font.current()
-- Crear la surface
logo_sf=surf.new(logo_sf_w,logo_sf_h)
-- logo_sf=surf.new(256,192)
-- Netejar el back
surf.target(logo_sf)
surf.cls(0)
-- Font per a escriure
font.current(font_sf)
surf.target(back)
surf.cls(16)
-- Logo
draw.text("JAILGAMES",0,0,15)
draw.text("presenta",0,20,14)
draw.text("JAILGAMES",0,40,2)
draw.text("presenta",0,10,14)
-- draw.text("JAILGAMES",0,20,2)
-- Restaurar font
font.current(font_default)
surf.target(0)
-- Inicialitzar animació
logo_anim_init()
-- flow:add_path({logo_animate, logo_end})
-- print("LOGO_ANIMATE= ")
-- print(logo_animate)
-- print("LOGO_END= ")
-- print(logo_end)
-- Següent bucle
-- game_update = logo_intro
local modul, pas=flow:next()
print("LOGO_INIT= "..modul..", "..pas)
end
function logo_intro()
logo_wait=logo_wait-1
if logo_wait==0 or key.press(key.ESCAPE) or key.press(keyShoot) or pad.press(btnShoot) or pad.press(btnPause) then
logo_wait=1
game_update = logo_update
fade.fadeoutin()
end
surf.source(back)
function logo_draw()
-- print("LOGO DRAW "..logo_step)
-- Seleccionar font i destí
surf.source(logo_sf)
surf.target(0)
-- Netejar destí
surf.cls(16)
-- Animació per a l'aparició del logo
if logo_step==1 then
-- Crear les barres
draw.surf(0,0,63,2, logo_anim[1].x0,logo_anim[1].y,logo_anim[1].w,logo_anim[1].h)
draw.surf(0,2,63,2, logo_anim[2].x0,logo_anim[2].y,logo_anim[2].w,logo_anim[2].h)
draw.surf(0,4,63,2, logo_anim[3].x0,logo_anim[3].y,logo_anim[3].w,logo_anim[3].h)
draw.surf(0,6,63,2, logo_anim[4].x0,logo_anim[4].y,logo_anim[4].w,logo_anim[4].h)
draw.surf(0,8,63,2, logo_anim[5].x0,logo_anim[5].y,logo_anim[5].w,logo_anim[5].h)
end
-- presenta
if logo_step==2 then
draw.surf(0,0,63,10, logo_anim[1].x0,logo_anim[1].y,logo_anim[1].w,logo_anim[1].h*5); -- JAILGAMES
draw.surf(0,10,55,10, 100,102,55,10); -- presenta
end
-- pausa
if logo_step==3 then
draw.surf(0,0,63,10, logo_anim[1].x0,logo_anim[1].y,logo_anim[1].w,logo_anim[1].h*5); -- JAILGAMES
draw.surf(0,10,55,10, 100,102,55,10); -- presenta
end
-- Brillo
if logo_step==4 then
draw.surf(0,0,63,10, logo_anim[1].x0,logo_anim[1].y,logo_anim[1].w,logo_anim[1].h*5); -- JAILGAMES
draw.surf(0,10,55,10, 100,102,55,10); -- presenta
-- if logo_step_wait>=1 then
pal.subpal(15,2)
draw.surf(0,0+math.floor(brillo_y),63,1,
logo_anim[1].x0, logo_anim[1].y+math.floor(brillo_y*2), logo_anim[1].w, 1);
pal.subpal(15)
-- end
end
-- Final
if logo_step>=5 then
pal.subpal(15,2)
draw.surf(0,0,63,10, logo_anim[1].x0,logo_anim[1].y,logo_anim[1].w,logo_anim[1].h*5); -- JAILGAMES
draw.surf(0,10,55,10, 100,102,55,10); -- presenta
pal.subpal(15)
end
end
function logo_update()
-- print("LOGO UPDATE "..logo_step)
-- Animació per a l'aparició del logo
if logo_step==1 then
step1_finished = true
logo_step_wait = logo_step_wait+1
if logo_step_wait>=1 then
@@ -81,17 +140,10 @@ function logo_intro()
end
-- presenta
if logo_step==2 then
-- draw.surf(0,0, 63,10, 65,80,126,20); -- JAILGAMES
draw.surf(0,0,63,10, logo_anim[1].x0,logo_anim[1].y,logo_anim[1].w,logo_anim[1].h*5); -- JAILGAMES
draw.surf(0,20,55,10, 100,102,55,10); -- presenta
logo_step = 3
end
if logo_step==2 then logo_step = 3 end
-- pausa
if logo_step==3 then
draw.surf(0,0,63,10, logo_anim[1].x0,logo_anim[1].y,logo_anim[1].w,logo_anim[1].h*5); -- JAILGAMES
draw.surf(0,20,55,10, 100,102,55,10); -- presenta
logo_step_wait = logo_step_wait+1
if logo_step_wait>=20 then
logo_step_wait = 0
@@ -101,31 +153,44 @@ function logo_intro()
-- Brillo
if logo_step==4 then
draw.surf(0,0,63,10, logo_anim[1].x0,logo_anim[1].y,logo_anim[1].w,logo_anim[1].h*5); -- JAILGAMES
draw.surf(0,20,55,10, 100,102,55,10); -- presenta
logo_step_wait = logo_step_wait+1
if logo_step_wait>=1 then
if logo_step_wait>=2 then
logo_step_wait = 0
draw.surf(0,40+math.floor(brillo_y),63,1,
logo_anim[1].x0, logo_anim[1].y+math.floor(brillo_y*2), logo_anim[1].w, 1);
brillo_y = brillo_y-0.5
if brillo_y==0 then logo_step = 5 end
if brillo_y<0 then logo_step = 5 end
end
end
-- Pausa final
if logo_step==5 then
logo_step = 6
logo_wait = 125
end
-- Final
if logo_step>=5 then
draw.surf(0,0,63,10, logo_anim[1].x0,logo_anim[1].y,logo_anim[1].w,logo_anim[1].h*5); -- JAILGAMES
draw.surf(0,20,55,10, 100,102,55,10); -- presenta
if logo_step==5 then logo_wait = 75 end
logo_step = 6
end
if logo_step==6 and logo_wait==0 then logo_step = 7 end
end
function logo_update()
fps_print()
intro_init()
function logo_end()
-- print("LOGO_END")
-- game_update = intro_init
print("logo_end")
flow:executar("intro")
-- surf.free(logo_sf)
end
function logo_animate()
-- print("LOGO_INTRO "..logo_step)
logo_wait=logo_wait-1
-- Següent bucle
if logo_step==7 or controller:check("ESC") or controller:check("shoot") then
local modul, pas=flow:next()
-- print("LOGO_ANIMATE 1= "..modul..", "..pas)
end
logo_draw()
logo_update()
end
flow:registrar("logo",{logo_init, logo_animate, logo_end})

View File

@@ -1,19 +1,25 @@
debug = require "debug"
arcade_config = require("arcade_config")
coords = require "coords"
require "helpers"
require "controller"
require "flow"
require "fps"
require "fade"
require "audio"
require "map"
require "mapa"
require "warp"
require "fade"
require "audio"
require "logo"
require "intro"
require "scenes"
require "title"
require "game"
require "switches"
-- require "scenes"
require "opcions"
require "opcions_input"
require "point"
require "fps"
--require "menu"
coords.set_config({
@@ -24,67 +30,39 @@ coords.set_config({
rooms_per_floor = mapa_rooms_per_piso,
})
function editor_to_map_tile(editor_tile)
local result = 0
if editor_tile<256 then result = editor_tile + arcade_config.tiles_offset end
return result
end
font_default = font.current()
function map_to_editor_tile(map_tile)
local result = map_tile - arcade_config.tiles_offset
if map_tile==0 then result = 256 end
return result
end
function load_tilemap( sf_mapa )
local mapa_tw, mapa_th = surf.size(sf_mapa)
local nrooms = mapa_rooms_per_piso*mapa_pisos
local x = 0
local y = 0
local yroom = 0
local xroom = 0
map.surf(sf_mapa)
for ty=0,mapa_th-1 do
if y == mapa_room_rows then
yroom = yroom + mapa_rooms_per_piso
y = 0
end
xroom = yroom
for tx=0,mapa_tw-1 do
local tile=editor_to_map_tile(mapa[1+xroom][1+x+y*mapa_room_cols])
map.tile(tx, ty, tile)
x = x + 1
if x == mapa_room_cols then
x = 0
xroom = xroom + 1
end
end
y = y +1
end
end
function mini.init()
function images_init()
tiles=surf.load("tiles.gif")
surf.source(tiles)
local paleta=pal.load("tiles.gif")
pal.set(paleta)
tiles2=surf.load("tiles2.gif")
-- Crear el warp
warp.init(tiles)
end
logo=surf.new(arcade_config.logo_sf.width,arcade_config.logo_sf.height)
back=surf.new(arcade_config.surface.width,arcade_config.surface.height)
function image_close()
surf.free(tiles)
warp.close()
end
function fonts_init()
font_sf=font.load("X2_font.fnt")
end
function mapa_init()
sf_mapa=surf.new(mapa_room_cols*mapa_rooms_per_piso,mapa_room_rows*mapa_pisos)
load_tilemap( sf_mapa )
fade.init()
font_sf=font.load("X2_font.fnt")
textsf=surf.new(arcade_config.org_resolucion.width,arcade_config.org_resolucion.height)
end
function audio_init()
-- Càrrega dels audios
audio_text_abad = sound.load(audio_text_abad)
audio_text_premiere = sound.load(audio_text_premiere)
audio_text_elalien = sound.load(audio_text_elalien)
audio_text_batman = sound.load(audio_text_batman)
audio_text_imp = sound.load(audio_text_imp)
audio_abad_jump = sound.load(audio_abad_jump)
audio_abad_fall = sound.load(audio_abad_fall)
audio_abad_hit = sound.load(audio_abad_hit)
@@ -96,29 +74,21 @@ function mini.init()
audio_switch = sound.load(audio_switch)
audio_hit = sound.load(audio_hit)
audio_low = sound.load(audio_low)
end
-- Configuració dels input
keyUp = tonumber(config.key("keyup")) or key.UP
keyDown = tonumber(config.key("keydown")) or key.DOWN
keyLeft = tonumber(config.key("keyleft")) or key.LEFT
keyRight = tonumber(config.key("keyright")) or key.RIGHT
keyJump = tonumber(config.key("keyjump")) or key.UP
keyShoot = tonumber(config.key("keyshoot")) or key.SPACE
btnUp = tonumber(config.key("btnup")) or pad.UP
btnDown = tonumber(config.key("btndown")) or pad.DOWN
btnLeft = tonumber(config.key("btnleft")) or pad.LEFT
btnRight = tonumber(config.key("btnright")) or pad.RIGHT
btnJump = tonumber(config.key("btnjump")) or pad.B
btnShoot = tonumber(config.key("btnshoot")) or pad.A
btnCycle1 = tonumber(config.key("btncycle1")) or pad.RIGHTSHOULDER
btnCycle2 = tonumber(config.key("btncycle2")) or pad.LEFTSHOULDER
btnPause = tonumber(config.key("btnpause")) or pad.START
-- logo_init()
-- intro_init()
game_init()
-- final_init()
function mini.init()
-- back_sf=surf.new(256,192)
math.randomseed(os.time())
fonts_init()
images_init()
mapa_init()
fade.init()
audio_init()
controller:init()
logo_config(font_sf)
surf.target(0)
surf.cls(16)
flow:executar("game")
end
function mini.update()
@@ -134,112 +104,12 @@ function mini.update()
if (game_update) then game_update() end
-- Pausa per a que vaja be en mini 1.5.1
-- local t0 = os.clock()
-- while os.clock()-t0<0.01 do end
-- draw.text(sys.fps(),0,15,2)
end
function arc_text(str, x, y, col)
local curr_surf_tgt = surf.target()
local curr_surf_src = surf.source()
local sw = arcade_config.org_resolucion.width
local sh = arcade_config.org_resolucion.height
local dw = arcade_config.resolucion.width
local dh = arcade_config.resolucion.height
surf.target(textsf)
surf.cls(0)
draw.text(str,0,0,col)
-- print("arc_ "..str)
surf.source(textsf)
surf.target(curr_surf_tgt)
draw.surf(0,0,sw,sh,x,y,dw,dh)
surf.source(curr_surf_src)
function mini.close()
surf.free(font_sf)
end
function arc_textB(str, x, y, col, colB)
local ox, oy = view.origin()
local curr_surf_tgt = surf.target()
local curr_surf_src = surf.source()
local sw = arcade_config.org_resolucion.width
local sh = arcade_config.org_resolucion.height
local dw = arcade_config.resolucion.width
local dh = arcade_config.resolucion.height
colB = colB or 16
surf.target(textsf)
view.origin(0,0)
surf.cls(0)
draw.text(str,0,0,colB)
draw.text(str,1,0,colB)
draw.text(str,2,0,colB)
draw.text(str,0,1,colB)
draw.text(str,2,1,colB)
draw.text(str,0,2,colB)
draw.text(str,1,2,colB)
draw.text(str,2,2,colB)
draw.text(str,1,1,col)
-- print("arc_B "..str)
surf.source(textsf)
surf.target(curr_surf_tgt)
view.origin(ox,oy)
draw.surf(0,0,sw,sh,x,y,dw,dh)
surf.source(curr_surf_src)
end
-- DEBUG
-- Imprime cualquier valor, incluyendo tablas anidadas
function dump(value, indent)
indent = indent or ""
if type(value) ~= "table" then
return tostring(value)
end
local parts = {"{"}
for k, v in pairs(value) do
local key = (type(k) == "string") and k or "["..tostring(k).."]"
table.insert(parts,
string.format("%s %s = %s,",
indent, key, dump(v, indent.." ")))
end
table.insert(parts, indent.."}")
return table.concat(parts, "\n")
end
function msg_print(x, y, msg, direct_print )
local scr_x, scr_y
direct_print = direct_print or false
if direct_print then
scr_x = x
scr_y = y
else
scr_x, scr_y = viewp:screen_coords(x, y)
end
draw.rectf(scr_x,scr_y,45,7,16)
draw.text(msg,scr_x+1,scr_y+1,2)
end
function view_coord(x, y, w, h, color)
local scr_x, scr_y = viewp:screen_coords(x, y)
draw.rect(scr_x, scr_y, w, h, color)
end
function debug.write_tile(x, y, yplus, print_type, align )
local scr_x, scr_y = viewp:screen_coords(x, y)
local hab, xx, yy = coords.world_to_tile(x, y)
yplus = yplus or 0
print_type = print_type or false
align = align or "R"
local txt_offset = -7
if align=="R" then txt_offset = -14
elseif align=="L" then txt_offset = 0
end
draw.rectf(scr_x+txt_offset,scr_y+yplus,14,7,16)
-- local msg = mapa_get_tile(hab,xx,yy)
local msg = arc_get_tile(x,y)
if print_type then
msg = msg.." "..arc_check_tile(x, y)
end
draw.text(msg,scr_x+txt_offset+1,scr_y+1+yplus,2)
end

View File

@@ -1,6 +1,4 @@
require "map"
local arcade_config = require("arcade_config")
-- require "map"
tiletype={void=0,nonpc=1,stair=2,switch=3,half=4,block=5}
mapa.wait=0
@@ -17,23 +15,23 @@ function mapa_is_half_block_tile (ntile)
return half_block_set[ntile]==true
end
function mapa_do_backup()
mapa_backup={}
for i=1,#mapa do
mapa_backup[i]={}
for j=1,#mapa[i] do
mapa_backup[i][j]=mapa[i][j]
end
end
end
function mapa_restore_backup()
for i=1,#mapa do
for j=1,#mapa[i] do
mapa[i][j]=mapa_backup[i][j]
end
end
end
-- function mapa_do_backup()
-- mapa_backup={}
-- for i=1,#mapa do
-- mapa_backup[i]={}
-- for j=1,#mapa[i] do
-- mapa_backup[i][j]=mapa[i][j]
-- end
-- end
-- end
--
-- function mapa_restore_backup()
-- for i=1,#mapa do
-- for j=1,#mapa[i] do
-- mapa[i][j]=mapa_backup[i][j]
-- end
-- end
-- end
function mapa_new()
for my=0,7 do
@@ -140,28 +138,30 @@ function arc_set_tile_by_index(hab,index,tile)
arc_set_tile(world_x, world_y, tile)
end
function arc_get_tile(world_x,world_y)
function arc_get_tile(world_x,world_y, debug)
local map_x, map_y = coords.world_to_mini_tile(world_x,world_y)
if debug then print(map_x..", "..map_y) end
return map.tile(map_x,map_y)
end
function arc_check_tile(world_x,world_y)
function arc_check_tile(world_x,world_y,debug)
-- tiletype => void=0 / nonpc=1 / stair=2 /
-- switch=3 / half=4 / block=5
local tile=map_to_editor_tile(arc_get_tile(world_x, world_y))
local tile=map_to_editor_tile(arc_get_tile(world_x, world_y, debug))
if tile<8 then
return tiletype.half
return tiletype.half, tile
elseif tile<15 then
return tiletype.stair
elseif tile==15 then
return tiletype.switch
return tiletype.stair, tile
-- 23 = Tile transparent, necesari per a dibuixar els switchos en la versió arcade
elseif tile==23 then
return tiletype.switch, tile
elseif tile<64 then
return tiletype.block
return tiletype.block, tile
elseif tile==111 then
return tiletype.nonpc
return tiletype.nonpc, tile
else
return tiletype.void
return tiletype.void, tile
end
end
@@ -178,7 +178,7 @@ function mapa_create_minimap()
print(x..","..y.."="..tile)
end
if tile<64 then
surf.pixel(x+(h%10)*12,y+math.floor(h/10)*6,pix[1+tile])
draw.pixel(x+(h%10)*12,y+math.floor(h/10)*6,pix[1+tile])
end
end
end

276
data/menu.lua Normal file
View File

@@ -0,0 +1,276 @@
function menu_init()
print("MENU INIT")
menu_sel=0
menu_state=update_main_menu;
abad.update = abad_nop
game_update=update_menu
menu_count=0
menu_change_room=300
menu_room=math.random(0,59)
music.play(audio_main_song)
end
function menu_update()
--game_update=update_game
music.stop()
end
function draw_hab(hab,x,y)
end
function mapa_update(hab1, hab2)
end
function redraw_menu_hab()
-- draw_hab(menu_room,16,41)
-- draw.rectf(0,0,15*o2aX,97*o2aX,16)
-- draw.rectf(114*o2aX,0,78*o2aX,97*o2aX,16)
-- draw.rect(15*o2aX,40*o2aX,99*o2aX,50*o2aX,2)
-- mapa_update(abad.hab,menu_room)
-- for key,actor in pairs(actors) do
-- actor:update()
-- end
-- imp.update()
-- bambolla.update()
-- cacau.update()
-- fireball.update()
-- switches.update()
end
function update_menu()
menu_change_room=menu_change_room-1
if menu_change_room==0 then
menu_room = math.random(0,59)
menu_change_room=300
end
surf.cls(16)
draw_title(14*o2aX, 0)
menu_state()
end
function update_options_menu()
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(28*o2aX,(28+(10*menu_sel))*o2aX,73*o2aX,9*o2aX,14)
if (not parpadeig) then draw.rect(28*o2aX,(28+(10*menu_sel))*o2aX,73*o2aX,9*o2aX,13) end
arc_text("MÚSICA", 30*o2aX, 30*o2aX, 14); arc_text(music.enabled() and "SI" or "NO",91*o2aX,30*o2aX,15)
arc_text("", 30*o2aX, 40*o2aX, 14); arc_text(sound.enabled() and "SI" or "NO",91*o2aX,40*o2aX,15)
arc_text("REDEFINIR TECLAT", 30*o2aX, 50*o2aX, 14)
arc_text("REDEFINIR GAMEPAD", 30*o2aX, 60*o2aX, 14)
arc_text("TORNAR", 30*o2aX, 70*o2aX, 14)
if key.press(keyShoot) or key.press(key.SPACE) or pad.press(pad.A) or pad.press(btnShoot) then
if menu_sel==0 then
music.enabled(not music.enabled())
if music.enabled() then music.play(audio_main_song) end
elseif menu_sel==1 then
sound.enabled(not sound.enabled())
elseif menu_sel==2 then
menu_count=0
menu_state=update_redefine_keys_menu
elseif menu_sel==3 then
menu_count=0
menu_state=update_redefine_pad_menu
else
menu_count=0
menu_sel=0
menu_state=update_main_menu
end
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==5 then menu_sel=0 end
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=4 end
elseif key.press(key.ESCAPE) or pad.press(btnPause) then
menu_count=0
menu_sel=0
menu_state=update_main_menu
end
end
function update_main_menu()
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(28*o2aX,(18+(10*menu_sel))*o2aX,73*o2aX,9*o2aX,14)
if (not parpadeig) then draw.rect(28*o2aX,(18+(10*menu_sel))*o2aX,73*o2aX,9*o2aX,13) end
arc_text("JUGAR", 54*o2aX, 20*o2aX, 14)
arc_text("OPCIONS", 50*o2aX, 30*o2aX, 14)
--if (not parpadeig or menu_sel~=2) then text("REDEFINIR GAMEPAD", 30, 32, 13) end
redraw_menu_hab()
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()
fade.fadeoutin()
elseif menu_sel==1 then
menu_count=0
menu_sel=0
menu_state=update_options_menu--update_redefine_keys_menu;
else
menu_count=0
menu_state=update_redefine_pad_menu
end
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==2 then menu_sel=0 end
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=1 end
elseif key.press(key.ESCAPE) or pad.press(btnPause) then
sys.quit()
end
end
function update_redefine_keys_menu()
if key.press(key.ESCAPE) then
menu_count = 0
menu_state = update_options_menu;
end
if menu_count==0 then
arc_textB("PULSA TECLA PER A AMUNT", 20*o2aX, 24*o2aX, 13)
local k = key.press();
if k ~= 0 and k~=key.ESCAPE then
menu_count = 1
keyUp=k
config.key("keyup", keyUp)
end
elseif menu_count==1 then
arc_textB("PULSA TECLA PER A AVALL", 20*o2aX, 24*o2aX, 13)
local k = key.press();
if k ~= 0 and k~=key.ESCAPE then
menu_count = 2
keyDown=k
config.key("keydown", keyDown)
end
elseif menu_count==2 then
arc_textB("PULSA TECLA PER A ESQUERRA", 14*o2aX, 24*o2aX, 13)
local k = key.press();
if k ~= 0 and k~=key.ESCAPE then
menu_count = 3
keyLeft=k
config.key("keleft", keyLeft)
end
elseif menu_count==3 then
arc_textB("PULSA TECLA PER A DRETA", 20*o2aX, 24*o2aX, 13)
local k = key.press();
if k ~= 0 and k~=key.ESCAPE then
menu_count = 4
keyRight=k
config.key("keyright", keyRight)
end
elseif menu_count==4 then
arc_textB("PULSA TECLA PER A BOTAR", 20*o2aX, 24*o2aX, 13)
local k = key.press();
if k ~= 0 and k~=key.ESCAPE then
menu_count = 5
keyJump=k
config.key("keyjump", keyJump)
end
elseif menu_count==5 then
arc_textB("PULSA TECLA PER A DISPAR", 18*o2aX, 24*o2aX, 13)
local k = key.press();
if k ~= 0 and k~=key.ESCAPE then
menu_count = 0
menu_state = update_options_menu;
keyShoot=k
config.key("keyshoot", keyShoot)
end
end
end
function update_redefine_pad_menu()
if key.press(key.ESCAPE) then
menu_count = 0
menu_state = update_options_menu;
end
if menu_count==0 then
arc_textB("PULSA BOTÓ PER A AMUNT", 22*o2aX, 24*o2aX, 13)
local btn = pad.press();
if btn ~= -1 then
menu_count = 1
btnUp=btn
config.key("btnup", btnUp)
end
elseif menu_count==1 then
arc_textB("PULSA BOTÓ PER A AVALL", 22*o2aX, 24*o2aX, 13)
local btn = pad.press();
if btn ~= -1 then
menu_count = 2
btnDown=btn
config.key("btndown", btnDown)
end
elseif menu_count==2 then
arc_textB("PULSA BOTÓ PER A ESQUERRA", 16*o2aX, 24*o2aX, 13)
local btn = pad.press();
if btn ~= -1 then
menu_count = 3
btnLeft=btn
config.key("keleft", btnLeft)
end
elseif menu_count==3 then
arc_textB("PULSA BOTÓ PER A DRETA", 22*o2aX, 24*o2aX, 13)
local btn = pad.press();
if btn ~= -1 then
menu_count = 4
btnRight=btn
config.key("btnright", btnRight)
end
elseif menu_count==4 then
arc_textB("PULSA BOTÓ PER A BOTAR", 22*o2aX, 24*o2aX, 13)
local btn = pad.press();
if btn ~= -1 then
menu_count = 5
btnJump=btn
config.key("btnjump", btnJump)
end
elseif menu_count==5 then
arc_textB("PULSA BOTÓ PER A DISPAR", 20*o2aX, 24*o2aX, 13)
local btn = pad.press();
if btn ~= -1 then
menu_count = 6
btnShoot=btn
config.key("btnshoot", btnShoot)
end
elseif menu_count==6 then
arc_textB("PULSA BOTÓ PER A GPS ARRERE", 14*o2aX, 24*o2aX, 13)
local btn = pad.press();
if btn ~= -1 then
menu_count = 7
btnCycle1=btn
config.key("btncycle1", btnCycle1)
end
elseif menu_count==7 then
arc_textB("PULSA BOTÓ PER A GPS AVANT", 14*o2aX, 24*o2aX, 13)
local btn = pad.press();
if btn ~= -1 then
menu_count = 8
btnCycle2=btn
config.key("btncycle2", btnCycle2)
end
elseif menu_count==8 then
arc_textB("PULSA BOTÓ PER A PAUSA", 22*o2aX, 24*o2aX, 13)
local btn = pad.press();
if btn ~= -1 then
menu_count = 0
menu_state = update_options_menu;
btnPause=btn
config.key("btnpause", btnPause)
end
end
end

BIN
data/mus_imp.ogg Normal file

Binary file not shown.

62
data/opcions.lua Normal file
View File

@@ -0,0 +1,62 @@
local menu_sel = 0
function opcions_init()
-- flow:add_path({opcions_show, opcions_end})
flow:next()
end
function opcions_draw()
surf.cls(16)
draw_shiny_rect(56,(56+(20*menu_sel)),146,18,14,15)
-- if (not parpadeig) then draw.rect(28*o2aX,(28+(10*menu_sel))*o2aX,73*o2aX,9*o2aX,13) end
arc_text("MÚSICA", 60, 60, 14); arc_text(music.enabled() and "SI" or "NO",91*o2aX,30*o2aX,15)
arc_text("", 60, 80, 14); arc_text(sound.enabled() and "SI" or "NO",91*o2aX,40*o2aX,15)
arc_text("REDEFINIR TECLAT", 60, 100, 14)
arc_text("REDEFINIR GAMEPAD", 60, 120, 14)
arc_text("TORNAR", 60, 140, 14)
end
function opcions_update()
if key.press(keyShoot) or key.press(key.SPACE) or pad.press(pad.A) or pad.press(btnShoot) then
if menu_sel==0 then
music.enabled(not music.enabled())
if music.enabled() then music.play(audio_main_song) end
elseif menu_sel==1 then
sound.enabled(not sound.enabled())
elseif menu_sel==2 then
-- menu_count=0
-- menu_state=update_redefine_keys_menu
flow:executar("opcions_teclat", true)
elseif menu_sel==3 then
-- menu_count=0
-- menu_state=update_redefine_pad_menu
flow:executar("opcions_gamepad", true)
else
-- Tornar
flow:next()
end
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==5 then menu_sel=0 end
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=4 end
elseif key.press(key.ESCAPE) or pad.press(btnPause) then
-- Tornar desde qualsevol lloc
flow:next()
end
end
function opcions_show()
opcions_draw()
opcions_update()
end
function opcions_end()
print("opcions_end")
-- flow:restore()
flow:finish()
end
flow:registrar("opcions",{opcions_init, opcions_show, opcions_end})

127
data/opcions_input.lua Normal file
View File

@@ -0,0 +1,127 @@
local input_type=controller.input.kb
local input_keys={}
local menu_opt = 0
function opcions_teclat_init()
input_type=controller.input.kb
-- definició de tecles a configurar en ordre
input_keys = controller.kb_keys
opcions_input_init()
end
function opcions_gamepad_init()
input_type=controller.input.pad
-- definició de botons a configurar en ordre
input_keys = controller.pad_keys
opcions_input_init()
end
function opcions_input_init()
surf.target(0)
surf.cls(16)
menu_opt = 1
flow:next()
end
function opcions_input_draw()
surf.target(0)
surf.cls(16)
local s=""
if input_type==controller.input.kb then
s="PULSA TECLA PER A "
if menu_opt==1 then
arc_textB(s.."AMUNT", 40, 48, 13)
elseif menu_opt==2 then
arc_textB(s.."AVALL", 40, 48, 13)
elseif menu_opt==3 then
arc_textB(s.."ESQUERRA", 28, 48, 13)
elseif menu_opt==4 then
arc_textB(s.."DRETA", 40, 48, 13)
elseif menu_opt==5 then
arc_textB(s.."BOTAR", 40, 48, 13)
elseif menu_opt==6 then
arc_textB(s.."DISPAR", 36, 48, 13)
end
elseif input_type==controller.input.pad then
s="PULSA BOTÓ PER A "
if menu_opt==1 then
arc_textB(s.."AMUNT", 44, 48, 13)
elseif menu_opt==2 then
arc_textB(s.."AVALL", 44, 48, 13)
elseif menu_opt==3 then
arc_textB(s.."ESQUERRA", 32, 48, 13)
elseif menu_opt==4 then
arc_textB(s.."DRETA", 44, 48, 13)
elseif menu_opt==5 then
arc_textB(s.."BOTAR", 44, 48, 13)
elseif menu_opt==6 then
arc_textB(s.."DISPAR", 40, 48, 13)
elseif menu_opt==7 then
arc_textB(s.."GPS ARRERE", 28, 48, 13)
elseif menu_opt==8 then
arc_textB(s.."GPS AVANT", 28, 48, 13)
elseif menu_opt==9 then
arc_textB(s.."PAUSA", 44, 48, 13)
end
end
end
function opcions_input_update()
local curr_key = input_keys[menu_opt]
if key.press(key.ESCAPE) then
flow:next()
return
end
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)
config_key(curr_key, k)
menu_opt = menu_opt+1
end
elseif input_type==controller.input.pad then
local btn = pad.press();
if btn ~= -1 then
config_key(curr_key, btn)
menu_opt = menu_opt+1
end
end
if menu_opt >#input_keys then menu_opt=1 end
end
function opcions_input_show()
opcions_input_draw()
opcions_input_update()
end
function opcions_input_end()
menu_opt = 0
flow:finish()
end
function config_key(def_key, k)
local end_setup=false
local valid_key = true
if (input_type==controller.input.kb and def_key.name=="shoot")
or (input_type==controller.input.pad and def_key.name=="pause") then
end_setup = true
end
if not controller:define(def_key.code, k) then valid_key=false end
if valid_key then
print("DEFINED > "..def_key.name..", "..def_key.code.." = "..k)
config.key(def_key.code, k)
else
print("ERROR AL DEFINIR")
end
if end_setup then flow:next() end
end
flow:registrar("opcions_teclat", { opcions_teclat_init, opcions_input_show, opcions_input_end } )
flow:registrar("opcions_gamepad", { opcions_gamepad_init, opcions_input_show, opcions_input_end } )

252
data/pattern.lua Normal file
View File

@@ -0,0 +1,252 @@
pattern={}
PATTERN_RANDOM = "random"
PATTERN_CHASE = "chase"
PATTERN_AVOID = "avoid"
function pattern.new()
return {
node = {}, -- array de punts ( node[1] = punt1,... node[n] = puntN )
path = {}, -- array de camins entre nodes ( path[1] = { {target=2, actions={ {action="right", until="land"} ...} } ...} )
path_idx = 0, -- punter a path actiu (coincidix en el node)
target_idx = 1, -- punter a target actiu, no al número de target si no a l'index dins del path
action_idx = 1, -- punter a l'acció actual
manual_target = {},
manual_path = {},
poi = {}, -- points of interest
-- target_modes = { PATTERN_RANDOM, PATTERN_CHASE, PATTERN_AVOID },
target_mode = PATTERN_RANDOM,
next_action = pattern.next_action,
next_target = pattern.next_target,
in_target = pattern.in_target,
target = pattern.target,
target_node = pattern.target_node,
action = pattern.action,
event = pattern.event,
actions = pattern.actions,
-- recovery = pattern.noop,
draw = pattern.draw,
collision = pattern.collision,
add_manual_target = pattern.add_manual_target,
set_target_mode = pattern.set_target_mode,
}
end
function pattern:set_target_mode ( mode, poi )
self.poi = poi or {}
self.target_mode = mode
end
function pattern:add_manual_target ( node, path )
self.manual_target = self.node[node]
self.manual_path = path
self.target_idx = 1
self.action_idx = 1
end
function pattern:noop()
print("NO OP")
end
function pattern:draw()
-- if true then return end
local scr_x = 0
local scr_y = 0
local target = self:target()
for k, v in pairs(self.node) do
scr_x, scr_y = viewp:screen_coords( v.x, v.y )
if self.path_idx==k or target==k then
draw.rectf(scr_x, scr_y, 16, 16, 13)
else
draw.rectf(scr_x, scr_y, 16, 16, 16)
draw.rect(scr_x, scr_y, 16, 16, k)
end
if target ~= nil and target==k then
draw.rectf(scr_x, scr_y, 16, 16, 15)
end
draw.text(k, scr_x+4, scr_y+4, k)
end
end
-- Necessite saber quina estrategia aplicar abans de moure al següent target
-- ara aleatori
function pattern:origin()
print_dbg("")
return self.node[self.path_idx]
end
function pattern:origin_num ()
print_dbg("")
return self.path_idx
end
function pattern:set_path ( num )
print_dbg("")
self.path_idx = num
end
function pattern:get_path ( num )
print_dbg("")
return self.path[num]
end
-- [OK] Torna el id del target actual
-- function pattern:get_target ( )
-- return self.path[self.path_idx][target_idx].target
-- end
function pattern:target()
if not empty_table(self.manual_path) then
-- print_dbg("MANUAL => "..self.manual_path.target)
return self.manual_path.target
else
if #self.path>0 then
-- print_dbg("PATH => "..self.path[self.path_idx][self.target_idx].target)
return self.path[self.path_idx][self.target_idx].target
end
end
return nil
end
-- [OK] Torna la llista d'accions actual
-- function pattern:get_actions ( )
-- return self.path[self.path_idx][target_idx].actions
-- end
function pattern:actions()
print_dbg("")
if not empty_table(self.manual_path) then
return self.manual_path.actions
else
return self.path[self.path_idx][self.target_idx].actions
end
end
-- [OK] Torna l'acció actual
-- function pattern:get_action ( )
-- return self.path[self.path_idx][target_idx].actions[self.action_idx]
-- end
function pattern:action()
if not empty_table(self.manual_path) then
-- print_dbg("MANUAL => "..self.manual_path.actions[self.action_idx].action)
return self.manual_path.actions[self.action_idx].action
else
-- print_dbg("PATH => "..self.path[self.path_idx][self.target_idx].actions[self.action_idx].action)
return self.path[self.path_idx][self.target_idx].actions[self.action_idx].action
end
end
-- [OK] Torna l'event actual
function pattern:event()
-- print_dbg("")
if not empty_table(self.manual_path) then
return self.manual_path.actions[self.action_idx].event
else
return self.path[self.path_idx][self.target_idx].actions[self.action_idx].event
end
end
-- [OK] Obtindre la següent acció a fer
-- function pattern:next()
-- self.action_idx = self.action_idx+1
-- if self.action_idx>#self.path[self.path_idx][self.target_idx].actions then
-- pattern:next_target() -- pasar per paràmetre o no
-- end
-- return pattern:action()
-- end
function pattern:next_action ( )
-- print_dbg("")
local num_actions = 0
-- index a la següent acció
self.action_idx = self.action_idx+1
-- comprovar si no queden accions disponibles
if not empty_table(self.manual_path) then
num_actions = #self.manual_path.actions
else
num_actions = #self.path[self.path_idx][self.target_idx].actions
end
if self.action_idx>num_actions then
-- avançar el target
self:next_target() -- pasar per paràmetre o no
end
-- Tornar l'acció
return self:action()
end
-- [OK] Canvia al següent target segons el path o al que se li pase
function pattern:next_target( target )
-- print_dbg("")
target = target or self:target()
-- Si hi ha una entrada manual eliminar-la
if not empty_table(self.manual_path) then
self.manual_path = {}
self.manual_target = {}
end
-- target id
self.path_idx = target
-- tindre en compte l'estrategia per a triar el següent target des del path actual per ara aleatori
if self.poi.x == nil or self.poi.y == nil then
self.target_mode = PATTERN_RANDOM
end
if #self.path[self.path_idx]==1 then
self.target_idx = 1
elseif self.target_mode == PATTERN_RANDOM then
self.target_idx = math.random(#self.path[self.path_idx])
else
-- calcular distancies
local next_target_min = 0
local next_target_max = 0
local min_distance = -1
local max_distance = 0
local d = 0
for k, v in pairs(self.path[self.path_idx]) do
d = distancia( self.node[v.target], self.poi )
if d>max_distance then
max_distance = d
next_target_max = k
end
if min_distance==-1 and d>=0 then min_distance=d+1 end
if d<min_distance and d>=0 then
min_distance = d
next_target_min = k
end
end
-- asignar target segons el mode
if self.target_mode==PATTERN_CHASE then
self.target_idx = next_target_min
elseif self.target_mode==PATTERN_AVOID then
self.target_idx = next_target_max
else
self.target_idx = math.random(#self.path[self.path_idx])
end
end
self.action_idx = 1
end
-- [OK] Torna el node del target actual
function pattern:target_node()
-- print_dbg(self.node[self:target()])
return self.node[self:target()]
end
-- Comprova si point ha arribat al target (Afegir precissio per si volem que estiga nomes tocar, dins o abans d'eixir?)
function pattern:in_target( a )
--if collision( a, self:target_node() ) then
-- print_dbg("COLLISION")
--else
-- print_dbg("-")
--end
return self:collision( a )
end
function pattern:collision( a )
local b = self:target_node()
return (a.x+a.bb.x+a.bb.w >= b.x+b.bb.x)
and (a.x+a.bb.x <= b.x+b.bb.x+b.bb.w)
and (a.y+a.bb.y+a.bb.h >= b.y+b.bb.y)
and (a.y+a.bb.y+a.bb.h == b.y+b.bb.y+b.bb.h) -- part de baix dels dos
end

View File

@@ -10,7 +10,8 @@ peu_gif_row = 2
peu={name="peu",hab=5,x=6,y=3,w=32,h=32,bb={x=0,y=0,w=16,h=16}}
function peu.init()
local habs={{18,8},{16,2},{16,7},{15,5},{27,1},{27,10},{29,2},{38,8},{69,2},{79,3}}
-- local habs={{18,8},{16,2},{16,7},{15,5},{27,1},{27,10},{29,2},{38,8},{69,2},{79,3}}
local habs={{69,0},{78,6},{59,8},{27,8},{16,0},{18,8}}
local r=1+math.random(0,#habs-1)
peu.hab=habs[r][1]
-- peu.x=habs[r][2]*8
@@ -37,16 +38,16 @@ function peu.draw()
end
function peu.update()
-- if peu.hab==abad.hab then
-- if aabb(abad,peu) then
-- abad.objects.peu=true
-- if elalien.scene_intro then
-- start_scene(scenes.peu_trobat)
-- else
-- start_scene(scenes.peu_trobat_nointro)
-- end
-- if abad.objects.gps~=nil then current_camera=4 end
-- remove_actor(peu)
-- end
-- end
if peu.hab==abad.hab then
if collision(abad,peu) then
abad.objects.peu=true
if elalien.scene_intro then
start_scene(scenes.peu_trobat)
else
start_scene(scenes.peu_trobat_nointro)
end
-- if abad.objects.gps~=nil then current_camera=4 end
remove_actor(peu)
end
end
end

33
data/point.lua Normal file
View File

@@ -0,0 +1,33 @@
point={}
function point.new(_hab,_x,_y,_x_offset,_y_offset,_id)
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
_x_offset = _x_offset or 0
_y_offset = _y_offset or 0
return {name="point",
id=_id,
hab=_hab,
x=world_x+_x_offset,
y=world_y+_y_offset,
w=16,
h=16,
draw=point.draw,
bb={x=4,y=0,w=8,h=16},
}
end
function point:draw(fill)
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
-- debug rect
if not fill then
draw.rect(scr_x,scr_y,self.w,self.h,3)
-- draw.rect(scr_x+self.bb.x,scr_y,self.bb.w,self.h,2)
else
draw.rectf(scr_x,scr_y,self.w,self.h,3)
-- draw.rectf(scr_x+self.bb.x,scr_y,self.bb.w,self.h,2)
end
end
function point:update()
-- do nothing
end

View File

@@ -1,8 +1,4 @@
o2aX = arcade_config.org2arc_escala
cxr = arcade_config.character_per_row-1
cxr2 = arcade_config.character_per_row_base2
cw = arcade_config.character_width
ch = arcade_config.character_height
premiere={name="premiere",
hab=75,
@@ -10,18 +6,18 @@ premiere={name="premiere",
y=24,
w=32,
h=32,
flip=true,
flip=false,
frame=12,
wait=0,
step=0,
anim={12,13,12,14},
bb={x=4,y=0,w=8,h=16},
bb={x=0,y=0,w=32,h=32},
scene_intro=false,
scene_object=false}
function premiere.init()
-- premiere.x=24
premiere.x=3
premiere.x=4
-- premiere.y=24
premiere.y=3
premiere.w=32
@@ -33,8 +29,11 @@ function premiere.init()
premiere.update=premiere.update_stay
premiere.scene_intro=false
premiere.scene_object=false
-- local habs={75,44,20,0}
local habs={75,44,20,0}
premiere.hab=habs[1+math.random(0,3)]
-- premiere.hab=habs[1+math.random(0,3)]
premiere.hab=0
local world_x, world_y = coords.room_to_world(premiere.hab,premiere.x,premiere.y)
premiere.x=world_x
@@ -43,14 +42,24 @@ function premiere.init()
end
function premiere.draw()
-- draw.surf((premiere.frame&7)*16,(premiere.frame>>3)*16,16,16,premiere.x,premiere.y,16,16,premiere.flip)
-- draw.surf((premiere.frame&7)*cw,(premiere.frame>>cxr2)*ch,cw,ch,premiere.x*o2aX,premiere.y*o2aX,cw,ch,premiere.flip)
local scr_x, scr_y = viewp:screen_coords( premiere.x, premiere.y )
-- draw.surf(premiere.x,premiere.y,premiere.w,premiere.h,scr_x,scr_y,premiere.w,premiere.h)
local x = (premiere.frame&7)*cw
local y = (premiere.frame>>cxr2)*ch
draw.surf(x,y,cw,ch,scr_x,scr_y,premiere.w,premiere.h,premiere.flip)
local x = (premiere.frame&7)*premiere.w
local y = (premiere.frame>>cxr2)*premiere.h
if premiere.update == premiere.update_stay then
-- dibuixar a premiere excepte els peus
draw.surf(x,y,premiere.w,premiere.h-8,scr_x,scr_y,premiere.w,premiere.h-8,premiere.flip)
-- dibuixar peus statics
scr_y = scr_y + 24; -- Posició dels peus en pantalla
if premiere.frame==13 then
draw.surf(224,16,premiere.w,8,scr_x,scr_y,premiere.w,8,premiere.flip)
elseif premiere.frame==14 then
draw.surf(224,24,premiere.w,8,scr_x,scr_y,premiere.w,8,premiere.flip)
else
draw.surf(x,y+24,premiere.w,8,scr_x,scr_y,premiere.w,8,premiere.flip)
end
else
draw.surf(x,y,premiere.w,premiere.h,scr_x,scr_y,premiere.w,premiere.h,premiere.flip)
end
end
function premiere.hit()
@@ -59,11 +68,32 @@ end
function premiere.update_stay()
premiere.wait=premiere.wait+1
if premiere.wait==6 then
if premiere.wait==96 then
premiere.wait=0
premiere.step=(premiere.step+1)%4
premiere.frame=premiere.anim[premiere.step+1]
end
if premiere.hab==abad.hab then
if collision(abad,premiere) then
if not premiere.scene_intro then
if abad.objects.gorro~=nil then
start_scene(scenes.premiere_intro_gorro)
premiere.scene_object=true
abad.objects.clau_premiere=true
abad.objects.gorro=nil
else
start_scene(scenes.premiere_intro)
end
premiere.scene_intro=true
elseif not premiere.scene_object and abad.objects.gorro~=nil then
start_scene(scenes.premiere_gorro)
premiere.scene_object=true
abad.objects.clau_premiere=true
abad.objects.gorro=nil
end
end
end
end
function premiere.update_normal()

36
data/remote_view.lua Normal file
View File

@@ -0,0 +1,36 @@
remote_view_wait = 0
remote_view_hab = ""
remote_sf_w = mapa_room_cols*arcade_config.tiles_width
remote_sf_h = mapa_room_rows*arcade_config.tiles_height
function remote_view_init ()
sf_remote=surf.new(remote_sf_w, remote_sf_h)
end
function remote_view(hab)
remote_view_hab = hab
remote_view_wait = 200
end
function remote_view_draw()
if remote_view_wait>0 then
local x,y = coords.room_to_coord ( remote_view_hab )
local curr_source = surf.source()
local curr_target = surf.target()
surf.target(sf_remote)
surf.cls(16)
render_map(sf_mapa, tiles, x, y, sf_remote )
surf.source(curr_source)
surf.target(curr_target)
local curr_source = surf.source()
surf.source(sf_remote)
draw.surf(0,0,remote_sf_w,remote_sf_h,11,11,(remote_sf_w/2)-2,(remote_sf_h/2)-2)
draw.rect(10,10,(remote_sf_w/2),(remote_sf_h/2),2)
surf.source(curr_source)
remote_view_wait = remote_view_wait-1
end
end

439
data/scenes.lua Normal file
View File

@@ -0,0 +1,439 @@
-- require "final"
-- require "audio"
o2aX = arcade_config.org2arc_escala
avatar_abad_x = 6
avatar_abad2_x = 6
avatar_abad_y = 0
avatar_batman_x = 8
avatar_batman_y = 96
avatar_premiere_x = 138
avatar_premiere_y = 40
avatar_elalien_x = 6
avatar_elalien_y = 32
avatar_w = 22
avatar_h = 21
avatar_photo_w = avatar_w*2
avatar_photo_h = avatar_h*2
avatar_imp_x = 134
avatar_imp_y = 96
avatar_sf=surf.new(avatar_w, avatar_h)
scene={
running = false,
stop_music = true
}
scenes={
lluita_imp= {
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Eh!?","...","MANTE! Tu de qui eres?"},die=20},
{x=avatar_imp_x, y=avatar_imp_y,flip=true,audio="imp",text={"","Aaaarrrrgghhh",""},die=20,musica=audio_song_imp},
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Ah! Que eres foraster","Que fas açí? Has","vingut a per pelailles?"},die=20},
{x=avatar_imp_x, y=avatar_imp_y,flip=true,audio="imp",text={"","Grwuuuunnnn",""},die=20},
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Pos jo lo unic que","tinc es un grapat","de cacaus"},die=20},
{x=avatar_imp_x, y=avatar_imp_y,flip=true,audio="imp",text={"","GROOOOAAAARRR",""},die=20},
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Haver parat en Alcoi!","A mi que me contes!"," CACAUS A MI!!!!"},die=20},
},
llibre_trobat={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Este llibre...","Es el de les tècniques","especials dels abad..."},mood="interessant"},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"...","TÈCNICA 'CACAU AERI'","salt i dispar"}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Ja se"," 'CACAU AERI'",""}},
},
intro_01= {
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Ah!, què bo!","Nit de Netflix amb","un bon bol de cacaus!"},die=20},
},
intro_02= {
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Eh! On està el","bol de cacaus???",""},die=20, mood="sorpresa"},
},
intro_03= {
{x=avatar_batman_x,y=avatar_batman_y,flip=true,audio="batman",musica=audio_song_batman,text={"ME L'HE ENDUT JO!!!", "S'HAN ACABAT ELS","CACAUS PA TU!"},die=20},
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Què??","Però perquè???",""},die=20},
{x=avatar_batman_x,y=avatar_batman_y,flip=true,audio="batman",text={"Estàs com una vaca!","Has de deixar de menjar", "eixes gorrinades"},die=20},
{x=avatar_batman_x,y=avatar_batman_y,flip=true,audio="batman",text={"Mira'm a mi. Estic","tot buenorro i faig", "esport"},die=20},
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Esport?????","I una merda!!","He de cuidar la panxa!"},die=20},
{x=avatar_batman_x,y=avatar_batman_y,flip=true,audio="batman",text={"Pos t'aguantes.","Ja pots despedir-te", "dels cacaus..."},die=20},
},
intro_04= {
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Serà mamó...","",""},die=20},
},
abad_inici={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Se va a enterar eixe","imbècil de Batman","quan el pille..."}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Ràpid! A casa de Batman!","Abans de que se menje","tots el cacaus"}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Vaig a parlar en Premiere","que està al pis de dalt", "a vore si me pot ajudar"}},
},
abad_corfes={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Osti, està ple de","monstruacos.",""}, mood="sorpresa"},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Els enviaré a altra","dimensió d'una cacauà!",""}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Si van altets","igual val la pena","ajupir-se..."}}
},
abad_portes={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Qui ha tancat totes","les portes?","",mood="interessant"}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"A saber on està","cada interruptor","per a obrir-les..."}},
},
abad_porta_casa={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Vaja, la porta de","casa també està","tancada."}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Però he de eixir!","Batman viu en la","casa de davant!"}},
},
abad_porta_batman={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Be, era de esperar","que Batman tinguera","la porta tancada."}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Crec que hi havia","un passadis secret","del meu sotan al seu."}},
},
gps_trobat={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Ale, ja tinc el GPS.","Ara puc trobar tot","el que necessite..."}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"polsant les tecles","de l'1 al 5",""}},
},
premiere_intro={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",musica=audio_song_premiere,text={"Premiere??","Qué fas per ma casa?",""}},
{x=avatar_premiere_x,y=avatar_premiere_y,flip=true,audio="premiere",text={"Porca miseria!!","l'uomo pipistrello!!","m'ha llevatto il gorro!"}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Pipistrello??","Això ques??",""}},
{x=avatar_premiere_x,y=avatar_premiere_y,flip=true,audio="premiere",text={"Il batmano!!","Incontrame il gorro","per l'amore d'un porco!"}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Tinc faena. A mi m'ha","furtat els cacaus i","he de trobarlos."}},
{x=avatar_premiere_x,y=avatar_premiere_y,flip=true,audio="premiere",text={"Lei tenne in su quarto!","Io tengo micha clave!","Achudame i t'achudo!"}}
},
premiere_intro_gorro={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",musica=audio_song_premiere,text={"Premiere??","Qué fas per ma casa?",""}},
{x=avatar_premiere_x,y=avatar_premiere_y,flip=true,audio="premiere",text={"Porca miseria!!","l'uomo pipistrello!!","m'ha llevatto il gorro!"}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Pipistrello??","Això... be, te igual","Ací el tens, atontat."}},
{x=avatar_premiere_x,y=avatar_premiere_y,flip=true,audio="premiere",text={"Per fortuna!","Grazie mille!","Come podo achudarte?"}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Pos Batman m'ha furtat","els cacaus. Supose que","els te amagats."}},
{x=avatar_premiere_x,y=avatar_premiere_y,flip=true,audio="premiere",text={"In lo suo quarto!","Io tengo micha clave!","Tenne, tenne!!"}}
},
premiere_gorro={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",musica=audio_song_premiere,text={"Tin, el ditxos gorro.","",""}},
{x=avatar_premiere_x,y=avatar_premiere_y,flip=true,audio="premiere",text={"Bravissimo!","Che giornatta","fantastica! Figo!"}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Tu si que eres un","figo. On està eixa","mitja clau?"}},
{x=avatar_premiere_x,y=avatar_premiere_y,flip=true,audio="premiere",text={"Giusto! Aquí tenne!","Buona fortuna per","la tua avventura!"}},
{x=avatar_premiere_x,y=avatar_premiere_y,flip=true,audio="premiere",text={"E NON TOCARE il","Batmano! Sei molto","poderoso!"}}
},
gorro_trobat_nointro={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Mira, el gorro","de Premiere.","Millor l'agafe."}}
},
gorro_trobat={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Mira, el gorro","de Premiere.","A la saca."}}
},
elalien_intro={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",musica=audio_song_elalien,text={"Que passa alien?","A tu també t'ha","putejat el Batman?"}},
{x=avatar_elalien_x,y=avatar_elalien_y,flip=true,audio="elalien",text={"CAGUEN L'OU!!","ESTAVA JO TAN TRANQUIL","PODANT AL MEU GOS..."}},
{x=avatar_elalien_x,y=avatar_elalien_y,flip=true,audio="elalien",text={"...I QUAN NO MIRABA","M'HA FURTAT EL","MARANÀ!!!"}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Es...taves podant","a un gos...?",""}},
{x=avatar_elalien_x,y=avatar_elalien_y,flip=true,audio="elalien",text={"EN JUPITER NO POTS","DEIXAR QUE LI CREIXEN","MES DE 12 PATES!!"}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Uh... clar...","A mi m'ha furtat","els cacaus."}},
{x=avatar_elalien_x,y=avatar_elalien_y,flip=true,audio="elalien",text={"ELS TÉ EN LA SEUA","HABITACIÓ SEGUR.","TROBA EL BERENAR..."}},
{x=avatar_elalien_x,y=avatar_elalien_y,flip=true,audio="elalien",text={"...I JO ET DONARÉ","LA MEITAT DE LA CLAU","PER A ENTRAR."}}
},
elalien_intro_peu={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",musica=audio_song_elalien,text={"Que passa alien?","A tu també t'ha","putejat el Batman?"}},
{x=avatar_elalien_x,y=avatar_elalien_y,flip=true,audio="elalien",text={"CAGUEN L'OU!!","ESTAVA JO TAN TRANQUIL","PODANT AL MEU GOS..."}},
{x=avatar_elalien_x,y=avatar_elalien_y,flip=true,audio="elalien",text={"...I QUAN NO MIRABA","M'HA FURTAT EL","MARANÀ!!!"}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Podant...? be, te","igual. Açò deu ser","el teu berenar."}},
{x=avatar_elalien_x,y=avatar_elalien_y,flip=true,audio="elalien",text={"OSTI QUE BÓ!!!","GRACIES AUELO!","A TU QUE T'HA FET?"}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"M'ha furtat els cacaus.","Segur que els té","al seu quarto."}},
{x=avatar_elalien_x,y=avatar_elalien_y,flip=true,audio="elalien",text={"SEGUR! PERO JO TINC","LA MEITAT DE LA CLAU.","TIN, I SORT!"}}
},
elalien_peu={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",musica=audio_song_elalien,text={"Ací tens...","Uff, que peste fa...",""}},
{x=avatar_elalien_x,y=avatar_elalien_y,flip=true,audio="elalien",text={"GRACIES!!!","SÍ, EH? QUE","SUCOSET I BÓ."}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Clar...","Be, i eixa","mitja clau?"}},
{x=avatar_elalien_x,y=avatar_elalien_y,flip=true,audio="elalien",text={"TIN! QUAN TINGUES","ELS CACAUS, PEGA-LI","CACAUÀ A BATMAN!"}},
},
peu_trobat_nointro={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Un peu podrit??","Qué asco!! Segur","que és d'el alien."}}
},
peu_trobat={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Joer, açò deu ser","el berenar d'el alien.","Ecs..."}}
},
habitacio_batman={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"L'habitació de Batman!","Segur que els cacaus","estàn ahí dins."}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Però necessite","una clau...",""}}
},
-- bol_trobat={
-- {x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"PER FI, JA TINC","ELS MEUS CACAUS!!!","OLE!! OLE!!"}},
-- {x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Se va a enterar","Batman ara quan","el pille..."}},
-- {x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Ara si que li puc","pegar una bona","cacauà..."}}
-- },
bol_trobat={
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"EH! ON ESTAN","ELS MEUS CACAUS!!?",""}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"Se va a enterar","Batman en quan","el pille..."}},
{x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"...","I eixe soroll?","Ve de dalt!"}}
},
final= {
{x=avatar_batman_x,y=avatar_batman_y,flip=true,audio="batman",musica=audio_song_batman,text={"AI!", "M'has fet mal!!!",""},die=20},
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Aixó per furtar-me","el bol de cacaus,","imbèsil"},die=20},
{x=avatar_batman_x,y=avatar_batman_y,flip=true,audio="batman",text={"Cert, esta me la","mereixia... però", "mira que be estàs!"},die=20},
{x=avatar_batman_x,y=avatar_batman_y,flip=true,audio="batman",text={"Amb el que t'ha","costat pillar-me", "t'has ficat en forma"},die=20},
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"No me vingues en","tonteries,","mamarratxo."},die=20},
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Creus que no he","notat que falta mig","bol de cacaus?"},die=20},
{x=avatar_batman_x,y=avatar_batman_y,flip=true,audio="batman",text={"Jejejeje, es que","estàn molt bons!", ""},die=20},
{x=avatar_batman_x,y=avatar_batman_y,flip=true,audio="batman",text={"Però si vols te","done del meu bol", "de tramussos."},die=20},
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"TRAMUSSOS...","",""},die=10},
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"M'atreviré a","passar l'última","frontera...?"},die=40},
},
}
function start_scene(_scene, offset, stop_music)
--bkg=newsurf(128,96)
--setdest(bkg)
--setsource(0)
--draw.surf(0,0,128,96,0,0)
--setsource(tiles)
--setdest(0)
scenes.current_scene=_scene
scenes.dnum=1
scenes.step=0
scenes.char=1
scenes.wait=0
scenes.offset=28
scenes.die=scenes.current_scene[scenes.dnum].die or 0
if _scene[1].musica then
--print(scene[1].musica)
music.play(scenes.current_scene[scenes.dnum].musica)
end
if offset then scenes.offset=offset end
-- old_update=game_update
-- game_update=update_scene
scene.running = true
if not stop_music then scene.stop_music = false end
flow:executar("scene", true); -- guardar l'estat anterior i executar
end
function playtext(snd)
if snd=="abad" then
sound.play(audio_text_abad)
elseif snd=="batman" then
sound.play(audio_text_batman)
elseif snd=="premiere" then
sound.play(audio_text_premiere)
elseif snd=="elalien" then
sound.play(audio_text_elalien)
elseif snd=="imp" then
sound.play(audio_text_imp)
end
end
function next_scene()
scenes.dnum=scenes.dnum+1
scenes.die=scenes.current_scene[scenes.dnum].die or 0
scenes.step=2
play_music()
-- print("NEXT SCENE")
end
function play_music()
if scenes.current_scene[scenes.dnum].musica then
-- print("PLAY MUSIC "..scenes.dnum)
music.stop()
music.play(scenes.current_scene[scenes.dnum].musica)
end
end
function draw_abad_with_mood(mood, dx, dy, dw, dh)
local ox, oy =view.origin()
view.origin(0,0)
-- -- composicio
local curr_sf = surf.target()
surf.target(avatar_sf)
surf.cls(16)
draw.surf(scenes.current_scene[scenes.dnum].x,scenes.current_scene[scenes.dnum].y,avatar_w,avatar_h,0,0,avatar_w,avatar_h)
abad_add_mood(0,scenes.current_scene[scenes.dnum].x,0,scenes.current_scene[scenes.dnum].y,false,mood)
-- if mood=="sorpresa" then
-- draw.surf(240,0,11,4,16-scenes.current_scene[scenes.dnum].x,5-scenes.current_scene[scenes.dnum].y,11,4)
-- elseif mood=="enfadat" then
-- draw.surf(240,4,11,4,16-scenes.current_scene[scenes.dnum].x,5-scenes.current_scene[scenes.dnum].y,11,4)
-- elseif mood=="interessant" then
-- draw.surf(240,8,11,4,16-scenes.current_scene[scenes.dnum].x,5-scenes.current_scene[scenes.dnum].y,11,4)
-- else
-- abad.mood="normal"
-- end
-- Dibuixar
view.origin(ox, oy)
surf.target(curr_sf)
curr_sf = surf.source()
surf.source(avatar_sf)
draw.surf(0,0,avatar_w,avatar_h, dx, dy, dw, dh)
surf.source(curr_sf)
-- draw.surf(scenes.current_scene[scenes.dnum].x,scenes.current_scene[scenes.dnum].y,avatar_w,avatar_h, dx, dy, dw, dh)
end
function draw_scene()
local txt_x = not scenes.current_scene[scenes.dnum].flip and 38 or 8
view.origin(0,scenes.offset*o2aX)
-- 0, 1, 2 -> Desplegar el cuadre de dialeg
if scenes.step==0 then
draw.rectf(0,16*o2aX,129*o2aX,2*o2aX,12)
draw.line(0,15*o2aX,128*o2aX,15*o2aX,16)
draw.line(0,18*o2aX,128*o2aX,18*o2aX,16)
elseif scenes.step==1 then
draw.rectf(0,8*o2aX,129*o2aX,19*o2aX,12)
draw.line(0,7*o2aX,128*o2aX,7*o2aX,16)
draw.line(0,27*o2aX,128*o2aX,27*o2aX,16)
elseif scenes.step==2 then
draw.rectf(0,0,129*o2aX,35*o2aX,12)
draw.line(0,0,128*o2aX,0,16)
draw.line(0,34*o2aX+1,128*o2aX,34*o2aX+1,16)
-- 3, 4 -> Desplegar el avatar
elseif scenes.step==3 then
if not scenes.current_scene[scenes.dnum].flip then
draw.rectf(8*o2aX,12*o2aX,avatar_photo_w+8, (avatar_photo_h+8)/2,16)
-- Només està disponible per a l'abad
if scenes.current_scene[scenes.dnum].mood then
draw_abad_with_mood(scenes.current_scene[scenes.dnum].mood, 18, 26, avatar_photo_w, avatar_photo_h/2)
-- draw.surf(scenes.current_scene[scenes.dnum].x,scenes.current_scene[scenes.dnum].y,avatar_w,avatar_h,9*o2aX,13*o2aX,20*o2aX,10*o2aX)
else
abad.mood="normal"
draw.surf(scenes.current_scene[scenes.dnum].x,scenes.current_scene[scenes.dnum].y,avatar_w,avatar_h,9*o2aX,13*o2aX,avatar_photo_w, avatar_photo_h/2)
end
else
draw.rectf(97*o2aX,12*o2aX,avatar_photo_w+8, (avatar_photo_h+8)/2,16)
draw.surf(scenes.current_scene[scenes.dnum].x,scenes.current_scene[scenes.dnum].y,avatar_w,avatar_h,98*o2aX,13*o2aX,avatar_photo_w, avatar_photo_h/2,true)
end
elseif scenes.step==4 then
if not scenes.current_scene[scenes.dnum].flip then
draw.rectf(8*o2aX,7*o2aX,avatar_photo_w+8,avatar_photo_h+4,16)
-- Només està disponible per a l'abad
if scenes.current_scene[scenes.dnum].mood then
draw_abad_with_mood(scenes.current_scene[scenes.dnum].mood, 18, 16, avatar_photo_w, avatar_photo_h)
-- draw.surf(scenes.current_scene[scenes.dnum].x,scenes.current_scene[scenes.dnum].y,avatar_w,avatar_h,9*o2aX,8*o2aX,20*o2aX,20*o2aX)
else
abad.mood="normal"
draw.surf(scenes.current_scene[scenes.dnum].x,scenes.current_scene[scenes.dnum].y,avatar_w,avatar_h,9*o2aX,8*o2aX,avatar_photo_w, avatar_photo_h)
end
else
draw.rectf(97*o2aX,7*o2aX,avatar_photo_w+8,avatar_photo_h+4,16)
draw.surf(scenes.current_scene[scenes.dnum].x,scenes.current_scene[scenes.dnum].y,avatar_w,avatar_h,98*o2aX,8*o2aX,avatar_photo_w, avatar_photo_h,true)
end
-- 5, 6, 7 -> Escriure les 3 frases de diàleg
elseif scenes.step==5 then
arc_textB(utf8.sub(scenes.current_scene[scenes.dnum].text[1],1,scenes.char),txt_x*o2aX,7*o2aX,2)
if scenes.char<#scenes.current_scene[scenes.dnum].text[1] then
scenes.step=scenes.step-1
scenes.char=scenes.char+1
playtext(scenes.current_scene[scenes.dnum].audio)
else
scenes.char=1
end
elseif scenes.step==6 then
arc_textB(utf8.sub(scenes.current_scene[scenes.dnum].text[2],1,scenes.char),txt_x*o2aX,15*o2aX,2)
if scenes.char<#scenes.current_scene[scenes.dnum].text[2] then
scenes.step=scenes.step-1
scenes.char=scenes.char+1
playtext(scenes.current_scene[scenes.dnum].audio)
else
scenes.char=1
end
elseif scenes.step==7 then
arc_textB(utf8.sub(scenes.current_scene[scenes.dnum].text[3],1,scenes.char),txt_x*o2aX,23*o2aX,2)
if scenes.char<#scenes.current_scene[scenes.dnum].text[3] then
scenes.step=scenes.step-1
scenes.char=scenes.char+1
playtext(scenes.current_scene[scenes.dnum].audio)
else
scenes.char=1
end
-- Render de tot lo anterior
elseif scenes.step==8 then
draw.rectf(0,0,129*o2aX,35*o2aX,12)
draw.line(0,0,128*o2aX,0,16)
draw.line(0,34*o2aX+1,128*o2aX,34*o2aX+1,16)
if not scenes.current_scene[scenes.dnum].flip then
draw.rectf(8*o2aX,7*o2aX,avatar_photo_w+8,avatar_photo_h+4,16)
if scenes.current_scene[scenes.dnum].mood then
draw_abad_with_mood(scenes.current_scene[scenes.dnum].mood, 18, 16, avatar_photo_w, avatar_photo_h)
-- draw.surf(scenes.current_scene[scenes.dnum].x,scenes.current_scene[scenes.dnum].y,avatar_w,avatar_h,9*o2aX,13*o2aX,20*o2aX,10*o2aX)
else
abad.mood="normal"
draw.surf(scenes.current_scene[scenes.dnum].x,scenes.current_scene[scenes.dnum].y,avatar_w,avatar_h,9*o2aX,8*o2aX,avatar_photo_w, avatar_photo_h)
end
else
draw.rectf(97*o2aX,7*o2aX,avatar_photo_w+8,avatar_photo_h+4,16)
draw.surf(scenes.current_scene[scenes.dnum].x,scenes.current_scene[scenes.dnum].y,avatar_w,avatar_h,98*o2aX,8*o2aX,avatar_photo_w, avatar_photo_h,true)
end
arc_textB(scenes.current_scene[scenes.dnum].text[1],txt_x*o2aX,7*o2aX,2)
arc_textB(scenes.current_scene[scenes.dnum].text[2],txt_x*o2aX,15*o2aX,2)
arc_textB(scenes.current_scene[scenes.dnum].text[3],txt_x*o2aX,23*o2aX,2)
end
if scenes.step<=8 then
scenes.step=scenes.step+1
end
view.origin(0,0)
end
function update_scene()
scenes.wait=scenes.wait+1
if scenes.wait>=6 then
scenes.wait=0
draw_scene()
if scenes.step>8 then
-- print("SCENES.DIE= "..scenes.die)
if scenes.die>0 then
scenes.die=scenes.die-1
if scenes.die==0 then
if scenes.dnum==#scenes.current_scene then
if scene.stop_music then music.stop() end
-- if batman.endgame then
-- final_init()
-- fade.fadeoutin()
-- else
-- game_update=old_update
-- flow:restore()
flow:next()
-- end
else
next_scene()
end
end
else
if math.floor(sys.time()*2)%2==0 then
draw.surf(104*o2aX,88*o2aX,7*o2aX,5*o2aX,118*o2aX,56*o2aX)
else
draw.rectf(118*o2aX,56*o2aX,8*o2aX,6*o2aX,12)
end
end
end
end
if (key.press(key.ESCAPE) or pad.press(btnPause)) and (scenes.current_scene~=scenes.final) then
if scenes.current_scene[scenes.dnum].die then
-- game_init(true)
-- flow:next()
-- game_update = menu_init
flow:executar("title")
else
pause()
end
end
if scenes.step>8 then
if controller:check("shoot") or controller:check("down") or
controller:check("up") or controller:check("left") or
controller:check("right") or key.press(key.RETURN) then
if scenes.dnum==#scenes.current_scene then
if scenes.stop_music then music.stop() end
-- if batman.endgame then
-- final_init()
-- fade.fadeoutin()
-- else
-- game_update=old_update
flow:next()
-- end
else
-- scenes.dnum=scenes.dnum+1
-- scenes.step=2
next_scene()
end
end
elseif key.press(keyShoot) or pad.press(btnShoot) then
scenes.step=8
end
end
function end_scene()
scene.running = false
flow:finish()
end
flow:registrar("scene",{update_scene, end_scene})

View File

@@ -1,4 +1,13 @@
score={}
score={
bar_meter = nil
}
local gorro_img_x = 10*16 -- col
local gorro_img_y = 11*16 -- row
local peu_img_x = 11*16
local peu_img_y = 11*16
local clau_img_x = 12*16
local clau_img_y = 11.5*16
function score.avatar()
local x = 64
@@ -69,11 +78,11 @@ function score.create()
surf.cls(0)
score.avatar()
score.bar_meter=bar_meter.new(0,2,51,10,1,1,abad)
-- score.border()
-- score.jailgames()
score.life_meter()
-- score.life_meter()
surf.target(0)
end
@@ -83,18 +92,27 @@ function score.draw()
surf.target(score.surf)
surf.cls(0)
score.avatar()
score.life_meter()
-- score.life_meter()
score.bar_meter:draw()
surf.target(0)
surf.source(score.surf)
draw.surf(0,0,arcade_config.resolucion.width,arcade_config.resolucion.height,170,10)
surf.source(tiles)
if abad.objects.gorro~=nil then draw.surf(96*o2aX,32*o2aX,16*o2aX,16*o2aX,99*o2aX,44*o2aX) end
if abad.objects.peu~=nil then draw.surf(112*o2aX,32*o2aX,16*o2aX,16*o2aX,109*o2aX,44*o2aX) end
if abad.objects.gps~=nil then draw.surf(112*o2aX,48*o2aX,16*o2aX,16*o2aX,100*o2aX,55*o2aX) end
if abad.objects.gorro~=nil then
draw.surf(gorro_img_x,gorro_img_y,16,16,137,7)
end
if abad.objects.peu~=nil then
local peu_offset = 0
if abad.objects.clau_premiere~=nil then
peu_offset = 16
end
draw.surf(peu_img_x, peu_img_y, 16,16,121+peu_offset,7)
end
-- if abad.objects.gps~=nil then draw.surf(gps_img_x, gps_img_y, 16,16,100*o2aX,55*o2aX) end
if abad.objects.clau_premiere~=nil then draw.surf(112*o2aX,8*o2aX,8*o2aX,8*o2aX,104*o2aX,48*o2aX) end
if abad.objects.clau_elalien~=nil then draw.surf(120*o2aX,8*o2aX,8*o2aX,8*o2aX,112*o2aX,48*o2aX) end
if abad.objects.clau_premiere~=nil then draw.surf(clau_img_x,clau_img_y,8,8,153,13) end
if abad.objects.clau_elalien~=nil then draw.surf(clau_img_x+8,clau_img_y,8,8,161,13) end
if abad.objects.bol~=nil then draw.surf(112*o2aX,88*o2aX,16*o2aX,8*o2aX,104*o2aX,46*o2aX) end

BIN
data/snd_txti.wav Normal file

Binary file not shown.

1152
data/stage1.lua Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,57 +0,0 @@
switches={
cooldown=0,
wait=0,
current_list=nil,
current_index=-1,
[1]={[0]={20, 53,41}},
[11]={[21]={11, 57,45}},
[35]={[14]={32, 50,38,26,53,41,29}},
[53]={[14]={72, 42,30}},
[61]={[14]={54, 54,42}},
[76]={[19]={77, 50,38,26},
[22]={57, 53,41}},
[80]={[18]={36, 56,44}},
[39]={[27]={39, 62,63}}
}
--switches[11]={[21]={11, 57,45}}
--switches[11][21]={11, 57,45}
function switches.start(x, y)
if switches.cooldown>0 then return end
local hab, hx, hy = coords.world_to_tile(x, y)
local tile_idx = (hx+hy*mapa_room_cols)+1
-- mapa_set_tile_by_index(hab,tile_idx,57)
arc_set_tile(x, y, editor_to_map_tile(57))
switches.current_list=switches[hab+1][tile_idx]
switches.current_index=2
switches.wait=0
switches.cooldown=60
sound.play(audio_switch)
end
function switches.update()
if switches.cooldown>0 then switches.cooldown=switches.cooldown-1 end
if switches.current_list==nil then return end
--cls(4)
switches.wait=switches.wait+1
if switches.wait>=6 then
switches.wait=0
local hab= switches.current_list[1]-1
local tile_idx= switches.current_list[switches.current_index]+1
-- print(hab.." ("..tile_x..", "..tile_y..")")
-- local tile_x, tile_y = coords.room_index_to_xy ( hab, tile_idx )
-- local world_x, world_y = coords.room_to_world(hab, tile_x, tile_y)
-- arc_set_tile(world_x, world_y, 256)
arc_set_tile_by_index(hab,tile_idx,mapa_empty_tile)
-- mapa_set_tile_by_index(switches.current_list[1]-1,switches.current_list[switches.current_index]+1,256)
switches.current_index=switches.current_index+1
if switches.current_index>#switches.current_list then
switches.current_list=nil
end
end
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

BIN
data/tiles2.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

103
data/tiles_layer2.lua Normal file
View File

@@ -0,0 +1,103 @@
tiles_layer2={
surf = nil,
tiles = {},
}
function tiles_layer2.new(_hab, _x, _y, _tx, _ty, _tw, _th, _anim, _draw)
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
table.insert(
tiles_layer2.tiles,
{ hab = _hab,
x = world_x,
y = world_y,
w = _tw,
h = _th,
tx = _tx,
ty = _ty,
tw = _tw,
th = _th,
off_x = 0,
off_y = 0,
draw = _draw,
anim = _anim,
anim_started = false,
}
)
end
function tiles_layer2.draw_tile( tile )
local curr_surf = surf.source()
if tiles_layer2.surf ~= nil then
surf.source(tiles_layer2.surf)
end
local scr_x, scr_y = viewp:screen_coords( tile.x, tile.y )
draw.surf(tile.tx, tile.ty, tile.tw, tile.th,
scr_x, scr_y, tile.tw, tile.th)
surf.source(curr_surf)
end
function tiles_layer2.draw()
for i, tile in ipairs(tiles_layer2.tiles) do
if viewp:inside(tile.x, tile.y, tile.w, tile.h) then
if tile.draw == nil then
tiles_layer2.draw_tile(tile)
else
tile.draw(tile)
end
end
end
end
function tiles_layer2.update()
for i, tile in ipairs(tiles_layer2.tiles) do
if viewp:inside(tile.x, tile.y, tile.w, tile.h) then
if tile.anim ~= nil then
tile.anim(tile)
end
end
end
end
function tiles_layer2.draw_aranya(tile)
local curr_surf = surf.source()
if tiles_layer2.surf ~= nil then
surf.source(tiles_layer2.surf)
end
local scr_x, scr_y = viewp:screen_coords( tile.x, tile.y )
draw.line(scr_x+11, scr_y, scr_x+11+tile.off_x, scr_y+tile.off_y, 2)
draw.surf(tile.tx, tile.ty, tile.tw, tile.th,
scr_x+tile.off_x, scr_y+tile.off_y, tile.tw, tile.th)
surf.source(curr_surf)
end
function tiles_layer2.update_aranya(tile)
if not tile.anim_started then
tile.wait = 6
tile.step = 0
tile.off_x= 0
tile.off_y= 0
tile.next_move = 16
tile.vy = 1
tile.anim_started = true
end
tile.wait = tile.wait + 1
if tile.wait>=6 then
tile.wait = 0
if tile.off_y==0 or tile.off_y==8 then
tile.next_move = tile.next_move - 1
if tile.next_move<=0 then
tile.next_move = 16+math.random(64)
if tile.off_y==0 then
tile.vy = 1
else
tile.vy = -1
end
tile.off_y = tile.off_y + tile.vy
end
else
tile.off_y = tile.off_y + tile.vy
end
end
end

175
data/title.lua Normal file
View File

@@ -0,0 +1,175 @@
local char_C = {x=0, y=0, w=6, h=7}
local char_a = {x=6, y=0, w=4, h=5}
local char_c = {x=4, y=7, w=3, h=5}
local char_u = {x=12, y=5, w=4, h=5}
local char_s = {x=12, y=0, w=4, h=5}
local frame = { {x=0, y=7, w=2, h=1}, --cantó sup esq
{x=2, y=7, w=1, h=1}, --linea sup
{x=3, y=7, w=1, h=1}, -- cantó sup dre 1
{x=3, y=9, w=1, h=1}, -- cantó sup dre 2
{x=2, y=8, w=2, h=1}, -- costat dre 1
{x=2, y=9, w=1, h=1}, -- costat dre 2
{x=1, y=10, w=2, h=1}, -- costat dre 3
{x=3, y=10, w=1, h=1}, -- cantó inf dre 1
{x=3, y=11, w=1, h=1}, -- cantó inf dre 2
{x=2, y=11, w=1, h=1}, -- linea inf
{x=1, y=11, w=1, h=1}, -- cantó inf esq 1
{x=0, y=8, w=1, h=4}, -- cantó inf esq 2 + costat esq 1
{x=1, y=8, w=1, h=2}, -- costat esq 2
}
local the = {x=7, y=8, w=5, h=2}
local arcade = {x=7, y=10, w=9, h=2}
local cycle_pal = {12, 13, 14}
local cycle_wait = 0
local cycle_step = 1
local menu_sel = 0
local rect_wait = 0
function title_init()
title_sf=surf.load("title_tiles.gif")
surf.source(title_sf)
music.play(audio_main_song)
flow:next()
end
function title_draw_frame ()
pal.subpal(9,cycle_pal[(cycle_step%3)+1])
-- draw.surf( frame[1].x*8, frame[1].y*8, frame[1].w*8, frame[1].h*8, 20, 58+4, frame[1].w*8, frame[1].h*8)
-- draw.surf( frame[2].x*8, frame[2].y*8, frame[2].w*8, frame[2].h*8, 36, 58+4, 24*frame[2].w*8, frame[2].h*8)
-- draw.surf( frame[3].x*8, frame[3].y*8, frame[3].w*8, frame[3].h*8, 228, 58+4, frame[3].w*8, frame[3].h*8)
-- draw.surf( frame[4].x*8, frame[4].y*8, frame[4].w*8, frame[4].h*8, 236, 58+4, frame[4].w*8, frame[4].h*8)
-- draw.surf( frame[5].x*8, frame[5].y*8, frame[5].w*8, frame[5].h*8, 228, 66+4, frame[5].w*8, frame[5].h*8)
-- draw.surf( frame[6].x*8, frame[6].y*8, frame[6].w*8, frame[6].h*8, 236, 74+4, frame[6].w*8, frame[6].h*8)
-- draw.surf( frame[7].x*8, frame[7].y*8, frame[7].w*8, frame[7].h*8, 236, 82+4, frame[7].w*8, frame[7].h*8)
draw.surf( frame[8].x*8, frame[8].y*8, frame[8].w*8, frame[8].h*8, 244, 90+4, frame[8].w*8, frame[8].h*8)
draw.surf( frame[9].x*8, frame[9].y*8, frame[9].w*8, frame[9].h*8, 236, 90+4, frame[9].w*8, frame[9].h*8)
draw.surf(frame[10].x*8, frame[10].y*8, frame[10].w*8, frame[10].h*8, 28, 90+4, 26*frame[10].w*8, frame[10].h*8)
draw.surf(frame[11].x*8, frame[11].y*8, frame[11].w*8, frame[11].h*8, 20, 90+4, frame[11].w*8, frame[11].h*8)
draw.surf(frame[12].x*8, frame[12].y*8, frame[12].w*8, frame[12].h*8, 12, 66+4, frame[12].w*8, frame[12].h*8)
-- draw.surf(frame[13].x*8, frame[13].y*8, frame[13].w*8, frame[13].h*8, 20, 66+4, frame[13].w*8, frame[13].h*8)
pal.subpal(9,cycle_pal[((cycle_step+1)%3)+1])
-- draw.surf( frame[1].x*8, frame[1].y*8, frame[1].w*8, frame[1].h*8, 20, 58+2, frame[1].w*8, frame[1].h*8)
-- draw.surf( frame[2].x*8, frame[2].y*8, frame[2].w*8, frame[2].h*8, 36, 58+2, 24*frame[2].w*8, frame[2].h*8)
-- draw.surf( frame[3].x*8, frame[3].y*8, frame[3].w*8, frame[3].h*8, 228, 58+2, frame[3].w*8, frame[3].h*8)
-- draw.surf( frame[4].x*8, frame[4].y*8, frame[4].w*8, frame[4].h*8, 236, 58+2, frame[4].w*8, frame[4].h*8)
-- draw.surf( frame[5].x*8, frame[5].y*8, frame[5].w*8, frame[5].h*8, 228, 66+2, frame[5].w*8, frame[5].h*8)
-- draw.surf( frame[6].x*8, frame[6].y*8, frame[6].w*8, frame[6].h*8, 236, 74+2, frame[6].w*8, frame[6].h*8)
-- draw.surf( frame[7].x*8, frame[7].y*8, frame[7].w*8, frame[7].h*8, 236, 82+2, frame[7].w*8, frame[7].h*8)
draw.surf( frame[8].x*8, frame[8].y*8, frame[8].w*8, frame[8].h*8, 244, 90+2, frame[8].w*8, frame[8].h*8)
draw.surf( frame[9].x*8, frame[9].y*8, frame[9].w*8, frame[9].h*8, 236, 90+2, frame[9].w*8, frame[9].h*8)
draw.surf(frame[10].x*8, frame[10].y*8, frame[10].w*8, frame[10].h*8, 28, 90+2, 26*frame[10].w*8, frame[10].h*8)
draw.surf(frame[11].x*8, frame[11].y*8, frame[11].w*8, frame[11].h*8, 20, 90+2, frame[11].w*8, frame[11].h*8)
draw.surf(frame[12].x*8, frame[12].y*8, frame[12].w*8, frame[12].h*8, 12, 66+2, frame[12].w*8, frame[12].h*8)
draw.rectf(12, 80+2, frame[12].w*8, 8, 16)
-- draw.surf(frame[13].x*8, frame[13].y*8, frame[13].w*8, frame[13].h*8, 20, 66+2, frame[13].w*8, frame[13].h*8)
pal.subpal(9,cycle_pal[((cycle_step+2)%3)+1])
draw.surf( frame[1].x*8, frame[1].y*8, frame[1].w*8, frame[1].h*8, 20, 58, frame[1].w*8, frame[1].h*8)
draw.surf( frame[2].x*8, frame[2].y*8, frame[2].w*8, frame[2].h*8, 36, 58, 24*frame[2].w*8, frame[2].h*8)
draw.surf( frame[3].x*8, frame[3].y*8, frame[3].w*8, frame[3].h*8, 228, 58, frame[3].w*8, frame[3].h*8)
draw.surf( frame[4].x*8, frame[4].y*8, frame[4].w*8, frame[4].h*8, 236, 58, frame[4].w*8, frame[4].h*8)
draw.surf( frame[5].x*8, frame[5].y*8, frame[5].w*8, frame[5].h*8, 228, 66, frame[5].w*8, frame[5].h*8)
draw.surf( frame[6].x*8, frame[6].y*8, frame[6].w*8, frame[6].h*8, 236, 74, frame[6].w*8, frame[6].h*8)
draw.surf( frame[7].x*8, frame[7].y*8, frame[7].w*8, frame[7].h*8, 236, 82, frame[7].w*8, frame[7].h*8)
draw.surf( frame[8].x*8, frame[8].y*8, frame[8].w*8, frame[8].h*8, 244, 90, frame[8].w*8, frame[8].h*8)
draw.surf( frame[9].x*8, frame[9].y*8, frame[9].w*8, frame[9].h*8, 236, 90, frame[9].w*8, frame[9].h*8)
draw.surf(frame[10].x*8, frame[10].y*8, frame[10].w*8, frame[10].h*8, 28, 90, 26*frame[10].w*8, frame[10].h*8)
draw.surf(frame[11].x*8, frame[11].y*8, frame[11].w*8, frame[11].h*8, 20, 90, frame[11].w*8, frame[11].h*8)
draw.surf(frame[12].x*8, frame[12].y*8, frame[12].w*8, frame[12].h*8, 12, 66, frame[12].w*8, frame[12].h*8)
draw.surf(frame[13].x*8, frame[13].y*8, frame[13].w*8, frame[13].h*8, 20, 66, frame[13].w*8, frame[13].h*8)
pal.subpal(9)
cycle_wait = cycle_wait+1
if cycle_wait==18 then
cycle_wait = 0
cycle_step = (cycle_step+1)%3+1
end
end
function title_draw_tile( tile, x, y )
draw.surf(tile.x*8,tile.y*8,tile.w*8,tile.h*8, x, y)
end
function title_draw_jg()
draw.text("JAILGAMES 2026",150,174,13)
end
function title_draw ()
title_draw_frame()
title_draw_tile(char_C,30,13)
title_draw_tile(char_a,76,28)
title_draw_tile(char_c,107,28)
title_draw_tile(char_a,129,28)
title_draw_tile(char_u,158,29)
title_draw_tile(char_s,192,28)
title_draw_tile(the,129,76)
title_draw_tile(arcade,162,76)
title_draw_jg()
end
function title_update()
end
function title_show()
-- print("title_show")
surf.source(title_sf)
surf.target(0)
surf.cls(16)
title_menu_draw()
title_draw()
title_update()
title_menu_update()
end
function title_end()
music.stop()
if menu_sel==0 then
-- game_exit()
-- game_init()
-- fade.fadeoutin()
to_game()
elseif menu_sel==1 then
-- menu_count=0
-- menu_sel=0
-- menu_state=update_options_menu--update_redefine_keys_menu;
to_options()
end
end
function title_menu_draw()
draw_shiny_rect(56,120+(20*menu_sel)-4,146,18,14,15)
arc_text("JUGAR", 108, 120, 14)
arc_text("OPCIONS", 102, 140, 14)
end
function title_menu_update()
if key.press(keyShoot) or key.press(key.SPACE) or pad.press(pad.A) or pad.press(btnShoot) then
title_end()
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==2 then menu_sel=0 end
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=1 end
elseif key.press(key.ESCAPE) or pad.press(btnPause) then
sys.quit()
end
end
function to_game()
print("to game")
fade.fadeoutin()
flow:executar("game")
end
function to_options()
print("to options")
flow:executar("opcions", true)
end
flow:registrar("title", {title_init, title_show, title_end})

BIN
data/title_tiles.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

194
data/trigger.lua Normal file
View File

@@ -0,0 +1,194 @@
trigger={}
function trigger.new(_hab,_x,_y,_action,_escena,_id,_type,_doors,_linked_id)
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
_bb={x=0,y=0,w=16,h=16} --default
-- if _type=="switch" then _bb={x=0,y=0,w=16,h=17} end
-- if _id then print("NEW => ".._id) end
_type = _type or "invisible"
return {
name="trigger",
type=_type,
id=_id,
escena=_escena,
hab=_hab,
x=world_x,
y=world_y,
w=16,
h=16,
fun=_action,
doors=_doors,
update=trigger.update,
draw=trigger.draw,
linked_id=_linked_id,
enabled=true,
disable_reason="",
bb=_bb,
run=trigger.run }
end
function trigger:run()
if self.fun ~= nil then
self:fun()
end
end
function trigger:update()
if not self.enabled then return end
if self.hab==abad.hab then
if collision(abad,self) then
if self.type=="switch" and self.enabled then
sound.play(audio_switch)
self.enabled=false
if self.linked_id then
disable_actor_by_id(self.linked_id)
end
end
self:fun()
end
end
end
function trigger:draw()
if self.type~="switch" and not self.enabled then return end
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
if self.type=="switch" then
if self.enabled then
draw.surf(240,128,16,16,scr_x,scr_y,16,16)
else
-- "flipar" i desactivar en gris
pal.subpal(2,1)
draw.surf(240,128,16,16,scr_x,scr_y,16,16,true)
pal.subpal(2)
end
end
-- debug rect
draw.rect(scr_x,scr_y,self.bb.w,self.bb.h,3)
end
--function trigger:do_touched()
-- start_scene(self.scene)
-- remove_actor(self)
--end
triggers={}
function triggers:open_door()
local hab= self.doors[1]-1
if hab~=abad.hab then
remote_view(hab)
end
for i=2,#self.doors do
local tile_idx= self.doors[i]+1
arc_set_tile_by_index(hab,tile_idx,mapa_empty_tile)
end
end
function triggers:escena_abad_inici()
start_scene(scenes.abad_inici)
remove_actor(self)
end
function triggers:escena_abad_corfes()
start_scene(scenes.abad_corfes)
remove_actor(self)
end
function triggers:escena_abad_portes()
local wx1,wy1 = coords.room_to_world(abad.hab,2,4)
local wx2,wy2 = coords.room_to_world(abad.hab,6,3)
if abad.escena_portes==nil
and ( (abad.hab==31 and arc_get_tile(wx1,wy1)~=256)
or (abad.hab==71 and arc_get_tile(wx2,wy2)~=256) ) then
start_scene(scenes.abad_portes)
end
abad.escena_portes=true
remove_actor(self)
end
function triggers:escena_abad_porta_casa()
local wx1,wy1 = coords.room_to_world(abad.hab,6,4)
if arc_get_tile(wx1,wy1)~=256 then
start_scene(scenes.abad_porta_casa)
end
remove_actor(self)
end
function triggers:escena_abad_porta_batman()
local wx1,wy1 = coords.room_to_world(abad.hab,5,4)
if arc_get_tile(wx1,wy1)~=256 then
start_scene(scenes.abad_porta_batman)
end
remove_actor(self)
end
function triggers:escena_habitacio_batman()
if abad.objects.clau_premiere==nil and
abad.objects.clau_elalien==nil
then
-- switches.start(0,0)
local trigger_porta = trigger.new(abad.hab,1,1,triggers.open_door,"switch","porta acces cacaus","",{20, 53,41})
trigger_porta:run()
bol.furtat=true
abad.objects.clau_premiere=nil
abad.objects.clau_elalien=nil
remove_actor(self)
else
if batman.habitacio_porta_intro==nil then
start_scene(scenes.habitacio_batman)
batman.habitacio_porta_intro=true
end
end
end
function triggers:escena_stage1_ending()
print("STAGE 1 ENDING")
remove_actor(self)
end
function triggers:escena_lluita_imp()
set_actors_enabled_by_room(false, "boss", stage1_boss_mapa.r0.r, stage1_boss_mapa.r1.r)
viewp:fixed({l=8,r=44,u=0,d=0}, viewp.x, viewp.y-48)
start_scene(scenes.lluita_imp, nil, false)
remove_actor(self)
stages.stage1_boss_ready()
end
-- function triggers:teleport_a()
-- abad.teleport=true
-- sound.play(audio_hit)
-- surf.cls(14)
-- imp.reset()
-- abad.hab=67
-- abad.x=24
-- end
--
-- function triggers:teleport_b()
-- if abad.teleport then
-- sound.play(audio_hit)
-- surf.cls(14)
-- imp.reset()
-- abad.hab=14
-- abad.x=16
-- end
-- end
--
-- function triggers:teleport_c()
-- abad.teleport2=true
-- sound.play(audio_hit)
-- surf.cls(14)
-- imp.reset()
-- abad.hab=61
-- abad.x=24
-- end
--
-- function triggers:teleport_d()
-- if abad.teleport2 then
-- sound.play(audio_hit)
-- surf.cls(14)
-- imp.reset()
-- abad.hab=29
-- abad.x=24
-- end
-- end

148
data/trigger_event.lua Normal file
View File

@@ -0,0 +1,148 @@
trigger_event = {
list = {},
}
trigger_ev = {}
function trigger_event.new ( _name, _tr_func, _tr_init, _tr_update, _a, _b, _time, _text, _distancia )
table.insert( trigger_event.list, {
name = _name,
trigger = _tr_func,
init = _tr_init,
update = _tr_update,
actor = _a,
actor_b = _b,
time = _time,
text = _text,
distancia = _distancia,
enabled = true,
running = false,
})
end
function trigger_event.update ()
for _,t in ipairs(trigger_event.list) do
if t.enabled and not t.running then
t.running = t:trigger()
end
end
end
function trigger_event.disable(_name)
print("Disabling ".._name)
for _,t in ipairs(trigger_event.list) do
if t.name == _name then
print("Disabled trigger ".._name)
t.running = false
t.enabled = false
end
end
end
-- PREMIERE HEALER - BOSS 1 TRIGGER
function trigger_ev:premiere_boss1_trigger( )
if stages.boss_loaded and
abad.objects.clau_premiere~=nil and
abad.energia<=abad.max_energia/2
then
self:init()
return true
end
return false
end
function trigger_ev:premiere_healer_init()
-- if premiere.update==premiere_update_healer then return true end
-- Guardar l'estat de Premiere
premiere.from_hab = premiere.hab
premiere.from_x = premiere.x
premiere.from_y = premiere.y
premiere.from_update = premiere.update
-- Moure a premiere al Boss stage
premiere.hab = 54
premiere.x = 2
premiere.y = 3
local world_x, world_y = coords.room_to_world(premiere.hab,premiere.x,premiere.y)
premiere.x=world_x
premiere.y=world_y
premiere.health_wait = 100
premiere.update = self.update
-- El trigger el deshabilitaria al acabar el update
-- pero en estos moments no se com fer-ho
-- perque l'update s'executa dins de premiere i no
-- dins del trigger
trigger_event.disable(self.name)
end
function trigger_ev:premiere_healer_update()
premiere.wait=premiere.wait+1
-- Esperar mentres dona la vida
if premiere.health_wait>0 and premiere.health_wait<100 then
premiere.health_wait = premiere.health_wait - 1
else
premiere.x = premiere.x+1
if premiere.wait>=6 then
premiere.wait = 0
premiere.step=(premiere.step+1)%4
premiere.frame=premiere.anim[premiere.step+1]
end
end
-- Lloc de pausa
local hab, tx, ty = coords.world_to_tile(premiere.x, premiere.y)
if hab == 55 and tx==0 and ty==3 and premiere.health_wait==100 then
-- 55 (0,3)
local _text = "Tenne! Io t'achudo. Figo!";
table.insert(
dialeg.list,
{ actor=premiere,
text=_text,
time=200,
w = math.floor(4.6*#_text),
h = 20,
}
)
premiere.health_wait = premiere.health_wait - 1
table.insert( actors, health_potion.new(
premiere.hab,
premiere.x+premiere.bb.x+premiere.bb.w,
premiere.y+premiere.bb.y+premiere.bb.h/3,
1, 24, 3)
)
-- health_potion.init(premiere.hab,
-- premiere.x+premiere.bb.x+premiere.bb.w,
-- premiere.y+premiere.bb.y+premiere.bb.h/3,
-- 1, 24, 2)
elseif hab >= 56 then
-- Restaurar a Premiere
premiere.hab = premiere.from_hab
premiere.x = premiere.from_x
premiere.y = premiere.from_y
premiere.update = premiere.from_update
end
end
-- DIALEG GENERAL
function trigger_ev:dialeg_trigger ()
if h_collision( self.actor, self.actor_b ) and
distancia ( self.actor, self.actor_b )<=self.distancia
then
self:init()
return true
end
return false
end
function trigger_ev:dialeg_init()
table.insert(
dialeg.list,
{ actor=self.actor,
text=self.text,
time=self.time,
w = math.floor(4.6*#self.text),
h = 20,
}
)
trigger_event.disable(self.name)
end

View File

@@ -14,7 +14,28 @@ function viewport.new(_width, _height)
tile= viewport.tile,
last_tile= viewport.last_tile,
screen_coords = viewport.screen_coords,
inside = viewport.inside }
inside = viewport.inside,
fixed = viewport.fixed,
free_move = viewport.free_move,
range = nil, -- rang de moviment quan està fixat {r= , l=, u=, d= }
fixed_coord = nil, -- coordenades fixades
smooth_adjust = nil,
adjust_speed = 2
}
end
function viewport:fixed(range, _x, _y)
self.range = range
_x = _x or self.x
_y = _y or self.y
self.fixed_coord = {x=_x, y=_y}
end
function viewport:free_move()
self.range = nil
if self.fixed_coord~=nil then print ("FIXED COORD= "..self.fixed_coord.x..", "..self.fixed_coord.y) end
self.smooth_adjust = self.fixed_coord
self.fixed_coord = nil
end
function viewport:get()
@@ -33,30 +54,6 @@ function viewport:inside( x, y, w, h )
return result
end
-- function viewport:coord2tile (x, y)
-- local tw = arcade_config.tiles_width
-- local th = arcade_config.tiles_height
-- local cols = mapa_room_cols
-- local rows = mapa_room_rows
-- local rooms_per_floor = mapa_rooms_per_piso
-- local xx = x or self.x
-- local yy = y or self.y
--
-- local calc_col = math.floor(xx / tw) % cols
-- local calc_row = math.floor(yy / th) % rows
-- local calc_room = math.floor(yy / (th * rows))*rooms_per_floor+math.floor(xx / (tw * cols))
-- -- print("X= "..self.x.." / W="..tw.." / C= "..cols.." > "..calc_col)
-- -- print("Y= "..self.y.." / H="..th.." / R= "..rows.." > "..calc_row)
-- -- print("CR= "..calc_row.." / RF= "..rooms_per_floor.." / CC= "..calc_col)
-- -- local tile_offset_x = self.x - (calc_col * tw * cols)
-- -- local tile_offset_y = self.y - (calc_row * th * rows)
-- local tile_offset_x = xx - (calc_col * tw) - ((calc_room%rooms_per_floor)*cols*tw)
-- local tile_offset_y = yy - (calc_row * th) - ( math.floor(calc_room/10)*rows*th)
-- -- print(self.x.." C"..calc_col.." W"..tw.." R"..calc_room.." c"..cols.." > "..tile_offset_x)
-- -- room, x, y, offset x, offset y
-- return calc_room, calc_col, calc_row, tile_offset_x, tile_offset_y
-- end
function viewport:tile ()
return coords.world_to_tile(self.x, self.y)
end
@@ -67,42 +64,68 @@ end
function viewport:coord2room ()
return coords.world_to_room(self.x, self.y)
-- local tw = arcade_config.tiles_width
-- local th = arcade_config.tiles_height
-- local cols = mapa_room_cols
-- local rows = mapa_room_rows
-- local rooms_per_floor = mapa_rooms_per_piso
--
-- local calc_col = math.floor(self.x / (tw * cols))
-- local calc_row = math.floor(self.y / (th * rows))
--
-- local calc_room = calc_row*rooms_per_floor+calc_col
-- return calc_room
end
-- function viewport:room2coord ( room )
-- local tw = arcade_config.tiles_width
-- local th = arcade_config.tiles_height
-- local cols = mapa_room_cols
-- local rows = mapa_room_rows
-- local rooms_per_floor = mapa_rooms_per_piso
--
-- local x = (room % rooms_per_floor) * cols * tw
-- local y = math.floor(room/rooms_per_floor) * rows * th
--
-- local room_center_x_offset = (cols * tw) >> 1
-- local room_center_y_offset = (rows * th) >> 1
--
-- -- return x+room_center_x_offset, y+room_center_y_offset
-- return x, y
-- end
function viewport:position(x, y)
local nx = (x ~= nil) and x or self.x
local ny = (y ~= nil) and y or self.y
if self.range==nil then
if self.smooth_adjust == nil then
self.x = nx
self.y = ny
else
-- viewport lliure després de fixar-lo -> Ajustar suau
local speed_x = self.adjust_speed
local speed_y = self.adjust_speed
local sm_x = self.smooth_adjust.x
local sm_y = self.smooth_adjust.y
self.x = nx
if sm_x~=nil then
if math.abs(nx-sm_x)<speed_x then
sm_x = nil
else
if nx<sm_x-speed_x then speed_x = -speed_x end
self.x=sm_x+speed_x
sm_x =sm_x+speed_x
end
self.smooth_adjust.x = sm_x
end
self.y = ny
if sm_y~=nil then
if math.abs(ny-sm_y)<speed_y then
sm_y = nil
else
if ny<sm_y-speed_y then speed_y = -speed_y end
self.y=sm_y+speed_y
sm_y =sm_y+speed_y
end
self.smooth_adjust.y = sm_y
end
if sm_x == nil and sm_y == nil then
self.smooth_adjust = nil
end
end
else
-- viewport fixe
self.x = nx
-- moure viewport left - right
if nx<self.fixed_coord.x-self.range.l then
self.x = self.fixed_coord.x-self.range.l
elseif nx>self.fixed_coord.x+self.range.r then
self.x = self.fixed_coord.x+self.range.r
end
self.y = ny
-- moure viewport up - down
if ny<self.fixed_coord.y-self.range.u then
self.y = self.fixed_coord.y-self.range.u
elseif ny>self.fixed_coord.y+self.range.d then
self.y = self.fixed_coord.y+self.range.d
end
end
return self.x, self.y
end

101
data/warp.lua Normal file
View File

@@ -0,0 +1,101 @@
warp={
max_warps=50,
warp_list={},
update=update_all,
}
function warp.init(tiles_sf)
local curr_source = surf.source()
local curr_target = surf.target()
warp_sf=surf.new(32,32)
surf.source(tiles_sf)
surf.target(warp_sf)
local sprite_x = 11*16
local sprite_y = 15*16
draw.surfrot(sprite_x, sprite_y, 16, 16, 0, 0, 0)
draw.surfrot(sprite_x, sprite_y, 16, 16, 15, 0, 90)
draw.surfrot(sprite_x, sprite_y, 16, 16, 15, 15, 180)
draw.surfrot(sprite_x, sprite_y, 16, 16, 0, 15, 270)
surf.source(curr_source)
surf.target(curr_target)
end
function warp.close()
surf.free(warp_sf)
end
function warp.new(_actor)
-- local world_x, world_y = coords.room_to_world(_hab,_x,_y)
return {name="warp",
hab=_hab,
x=_actor.x,
y=_actor.y,
w=arcade_config.sprite_size.w,
h=arcade_config.sprite_size.h,
frame=0,
wait=0,
step=0,
angle=0,
d_angle=5,
update=warp.update,
draw=warp.draw,
alive=true,
actor=_actor}
end
function warp:draw()
if not self.alive then return end
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
local curr_sf=surf.source()
local target_sf=surf.target()
surf.source(warp_sf)
surf.target(0)
draw.surfrot(0,0,32,32,scr_x,scr_y,self.angle)
surf.source(curr_sf)
surf.target(target_sf)
end
function warp:update()
if not self.actor.warping then self.alive=false end
if not self.alive then return end
self.wait=self.wait+1
self.angle=self.angle+self.d_angle
if self.wait==10 then
self.d_angle=self.d_angle+1
self.wait = 0
end
if self.d_angle==20 then
self.d_angle=5
self.alive = false
end
if self.angle>=360 then self.angle=self.angle % 360 end
end
function warp.open(actor)
for _, w in ipairs(warp.warp_list) do
if not w.alive then
w.alive = true
w.x = actor.x
w.y = actor.y
w.actor = actor
w.frame = 0
w.wait = 0
w.step = 0
w.angle = 0
w.d_angle = 5
return e; -- reutilitzar
end
end
table.insert(warp.warp_list, warp.new(actor) )
end
function warp.update_all()
for _, w in ipairs(warp.warp_list) do
if w.alive then
w:update()
end
end
end

View File

@@ -4,7 +4,8 @@ ch = arcade_config.character_height
zombie={}
function zombie.new(_hab,_x,_y,_flip)
function zombie.new(_hab,_x,_y,_flip, _energy)
_energy = _energy or 1
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
return {name="zombie",
hab=_hab,
@@ -16,24 +17,52 @@ function zombie.new(_hab,_x,_y,_flip)
frame=0,
wait=0,
step=0,
energy=_energy,
max_energy = _energy,
hit=zombie.hit,
update=zombie.update_normal,
draw=zombie.draw,
jumpfwd=false,
anim={16,17,16,18},
bb={x=4,y=0,w=26,h=32}}
bb={x=4,y=1,w=26,h=30},
can_warp=true,
warping=false,
shrink=1,
d_shrink=1,
angle=0,
d_angle=15,
dying=false,
death_time=40,
enabled=true,
disable_reason=""}
end
function zombie:draw()
if not self.enabled then return end
-- if self.frame>0 then draw.surf((self.frame&7)*16,(self.frame>>3)*16,16,16,self.x,self.y,16,16,self.flip) end
-- if self.frame>0 then draw.surf((self.frame&7)*cw,(self.frame>>cxr2)*ch,cw,ch,self.x*o2aX,self.y*o2aX,cw,ch,self.flip) end
if self.energy==2 then
pal.subpal(10,14)
elseif self.energy>2 then
pal.subpal(10,9)
end
if self.warping then
actor_warp_draw(self)
else
if self.frame>0 then
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
draw.surf((self.frame&7)*cw, (self.frame>>cxr2)*ch, cw, ch, scr_x, scr_y, cw, ch, self.flip)
end
end
pal.subpal(10)
end
function zombie:update_normal()
if not self.enabled then return end
self.wait=self.wait+1
if self.wait==18 then
@@ -62,6 +91,14 @@ function zombie:update_normal()
self.flip=not self.flip
end
if viewp:inside(self.x, self.y, self.w, self.h) then
if collision(abad,self) then
abad_hurt(1)
end
end
self.hab = coords.world_to_room(self.x, self.y)
-- if self.hab==abad.hab then
-- if aabb(abad,self) then
-- abad_hurt(1)
@@ -74,25 +111,57 @@ function zombie:update_normal()
end
function zombie:update_hit()
if not self.enabled then return end
self.wait=self.wait+1
if self.wait==6 then
if self.wait>=6 then
self.wait=0
self.step=self.step+1
if self.step<40 then
if self.can_warp then
actor_warp_update(self)
else
-- Continuar si encara te vida
if self.energy>0 then
self.update=zombie.update_normal
return
end
-- Parpadejar
if self.step<self.death_time then
if self.step%2==0 then
self.frame=16
self.frame=self.anim[#self.anim]
else
self.frame=-1
end
elseif self.step>=40 then
elseif self.step>=self.death_time then
self.frame=self.anim[0]
self.step=0
self.wait=0
self.update=zombie.update_normal
self.dying = false
end
end
end
end
function zombie:hit()
if not self.enabled then return end
self.energy = self.energy-1
if self.energy>0 then
self.can_warp = false
else
self.can_warp = true
if self.can_warp then self.warping=true end
self.shrink=1
self.angle=0
self.dying=true
-- calcular velocitat per al warp
local warp_time = self.death_time/3
self.d_angle = 720 / warp_time; -- 720 = 2 voltes
self.d_shrink = self.shrink / warp_time
end
self.update=zombie.update_hit
end