- [NEW] Comence a implementar enemics
- [NEW] Sistema de IA bàsica
This commit is contained in:
@@ -33,4 +33,12 @@ animations = {
|
|||||||
{ frame={x=48,y=0,w=16,h=17}, wait=4, reversed=true }
|
{ frame={x=48,y=0,w=16,h=17}, wait=4, reversed=true }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
["mummy_walk"] = {
|
||||||
|
cycle = {1,2,1,3},
|
||||||
|
frames = {
|
||||||
|
{ frame={x=0,y=24,w=16,h=17}, wait=4 },
|
||||||
|
{ frame={x=16,y=24,w=16,h=17}, wait=4 },
|
||||||
|
{ frame={x=32,y=24,w=16,h=17}, wait=4 }
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ game = {
|
|||||||
-- Pintar el mapa i sprites
|
-- Pintar el mapa i sprites
|
||||||
rooms.draw()
|
rooms.draw()
|
||||||
sprites.update()
|
sprites.update()
|
||||||
sprites.update_hero()
|
--sprites.update_hero()
|
||||||
|
|
||||||
if key.press(key.ESCAPE) or key.press(key.F9) then
|
if key.press(key.ESCAPE) or key.press(key.F9) then
|
||||||
editor.enable()
|
editor.enable()
|
||||||
@@ -29,6 +29,7 @@ game = {
|
|||||||
game.chg_adv.x = x
|
game.chg_adv.x = x
|
||||||
game.chg_adv.y = y
|
game.chg_adv.y = y
|
||||||
game.chg_step = 8
|
game.chg_step = 8
|
||||||
|
sprites.pause_ia = true
|
||||||
app.push(game.update_change_room)
|
app.push(game.update_change_room)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -48,6 +49,7 @@ game = {
|
|||||||
sprites.update()
|
sprites.update()
|
||||||
game.chg_step = game.chg_step - 1
|
game.chg_step = game.chg_step - 1
|
||||||
if game.chg_step == 0 then
|
if game.chg_step == 0 then
|
||||||
|
sprites.pause_ia = false
|
||||||
app.pop()
|
app.pop()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 905 B After Width: | Height: | Size: 902 B |
@@ -3,19 +3,32 @@ require "animations"
|
|||||||
sprites = {
|
sprites = {
|
||||||
hero = nil,
|
hero = nil,
|
||||||
list = {},
|
list = {},
|
||||||
|
pause_ia = false,
|
||||||
|
|
||||||
init = function()
|
init = function()
|
||||||
sprites.hero = {
|
sprites.hero = {
|
||||||
pos = { x=28, y=4*12*8+71 },
|
pos = { x=28, y=4*12*8+71 },
|
||||||
size= { w=16, h=17 },
|
size= { w=16, h=17 },
|
||||||
bbo = { left=0, top=0, right=0, bottom=0 },
|
bbo = { left=0, top=0, right=0, bottom=0 },
|
||||||
flipped = false,
|
|
||||||
jumping = 0,
|
|
||||||
animation = "hero_stand",
|
|
||||||
stairs = false,
|
|
||||||
current_frame = 1,
|
current_frame = 1,
|
||||||
current_wait = 1
|
current_wait = 1,
|
||||||
|
flipped = false,
|
||||||
|
animation = "hero_stand",
|
||||||
|
ia = sprites.update_hero,
|
||||||
|
jumping = 0,
|
||||||
|
stairs = false
|
||||||
}
|
}
|
||||||
|
local mummy = {
|
||||||
|
pos = { x=100, y=4*12*8+71 },
|
||||||
|
size = { w=16,h=17 },
|
||||||
|
bbo = { left=0, top=0, right=0, bottom=0 },
|
||||||
|
current_frame = 1,
|
||||||
|
current_wait = 1,
|
||||||
|
flipped = true,
|
||||||
|
animation = "mummy_walk",
|
||||||
|
ia = sprites.update_mummy
|
||||||
|
}
|
||||||
|
table.insert(sprites.list, mummy)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
set_animation=function(sprite, animation)
|
set_animation=function(sprite, animation)
|
||||||
@@ -35,27 +48,51 @@ sprites = {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
update = function()
|
update = function()
|
||||||
|
if not sys.beat() then return end
|
||||||
sprites.update_sprite(sprites.hero)
|
sprites.update_sprite(sprites.hero)
|
||||||
|
for i,v in ipairs(sprites.list) do
|
||||||
|
sprites.update_sprite(v)
|
||||||
|
end
|
||||||
|
if not sprites.pause_ia then
|
||||||
|
sprites.hero.ia()
|
||||||
|
for i,v in ipairs(sprites.list) do
|
||||||
|
v.ia(v)
|
||||||
|
end
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
update_sprite = function(sprite)
|
update_sprite = function(sprite)
|
||||||
if sys.beat() then
|
sprite.current_wait = sprite.current_wait - 1
|
||||||
sprite.current_wait = sprite.current_wait - 1
|
if sprite.current_wait == 0 then
|
||||||
if sprite.current_wait == 0 then
|
if sprite.current_frame < #animations[sprite.animation].cycle then
|
||||||
if sprite.current_frame < #animations[sprite.animation].cycle then
|
sprite.current_frame = sprite.current_frame + 1
|
||||||
sprite.current_frame = sprite.current_frame + 1
|
else
|
||||||
else
|
sprite.current_frame = 1
|
||||||
sprite.current_frame = 1
|
end
|
||||||
end
|
local cycle = animations[sprite.animation].cycle[sprite.current_frame]
|
||||||
local cycle = animations[sprite.animation].cycle[sprite.current_frame]
|
sprite.current_wait = animations[sprite.animation].frames[cycle].wait
|
||||||
sprite.current_wait = animations[sprite.animation].frames[cycle].wait
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
update_mummy = function(spr)
|
||||||
|
if spr.flipped then
|
||||||
|
local tx, ty = (spr.pos.x+3)>>3, (spr.pos.y+16)>>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+16)>>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
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
update_hero = function()
|
update_hero = function()
|
||||||
if not sys.beat() then return end
|
|
||||||
|
|
||||||
-- Update hero
|
-- Update hero
|
||||||
local anim = "hero_stand"
|
local anim = "hero_stand"
|
||||||
local move_anim = "hero_walk"
|
local move_anim = "hero_walk"
|
||||||
@@ -68,7 +105,7 @@ sprites = {
|
|||||||
--draw.rect(tx1<<3,ty<<3,8,8,8)
|
--draw.rect(tx1<<3,ty<<3,8,8,8)
|
||||||
--draw.rect(tx2<<3,ty<<3,8,8,28)
|
--draw.rect(tx2<<3,ty<<3,8,8,28)
|
||||||
if map.tile(tx1,ty) == 0 and map.tile(tx2,ty) == 0 then
|
if map.tile(tx1,ty) == 0 and map.tile(tx2,ty) == 0 then
|
||||||
if ty<rooms.pos.y then
|
if ty+1<rooms.pos.y then
|
||||||
game.change_room(0,-1)
|
game.change_room(0,-1)
|
||||||
else
|
else
|
||||||
if sprites.hero.jumping > 1 then sprites.hero.pos.y = sprites.hero.pos.y - 1 end
|
if sprites.hero.jumping > 1 then sprites.hero.pos.y = sprites.hero.pos.y - 1 end
|
||||||
@@ -87,7 +124,7 @@ sprites = {
|
|||||||
anim = move_anim
|
anim = move_anim
|
||||||
local tx1, tx2, ty = (sprites.hero.pos.x+4)>>3, (sprites.hero.pos.x+11)>>3, (sprites.hero.pos.y)>>3
|
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 map.tile(tx1,ty) < 16 or map.tile(tx2,ty) < 16 then
|
||||||
if ty<rooms.pos.y then
|
if ty+1<rooms.pos.y then
|
||||||
game.change_room(0,-1)
|
game.change_room(0,-1)
|
||||||
else
|
else
|
||||||
sprites.hero.pos.y = sprites.hero.pos.y - 1
|
sprites.hero.pos.y = sprites.hero.pos.y - 1
|
||||||
@@ -169,7 +206,9 @@ sprites = {
|
|||||||
|
|
||||||
draw = function()
|
draw = function()
|
||||||
surf.source(surf_sprites)
|
surf.source(surf_sprites)
|
||||||
|
for i,v in ipairs(sprites.list) do
|
||||||
|
sprites.draw_sprite(v)
|
||||||
|
end
|
||||||
sprites.draw_sprite(sprites.hero)
|
sprites.draw_sprite(sprites.hero)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user