Files
cacaus-arcade/data/elalien.lua
2026-04-30 22:55:02 +02:00

359 lines
12 KiB
Lua

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
elalien={name="elalien",
hab=66,
x=24,
y=24,
w=32,
h=32,
flip=true,
goup=true,
frame=8,
parpadeig=false,
stairscooldown=0,
wait=0,
step=0,
anim={8,9,8,10},
bb={x=4,y=0,w=8,h=16},
scene_intro=false,
scene_object=false}
function elalien.init()
-- elalien.x=24
elalien.x=9
-- elalien.y=24
elalien.y=3
elalien.w=32
elalien.h=32
elalien.frame=8
elalien.stairscooldown=0
elalien.wait=0
elalien.step=0
-- elalien.update=elalien.update_normal
elalien.update=elalien.update_stay
elalien.scene_intro=false
elalien.scene_object=false
local habs={66,56,59,53}
-- elalien.hab=habs[1+math.random(0,3)]
elalien.hab=56
local world_x, world_y = coords.room_to_world(elalien.hab,elalien.x,elalien.y)
elalien.x=world_x
elalien.y=world_y
end
function elalien.draw()
local flip=elalien.flip
if elalien.update==elalien.update_stairs then
flip=(((elalien.x>>1)+(elalien.y>>1))%2)==0
end
local xoff0 = 18
local xoff1 = 19
local xoff2 = 20
local xoff3 = 21
-- draw.surf((elalien.frame&7)*cw,(elalien.frame>>cxr2)*ch,cw,ch,elalien.x*o2aX,elalien.y*o2aX,cw,ch,flip)
local scr_x, scr_y = viewp:screen_coords( elalien.x, elalien.y )
if elalien.update == elalien.update_stay then
draw.surf(0,32,elalien.w,elalien.h,scr_x,scr_y,elalien.w,elalien.h,flip)
if elalien.parpadeig then
if elalien.flip then
xoff0 = 13
xoff1 = 12
xoff2 = 11
xoff3 = 10
end
if elalien.step==0 then
draw.line(scr_x+xoff0, scr_y+6, scr_x+xoff0, scr_y+11, 11)
surf.pixel(scr_x+xoff1, scr_y+11, 11)
surf.pixel(scr_x+xoff1, scr_y+7, 11)
elseif elalien.step<3 then
draw.line(scr_x+xoff0, scr_y+6, scr_x+xoff0, scr_y+11, 11)
draw.line(scr_x+xoff1, scr_y+7, scr_x+xoff1, scr_y+11, 11)
draw.line(scr_x+xoff2, scr_y+8, scr_x+xoff2, scr_y+11, 11)
draw.line(scr_x+xoff3, scr_y+8, scr_x+xoff3, scr_y+11, 11)
elseif elalien.step==3 then
draw.line(scr_x+xoff0, scr_y+6, scr_x+xoff0, scr_y+11, 11)
draw.line(scr_x+xoff1, scr_y+7, scr_x+xoff1, scr_y+11, 11)
draw.line(scr_x+xoff2, scr_y+8, scr_x+xoff2, scr_y+11, 11)
draw.line(scr_x+xoff3, scr_y+8, scr_x+xoff3, scr_y+11, 11)
elalien.parpadeig = false
end
end
else
local x = (elalien.frame&7)*cw
local y = (elalien.frame>>cxr2)*ch
draw.surf(x,y,cw,ch,scr_x,scr_y,elalien.w,elalien.h,flip)
end
end
function elalien.hit()
end
function elalien.update_stay()
elalien.wait=elalien.wait+1
if elalien.wait==18 then
elalien.wait=0
elalien.step=(elalien.step+1)%4
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
function elalien.update_normal()
elalien.wait=elalien.wait+1
if elalien.wait>=6 then
elalien.wait=0
if elalien.stairscooldown>0 then elalien.stairscooldown=elalien.stairscooldown-1 end
elalien.step=(elalien.step+1)%4
elalien.frame=elalien.anim[elalien.step+1]
local inc=12 if elalien.flip then inc=2 end
if not elalien.flip and elalien.x==84 then
elalien.hab=elalien.hab+1
elalien.x=-4
elseif check_tile(elalien.hab,elalien.x+inc,elalien.y+14)==tiletype.nonpc then
--if rnd(10)<8 then
elalien.update=elalien.update_jumping
elalien.step=0
--else
-- elalien.flip=not elalien.flip
--end
elseif check_tile(elalien.hab,elalien.x+inc,elalien.y+14)<tiletype.half then
if elalien.flip then
elalien.x=elalien.x-2
else
elalien.x=elalien.x+2
end
if elalien.x<-4 then
elalien.hab=elalien.hab-1
elalien.x=84
end
elseif check_tile(elalien.hab,elalien.x+inc,elalien.y+6)<tiletype.half then
local r=math.random(0,1)
if check_tile(elalien.hab,elalien.x+inc,elalien.y+14)==tiletype.block then r=0 end
if r==0 then
elalien.update=elalien.update_jumping
elalien.step=0
else
if elalien.flip then
elalien.x=elalien.x-2
else
elalien.x=elalien.x+2
end
if elalien.x<-4 then
elalien.hab=elalien.hab-1
elalien.x=84
end
end
else
--if check_tile(elalien.hab,elalien.x+4,elalien.y+16)==tiletype.void and ((elalien.x+4)&7==0 or check_tile(elalien.hab,elalien.x+12,elalien.y+16)==tiletype.void) then
--elalien.update=elalien.update_falling
--else
elalien.flip=not elalien.flip
--end
end
if elalien.stairscooldown==0 and
check_tile(elalien.hab,elalien.x+6,elalien.y+8)==tiletype.stair and
check_tile(elalien.hab,elalien.x+14,elalien.y+8)==tiletype.stair then
if math.random(0,9)<8 then
elalien.update=elalien.update_stairs
if check_tile(elalien.hab,elalien.x+4,elalien.y+16)==tiletype.block then
elalien.goup=true
else
elalien.goup=false
end
--elalien.goup=rnd(2)==0 and true or false
else
elalien.stairscooldown=50
end
elseif elalien.update==elalien.update_stairs then
elalien.stairscooldown=50
elalien.update=elalien.update_normal
elalien.frame=8
end
if check_tile(elalien.hab,elalien.x+4,elalien.y+16)==tiletype.void and ((elalien.x+4)&7==0 or check_tile(elalien.hab,elalien.x+12,elalien.y+16)==tiletype.void) then
local option=math.random(0,1)
if elalien.stairscooldown>0 then option=0 end
if option==0 then
elalien.update=elalien.update_falling
else
elalien.update=elalien.update_jumping
elalien.step=0
elalien.wait=0
--else
-- elalien.flip=not elalien.flip
end
end
if elalien.hab==abad.hab then
if aabb(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
function elalien.update_jumping()
elalien.frame=9
elalien.wait=elalien.wait+1
if elalien.wait>=6 then
elalien.wait=0
local inc=12 if elalien.flip then inc=2 end
if not elalien.flip and elalien.x==84 then
elalien.hab=elalien.hab+1
elalien.x=-4
elseif check_tile(elalien.hab,elalien.x+inc,elalien.y+14)<tiletype.half then
if elalien.flip then
elalien.x=elalien.x-2
else
elalien.x=elalien.x+2
end
if elalien.x<-4 then
elalien.hab=elalien.hab-1
elalien.x=84
end
end
if elalien.step<6 then
if elalien.y>0 then
if check_tile(elalien.hab,elalien.x+4,elalien.y-2)~=tiletype.block then
if (elalien.x+4)&7==0 or check_tile(elalien.hab,elalien.x+12,elalien.y-2)~=tiletype.block then
elalien.y=elalien.y-2
end
end
else
elalien.hab=elalien.hab-10
elalien.y=32
end
elseif elalien.step>6 then
elalien.update=elalien.update_falling
end
elalien.step=elalien.step+1
end
end
function elalien.update_falling()
elalien.frame=9
elalien.wait=elalien.wait+1
if elalien.wait>=6 then
elalien.wait=0
local inc=12 if elalien.flip then inc=2 end
if not elalien.flip and elalien.x==84 then
elalien.hab=elalien.hab+1
elalien.x=-4
elseif check_tile(elalien.hab,elalien.x+inc,elalien.y+14)<tiletype.half then
if elalien.flip then
elalien.x=elalien.x-2
else
elalien.x=elalien.x+2
end
if elalien.x<-4 then
elalien.hab=elalien.hab-1
elalien.x=84
end
end
if elalien.y<32 then
if (elalien.y+16)&7==0 and (check_tile(elalien.hab,elalien.x+4,elalien.y+16)>=tiletype.half or ((elalien.x+4)&7~=0 and check_tile(elalien.hab,elalien.x+12,elalien.y+16)>=tiletype.half)) then
elalien.update=elalien.update_normal
return
end
elalien.y=elalien.y+2
else
elalien.hab=elalien.hab+10
elalien.y=0
end
end
end
function elalien.update_stairs()
elalien.frame=11
elalien.wait=elalien.wait+1
if elalien.wait>=6 then
elalien.wait=0
if elalien.goup then
if elalien.y>0 then
if check_tile(elalien.hab,elalien.x+4,elalien.y+8)==tiletype.stair or (elalien.x+4)&7~=0 and check_tile(elalien.hab,elalien.x+12,elalien.y+8)==tiletype.stair then
elalien.y=elalien.y-2
else
elalien.update=elalien.update_normal
if math.random(0,2)>0 then elalien.flip=not elalien.flip end
elalien.stairscooldown=50
end
else
elalien.hab=elalien.hab-10
elalien.y=32
end
else
if elalien.y<32 then
if check_tile(elalien.hab,elalien.x+4,elalien.y+16)==tiletype.stair or (elalien.x+4)&7~=0 and check_tile(elalien.hab,elalien.x+12,elalien.y+16)==tiletype.stair then
elalien.y=elalien.y+2
else
elalien.update=elalien.update_normal
if math.random(0,2)>0 then elalien.flip=not elalien.flip end
elalien.stairscooldown=50
end
else
elalien.hab=elalien.hab+10
elalien.y=0
end
end
end
end