- [NEW] Ja es mou entre habitacions
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
game = {
|
game = {
|
||||||
|
chg_adv = {x=0, y=0},
|
||||||
|
chg_step = 0,
|
||||||
|
|
||||||
enable = function()
|
enable = function()
|
||||||
app.update = game.update
|
app.update = game.update
|
||||||
@@ -16,9 +18,37 @@ game = {
|
|||||||
-- Pintar el mapa i sprites
|
-- Pintar el mapa i sprites
|
||||||
rooms.draw()
|
rooms.draw()
|
||||||
sprites.update()
|
sprites.update()
|
||||||
|
sprites.update_hero()
|
||||||
|
|
||||||
if key.down(key.ESCAPE) then
|
if key.down(key.ESCAPE) then
|
||||||
editor.enable()
|
editor.enable()
|
||||||
end
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
change_room = function(x,y)
|
||||||
|
game.chg_adv.x = x
|
||||||
|
game.chg_adv.y = y
|
||||||
|
game.chg_step = 8
|
||||||
|
app.push(game.update_change_room)
|
||||||
|
end,
|
||||||
|
|
||||||
|
update_change_room = function()
|
||||||
|
view.origin(0,0)
|
||||||
|
surf.target(0)
|
||||||
|
view.clip()
|
||||||
|
|
||||||
|
score.draw()
|
||||||
|
|
||||||
|
-- Pintar el mapa i sprites
|
||||||
|
rooms.pos.x = rooms.pos.x + game.chg_adv.x*2.5
|
||||||
|
rooms.pos.y = rooms.pos.y + game.chg_adv.y*1.5
|
||||||
|
sprites.hero.pos.x = sprites.hero.pos.x + game.chg_adv.x
|
||||||
|
sprites.hero.pos.y = sprites.hero.pos.y + game.chg_adv.y
|
||||||
|
rooms.draw()
|
||||||
|
sprites.update()
|
||||||
|
game.chg_step = game.chg_step - 1
|
||||||
|
if game.chg_step == 0 then
|
||||||
|
app.pop()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 300 B After Width: | Height: | Size: 348 B |
180
data/sprites.lua
180
data/sprites.lua
@@ -36,77 +36,6 @@ sprites = {
|
|||||||
|
|
||||||
update = function()
|
update = function()
|
||||||
sprites.update_sprite(sprites.hero)
|
sprites.update_sprite(sprites.hero)
|
||||||
|
|
||||||
-- Update hero
|
|
||||||
local anim = "hero_stand"
|
|
||||||
local move_anim = "hero_walk"
|
|
||||||
if sprites.hero.jumping > 0 then
|
|
||||||
anim = "hero_jump"
|
|
||||||
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) == 0 and map.tile(tx2,ty) == 0 then
|
|
||||||
sprites.hero.pos.y = sprites.hero.pos.y - 2
|
|
||||||
end
|
|
||||||
sprites.hero.jumping = sprites.hero.jumping - 2
|
|
||||||
else
|
|
||||||
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"
|
|
||||||
if key.down(key.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
|
|
||||||
sprites.hero.pos.y = sprites.hero.pos.y - 1
|
|
||||||
end
|
|
||||||
elseif key.down(key.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
|
|
||||||
sprites.hero.pos.y = sprites.hero.pos.y + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
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
|
|
||||||
draw.rect(tx1<<3, (ty+2)<<3,8,8,8)
|
|
||||||
draw.rect(tx2<<3, (ty+2)<<3,8,8,28)
|
|
||||||
if map.tile(tx1,ty+2) == 0 and map.tile(tx2,ty+2) == 0 then
|
|
||||||
sprites.hero.pos.y = sprites.hero.pos.y + 2
|
|
||||||
else
|
|
||||||
sprites.hero.pos.y = (ty<<3)-1
|
|
||||||
anim = "hero_stand"
|
|
||||||
if (map.tile(txm,ty+2) < 16 and map.tile(txm,ty+2) > 0) then
|
|
||||||
if key.down(key.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
|
|
||||||
if key.down(key.SPACE) then
|
|
||||||
sprites.hero.jumping = 16
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if key.down(key.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
|
|
||||||
sprites.hero.pos.x = sprites.hero.pos.x - 1
|
|
||||||
end
|
|
||||||
elseif key.down(key.RIGHT) then
|
|
||||||
sprites.hero.flipped = false
|
|
||||||
anim = move_anim
|
|
||||||
local tx, ty = (sprites.hero.pos.x+13)>>3, (sprites.hero.pos.y+16)>>3
|
|
||||||
if map.tile(tx,ty) < 16 and map.tile(tx,ty-1) < 16 then
|
|
||||||
sprites.hero.pos.x = sprites.hero.pos.x + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
sprites.set_animation(sprites.hero, anim)
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
update_sprite = function(sprite)
|
update_sprite = function(sprite)
|
||||||
@@ -124,6 +53,115 @@ sprites = {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
update_hero = function()
|
||||||
|
-- Update hero
|
||||||
|
local anim = "hero_stand"
|
||||||
|
local move_anim = "hero_walk"
|
||||||
|
|
||||||
|
-- SI ESTÀ BOTANT...
|
||||||
|
if sprites.hero.jumping > 0 then
|
||||||
|
anim = "hero_jump"
|
||||||
|
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) == 0 and map.tile(tx2,ty) == 0 then
|
||||||
|
if ty<rooms.pos.y then
|
||||||
|
game.change_room(0,-1)
|
||||||
|
else
|
||||||
|
sprites.hero.pos.y = sprites.hero.pos.y - 2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
sprites.hero.jumping = sprites.hero.jumping - 2
|
||||||
|
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) 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<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) 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+11 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
|
||||||
|
--draw.rect(tx1<<3, (ty+2)<<3,8,8,8)
|
||||||
|
--draw.rect(tx2<<3, (ty+2)<<3,8,8,28)
|
||||||
|
-- SI ESTÀ CAIGUENT...
|
||||||
|
if map.tile(tx1,ty+2) == 0 and map.tile(tx2,ty+2) == 0 then
|
||||||
|
if ty+2>rooms.pos.y+11 then
|
||||||
|
game.change_room(0,1)
|
||||||
|
else
|
||||||
|
sprites.hero.pos.y = sprites.hero.pos.y + 2
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- SI NO ESTÀ CAIGUENT...
|
||||||
|
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) 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 SPACE...
|
||||||
|
if key.down(key.SPACE) then
|
||||||
|
sprites.hero.jumping = 16
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- ESTIGA COM ESTIGA, SI POLSA ESQUERRA O DRETA...
|
||||||
|
if key.down(key.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) then
|
||||||
|
sprites.hero.flipped = false
|
||||||
|
anim = move_anim
|
||||||
|
local tx, ty = (sprites.hero.pos.x+13)>>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
|
||||||
|
|
||||||
|
sprites.set_animation(sprites.hero, anim)
|
||||||
|
end,
|
||||||
|
|
||||||
draw = function()
|
draw = function()
|
||||||
surf.source(surf_sprites)
|
surf.source(surf_sprites)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user