diff --git a/data/elalien.lua b/data/elalien.lua new file mode 100644 index 0000000..f0a345e --- /dev/null +++ b/data/elalien.lua @@ -0,0 +1,300 @@ +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={hab=66, + x=24, + y=24, + w=32, + h=32, + 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.x=24 + elalien.x=3 + -- 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)] + + 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 + -- draw.surf((elalien.frame&7)*cw,(elalien.frame>>cxr2)*ch,cw,ch,elalien.x*o2aX,elalien.y*o2aX,cw,ch,flip) + + if viewp:inside(elalien.x, elalien.y, elalien.w, elalien.h) then + local scr_x, scr_y = viewp:screen_coords( elalien.x, elalien.y ) + local x = (elalien.frame&7)*cw + local y = (elalien.frame>>cxr2)*ch + draw.surf(x,y,cw,ch,scr_x,scr_y,elalien.w,elalien.h,flip) + end +end + +function elalien.hit() +end + +function elalien.update_stay() + elalien.wait=elalien.wait+1 + + if elalien.wait==6 then + elalien.wait=0 + elalien.step=(elalien.step+1)%4 + elalien.frame=elalien.anim[elalien.step+1] + 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)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)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 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 \ No newline at end of file diff --git a/data/game.lua b/data/game.lua index bbe5581..55f759e 100644 --- a/data/game.lua +++ b/data/game.lua @@ -13,6 +13,7 @@ require "gorro" require "gps" require "peu" require "premiere" +require "elalien" local tile_w = arcade_config.tiles_width local tile_h = arcade_config.tiles_height @@ -42,7 +43,10 @@ function game_init(menu) premiere.init() table.insert(actors,premiere) - + + elalien.init() + table.insert(actors,elalien) + bol.init() table.insert(actors,bol) diff --git a/data/premiere.lua b/data/premiere.lua index a9d35ee..59be018 100644 --- a/data/premiere.lua +++ b/data/premiere.lua @@ -38,14 +38,13 @@ function premiere.init() local world_x, world_y = coords.room_to_world(premiere.hab,premiere.x,premiere.y) premiere.x=world_x premiere.y=world_y - print(premiere.hab) + -- print(premiere.hab) end function premiere.draw() -- draw.surf((premiere.frame&7)*16,(premiere.frame>>3)*16,16,16,premiere.x,premiere.y,16,16,premiere.flip) -- draw.surf((premiere.frame&7)*cw,(premiere.frame>>cxr2)*ch,cw,ch,premiere.x*o2aX,premiere.y*o2aX,cw,ch,premiere.flip) - draw.surf((premiere.frame&7)*cw,(premiere.frame>>cxr2)*ch,cw,ch,premiere.x*o2aX,premiere.y*o2aX,cw,ch,premiere.flip) if viewp:inside(premiere.x, premiere.y, premiere.w, premiere.h) then local scr_x, scr_y = viewp:screen_coords( premiere.x, premiere.y ) -- draw.surf(premiere.x,premiere.y,premiere.w,premiere.h,scr_x,scr_y,premiere.w,premiere.h)