Files
cacaus/elalien.lua
JailDoctor a710317c0a - [WIP] Batman AI
- [WIP] EL_ALIEN AI
- Multi-camera
- Random starting places
2022-10-27 14:59:47 +02:00

245 lines
8.3 KiB
Lua

elalien={hab=66,x=24,y=24,flip=true,goup=true,frame=8,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.hit=elalien.hit
elalien.update=elalien.update_normal
elalien.draw=elalien.draw
local habs={66,56,59,53}
premiere.hab=habs[1+rnd(4)]
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
sspr((elalien.frame&7)*16,(elalien.frame>>3)*16,16,16,elalien.x,elalien.y,16,16,flip)
end
function elalien.hit()
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=rnd(2)
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 rnd(10)<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=rnd(2)
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
start_scene(scenes.elalien_intro)
elalien.scene_intro=true
elseif not elalien.scene_object and abad.objects.gorro~=nil then
start_scene(scenes.elalien_gorro)
elalien.scene_object=true
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 btn(KEY_RIGHT) then
-- elalien.flip=false
-- elalien_advance()
--elseif btn(KEY_LEFT) then
-- elalien.flip=true
-- elalien_advance()
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 rnd(3)>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 rnd(3)>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