- Reestructuració completa
This commit is contained in:
14
data/modules/ia/brick.lua
Normal file
14
data/modules/ia/brick.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
function ia.update_brick(spr)
|
||||
if spr.timeout > 0 then
|
||||
spr.timeout = spr.timeout - 1
|
||||
if spr.timeout == 0 then
|
||||
local tx, ty = spr.pos.x>>3, spr.pos.y>>3
|
||||
map.tile(tx,ty,0)
|
||||
end
|
||||
else
|
||||
spr.pos.y = spr.pos.y + 2
|
||||
local tx, ty = (spr.pos.x+2)>>3, (spr.pos.y)>>3
|
||||
if rooms.is_outside(tx,ty) then sprites.remove(spr) return end
|
||||
end
|
||||
end
|
||||
29
data/modules/ia/bullet.lua
Normal file
29
data/modules/ia/bullet.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
function ia.update_bullet(spr)
|
||||
local tx, ty, ty2 = (spr.pos.x+2)>>3, (spr.pos.y+1)>>3, (spr.pos.y+2)>>3
|
||||
|
||||
if rooms.is_outside(tx,ty) then sprites.remove(spr) return end
|
||||
|
||||
local x1,y1,w1,h1 = util.aabb(spr)
|
||||
for i,v in ipairs(sprites.list) do
|
||||
if v.enemy and v.state ~= templates.DEAD then
|
||||
local x2,y2,w2,h2 = util.aabb(v)
|
||||
if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then
|
||||
if v.state == templates.ALIVE then v.state = templates.DYING end
|
||||
sprites.remove(spr)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if map.tile(tx,ty) < 16 or map.tile(tx,ty2) < 16 then
|
||||
if spr.flipped then
|
||||
spr.pos.x = spr.pos.x - 8
|
||||
else
|
||||
spr.pos.x = spr.pos.x + 8
|
||||
end
|
||||
else
|
||||
sprites.remove(spr)
|
||||
end
|
||||
end
|
||||
|
||||
15
data/modules/ia/clau.lua
Normal file
15
data/modules/ia/clau.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
function ia.update_clau(spr)
|
||||
if spr.state == templates.ALIVE then
|
||||
local x1,y1,w1,h1 = util.aabb(spr)
|
||||
local x2,y2,w2,h2 = util.aabb(sprites.hero)
|
||||
if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then
|
||||
if sprites.hero.give_key(spr.color) then
|
||||
local tx, ty = (spr.pos.x)>>3, (spr.pos.y)>>3
|
||||
map.surf(rooms.surf_items)
|
||||
map.tile(tx,ty,0)
|
||||
sprites.remove(spr)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
26
data/modules/ia/coin.lua
Normal file
26
data/modules/ia/coin.lua
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
function ia.update_coin(spr)
|
||||
if spr.state == templates.ALIVE then
|
||||
local x1,y1,w1,h1 = util.aabb(spr)
|
||||
local x2,y2,w2,h2 = util.aabb(sprites.hero)
|
||||
if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then
|
||||
local tx, ty = (spr.pos.x)>>3, (spr.pos.y)>>3
|
||||
map.surf(rooms.surf_items)
|
||||
map.tile(tx,ty,0)
|
||||
|
||||
spr.state = templates.DYING
|
||||
sprites.set_animation(spr, "coin_picked")
|
||||
spr.pos.y=spr.pos.y-16
|
||||
spr.pos.x=spr.pos.x-4
|
||||
spr.timer = 0
|
||||
score.inc(10)
|
||||
return
|
||||
end
|
||||
elseif spr.state == templates.DYING then
|
||||
spr.pos.y = spr.pos.y - 0.5
|
||||
spr.timer = spr.timer + 1
|
||||
if spr.timer == 32 then
|
||||
sprites.remove(spr)
|
||||
end
|
||||
end
|
||||
end
|
||||
232
data/modules/ia/hero.lua
Normal file
232
data/modules/ia/hero.lua
Normal file
@@ -0,0 +1,232 @@
|
||||
|
||||
function ia.update_hero()
|
||||
|
||||
if sprites.hero.state == templates.DEAD then
|
||||
if sprites.hero.cooldown > 0 then
|
||||
local tx1, tx2, ty = (sprites.hero.pos.x+4)>>3, (sprites.hero.pos.x+11)>>3, (sprites.hero.pos.y+1)>>3
|
||||
local tile_under_me1 = map.tile(tx1,ty+2)
|
||||
local tile_under_me2 = map.tile(tx2,ty+2)
|
||||
if tile_under_me1 == 0 and tile_under_me2 == 0 then
|
||||
if rooms.pos.y<84 and ty+2>rooms.pos.y+12 then
|
||||
game.change_room(0,1)
|
||||
else
|
||||
if sprites.hero.cooldown % 4 == 0 then
|
||||
sprites.hero.pos.y = sprites.hero.pos.y + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
sprites.hero.cooldown = sprites.hero.cooldown - 1
|
||||
if sprites.hero.cooldown == 0 then
|
||||
sprites.lights_out()
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- Update hero
|
||||
local anim = "hero_stand"
|
||||
local move_anim = "hero_walk"
|
||||
|
||||
-- Si estem en cooldown desde l'ultim dispar, decrementem el contador
|
||||
if sprites.hero.cooldown > 0 then
|
||||
sprites.hero.cooldown = sprites.hero.cooldown - 1
|
||||
end
|
||||
|
||||
-- Si estem en jump_throttle desde l'ultim bot, decrementem el contador
|
||||
if sprites.hero.jump_throttle > 0 then
|
||||
sprites.hero.jump_throttle = sprites.hero.jump_throttle - 1
|
||||
end
|
||||
|
||||
if sprites.hero.state == templates.DYING then
|
||||
if (sprites.hero.cooldown//5) % 2 == 0 then
|
||||
sprites.hero.invisible = true
|
||||
else
|
||||
sprites.hero.invisible = nil
|
||||
end
|
||||
if sprites.hero.cooldown == 0 then
|
||||
sprites.hero.state = templates.ALIVE
|
||||
sprites.hero.invisible = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- si està en l'animació de disparar, no podem fer res i eixim ja
|
||||
if sprites.hero.shooting then
|
||||
-- A no ser que siga l'ultim frame, en tal cas tornem a estar de peu i au
|
||||
if sprites.hero.current_frame==3 then
|
||||
sprites.hero.shooting = false
|
||||
sprites.set_animation(sprites.hero, "hero_stand")
|
||||
else
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- SI ESTÀ BOTANT...
|
||||
if sprites.hero.jumping > 0 then
|
||||
anim = "hero_jump"
|
||||
move_anim = "hero_jump"
|
||||
local tx1, tx2, ty = (sprites.hero.pos.x+4)>>3, (sprites.hero.pos.x+11)>>3, (sprites.hero.pos.y)>>3
|
||||
--draw.rect(tx1<<3,ty<<3,8,8,8)
|
||||
--draw.rect(tx2<<3,ty<<3,8,8,28)
|
||||
if map.tile(tx1,ty) == 0 and map.tile(tx2,ty) == 0 then
|
||||
if ty+1<rooms.pos.y then
|
||||
game.change_room(0,-1)
|
||||
else
|
||||
if sprites.hero.jumping > 1 then sprites.hero.pos.y = sprites.hero.pos.y - 1 end
|
||||
end
|
||||
else
|
||||
sprites.hero.jumping = 0
|
||||
sprites.hero.jump_throttle = 10
|
||||
end
|
||||
sprites.hero.jumping = sprites.hero.jumping - 1
|
||||
else
|
||||
-- SI NO ESTÀ BOTANT...
|
||||
-- SI ESTÀ EN UNES ESCALERES...
|
||||
local txm, ty = (sprites.hero.pos.x+8)>>3, (sprites.hero.pos.y+8)>>3
|
||||
if (map.tile(txm,ty) > 0 and map.tile(txm,ty) < 16) or (map.tile(txm,ty+1) > 0 and map.tile(txm,ty+1) < 16) then
|
||||
anim = "hero_stairs_idle"
|
||||
move_anim = "hero_stairs"
|
||||
-- SI PULSA AMUNT...
|
||||
if key.down(key.UP) or pad.down(pad.UP) then
|
||||
anim = move_anim
|
||||
local tx1, tx2, ty = (sprites.hero.pos.x+4)>>3, (sprites.hero.pos.x+11)>>3, (sprites.hero.pos.y)>>3
|
||||
if map.tile(tx1,ty) < 16 or map.tile(tx2,ty) < 16 then
|
||||
if ty+1<rooms.pos.y then
|
||||
game.change_room(0,-1)
|
||||
else
|
||||
sprites.hero.pos.y = sprites.hero.pos.y - 1
|
||||
end
|
||||
end
|
||||
-- SI PULSA AVALL...
|
||||
elseif key.down(key.DOWN) or pad.down(pad.DOWN) then
|
||||
anim = move_anim
|
||||
local tx1, tx2, ty = (sprites.hero.pos.x+4)>>3, (sprites.hero.pos.x+11)>>3, (sprites.hero.pos.y+1)>>3
|
||||
if map.tile(tx1,ty+2) < 16 or map.tile(tx2,ty+2) < 16 then
|
||||
if ty+2>rooms.pos.y+12 then
|
||||
game.change_room(0,1)
|
||||
else
|
||||
sprites.hero.pos.y = sprites.hero.pos.y + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
-- SI NO ESTÀ EN UNES ESCALERES...
|
||||
local tx1, txm, tx2, ty = (sprites.hero.pos.x+4)>>3, (sprites.hero.pos.x+8)>>3, (sprites.hero.pos.x+11)>>3, (sprites.hero.pos.y+1)>>3
|
||||
-- SI ESTÀ CAIGUENT...
|
||||
local tile_under_me1 = map.tile(tx1,ty+2)
|
||||
local tile_under_me2 = map.tile(tx2,ty+2)
|
||||
if tile_under_me1 == 0 and tile_under_me2 == 0 then
|
||||
if rooms.pos.y<84 and ty+2>rooms.pos.y+12 then
|
||||
game.change_room(0,1)
|
||||
else
|
||||
if sprites.hero.pos.y >= 808 then
|
||||
sprites.hero.hit(0)
|
||||
return
|
||||
end
|
||||
sprites.hero.pos.y = sprites.hero.pos.y + 2
|
||||
end
|
||||
else
|
||||
-- SI NO ESTÀ CAIGUENT...
|
||||
if tile_under_me1==84 then
|
||||
map.tile(tx1,ty+2,68)
|
||||
local broken_tile = templates.create("brick", {pos={x=tx1<<3, y=(ty+2)<<3}, flipped=sprites.hero.flipped})
|
||||
table.insert(sprites.list, broken_tile)
|
||||
end
|
||||
if tile_under_me2==84 then
|
||||
map.tile(tx2,ty+2,68)
|
||||
local broken_tile = templates.create("brick", {pos={x=tx2<<3, y=(ty+2)<<3}, flipped=sprites.hero.flipped})
|
||||
table.insert(sprites.list, broken_tile)
|
||||
end
|
||||
sprites.hero.pos.y = (ty<<3)-1
|
||||
anim = "hero_stand"
|
||||
-- SI ESTÀ SOBRE UNES ESCALERES I POLSA AVALL...
|
||||
if (map.tile(txm,ty+2) < 16 and map.tile(txm,ty+2) > 0) then
|
||||
if key.down(key.DOWN) or pad.down(pad.DOWN) then
|
||||
anim = "hero_stairs"
|
||||
--local tx1, tx2, ty = (sprites.hero.pos.x+4)>>3, (sprites.hero.pos.x+11)>>3, (sprites.hero.pos.y+1)>>3
|
||||
--if map.tile(tx1,ty+2) < 16 or map.tile(tx2,ty+2) < 16 then
|
||||
sprites.hero.pos.x = (txm << 3)-4
|
||||
sprites.hero.pos.y = sprites.hero.pos.y + 1
|
||||
--end
|
||||
end
|
||||
end
|
||||
-- SI POLSA BOTAR...
|
||||
if ( key.down(key.X) or pad.down(pad.A) ) and sprites.hero.jump_throttle == 0 then
|
||||
sprites.hero.jumping = 17
|
||||
|
||||
-- SI POLSA DISPAR...
|
||||
elseif (sprites.hero.cooldown==0) and (key.down(key.Z) or pad.down(pad.B)) then
|
||||
sprites.hero.shooting = true
|
||||
sprites.hero.cooldown = 20
|
||||
local bullet = templates.create("bullet", {pos={x=sprites.hero.pos.x, y=sprites.hero.pos.y+7}, flipped=sprites.hero.flipped})
|
||||
table.insert(sprites.list, bullet)
|
||||
anim = "hero_shoot"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- ESTIGA COM ESTIGA, SI POLSA ESQUERRA O DRETA...
|
||||
if not sprites.hero.shooting then
|
||||
if key.down(key.LEFT) or pad.down(pad.LEFT) then
|
||||
sprites.hero.flipped = true
|
||||
anim = move_anim
|
||||
local tx, ty = (sprites.hero.pos.x+3)>>3, (sprites.hero.pos.y+16)>>3
|
||||
if map.tile(tx,ty) < 16 and map.tile(tx,ty-1) < 16 then
|
||||
if tx<rooms.pos.x then
|
||||
game.change_room(-1,0)
|
||||
else
|
||||
sprites.hero.pos.x = sprites.hero.pos.x - 1
|
||||
end
|
||||
end
|
||||
elseif key.down(key.RIGHT) or pad.down(pad.RIGHT) then
|
||||
sprites.hero.flipped = false
|
||||
anim = move_anim
|
||||
local tx, ty = (sprites.hero.pos.x+12)>>3, (sprites.hero.pos.y+16)>>3
|
||||
if map.tile(tx,ty) < 16 and map.tile(tx,ty-1) < 16 then
|
||||
if tx>rooms.pos.x+19 then
|
||||
game.change_room(1,0)
|
||||
else
|
||||
sprites.hero.pos.x = sprites.hero.pos.x + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
sprites.set_animation(sprites.hero, anim)
|
||||
end
|
||||
|
||||
|
||||
function ia.hero_hit(live)
|
||||
live = live or sprites.hero.lives-1
|
||||
local light_table = {[0]=20, 30, 50, 80, 100}
|
||||
local red_table = {[0]=0, 0.25, 0.5, 0.75, 1}
|
||||
if live==4 then
|
||||
tweening.add(1,0,0.25,easing.linear,function(value,n,finished)palfade.fade_white(value)end)
|
||||
else
|
||||
tweening.add(1,0,0.25,easing.linear,function(value,n,finished)palfade.fade_red(value)end)
|
||||
end
|
||||
local start_light = light_table[sprites.hero.lives]
|
||||
local start_red = red_table[sprites.hero.lives]
|
||||
local end_light = light_table[live]
|
||||
local end_red = red_table[live]
|
||||
|
||||
sprites.hero.lives = live
|
||||
tweening.add(start_light,end_light,1,easing.linear,function(value,n,finished)sprites.hero.light = value end)
|
||||
tweening.add(start_red,end_red,1,easing.linear,function(value,n,finished)palfade.fade_reddish(value)end)
|
||||
|
||||
if sprites.hero.lives == 0 then
|
||||
sprites.hero.state = templates.DEAD
|
||||
sprites.hero.surf = surf.load("gfx/mummy.gif")
|
||||
sprites.set_animation(sprites.hero, "mummy_dying")
|
||||
sprites.hero.jumping = 0
|
||||
sprites.hero.cooldown = 120
|
||||
elseif sprites.hero.lives < 4 then
|
||||
sprites.hero.state = templates.DYING
|
||||
sprites.hero.cooldown = 60
|
||||
end
|
||||
end
|
||||
|
||||
function ia.hero_give_key(color)
|
||||
if sprites.hero.keys[color] then return false end
|
||||
sprites.hero.keys[color] = true
|
||||
tweening.add(1,0,0.25,easing.linear,function(value,n,finished)palfade.fade_white(value)end)
|
||||
return true
|
||||
end
|
||||
49
data/modules/ia/mummy.lua
Normal file
49
data/modules/ia/mummy.lua
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
function ia.update_mummy(spr)
|
||||
map.surf(rooms.surf_foreground)
|
||||
if spr.state == templates.ALIVE then
|
||||
if sprites.hero.state == templates.ALIVE then
|
||||
local x1,y1,w1,h1 = util.aabb(spr) -- El meu aabb
|
||||
local x2,y2,w2,h2 = util.aabb(sprites.hero) -- el aabb del heroi
|
||||
-- Si toca al heroi...
|
||||
if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then
|
||||
sprites.hero.hit()
|
||||
end
|
||||
end
|
||||
|
||||
if spr.flipped then
|
||||
local tx, ty = (spr.pos.x+3)>>3, (spr.pos.y+15)>>3
|
||||
if map.tile(tx,ty) < 16 and map.tile(tx,ty-1) < 16 and map.tile(tx,ty+1) > 0 then
|
||||
spr.pos.x = spr.pos.x - 1
|
||||
else
|
||||
spr.flipped = not spr.flipped
|
||||
end
|
||||
else
|
||||
local tx, ty = (spr.pos.x+12)>>3, (spr.pos.y+15)>>3
|
||||
if map.tile(tx,ty) < 16 and map.tile(tx,ty-1) < 16 and map.tile(tx,ty+1) > 0 then
|
||||
spr.pos.x = spr.pos.x + 1
|
||||
else
|
||||
spr.flipped = not spr.flipped
|
||||
end
|
||||
end
|
||||
elseif spr.state == templates.DYING then
|
||||
if spr.animation ~= "mummy_dying" then
|
||||
sprites.set_animation(spr, "mummy_dying")
|
||||
else
|
||||
if spr.current_frame == 8 then
|
||||
sprites.set_animation(spr, "mummy_dead")
|
||||
spr.state = templates.DEAD
|
||||
end
|
||||
end
|
||||
elseif spr.state == templates.DEAD then
|
||||
if spr.current_wait == 1 then
|
||||
sprites.set_animation(spr, "mummy_undying")
|
||||
spr.state = templates.RESURRECTING
|
||||
end
|
||||
elseif spr.state == templates.RESURRECTING then
|
||||
if spr.current_frame == 13 then
|
||||
sprites.set_animation(spr, "mummy_walk")
|
||||
spr.state = templates.ALIVE
|
||||
end
|
||||
end
|
||||
end
|
||||
24
data/modules/ia/porta.lua
Normal file
24
data/modules/ia/porta.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
function ia.update_porta(spr)
|
||||
if spr.state == templates.ALIVE then
|
||||
local x1,y1,w1,h1 = util.aabb(spr)
|
||||
local x2,y2,w2,h2 = util.aabb(sprites.hero)
|
||||
if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then
|
||||
if sprites.hero.keys[spr.color] then
|
||||
sprites.hero.keys[spr.color] = nil
|
||||
sprites.set_animation(spr, "porta_obrint")
|
||||
spr.state = templates.DYING
|
||||
end
|
||||
end
|
||||
elseif spr.state == templates.DYING then
|
||||
if spr.current_frame == 15 then
|
||||
local tx, ty = (spr.pos.x)>>3, (spr.pos.y)>>3
|
||||
map.surf(rooms.surf_items)
|
||||
map.tile(tx,ty,0)
|
||||
map.surf(rooms.surf_foreground)
|
||||
map.tile(tx,ty,0)
|
||||
map.tile(tx,ty+1,0)
|
||||
sprites.remove(spr)
|
||||
end
|
||||
end
|
||||
end
|
||||
36
data/modules/ia/sucubo.lua
Normal file
36
data/modules/ia/sucubo.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
function ia.update_sucubo(spr)
|
||||
map.surf(rooms.surf_foreground)
|
||||
if spr.state == templates.ALIVE then
|
||||
if sprites.hero.state == templates.ALIVE then
|
||||
local x1,y1,w1,h1 = util.aabb(spr) -- El meu aabb
|
||||
local x2,y2,w2,h2 = util.aabb(sprites.hero) -- el aabb del heroi
|
||||
-- Si toca al heroi...
|
||||
if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then
|
||||
sprites.hero.hit()
|
||||
end
|
||||
end
|
||||
|
||||
elseif spr.state == templates.DYING then
|
||||
if spr.animation ~= "mummy_dying" then
|
||||
sprites.set_animation(spr, "mummy_dying")
|
||||
spr.surf = surf.load("gfx/mummy.gif")
|
||||
else
|
||||
if spr.current_frame == 8 then
|
||||
sprites.set_animation(spr, "mummy_dead")
|
||||
spr.state = templates.DEAD
|
||||
end
|
||||
end
|
||||
elseif spr.state == templates.DEAD then
|
||||
if spr.current_wait == 1 then
|
||||
sprites.set_animation(spr, "mummy_undying")
|
||||
spr.state = templates.RESURRECTING
|
||||
end
|
||||
elseif spr.state == templates.RESURRECTING then
|
||||
if spr.current_frame == 13 then
|
||||
sprites.set_animation(spr, "sucubo_stand")
|
||||
spr.surf = surf.load("gfx/sucubo.gif")
|
||||
spr.state = templates.ALIVE
|
||||
end
|
||||
end
|
||||
end
|
||||
19
data/modules/ia/torxa.lua
Normal file
19
data/modules/ia/torxa.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
function ia.update_torxa(spr)
|
||||
if spr.state == templates.ALIVE then
|
||||
if sprites.hero.lives == 4 then return end
|
||||
local x1,y1,w1,h1 = util.aabb(spr)
|
||||
local x2,y2,w2,h2 = util.aabb(sprites.hero)
|
||||
if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then
|
||||
sprites.hero.hit(4)
|
||||
spr.state = templates.DYING
|
||||
spr.timer = 0
|
||||
return
|
||||
end
|
||||
elseif spr.state == templates.DYING then
|
||||
spr.timer = spr.timer + 1
|
||||
if spr.timer == 32 then
|
||||
spr.state = templates.ALIVE
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user