Compare commits

..

56 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
33 changed files with 3010 additions and 1177 deletions

1
.gitignore vendored
View File

@@ -3,6 +3,7 @@ release/*
*.exe *.exe
*.dll *.dll
*.xcf *.xcf
desktop.ini
mini mini
mini_debug mini_debug
data-old data-old

View File

@@ -44,6 +44,7 @@ function abad_init()
step=0, step=0,
mustep=1, mustep=1,
stairs_flip=false, stairs_flip=false,
stairs_moves=0, --contador de moviments dins de les escales
draw=abad.draw, draw=abad.draw,
hurting=0, hurting=0,
update=nil, update=nil,
@@ -99,13 +100,22 @@ function abad:draw()
local flip = abad.flip local flip = abad.flip
local x, y = viewp:screen_coords(self.x, self.y) local x, y = viewp:screen_coords(self.x, self.y)
if abad.update==abad_state_stairs then if abad.update==abad_state_stairs then
flip=abad.stairs_flip -- flip=abad.stairs_flip
-- flip=(((abad.x>>1)+(abad.y>>1))%2)==0 -- -- 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 if math.abs(abad.stairs_moves-(abad.x+abad.y))>12 then
local msg = "-- "..abad.x.." "..abad.y abad.stairs_moves = abad.x+abad.y
if flip then msg = "FLIP"..abad.x.." "..abad.y end abad.flip = not abad.flip
msg_print(0,35,msg,true)
end 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 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) draw.surf(abad.frame*abad.w,0,abad.w,abad.h,x,y,abad.w,abad.h,flip)
-- caminant, parat, disparant o saltant -- caminant, parat, disparant o saltant
@@ -118,7 +128,7 @@ function abad:draw()
abad.respawning=abad.respawning-1 abad.respawning=abad.respawning-1
end end
-- draw.rect(x+abad.bb.x,y+abad.bb.y,abad.bb.w,abad.bb.h,3) draw.rect(x+abad.bb.x,y+abad.bb.y,abad.bb.w,abad.bb.h,3)
end end
function abad_make_safe( force ) function abad_make_safe( force )
@@ -131,6 +141,12 @@ function abad_make_safe( force )
end end
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) function abad_hurt(howmuch)
howmuch = 0 howmuch = 0
@@ -201,9 +217,9 @@ function abad_jump()
local tile1_hit_type= arc_check_tile(x1_check, y_check ) local tile1_hit_type= arc_check_tile(x1_check, y_check )
local tile2_hit_type= arc_check_tile(x2_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 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 local switch_tile = tile1_hit_type == tiletype.switch or tile2_hit_type == tiletype.switch
-- print("JUMP > "..x1_check..", "..x2_check..", "..y_check) -- 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" -- local msg = "BLOCK TILE HITTED"
-- if not_block_tile then msg="not block" end -- if not_block_tile then msg="not block" end
-- print(msg) -- print(msg)
@@ -220,7 +236,16 @@ function abad_jump()
--else --else
-- abad.y=abad.y-vspace -- abad.y=abad.y-vspace
--end --end
if switch_tile then
-- 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 abad.y=abad.y-vspace
end
else
abad.y=abad.y-vspace
end
else else
local tile1_hit = arc_get_tile(x1_check, y_check ) local tile1_hit = arc_get_tile(x1_check, y_check )
local tile2_hit = arc_get_tile(x2_check, y_check) local tile2_hit = arc_get_tile(x2_check, y_check)
@@ -283,29 +308,88 @@ function abad_land ()
return can_land return can_land
end 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() function abad_advance()
local step_length=abad.step_length; --lo que avança l'abad cada pas local step_length=abad.step_length; --lo que avança l'abad cada pas
local limit=tiletype.block 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 local x_check = abad.x+abad.bb.x+abad.bb.w+step_length
if abad.flip then if abad.flip then
step_length = -step_length step_length = -step_length
x_check = abad.x+abad.bb.x+step_length x_check = abad.x+abad.bb.x+step_length
end 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 if arc_check_tile(x_check, y_check)<limit then
abad.x=abad.x+step_length abad.x=abad.x+step_length
end end
if arc_check_tile(x_check,y_check)==tiletype.stair then -- if arc_check_tile(x_check,y_check)==tiletype.stair then
abad.update=abad_state_stairs -- print("STAIRS "..math.random(50))
elseif abad.update==abad_state_stairs then -- 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.update=abad_state_normal
abad.frame=0 abad.frame=0
end end
local hab,xx, yy = coords.world_to_tile(abad.x, abad.y) local hab,xx, yy = coords.world_to_tile(abad.x, abad.y)
abad.hab = hab abad.hab = hab
end end
@@ -324,9 +408,10 @@ function abad_state_normal()
end end
if abad.falling>0 then if abad.falling>0 then
if abad.falling>(abad.max_jump_height<<1) then local altura_piso = (mapa_room_rows*arcade_config.tiles_height)
-- numero de pisos caiguts * 2 local pisos_caiguts = math.floor(abad.falling/altura_piso)
local damage = math.floor(abad.falling/(mapa_room_rows*arcade_config.tiles_height))*2 local damage = pisos_caiguts*2
if damage>0 then
if damage>abad.energia then damage=abad.energia end if damage>abad.energia then damage=abad.energia end
abad_hurt(damage) abad_hurt(damage)
end end
@@ -338,13 +423,19 @@ function abad_state_normal()
if controller:check("right") then if controller:check("right") then
abad.update=abad_state_walking abad.update=abad_state_walking
abad.flip=false abad.flip=false
elseif controller:check("up") and abad_in_stairs() then
abad.update=abad_state_stairs
elseif controller:check("left") then elseif controller:check("left") then
abad.update=abad_state_walking abad.update=abad_state_walking
abad.flip=true abad.flip=true
elseif controller:check("jump") then elseif controller:check("jump") then
abad_do_jump() abad_do_jump()
elseif controller:check("down") then elseif controller:check("down") then
if abad_in_stairs() then
abad.update=abad_state_stairs
else
abad.update=abad_state_crouch abad.update=abad_state_crouch
end
--elseif btn(KEY_Z) then --elseif btn(KEY_Z) then
-- abad.respawning=240 -- abad.respawning=240
elseif controller:check("shoot") then elseif controller:check("shoot") then
@@ -504,32 +595,46 @@ end
function abad_state_stairs() function abad_state_stairs()
abad.frame=4 abad.frame=4
abad.wait=abad.wait+1 abad.wait=abad.wait+1
local moved = false
local x1_check = abad.x+abad.bb.x --local x1_check = abad.x+abad.bb.x
local x2_check = abad.x+abad.bb.x+abad.bb.w-1 --local x2_check = abad.x+abad.bb.x+abad.bb.w-1
local y_check = abad.y+abad.bb.h-1 --local y_check = abad.y+abad.bb.h
if controller:check("right") then if controller:check("right") then
abad.flip=false abad.flip=false
abad_advance() abad_advance()
if abad.wait==6 then sound.play(audio_low) end moved = true
elseif controller:check("left") then elseif controller:check("left") then
abad.flip=true abad.flip=true
abad_advance() abad_advance()
if abad.wait==6 then sound.play(audio_low) end moved = true
elseif controller:check("up") then elseif controller:check("up") then
if arc_check_tile(x1_check,y_check)==tiletype.stair and --y_check = y_check - 1
arc_check_tile(x2_check,y_check)==tiletype.stair then --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 abad.y=abad.y-1
if abad.wait==6 then sound.play(audio_low) end moved = true
end end
elseif controller:check("down") then elseif controller:check("down") then
if arc_check_tile(x1_check,y_check)==tiletype.stair and -- y_check = y_check + 1
arc_check_tile(x2_check,y_check)==tiletype.stair then -- 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 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
end end
if moved and abad.wait==6 then sound.play(audio_low) end
if abad.wait==6 then abad.wait=0 end if abad.wait==6 then abad.wait=0 end
end end

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_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=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() function bol.init()
local world_x, world_y = coords.room_to_world(bol.hab,bol.x,bol.y) 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 x = bol_gif_col*tw
local y = toff+bol_gif_row*th local y = toff+bol_gif_row*th
local scr_x, scr_y = viewp:screen_coords( bol.x, bol.y ) 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) 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 end
function bol.update() function bol.update()
@@ -37,4 +57,16 @@ function bol.update()
-- remove_actor(bol) -- remove_actor(bol)
-- end -- end
-- 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 end

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, flip=true,
goup=true, goup=true,
frame=8, frame=8,
parpadeig=false,
stairscooldown=0, stairscooldown=0,
wait=0, wait=0,
step=0, step=0,
@@ -23,7 +24,7 @@ elalien={name="elalien",
function elalien.init() function elalien.init()
-- elalien.x=24 -- elalien.x=24
elalien.x=3 elalien.x=9
-- elalien.y=24 -- elalien.y=24
elalien.y=3 elalien.y=3
elalien.w=32 elalien.w=32
@@ -37,7 +38,8 @@ function elalien.init()
elalien.scene_intro=false elalien.scene_intro=false
elalien.scene_object=false elalien.scene_object=false
local habs={66,56,59,53} 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) local world_x, world_y = coords.room_to_world(elalien.hab,elalien.x,elalien.y)
elalien.x=world_x elalien.x=world_x
@@ -49,24 +51,82 @@ function elalien.draw()
if elalien.update==elalien.update_stairs then if elalien.update==elalien.update_stairs then
flip=(((elalien.x>>1)+(elalien.y>>1))%2)==0 flip=(((elalien.x>>1)+(elalien.y>>1))%2)==0
end 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 ) 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 x = (elalien.frame&7)*cw
local y = (elalien.frame>>cxr2)*ch local y = (elalien.frame>>cxr2)*ch
draw.surf(x,y,cw,ch,scr_x,scr_y,elalien.w,elalien.h,flip) draw.surf(x,y,cw,ch,scr_x,scr_y,elalien.w,elalien.h,flip)
end
end end
function elalien.hit() function elalien.hit()
end end
function elalien.update_stay() function elalien.update_stay()
elalien.wait=elalien.wait+1 elalien.wait=elalien.wait+1
if elalien.wait==6 then if elalien.wait==18 then
elalien.wait=0 elalien.wait=0
elalien.step=(elalien.step+1)%4 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
end end

View File

@@ -1,52 +1,124 @@
local arcade_config = require("arcade_config")
o2aX = arcade_config.org2arc_escala
fireball={hab=-1,x=0,y=0,wait=0,flip=false,bb={x=0,y=0,w=4,h=4}} 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) 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 if fireball.hab ~= -1 then return end
_off_x = _off_x or 0
_off_y = _off_y or 0
fireball.hab=_hab fireball.hab=_hab
fireball.x=_x fireball.x= world_x+_off_x
fireball.y=_y fireball.y= world_y+_off_y
fireball.flip=_flip 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 end
function fireball.draw() function fireball.draw()
draw.circf(fireball.x*o2aX,fireball.y*o2aX,3*o2aX,16) if fireball.hab == -1 then return end
draw.circf(fireball.x*o2aX,fireball.y*o2aX,2*o2aX,3) local scr_x, scr_y = viewp:screen_coords( fireball.x, fireball.y )
draw.circf(fireball.x*o2aX,fireball.y*o2aX,1*o2aX,8) 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 end
function fireball.update() function fireball.update()
if fireball.hab == -1 then return end if fireball.power==2 and fireball.power>fireball.size then
fireball.wait=fireball.wait+1 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
if fireball.wait==3 then 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 fireball.wait=0
if fireball.x>96 then --if viewp:inside(fireball.x, fireball.y, fireball.w, fireball.h)==false then
fireball.hab=-1 -- fireball.hab=-1
return -- return
elseif check_tile(fireball.hab,fireball.x,fireball.y)<tiletype.block then --end
if fireball.power==1 then
if arc_check_tile(fireball.x,fireball.y)<tiletype.block then
if fireball.flip then if fireball.flip then
fireball.x=fireball.x-4 fireball.x=fireball.x-fireball.step_length
else else
fireball.x=fireball.x+4 fireball.x=fireball.x+fireball.step_length
end
if fireball.x<-4 then
fireball.hab=-1
return
end end
else else
fireball.hab=-1 fireball.hab=-1
return return
end end
elseif fireball.power==2 then
fireball.x = fireball.x+fireball.step_length_x
fireball.y = fireball.y+fireball.step_length_y
end
if fireball.hab==abad.hab then if viewp:inside(fireball.x, fireball.y, fireball.w, fireball.h) then
if aabb(fireball,abad) and abad.update~=abad_state_crouch then if collision(fireball,abad) then
fireball.hab=-1 if fireball.power==1 and abad.update~=abad_state_crouch then
abad_hurt(1) abad_hurt(1)
fireball.hab=-1
elseif fireball.power==2 then
abad_hurt(2)
fireball.hab=-1
end end
end end
else
fireball.hab=-1
end end
--end
end end

View File

@@ -14,10 +14,19 @@ require "zombie"
require "score" require "score"
-- require "switches" -- require "switches"
require "trigger" require "trigger"
require "imp" require "imp3"
require "fireball"
require "bar_meter"
require "stage1" require "stage1"
require "remote_view" require "remote_view"
require "dialeg"
require "trigger_event"
require "batman"
require "health_potion"
require "tiles_layer2"
require "batvio"
local DEBUG = false local DEBUG = false
@@ -30,10 +39,18 @@ local view_tile_id = false
local view_checking_tile = false local view_checking_tile = false
local stage= 1 local stage= 1
local stage_loaded = 0 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 = viewport.new(arcade_config.resolucion.width, arcade_config.resolucion.height)
viewp:position(0,0) viewp:position(0,0)
function foo()
print("foo")
end
function actor_warp_draw(actor) function actor_warp_draw(actor)
local shrink_w = actor.w*actor.shrink local shrink_w = actor.w*actor.shrink
local shrink_h = actor.h*actor.shrink local shrink_h = actor.h*actor.shrink
@@ -68,6 +85,9 @@ function actor_warp_update(actor)
actor.warping = false actor.warping = false
actor.frame = -1 actor.frame = -1
actor.step = 0 actor.step = 0
if actor.energy~=nil then
actor.energy = actor.max_energy
end
end end
end end
elseif actor.step<actor.death_time/2 then elseif actor.step<actor.death_time/2 then
@@ -139,6 +159,11 @@ end
function load_boss_stage() function load_boss_stage()
local stage_boss = stages["stage"..stage.."_boss"] local stage_boss = stages["stage"..stage.."_boss"]
if stage_boss and not scene_running and not stages.loaded_boss then 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() stage_boss()
print("Stage "..stage.." Boss loaded") print("Stage "..stage.." Boss loaded")
else else
@@ -167,6 +192,7 @@ end
function world_update() function world_update()
-- Actualitzar moviment del mapa (ex: tiles animats) -- Actualitzar moviment del mapa (ex: tiles animats)
arc_mapa_update() arc_mapa_update()
tiles_layer2.update()
-- Moure a tots -- Moure a tots
for key,actor in pairs(actors) do for key,actor in pairs(actors) do
@@ -189,15 +215,27 @@ function world_update()
end end
end end
if stages.boss_loaded then
stage_update()
else
-- print("NO BOSS")
end
-- Actualizar el que queda -- Actualizar el que queda
cacau.update() cacau.update()
-- switches.update() -- switches.update()
warp.update_all() warp.update_all()
trigger_event.update()
end end
function world_draw() function world_draw()
-- Pintar la finestra del mon -- Pintar la finestra del mon
render_map(sf_mapa, tiles, viewp.x, viewp.y) render_map(sf_mapa, tiles, viewp.x, viewp.y)
tiles_layer2.draw()
if stages.boss_loaded then stage_draw_back() end
-- pintar warps -- pintar warps
for key,warp in pairs(warp.warp_list) do for key,warp in pairs(warp.warp_list) do
@@ -213,14 +251,31 @@ function world_draw()
end end
end end
dialeg.draw()
if stages.boss_loaded then stage_draw_middle() end
cacau:draw() cacau:draw()
if stages.boss_loaded then stage_draw_front() end
remote_view_draw() remote_view_draw()
end end
function update_game() function update_game()
if stage~=stage_loaded then load_stage() end 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 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.target(0)
surf.cls(16) surf.cls(16)
@@ -233,9 +288,9 @@ function update_game()
score.draw() score.draw()
if DEBUG then
special_keys() special_keys()
debug_info() debug_info()
if DEBUG then
end end
end end
@@ -310,26 +365,81 @@ function update_pause()
end 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() 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 if key.press(key.N1) then
-- -- abad prev room -- abad prev room
-- local hab = abad.hab-1 local hab = abad.hab-1
-- if hab<0 then hab=0 end if hab<0 then hab=0 end
-- local hab_x = 4 local hab_x = 4
-- local hab_y = 3 local hab_y = 3
-- local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y) local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y)
-- abad:move(abad_x, abad_y) abad:move(abad_x, abad_y)
-- local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y) local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end end
if key.press(key.N2) then if key.press(key.N2) then
-- -- abad next room -- abad next room
-- local hab = abad.hab+1 local hab = abad.hab+1
-- if hab<0 then hab=0 end if hab<0 then hab=0 end
-- local hab_x = 4 local hab_x = 4
-- local hab_y = 3 local hab_y = 3
-- local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y) local abad_x, abad_y = coords.room_to_world ( hab, hab_x, hab_y)
-- abad:move(abad_x, abad_y) abad:move(abad_x, abad_y)
-- local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y) local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end end
if key.press(key.N8) then if key.press(key.N8) then
-- local abad_x, abad_y = coords.room_to_world ( 31, 8, 3 ) -- local abad_x, abad_y = coords.room_to_world ( 31, 8, 3 )
@@ -359,14 +469,15 @@ function special_keys()
end end
function debug_info() function debug_info()
if true then return end -- fps_print()
-- if true then return end
font.current(font_default) font.current(font_default)
viewp:print() -- viewp:print()
msg_print(0,14,"ABAD= "..abad.x..", "..abad.y, true) -- msg_print(0,14,"ABAD= "..abad.x..", "..abad.y, true)
msg_print(0,21,"VIEW= "..viewp.x..", "..viewp.y, true) -- msg_print(0,21,"VIEW= "..viewp.x..", "..viewp.y, true)
local hab, xx, yy = coords.world_to_tile(abad.x, abad.y) local hab, xx, yy = coords.world_to_tile(abad.x, abad.y)
msg_print(0,28,hab.." ( "..xx..", "..yy.." )", true) msg_print(0,28,hab.." ( "..xx..", "..yy.." )", true)
msg_print(0,35,hab.." ( "..xx..", "..yy.." )", true) -- msg_print(0,35,hab.." ( "..xx..", "..yy.." )", true)
-- msg_print(0,42," JH= "..abad.jump_height,true) -- msg_print(0,42," JH= "..abad.jump_height,true)
-- view_coord(abad.x+8, abad.y+0, 16, 32, 6) -- view_coord(abad.x+8, abad.y+0, 16, 32, 6)

View File

@@ -112,7 +112,7 @@ function gota:draw_falling()
local gota_x, gota_y = viewp:screen_coords( self.x, self.y ) 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+4, gota_y+12, 4, 16)
draw.circf( gota_x+5, gota_y+13, 3, 11) draw.circf( gota_x+5, gota_y+13, 3, 11)
surf.pixel( gota_x+3, gota_y+13, 2) draw.pixel( gota_x+3, gota_y+13, 2)
end end
function gota:draw_drop( x, y ) function gota:draw_drop( x, y )

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

View File

@@ -4,11 +4,39 @@ local shine_pos = 0
local map_backup = {} local map_backup = {}
local actors_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) function collision(a, b)
return (a.x+a.bb.x+a.bb.w >= b.x+b.bb.x) 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.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)
and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h) and (a.y+a.bb.y < b.y+b.bb.y+b.bb.h)
end end
function half_collision(a, b) function half_collision(a, b)
@@ -38,8 +66,8 @@ function remove_actor(actor)
end end
function set_actors_enabled_by_room(_enabled, _reason, room0, room1) function set_actors_enabled_by_room(_enabled, _reason, room0, room1)
print("set_actors_enabled_by_room") -- print("set_actors_enabled_by_room")
print(" hab_list") -- print(" hab_list")
room1 = room1 or room0 room1 = room1 or room0
local rw=(room1-room0)%mapa_rooms_per_piso local rw=(room1-room0)%mapa_rooms_per_piso
local hab_list = {} local hab_list = {}
@@ -47,25 +75,25 @@ print(" hab_list")
while y<=room1 do while y<=room1 do
for x=y, y+rw do for x=y, y+rw do
hab_list[x]=true hab_list[x]=true
print(" "..x) -- print(" "..x)
end end
y = y+mapa_rooms_per_piso y = y+mapa_rooms_per_piso
end end
for index, actor in pairs(actors) do for index, actor in pairs(actors) do
if hab_list[actor.hab] and actor~=abad then if hab_list[actor.hab] and actor~=abad then
if actor.name then print(" "..actor.name) end -- if actor.name then print(" "..actor.name) end
if actor.disable_reason then print(" "..actor.disable_reason) end -- if actor.disable_reason then print(" "..actor.disable_reason) end
if actor.enabled then print("ENABLED") end -- if actor.enabled then print("ENABLED") end
if not _enabled then if not _enabled then
print("DISABLE ACTORS") -- print("DISABLE ACTORS")
-- disable -- disable
if actor.enabled then if actor.enabled then
-- Si el actor està actiu -> deshabilitar amb motiu -- Si el actor està actiu -> deshabilitar amb motiu
actor.enabled=_enabled actor.enabled=_enabled
actor.disable_reason = _reason actor.disable_reason = _reason
print("-> ".._reason) -- print("-> ".._reason)
end end
else else
-- enable -- enable
@@ -316,7 +344,7 @@ function msg_print(x, y, msg, direct_print )
else else
scr_x, scr_y = viewp:screen_coords(x, y) scr_x, scr_y = viewp:screen_coords(x, y)
end end
draw.rectf(scr_x,scr_y,256,20,16) draw.rectf(scr_x,scr_y,64,8,16)
draw.text(msg,scr_x+1,scr_y+1,2) draw.text(msg,scr_x+1,scr_y+1,2)
end end

View File

@@ -1,966 +0,0 @@
cxr2 = arcade_config.character_per_row_base2
imp = {}
local DEBUG_FN_NAME = false
function imp.reset()
imp.hit=imp.hit
imp.update=imp.update
imp.draw=imp.draw
imp.hab=abad.hab
imp.enabled=false
imp.counter=500
end
function imp.new(_hab, _x, _y)
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
_fight_modes={"chase","away","super","shot"}
for i,v in ipairs(_fight_modes) do _fight_modes[v] = i end
return { name="imp",
hab=_hab,
x=world_x, y=world_y,
w=32, h=32,
flip=true,
frame=28,
wait=0,
vides=1,
energia=6,
max_energia=6,
falling=0,
step=0,
hurting=0,
jumpfwd=false,
step_length=1,
vmove_space=1,
max_jump_height=24,
jump_height=0,
jump_in_half_block=0,
jump_in_half_block_used = false,
max_shoot_cooldown=24,
shot_power=1,
shot_num_shots=1,
shoot_cooldown=25,
anim={28,29,28,30},
bb={x=8,y=0,w=16,h=32},
scene_intro=false,
scene_object=false,
fight_modes=_fight_modes,
mode="stop",
mode_cooldown=500,
super_cooldown=2000,
shot_cooldown=500,
action="",
movement="",
movement_type="",
enabled=true,
disable_reason="",
can_warp=false,
fight=imp.fight,
draw=imp.draw,
hit=imp.hit,
hot_points={},
target={},
old_target={},
path={},
paths={},
action_event="",
path_curr_action=1,
analisis={},
invencible=false,
-- direccio=imp.direccio,
do_jump=imp.do_jump,
jump=imp.jump,
state_jumping=imp.state_jumping,
chase=imp.chase,
away=imp.away,
move=imp.move,
super=imp.super,
shot=imp.shot,
do_flip=imp.do_flip,
update=imp.state_normal,
land=imp.land,
mode_controller=imp.mode_controller,
advance=imp.advance,
reduce_cooldown=imp.reduce_cooldown,
think=imp.think,
move=imp.move,
controller_input=imp.controller_input,
ia=imp.ia,
analyze_env=imp.analyze_env,
next_pattern_action=imp.next_pattern_action,
pattern_action=imp.pattern_action,
reset_mode_cooldown=imp.reset_mode_cooldown,
free_movement=imp.free_movement,
free_move=imp.free_move,
reset_pattern_movement=imp.reset_pattern_movement,
pattern_move=imp.pattern_move,
next_pattern_target=imp.next_pattern_target,
next_free_target=imp.next_free_target,
old_action="-"
-- imp.enabled=false
-- imp.counter=500
}
end
function imp:fight()
if DEBUG_FN_NAME then print("fight") end
self.hot_points[1] = point.new(44, 5, 1, 0, 8,"P1")
self.hot_points[2] = point.new(45, 8, 1, 0, 8,"P2")
self.hot_points[3] = point.new(44,12, 5, 8, 0,"P3")
self.hot_points[4] = point.new(54, 5, 4, -8, 0,"P4")
self.hot_points[5] = point.new(54,12, 4, 8, 0,"P5")
self.hot_points[6] = point.new(55, 8, 4, 8, 0,"P6")
self.hot_points[7] = point.new(55, 8, 0, 0, 0,"P7")
self.hot_points[8] = point.new(54, 5, 0, 0, 0,"P8")
self.hot_points[9] = point.new(54, 9, 1, 0, 0,"P9")
self.hot_points[10] = point.new(55,4, 1, 0, 0,"P10")
self.hot_points[11] = abad
self.target = self.hot_points[6]
self.path = {next=6, actions={{action="right",event="target"}}}
self.paths[1] = {
{next=3, actions= {{action="right" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="target"}}},
{next=4, actions= {{action="right" , event="land"},
{action="left" , event="target"}}},
{next=4, actions= {{action="right" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="target"}}},
{next=10, actions= {{action="right" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="target"}}},
{next=6, actions= {{action="right" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="target"}}},
{next=5, actions= {{action="right" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="land"},
{action="left" , event="target"}}},
{next=5, actions= {{action="right" , event="target"}}}
}
self.paths[2] = {
{next=3, actions={{action="left" , event="prefall"},
{action="jumpfwd" , event="land"},
{action="left" , event="target"}}},
{next=6, actions={{action="left" , event="land"},
{action="right" , event="target"}}},
{next=6, actions= {{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="target"}}},
{next=9, actions= {{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="target"}}},
{next=4, actions= {{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="target"}}},
{next=5, actions= {{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="land"},
{action="right" , event="target"}}},
{next=5, actions={{action="left" , event="target"}}}
}
self.paths[3] = {
{next=1, actions={{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="prefall"},
{action="jump" , event="target"}}},
{next=2, actions={{action="right" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="prefall"},
{action="jump" , event="target"}}},
{next=4, actions={{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="right" , event="land"},
{action="left" , event="target"}}},
{next=5, actions={{action="left" , event="land"},
{action="right" , event="target"}}},
{next=6, actions={{action="left" , event="land"},
{action="right" , event="target"}}}
}
self.paths[4] = {
{next=1, actions={{action="jump" , event="target"}}},
{next=5, actions={{action="right", event="target"}}},
{next=6, actions={{action="right", event="target"}}},
{next=8, actions={{action="jump" , event="target"}}},
}
self.paths[5] = {
{next=4, actions={{action="left" , event="target"}}},
{next=6, actions={{action="right", event="target"}}}
}
self.paths[6] = {
{next=2, actions={{action="jump", event="target"}}},
{next=5, actions={{action="left", event="target"}}},
{next=7, actions={{action="jump", event="target"}}},
{next=4, actions={{action="left", event="target"}}}
}
self.paths[7] = {
{next=5, actions={{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="target"}}},
{next=10,actions={{action="left" , event="prefall"},
{action="jumpfwd", event="land"},
{action="left" , event="target"}}},
{next=2, actions={{action="jump" , event="target"}}}
}
self.paths[8] = {
{next=5, actions={{action="right" , event="prefall"},
{action="jumpfwd" , event="land"},
{action="right" , event="target"}}},
{next=9, actions={{action="right" , event="prefall"},
{action="jumpfwd" , event="land"},
{action="right" , event="target"}}},
{next=1, actions={{action="jump" , event="target"}}}
}
self.paths[9] = {
{next=5, actions={{action="right" , event="target"}}},
{next=1, actions={{action="left" , event="prefall"},
{action="jumpfwd" , event="land"},
{action="left" , event="prefall"},
{action="jump" , event="target"}}},
{next=4, actions={{action="left" , event="target"}}}
}
self.paths[10] = {
{next=5, actions={{action="left" , event="target"}}},
{next=2, actions={{action="right" , event="prefall"},
{action="jumpfwd" , event="land"},
{action="right" , event="prefall"},
{action="jump" , event="target"}}},
{next=6, actions={{action="right" , event="target"}}}
}
self.paths[11] = {}
self.mode="chase"
end
function imp:draw()
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
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)
draw.rect(scr_x+self.bb.x,scr_y+self.bb.y,self.bb.w,self.bb.h,3)
if #self.hot_points>0 then
for _, p in pairs(self.hot_points) do
if self.target==p then
p:draw(true)
else
p:draw()
end
end
end
-- print("DRAW path= "..#self.path)
if #self.path>0 then
for i=1,#self.path do
local world_x, world_y = coords.room_to_world(self.path[i][1], self.path[i][2], self.path[i][3])
local scr_x, scr_y = viewp:screen_coords( world_x, world_y )
draw.rect(scr_x, scr_y, 16, 16, 14)
end
end
end
function imp:hit()
if DEBUG_FN_NAME then print("hit") end
end
function imp:do_jump ( jumpfwd )
if DEBUG_FN_NAME then print("do_jump") end
-- msg_print(0,0,"do_jump",true)
-- Inicialització de fer el salt
jumpfwd = jumpfwd or false
self.jump_height = 0
self.update=imp.state_jumping
self.step=0
self.jumpfwd=jumpfwd
self.action=""
end
function imp:state_jumping()
if DEBUG_FN_NAME then print("state_jumping") end
-- msg_print(0,0,"state_jumping",true)
-- ??
self.wait=self.wait+1
self.wait=0
-- Pujar o caure
if self.jump_height<self.max_jump_height then
-- Comprovar que pasa en l'aire
self:jump()
else
-- Canviar a mode caure
self.update=imp.state_falling
end
self.step=self.step+1
-- cap endavant?
if self.jumpfwd then self:advance() end
self:ia()
end
function imp:jump()
if DEBUG_FN_NAME then print("jump") end
-- msg_print(0,0,"jump",true)
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.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.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+1
end
function imp:state_walking()
if DEBUG_FN_NAME then print("state_walking") end
-- msg_print(16,48,"state_walking",true)
-- Limitar la velocitat de moviment
self.wait=self.wait+1
-- representació del moviment
-- Selecció de frame
if self.wait==6 then
self.wait=0
self.step=(self.step+1)%4
self.frame=self.anim[self.step+1]
end
-- 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.update=imp.state_falling
return
end
self:advance()
self:ia()
end
function imp:state_falling()
if DEBUG_FN_NAME then print("state_falling") end
-- msg_print(16,16,"state_falling",true)
self.frame=30
self.wait=self.wait+1
-- Si toca terra canviar el mode
if self:land() then
self.update=imp.state_normal
return
end
-- Seguir caiguent
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
self:ia()
end
function imp:land ()
if DEBUG_FN_NAME then print("land") end
-- msg_print(16,32,"land",true)
-- 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.action_event = "land"
end
return can_land
end
function imp:advance()
if DEBUG_FN_NAME then print("advance") end
-- msg_print(0,0,"advance",true)
local step_length=self.step_length; --lo que avança el imp cada pas
local limit=tiletype.block
if self.update~=imp.state_walking then limit=tiletype.half end
local x_check = self.x+self.bb.x+self.bb.w+step_length
-- if self.flip then
-- step_length = -step_length
-- x_check = self.x+self.bb.x+step_length
-- end
-- self.action=="right"
-- if self.action=="left" then
-- print("ADVANCE => "..self.movement)
if self.movement=="left" then
step_length = -step_length
x_check = self.x+self.bb.x+step_length
end
local y_check = self.y+self.bb.h-4
if arc_check_tile(x_check, y_check)<limit then
self.x=self.x+step_length
end
local hab,xx, yy = coords.world_to_tile(self.x, self.y)
self.hab = hab
-- self.movement = ""
end
-- Controlador principal del personatge
function imp:state_normal()
if DEBUG_FN_NAME then print("state_normal") end
self.frame=28
self.wait=0
self.step=0
self.jumpfwd=false
self.jump_height = 0
self:ia()
end
function imp:state_super()
if DEBUG_FN_NAME then print("state_super") end
self.mode = self.fight_modes["super"]
self.mode_cooldown=1
self.super_cooldown=2000
self.update=imp.state_normal
end
function imp:shot(actor)
if DEBUG_FN_NAME then print("shot") end
self.mode = self.fight_modes["shot"]
self.mode_cooldown=1
print("FIREBALL!!")
self.shot_cooldown = 500
end
function imp:do_flip(actor)
if DEBUG_FN_NAME then print("do_flip") end
if actor.x<self.x then self.flip=true else self.flip=false end
end
function imp:reduce_cooldown()
if DEBUG_FN_NAME then print("reduce_cooldown") end
if self.mode=="stop" then return end
self.mode_cooldown = self.mode_cooldown -1
self.super_cooldown = self.super_cooldown -1
self.shoot_cooldown = self.shoot_cooldown -1
end
function imp:reset_mode_cooldown( value )
if DEBUG_FN_NAME then print("reset_mode_cooldown") end
value = value or 500
self.mode_cooldown = value
return value
end
function imp:reset_pattern_movement()
if DEBUG_FN_NAME then print("reset_pattern_movement") end
self.path={}
self.path_curr_action=1;
end
function imp:pattern_action()
if DEBUG_FN_NAME then print("pattern_action") end
local action = self.path.actions[self.path_curr_action].action
-- print("PATTERN");
-- print(" TARGET= "..self.path.next)
-- print(" ACTION= "..action)
return action
end
function imp:pattern_move()
if DEBUG_FN_NAME then print("pattern_move") end
local path_event = self.path.actions[self.path_curr_action].event
-- print(" PATH_EVENT= "..path_event)
-- print(" ACTION_EV = "..self.action_event)
-- Si no s'ha donat l'event mantindre el moviment
if self.action_event~=path_event then
action = self.path.actions[self.path_curr_action].action
else
-- Si s'ha donat l'event avançar el punter del path
-- print(" #"..self.path_curr_action.." / "..#self.path.actions)
if self.path_curr_action<#self.path.actions then
-- En el path
self.path_curr_action = self.path_curr_action + 1
-- print(" CURR_ACC= "..self.path_curr_action)
action = self:pattern_action()
-- print(" ACTION 1= "..action)
else
-- Path acabat, anar al següent
action = self:next_pattern_action()
-- print(" ACTION 2= "..action)
end
end
-- print(" ACTION ="..action)
return action
end
function imp:next_pattern_target(from)
if DEBUG_FN_NAME then print("next_pattern_target") end
-- obtindre uno dels possibles camins des del punt "from" (en el que està)
local next_path_idx = math.random(#self.paths[from])
self.path = self.paths[from][next_path_idx]
self.path_curr_action = 1
self.target = self.hot_points[self.path.next]
end
function imp:next_pattern_action( from )
from = from or self.path.next
if DEBUG_FN_NAME then print("next_pattern_action "..from) end
if #self.paths[from]>0 then
self.movement_type = "pattern"
self:reset_mode_cooldown()
-- Activar següent target
self:next_pattern_target(from)
action = self:pattern_action()
-- self.action_event=""
else
self:free_movement()
action = self:free_move()
end
return action
end
function imp:free_movement()
if DEBUG_FN_NAME then print("free_movement") end
self.movement_type = "free"
print("Free")
end
function imp:free_move()
if DEBUG_FN_NAME then print("free_move") end
-- Moviment horitzontal
if self.target.x+self.target.bb.x>=self.x+self.bb.x then
action="right"
elseif self.target.x+self.target.bb.x<self.x+self.bb.x then
action="left"
end
-- Els dos punts de baix pero un poc mes alt que el piso
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
-- Tiles on esta
local tile_type1, tile_code1= arc_check_tile(x1_check,y_check)
local tile_type2, tile_code2= arc_check_tile(x2_check,y_check)
-- debug
local scr_x1, scr_y = viewp:screen_coords( x1_check, y_check )
local scr_x2, scr_y = viewp:screen_coords( x2_check, y_check )
draw.rect(scr_x1,scr_y,scr_x2-scr_x1,8,2)
-- /debug
--Comprovar si está en target
if collision(self, self.target) then
self:reset_mode_cooldown()
-- Buscar quin es el target
local idx = 1
for i=1,#self.hot_points do
if self.target==self.hot_points[i] then
idx= i
-- print("TARGET ID= "..self.target.id.." HOT POINT IDX= "..i.." Reached")
end
end
-- Canviar a moviment per patro
action = self:next_pattern_action(idx)
-- elseif half_collision(self, self.target)
-- and tile_type1==tiletype.void
-- and tile_type2==tiletype.void then -- and (self.y>self.target.y or self.y<self.target.y) ) then -- afegir que no hi haja tile per a escalar
-- -- print("Next Target 2 "..tile_type1.." "..tile_code1)
-- elseif tile_type1~=tiletype.void
-- or tile_type2~=tiletype.void then
-- action="jump"
end
return action
end
function imp:next_free_target()
if DEBUG_FN_NAME then print("next_free_target") end
local new_point = math.random(#self.hot_points)
if self.target == self.hot_points[new_point] then
new_point = ((new_point+1)%#self.hot_points)+1
end
self.old_target = self.target
self.target=self.hot_points[new_point]
end
function imp:analyze_env()
if DEBUG_FN_NAME then print("analyze_env") end
-- Distancia fins els punts
local scr_x, scr_y = viewp:screen_coords(self.x, self.y)
-- for _, p in pairs(self.hot_points) do
-- local scr_x1, scr_y1 = viewp:screen_coords(p.x, p.y)
-- local color = 2
-- if self.target == p then color = 4 end
-- draw.line(scr_x, scr_y, scr_x1, scr_y1, color)
--
-- dx = (self.x-p.x)
-- dy = (self.y-p.y)
-- d = math.sqrt(dx*dx+dy*dy)
-- end
-- Distancia fins a l'abad
dx = (self.x-abad.x)
dy = (self.y-abad.y)
r = math.sqrt(dx*dx+dy*dy)
-- msg_print(10,20,r,true)
self.analisis.can_chase_abad = false
if r<=100 then
-- draw.circ(scr_x+self.bb.w/2,scr_y+self.bb.h/2,r,2)
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.super_cooldown<=0 then self.analisis.can_super=true end
-- Acces a la zona central
x1_check = self.x+self.bb.x
x2_check = self.x+self.bb.x+self.bb.w
y_check = self.y+self.bb.h
self.analisis.can_go_altar = false
local hab1, tx1, ty1 = coords.world_to_tile(x1_check, y_check)
local 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
self.analisis.can_go_altar = true
end
-- Cau al següent moviment
self.analisis.going_to_fall = false
if self.movement=="left" then
x1_check=x1_check-self.step_length
x2_check=x2_check-self.step_length
elseif self.movement=="right" then
x1_check=x1_check+self.step_length
x2_check=x2_check+self.step_length
end
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.going_to_fall = true
end
self.analisis.target_reached = false
-- local target_aligned = false
-- self.path= {}
-- -- print("ANALYZE => "..#self.target)
if not empty_table(self.target) then
-- Target reached
if collision(self, self.target) then self.analisis.target_reached=true end
--
-- -- Target aligned
-- if half_collision(self, self.target) then target_aligned=true end
--
-- local hab1, tx1, ty1 = coords.world_to_tile(self.x+self.bb.x, self.y+self.bb.y+self.h/2)
-- local hab2, tx2, ty2 = coords.world_to_tile(self.target.x, self.target.y)
-- -- print(hab1..", "..tx1..", "..ty1)
-- -- print(hab2..", "..tx2..", "..ty2)
-- local floorImp = math.floor(hab1 / 10)
-- local floorTarget = math.floor(hab2 / 10)
-- local roomImp = hab1 % 10
-- local roomTarget = hab2 % 10
--
-- local sentit_y = 1
-- if floorImp>floorTarget then
-- sentit_y = -1
-- elseif floorImp==floorTarget then
-- sentit_y = 1
-- if ty1>ty2 then
-- sentit_y= -1
-- elseif ty1==ty2 then
-- sentit_y = 0
-- end
-- end
--
-- local sentit_x = 1
-- if roomImp>roomTarget then
-- sentit_x = -1
-- elseif roomImp==roomTarget then
-- sentit_x = 1
-- if tx1>tx2 then
-- sentit_x = -1
-- elseif tx1==tx2 then
-- sentit_x = 0
-- end
-- end
--
-- local max_steps = 50
-- local found = false
-- while not found and max_steps>0 do
-- max_steps = max_steps -1
-- end
--
-- if hab1==hab2 then
-- local tx = 0
-- local ty = 0
-- if tx2<tx1 then
-- for i=tx2,tx1 do
-- tx = i
-- self.path[#self.path+1] = {hab1, tx, ty1}
-- end
-- if ty2<ty1 then
-- for j=ty2,ty1 do
-- ty = j
-- self.path[#self.path+1] = {hab1, tx, ty}
-- end
-- else
-- for j=ty1,ty2 do
-- ty = j
-- self.path[#self.path+1] = {hab1, tx, ty}
-- end
-- end
-- elseif tx1<tx2 then
-- for i=tx1,tx2 do
-- tx = i
-- self.path[#self.path+1] = {hab1, tx, ty1}
-- end
-- if ty2<ty1 then
-- for j=ty2,ty1 do
-- ty = j
-- self.path[#self.path+1] = {hab1, tx, ty}
-- end
-- else
-- for j=ty1,ty2 do
-- ty = j
-- self.path[#self.path+1] = {hab1, tx, ty}
-- end
-- end
-- end
-- end
--
-- self.path[#self.path+1] = {hab1, tx1, ty1}
-- self.path[#self.path+1] = {hab2, tx2, ty2}
end
-- if can_climb then print("Climb!") end
-- if can_shot then print("Shot!") end
-- if can_super then print("Super!") end
-- if can_go_altar then
-- -- msg_print(10,20,"Altar READY!", true)
-- print("Altar!")
-- end
-- msg_print(10,40,hab1..", "..tx1..", "..ty1, true)
-- msg_print(10,60,hab2..", "..tx2..", "..ty2, true)
end
function imp:ia()
if DEBUG_FN_NAME then print("ia") end
self:reduce_cooldown()
-- if self.update==imp.state_jumping or self.update==imp.state_falling then
-- -- self:think()
-- -- self:move()
-- end
self:analyze_env()
if self.update==imp.state_walking or self.update==imp.state_normal then
self:think()
self:move()
end
self:controller_input()
end
-------------------------------
-- imp.controller_input()
--
-- Traduir a una entrada de pad
-------------------------------
function imp:controller_input()
if DEBUG_FN_NAME then print("controller_input") end
if self.action == "right" or self.action == "left" then
self.movement = self.action
self.update=imp.state_walking
elseif self.action == "jump" then
self:do_jump()
elseif self.action == "jumpfwd" then
self:do_jump(true)
elseif self.action == "shot" then
self:shot()
elseif self.action == "super" then
self.update=imp.state_super
end
self.action = ""
end
-------------------------------
-- imp.move()
--
-- Cridar en cada iteració per
-- a triar l'acció a fer i
-- traduir a acció de pad
-------------------------------
function imp:move( )
if DEBUG_FN_NAME then print("move") end
local action = "stay"
if self.mode=="stop" then return action end
if self.analisis.going_to_fall then self.action_event="prefall" end
if self.analisis.target_reached then self.action_event="target" end
if self.movement_type=="free" then
msg_print(10,20,"FREE",true)
action = self:free_move()
else
msg_print(10,20,"PATTERN "..self.action_event,true)
action=self:pattern_move()
end
if self.old_action~=action then
self.old_action=action
-- print(self.old_action)
end
self.action = action
self.action_event = ""
return action
end
-------------------------------
-- imp.think()
--
-- Cridar en cada iteració per
-- a determinar que fer
-------------------------------
function imp:think()
if DEBUG_FN_NAME then print("think") end
if self.mode=="stop" then return end
-- print("SET FIGHT MODE")
-- S'ha acabat el temps per a arribar a un target
if self.mode_cooldown <= 0 then
-- Canviar a moviment lliure
self:free_movement()
-- seleccionar mode d'acció
local last_mode=self.mode
-- Reinicialitzar el patró de moviment i el cooldown
self:reset_mode_cooldown()
self:reset_pattern_movement()
self.mode=self.fight_modes["chase"]
-- Seleccionar el següent target aleatoriament
self:next_free_target()
print("Next random target => "..self.target.id)
end
self:do_flip(abad)
--if imp.wait==6 then
-- imp.wait=0
-- if not imp.enabled then
-- imp.counter=imp.counter-1
-- local r = math.random(0,imp.counter-1)
-- --print(r)
-- if imp.counter==1 or r==1 then
-- imp.init()
-- end
-- return
-- end
--
-- imp.step=(imp.step+1)%4
-- imp.frame=imp.anim[imp.step+1]
--
-- if imp.flip then
-- imp.x=imp.x-2
-- if imp.x==78 then
-- fireball.init(imp.hab,imp.x+8,imp.y+4,imp.flip)
-- sound.play(audio_hit)
-- imp.flip=not imp.flip
-- elseif imp.x==-12 then
-- imp.reset()
-- end
-- else
-- imp.x=imp.x+2
-- if imp.x==4 then
-- fireball.init(imp.hab,imp.x+8,imp.y+4,imp.flip)
-- sound.play(audio_hit)
-- imp.flip=not imp.flip
-- elseif imp.x==92 then
-- imp.reset()
-- end
-- end
--
--end
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

@@ -18,7 +18,7 @@ require "opcions"
require "opcions_input" require "opcions_input"
require "point" require "point"
--require "fps" require "fps"
--require "menu" --require "menu"
@@ -37,7 +37,7 @@ function images_init()
surf.source(tiles) surf.source(tiles)
local paleta=pal.load("tiles.gif") local paleta=pal.load("tiles.gif")
pal.set(paleta) pal.set(paleta)
tiles2=surf.load("tiles2.gif")
-- Crear el warp -- Crear el warp
warp.init(tiles) warp.init(tiles)
end end
@@ -78,6 +78,7 @@ end
function mini.init() function mini.init()
-- back_sf=surf.new(256,192) -- back_sf=surf.new(256,192)
math.randomseed(os.time())
fonts_init() fonts_init()
images_init() images_init()
mapa_init() mapa_init()
@@ -87,7 +88,6 @@ function mini.init()
logo_config(font_sf) logo_config(font_sf)
surf.target(0) surf.target(0)
surf.cls(16) surf.cls(16)
flow:executar("game") flow:executar("game")
end end
@@ -104,6 +104,10 @@ function mini.update()
if (game_update) then game_update() end 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 end
function mini.close() function mini.close()

View File

@@ -153,7 +153,8 @@ function arc_check_tile(world_x,world_y,debug)
return tiletype.half, tile return tiletype.half, tile
elseif tile<15 then elseif tile<15 then
return tiletype.stair, tile return tiletype.stair, tile
elseif tile==15 then -- 23 = Tile transparent, necesari per a dibuixar els switchos en la versió arcade
elseif tile==23 then
return tiletype.switch, tile return tiletype.switch, tile
elseif tile<64 then elseif tile<64 then
return tiletype.block, tile return tiletype.block, tile
@@ -177,7 +178,7 @@ function mapa_create_minimap()
print(x..","..y.."="..tile) print(x..","..y.."="..tile)
end end
if tile<64 then 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 end
end 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}} 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() 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) local r=1+math.random(0,#habs-1)
peu.hab=habs[r][1] peu.hab=habs[r][1]
-- peu.x=habs[r][2]*8 -- peu.x=habs[r][2]*8
@@ -37,16 +38,16 @@ function peu.draw()
end end
function peu.update() function peu.update()
-- if peu.hab==abad.hab then if peu.hab==abad.hab then
-- if aabb(abad,peu) then if collision(abad,peu) then
-- abad.objects.peu=true abad.objects.peu=true
-- if elalien.scene_intro then if elalien.scene_intro then
-- start_scene(scenes.peu_trobat) start_scene(scenes.peu_trobat)
-- else else
-- start_scene(scenes.peu_trobat_nointro) start_scene(scenes.peu_trobat_nointro)
-- end end
-- if abad.objects.gps~=nil then current_camera=4 end -- if abad.objects.gps~=nil then current_camera=4 end
-- remove_actor(peu) remove_actor(peu)
-- end end
-- end end
end end

View File

@@ -31,7 +31,7 @@ function premiere.init()
premiere.scene_object=false premiere.scene_object=false
-- local habs={75,44,20,0} -- local habs={75,44,20,0}
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 premiere.hab=0
@@ -45,7 +45,21 @@ function premiere.draw()
local scr_x, scr_y = viewp:screen_coords( premiere.x, premiere.y ) local scr_x, scr_y = viewp:screen_coords( premiere.x, premiere.y )
local x = (premiere.frame&7)*premiere.w local x = (premiere.frame&7)*premiere.w
local y = (premiere.frame>>cxr2)*premiere.h 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) draw.surf(x,y,premiere.w,premiere.h,scr_x,scr_y,premiere.w,premiere.h,premiere.flip)
end
end end
function premiere.hit() function premiere.hit()

View File

@@ -28,13 +28,13 @@ scene={
scenes={ scenes={
lluita_imp= { lluita_imp= {
{x=avatar_abad_x,y=avatar_abad_y,flip=false,audio="abad",text={"Eh!?","...","Tu qui eres?"},die=20}, {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_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={"What is your name?","Come ti chiami?","Quod nomen tibi est?"},die=20}, {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_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={"Eeeerrrrggggg","Prruuuuuuummm","Uooooorrrr"},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_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={"A saber que li he dit!","TRANQUIL! TRANQUIL!!!"," CACAUS A MI!!!!"},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={ 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={"Este llibre...","Es el de les tècniques","especials dels abad..."},mood="interessant"},
@@ -148,10 +148,15 @@ scenes={
{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={"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...",""}} {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={ 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={"EH! ON ESTAN","ELS MEUS CACAUS!!?",""}},
{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={"Se va a enterar","Batman en 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à..."}} {x=avatar_abad2_x,y=avatar_abad_y,flip=false,audio="abad",text={"...","I eixe soroll?","Ve de dalt!"}}
}, },
final= { 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_batman_x,y=avatar_batman_y,flip=true,audio="batman",musica=audio_song_batman,text={"AI!", "M'has fet mal!!!",""},die=20},

View File

@@ -1,4 +1,6 @@
score={} score={
bar_meter = nil
}
local gorro_img_x = 10*16 -- col local gorro_img_x = 10*16 -- col
local gorro_img_y = 11*16 -- row local gorro_img_y = 11*16 -- row
@@ -76,11 +78,11 @@ function score.create()
surf.cls(0) surf.cls(0)
score.avatar() score.avatar()
score.bar_meter=bar_meter.new(0,2,51,10,1,1,abad)
-- score.border() -- score.border()
-- score.jailgames() -- score.jailgames()
score.life_meter() -- score.life_meter()
surf.target(0) surf.target(0)
end end
@@ -90,15 +92,24 @@ function score.draw()
surf.target(score.surf) surf.target(score.surf)
surf.cls(0) surf.cls(0)
score.avatar() score.avatar()
score.life_meter() -- score.life_meter()
score.bar_meter:draw()
surf.target(0) surf.target(0)
surf.source(score.surf) surf.source(score.surf)
draw.surf(0,0,arcade_config.resolucion.width,arcade_config.resolucion.height,170,10) draw.surf(0,0,arcade_config.resolucion.width,arcade_config.resolucion.height,170,10)
surf.source(tiles) surf.source(tiles)
if abad.objects.gorro~=nil then draw.surf(gorro_img_x,gorro_img_y,16,16,153,7) end if abad.objects.gorro~=nil then
if abad.objects.peu~=nil then draw.surf(peu_img_x, peu_img_y, 16,16,109*o2aX,44*o2aX) end draw.surf(gorro_img_x,gorro_img_y,16,16,137,7)
if abad.objects.gps~=nil then draw.surf(gps_img_x, peu_img_y, 16,16,100*o2aX,55*o2aX) end 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(clau_img_x,clau_img_y,8,8,153,13) 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.clau_elalien~=nil then draw.surf(clau_img_x+8,clau_img_y,8,8,161,13) end

View File

@@ -1,8 +1,8 @@
stages = {} stages = {}
stages.boss_ready = false stages.boss_ready = false
stages.boss_finished = false
stages.boss_loaded = false stages.boss_loaded = false
stages.boss_hot_points = {}
boss = nil boss = nil
function stages.stage1_init() function stages.stage1_init()
@@ -27,8 +27,12 @@ function stages.stage1_init()
elalien.init() elalien.init()
table.insert(actors,elalien) table.insert(actors,elalien)
batvio.init()
table.insert(actors,batvio)
boss = imp.new(55,4,3) boss = imp.new(55,4,3)
table.insert( actors, boss ) table.insert( actors, boss )
boss_meter = bar_meter.new(20,12,128,10,1,1,boss,5)
--batman --batman
@@ -58,20 +62,47 @@ function stages.stage1_init()
table.insert( actors, caco.new(17,3,2,false) ) table.insert( actors, caco.new(17,3,2,false) )
table.insert( actors, caco.new(20,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(26,3,2,false) )
table.insert( actors, caco.new(30,4,2,false) )
table.insert( actors, caco.new(37,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(41,3,2,false) )
table.insert( actors, caco.new(40,3,2,false) )
table.insert( actors, caco.new(50,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(57,3,2,false) )
table.insert( actors, caco.new(61,3,2,false) ) table.insert( actors, caco.new(61,3,2,false) )
table.insert( actors, caco.new(74,3,2,false) )
table.insert( actors, caco.new(75,3,2,false) )
table.insert( actors, zombie.new(2, 3, 3,false) ) local zombie1 = zombie.new(2, 3, 3,false)
table.insert( actors, zombie1 )
table.insert( actors, zombie.new(2, 4, 3,true) )
table.insert( actors, zombie.new(2, 5, 3,false) )
table.insert( actors, zombie.new(3, 3, 3,true) )
table.insert( actors, zombie.new(23, 0, 3,false) )
table.insert( actors, zombie.new(23, 9, 3,true) )
table.insert( actors, zombie.new(24, 6, 3,true) )
table.insert( actors, zombie.new(28, 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(32, 3, 3,false) )
table.insert( actors, zombie.new(42, 7, 3,true) )
table.insert( actors, zombie.new(43, 3, 3,true) )
table.insert( actors, zombie.new(44, 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(46, 3, 3,false,2) )
table.insert( actors, zombie.new(46, 1, 3,false) )
table.insert( actors, zombie.new(47, 9, 3,false) )
table.insert( actors, zombie.new(54, 3, 3,false) ) table.insert( actors, zombie.new(54, 3, 3,false) )
table.insert( actors, zombie.new(59, 1, 3,false) )
table.insert( actors, zombie.new(67, 8, 3,false,2) )
table.insert( actors, zombie.new(68, 3, 3,false) ) table.insert( actors, zombie.new(68, 3, 3,false) )
table.insert( actors, zombie.new(73, 3, 3,false) ) local zombie2 = zombie.new(73, 3, 3,false)
table.insert( actors, zombie2 )
table.insert( actors, zombie.new(73, 5, 3,false) )
table.insert( actors, zombie.new(73, 7, 3,false) )
table.insert( actors, zombie.new(75, 3, 3,true) )
local hp_x, hp_y = coords.room_to_world(14, 10, 4)
table.insert( actors, health_potion.new(14, hp_x, hp_y, 0, 0, 2) )
local hp_x, hp_y = coords.room_to_world(77, 8, 4)
table.insert( actors, health_potion.new(77, hp_x, hp_y, 0, 0, 3) )
-- TRIGGERS -- TRIGGERS
-- if not menu then table.insert(actors,trigger.new(10,57,32,triggers.escena_abad_inici)) end -- if not menu then table.insert(actors,trigger.new(10,57,32,triggers.escena_abad_inici)) end
@@ -85,7 +116,7 @@ function stages.stage1_init()
table.insert( actors, trigger.new(53,5,3,triggers.escena_abad_porta_casa,"porta casa","TR06")) table.insert( actors, trigger.new(53,5,3,triggers.escena_abad_porta_casa,"porta casa","TR06"))
table.insert( actors, trigger.new(56,4,3,triggers.escena_abad_porta_batman,"porta batman","TR07")) table.insert( actors, trigger.new(56,4,3,triggers.escena_abad_porta_batman,"porta batman","TR07"))
table.insert( actors, trigger.new(19,32,32,triggers.escena_habitacio_batman,"habitacio batman")) table.insert( actors, trigger.new(19,4,3,triggers.escena_habitacio_batman,"habitacio batman","TR08"))
-- --
table.insert( actors, trigger.new(55,1,3,triggers.escena_lluita_imp,"lluita imp")) table.insert( actors, trigger.new(55,1,3,triggers.escena_lluita_imp,"lluita imp"))
@@ -97,14 +128,47 @@ function stages.stage1_init()
table.insert( actors, trigger.new(75,9,1,triggers.open_door,"","acces inf casa batman","switch",{57, 53,41},{"TR07"}) ) table.insert( actors, trigger.new(75,9,1,triggers.open_door,"","acces inf casa batman","switch",{57, 53,41},{"TR07"}) )
table.insert( actors, trigger.new(79,5,1,triggers.open_door,"","sotan casa batman","switch",{36, 56,44}) ) table.insert( actors, trigger.new(79,5,1,triggers.open_door,"","sotan casa batman","switch",{36, 56,44}) )
table.insert( actors, trigger.new(38,2,2,triggers.open_door,"","","switch",{39, 62,63}) ) table.insert( actors, trigger.new(38,2,2,triggers.open_door,"","","switch",{39, 62,63}) )
-- table.insert( actors, trigger.new(1, 1,1,triggers.open_door,"","acces cacaus","switch",{20, 53,41},{"TR08"}))
-- table.insert(actors,trigger.new(14,40,32,triggers.teleport_a)) -- table.insert(actors,trigger.new(14,40,32,triggers.teleport_a))
-- table.insert(actors,trigger.new(67,8,32,triggers.teleport_b)) -- table.insert(actors,trigger.new(67,8,32,triggers.teleport_b))
-- table.insert(actors,trigger.new(29,40,32,triggers.teleport_c)) -- table.insert(actors,trigger.new(29,40,32,triggers.teleport_c))
-- table.insert(actors,trigger.new(61,8,32,triggers.teleport_d)) -- table.insert(actors,trigger.new(61,8,32,triggers.teleport_d))
trigger_event.new("Premiere dialeg 1",
trigger_ev.dialeg_trigger,
trigger_ev.dialeg_init,
nil,
premiere, abad, 150, "Ma que cosa fare", 150)
trigger_event.new("Zombie 1 dialeg",
trigger_ev.dialeg_trigger,
trigger_ev.dialeg_init,
nil,
zombie1, abad, 150, "Sereeeeebrooooosssss", 250)
trigger_event.new("Zombie 2 dialeg",
trigger_ev.dialeg_trigger,
trigger_ev.dialeg_init,
nil,
zombie2, abad, 150, "Aaaaaargh... per ell!", 250)
trigger_event.new("Elalien dialeg",
trigger_ev.dialeg_trigger,
trigger_ev.dialeg_init,
nil,
elalien, abad, 150, "I les tisores de podar?", 250)
tiles_layer2.new(13,11,3,144,144,16,16)
tiles_layer2.new(13,11,4,144,144,16,16)
tiles_layer2.new(11,10,2,128,208,16,16, tiles_layer2.update_aranya, tiles_layer2.draw_aranya)
tiles_layer2.new(76,3,2,128,208,16,16, tiles_layer2.update_aranya, tiles_layer2.draw_aranya)
tiles_layer2.new(78,6,2,128,208,16,16, tiles_layer2.update_aranya, tiles_layer2.draw_aranya)
local abad_x, abad_y = coords.room_to_world ( 10, 4, 3 ) local abad_x, abad_y = coords.room_to_world ( 10, 4, 3 )
local abad_x, abad_y = coords.room_to_world ( 54, 8, 3 ) -- local abad_x, abad_y = coords.room_to_world ( 54, 8, 3 )
local abad_x, abad_y = coords.room_to_world ( 18, 9, 3 )
abad:move(abad_x, abad_y) abad:move(abad_x, abad_y)
abad_make_safe( true ) abad_make_safe( true )
@@ -118,12 +182,36 @@ function stages.stage1_init()
stages.boss_loaded = false stages.boss_loaded = false
end end
function stages.stage1_update()
-- print("stage1_update")
fireball.update()
-- if (abad.energia<=abad.max_energia/2) then
-- -- Requeriment: tindre mitja clau
-- premiere.healer_init()
-- end
end
function stages.stage1_draw_back()
-- print("stage1_draw_back")
end
function stages.stage1_draw_middle()
-- print("stage1_draw_middle")
end
function stages.stage1_draw_front()
-- print("stage1_draw_front")
fireball.draw()
boss_meter:draw()
end
function stages.stage2_init() function stages.stage2_init()
print("stage 2 init") -- print("stage 2 init")
end end
function stages.stage1_boss_ready() function stages.stage1_boss_ready()
stages.boss_ready = true stages.boss_ready = true
stages.boss_finished = false
end end
function stages.stage1_boss() function stages.stage1_boss()
@@ -136,9 +224,28 @@ function stages.stage1_boss()
boss.reason="" boss.reason=""
boss.enabled=true boss.enabled=true
boss:fight() boss:fight()
trigger_event.new("Premiere Boss 1",
trigger_ev.premiere_boss1_trigger,
trigger_ev.premiere_healer_init,
trigger_ev.premiere_healer_update)
end end
end end
function stages.stage1_boss_finished()
stages.boss_ready = true
stages.boss_finished = true
end
function stages.stage1_boss_end()
mapa_restore_backup()
set_actors_enabled_by_room(true, "boss", stage1_boss_mapa.r0.r, stage1_boss_mapa.r1.r)
remove_actor(boss)
stages.boss_ready = false
stages.boss_finished = false
stages.boss_loaded = false
viewp:free_move()
end
stage1_mapa={ stage1_mapa={
-- 1 -- 1
{ {
@@ -256,33 +363,36 @@ stage1_mapa={
-- 12 -- 12
{ {
-- 28,29,28,29,28,29,29,256,256,256,26,27, -- 28,29,28,29,28,29,29,256,256,256,26,27,
28,29,28,29,28,29,29,1,256,256,26,27, 28, 29, 28, 29, 28, 29, 29, 1,256,256, 26, 27,
256,256,256,256,256,256,256,256,256,25,72,256, 256,256,256,256,256,256,256,256,256, 25, 72,256,
256,256,73,74,256,256,256,256,1,256,88,256, -- 256,256, 73, 74,256,256,256,256, 1,256, 88,256,
256,256,89,90,256,256,256,1,256,256,256,256, 256,256, 73, 74,256,256,256,256, 1,256,256,256,
256,256,256,256,256,256,1,256,256,256,256,256, 256,256, 89, 90,256,256,256, 1,256,256,256,256,
28,29,28,29,28,29,28,29,28,29,28,29, 256,256,256,256,256,256, 1,256,256,256,256,256,
28, 29, 28, 29, 28, 29, 28, 29, 28, 29, 28, 29,
}, },
-- 13 -- 13
{ {
28,29,26,27,26,27,28,29,28,29,28,29, 28, 29, 26, 27, 26, 27, 28, 29, 28, 29, 28, 29,
256,256,256,26,27,256,256,256,256,256,256,256, 256,256,256, 26, 27,256,256,256,256,256,256,256,
256,256,256,256,256,256,256,256,73,74,256,256, 256,256,256,256,256,256,256,256, 73, 74,256,256,
256,256,256,98,98,256,256,256,89,90,256,256, 256,256,256, 98, 98,256,256,256, 89, 90,256,256,
256,256,104,101,102,103,256,256,256,256,256,256, 256,256,104,101,102,103,256,256,256,256,256,256,
-- 28,29,28,29,28,29,29,256,81,25,28,29, -- 28,29,28,29,28,29,29,256,81,25,28,29,
28,29,28,29,28,29,29,256,256,1,28,29, 28, 29, 28, 29, 28, 29, 29,256,256, 1, 28, 29,
}, },
-- 14 -- 14
{ {
28,29,28,29,28,29,28,29,10,11,28,25, 28, 29, 28, 29, 28, 29, 28, 29, 10, 11, 28, 25,
256,256,256,256,256,256,256,256,10,11,256,25, 256,256,256,256,256,256,256,256, 10, 11,256, 25,
256,73,74,256,256,256,256,256,10,11,256,256, -- 256, 73, 74,256,256,256,256,256, 10, 11,256,256,
256,89,90,256,256,75,76,256,10,11,256,25, 256, 73, 74,256,256,256,256,256, 10, 11,256, 25,
256,256,256,256,256,91,92,256,10,11,256,25, 256, 89, 90,256,256, 75, 76,256, 10, 11,256,256,
28,29,28,29,28,29,28,29,28,29,28,29, -- 256,256,256,256,256, 91, 92,256, 10, 11,256, 25,
256,256,256,256,256, 91, 92,256, 10, 11,256,256,
28, 29, 28, 29, 28, 29, 28, 29, 28, 29, 28, 29,
}, },
-- 15 -- 15
@@ -537,13 +647,13 @@ stage1_mapa={
}, },
-- 39 -- 39
{ {
28,29,25,25,28,29,25,25,28,29,25,25, 28, 29, 25, 25, 28, 29, 25, 25, 28, 29, 25, 25,
256,256,25,25,256,256,256,256,256,256,106,24, 256,256, 25, 25,256,256,256,256,256,256,106, 24,
-- 256,256,15,256,256,256,256,256,256,256,95,24, -- 256,256,15,256,256,256,256,256,256,256,95,24,
256,256,23,256,256,256,256,256,256,256,95,24, 256,256, 23,256,256,256,256,256,256,256, 95, 24,
256,256,256,256,78,97,107,108,256,106,105,24, 256,256,256,256, 78, 97,107,108,256,106,105, 24,
256,256,256,256,94,101,102,110,103,105,98,24, 256,256,256,256, 94,101,102,110,103,105, 98, 24,
28,29,28,29,28,29,28,29,28,29,28,29, 28, 29, 28, 29, 28, 29, 28, 29, 28, 29, 28, 29,
}, },
-- 40 -- 40
@@ -937,7 +1047,8 @@ stage1_mapa={
-- 18,19,18,19,18,19,256,256,256,18,19,52, -- 18,19,18,19,18,19,256,256,256,18,19,52,
18,19,18,19,18,19,256,256,0,18,19,52, 18,19,18,19,18,19,256,256,0,18,19,52,
256,256,17,72,256,256,17,256,256,256,256,256, 256,256,17,72,256,256,17,256,256,256,256,256,
256,256,38,88,256,113,256,0,256,256,256,256, -- 256,256,38,88,256,113,256,0,256,256,256,256,
256,256,38,256,256,113,256,0,256,256,256,256,
256,256,38,256,256,256,256,256,0,256,256,256, 256,256,38,256,256,256,256,256,0,256,256,256,
256,256,38,256,256,256,256,256,256,0,256,256, 256,256,38,256,256,256,256,256,256,0,256,256,
52,51,52,53,52,53,51,52,51,53,52,53, 52,51,52,53,52,53,51,52,51,53,52,53,
@@ -957,7 +1068,8 @@ stage1_mapa={
{ {
256,256,256,256,42,43,42,43,8,9,42,43, 256,256,256,256,42,43,42,43,8,9,42,43,
256,256,256,256,42,43,72,256,8,9,256,256, 256,256,256,256,42,43,72,256,8,9,256,256,
256,126,127,256,42,43,88,256,8,9,256,256, -- 256,126,127,256,42,43,88,256,8,9,256,256,
256,126,127,256,42,43,256,256,8,9,256,256,
256,256,256,256,42,43,256,256,8,9,256,256, 256,256,256,256,42,43,256,256,8,9,256,256,
256,256,256,256,42,43,256,256,8,9,256,256, 256,256,256,256,42,43,256,256,8,9,256,256,
256,256,256,256,42,43,42,43,42,43,42,43, 256,256,256,256,42,43,42,43,42,43,42,43,

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -23,7 +23,14 @@ function trigger.new(_hab,_x,_y,_action,_escena,_id,_type,_doors,_linked_id)
linked_id=_linked_id, linked_id=_linked_id,
enabled=true, enabled=true,
disable_reason="", disable_reason="",
bb=_bb } bb=_bb,
run=trigger.run }
end
function trigger:run()
if self.fun ~= nil then
self:fun()
end
end end
function trigger:update() function trigger:update()
@@ -49,7 +56,7 @@ function trigger:draw()
if self.enabled then if self.enabled then
draw.surf(240,128,16,16,scr_x,scr_y,16,16) draw.surf(240,128,16,16,scr_x,scr_y,16,16)
else else
-- flipar i desactivar en gris -- "flipar" i desactivar en gris
pal.subpal(2,1) pal.subpal(2,1)
draw.surf(240,128,16,16,scr_x,scr_y,16,16,true) draw.surf(240,128,16,16,scr_x,scr_y,16,16,true)
pal.subpal(2) pal.subpal(2)
@@ -117,8 +124,13 @@ function triggers:escena_abad_porta_batman()
end end
function triggers:escena_habitacio_batman() function triggers:escena_habitacio_batman()
if abad.objects.clau_premiere~=nil and abad.objects.clau_elalien~=nil then if abad.objects.clau_premiere==nil and
switches.start(0,0) 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_premiere=nil
abad.objects.clau_elalien=nil abad.objects.clau_elalien=nil
remove_actor(self) remove_actor(self)
@@ -130,10 +142,15 @@ function triggers:escena_habitacio_batman()
end end
end end
function triggers:escena_stage1_ending()
print("STAGE 1 ENDING")
remove_actor(self)
end
function triggers:escena_lluita_imp() function triggers:escena_lluita_imp()
set_actors_enabled_by_room(false, "boss", stage1_boss_mapa.r0.r, stage1_boss_mapa.r1.r) 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) viewp:fixed({l=8,r=44,u=0,d=0}, viewp.x, viewp.y-48)
-- start_scene(scenes.lluita_imp, nil, false) start_scene(scenes.lluita_imp, nil, false)
remove_actor(self) remove_actor(self)
stages.stage1_boss_ready() stages.stage1_boss_ready()
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

@@ -33,6 +33,7 @@ end
function viewport:free_move() function viewport:free_move()
self.range = nil 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.smooth_adjust = self.fixed_coord
self.fixed_coord = nil self.fixed_coord = nil
end end
@@ -75,33 +76,35 @@ function viewport:position(x, y)
self.y = ny self.y = ny
else else
-- viewport lliure després de fixar-lo -> Ajustar suau -- 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 self.x = nx
if self.smooth_adjust.x~=nil then if sm_x~=nil then
if nx<self.smooth_adjust.x-self.adjust_speed then if math.abs(nx-sm_x)<speed_x then
self.x=self.smooth_adjust.x-self.adjust_speed sm_x = nil
self.smooth_adjust.x=self.smooth_adjust.x-self.adjust_speed else
elseif nx>self.smooth_adjust.x+self.adjust_speed then if nx<sm_x-speed_x then speed_x = -speed_x end
self.x=self.smooth_adjust.x+self.adjust_speed self.x=sm_x+speed_x
self.smooth_adjust.x=self.smooth_adjust.x+self.adjust_speed sm_x =sm_x+speed_x
elseif math.abs(nx-self.smooth_adjust.x)<self.adjust_speed then
self.smooth_adjust.x = nil
end end
self.smooth_adjust.x = sm_x
end end
self.y = ny self.y = ny
if self.smooth_adjust.y~=nil then if sm_y~=nil then
if ny<self.smooth_adjust.y-self.adjust_speed then if math.abs(ny-sm_y)<speed_y then
self.y=self.smooth_adjust.y-self.adjust_speed sm_y = nil
self.smooth_adjust.y=self.smooth_adjust.y-self.adjust_speed else
elseif ny>self.smooth_adjust.y+self.adjust_speed then if ny<sm_y-speed_y then speed_y = -speed_y end
self.y=self.smooth_adjust.y+self.adjust_speed self.y=sm_y+speed_y
self.smooth_adjust.y=self.smooth_adjust.y-self.adjust_speed sm_y =sm_y+speed_y
elseif math.abs(ny-self.smooth_adjust.y)<self.adjust_speed then
self.smooth_adjust.y = nil
end end
self.smooth_adjust.y = sm_y
end end
if self.smooth_adjust.x == nil and self.smooth_adjust.y == nil then if sm_x == nil and sm_y == nil then
self.smooth_adjust = nil self.smooth_adjust = nil
end end
end end

View File

@@ -79,6 +79,11 @@ function warp.open(actor)
w.x = actor.x w.x = actor.x
w.y = actor.y w.y = actor.y
w.actor = actor w.actor = actor
w.frame = 0
w.wait = 0
w.step = 0
w.angle = 0
w.d_angle = 5
return e; -- reutilitzar return e; -- reutilitzar
end end
end end

View File

@@ -4,7 +4,8 @@ ch = arcade_config.character_height
zombie={} 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) local world_x, world_y = coords.room_to_world(_hab,_x,_y)
return {name="zombie", return {name="zombie",
hab=_hab, hab=_hab,
@@ -16,12 +17,14 @@ function zombie.new(_hab,_x,_y,_flip)
frame=0, frame=0,
wait=0, wait=0,
step=0, step=0,
energy=_energy,
max_energy = _energy,
hit=zombie.hit, hit=zombie.hit,
update=zombie.update_normal, update=zombie.update_normal,
draw=zombie.draw, draw=zombie.draw,
jumpfwd=false, jumpfwd=false,
anim={16,17,16,18}, 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, can_warp=true,
warping=false, warping=false,
shrink=1, shrink=1,
@@ -38,6 +41,13 @@ function zombie:draw()
if not self.enabled then return end 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)*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.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 if self.warping then
actor_warp_draw(self) actor_warp_draw(self)
else else
@@ -46,10 +56,13 @@ function zombie:draw()
draw.surf((self.frame&7)*cw, (self.frame>>cxr2)*ch, cw, ch, scr_x, scr_y, cw, ch, self.flip) draw.surf((self.frame&7)*cw, (self.frame>>cxr2)*ch, cw, ch, scr_x, scr_y, cw, ch, self.flip)
end end
end end
pal.subpal(10)
end end
function zombie:update_normal() function zombie:update_normal()
if not self.enabled then return end if not self.enabled then return end
self.wait=self.wait+1 self.wait=self.wait+1
if self.wait==18 then if self.wait==18 then
@@ -108,6 +121,13 @@ function zombie:update_hit()
if self.can_warp then if self.can_warp then
actor_warp_update(self) actor_warp_update(self)
else 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<self.death_time then
if self.step%2==0 then if self.step%2==0 then
self.frame=self.anim[#self.anim] self.frame=self.anim[#self.anim]
@@ -127,8 +147,13 @@ end
function zombie:hit() function zombie:hit()
if not self.enabled then return end if not self.enabled then return end
self.update=zombie.update_hit
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 if self.can_warp then self.warping=true end
self.shrink=1 self.shrink=1
self.angle=0 self.angle=0
@@ -137,4 +162,6 @@ function zombie:hit()
local warp_time = self.death_time/3 local warp_time = self.death_time/3
self.d_angle = 720 / warp_time; -- 720 = 2 voltes self.d_angle = 720 / warp_time; -- 720 = 2 voltes
self.d_shrink = self.shrink / warp_time self.d_shrink = self.shrink / warp_time
end
self.update=zombie.update_hit
end end