diff --git a/data/animations.lua b/data/animations.lua index 96902e7..69fc144 100644 --- a/data/animations.lua +++ b/data/animations.lua @@ -1,11 +1,17 @@ animations = { + ["hero_stand"] = { + cycle = {1}, + frames = { + { frame={x=0,y=0,w=16,h=17}, wait=2 }, + } + }, ["hero_walk"] = { cycle = {1,2,1,3}, frames = { - { frame={x=0,y=0,w=16,h=17}, wait=4 }, - { frame={x=16,y=0,w=16,h=17}, wait=4 }, - { frame={x=32,y=0,w=16,h=17}, wait=4 } + { frame={x=0,y=0,w=16,h=17}, wait=2 }, + { frame={x=16,y=0,w=16,h=17}, wait=2 }, + { frame={x=32,y=0,w=16,h=17}, wait=2 } } } } \ No newline at end of file diff --git a/data/editor.lua b/data/editor.lua index ccbf50f..2b9e691 100644 --- a/data/editor.lua +++ b/data/editor.lua @@ -12,6 +12,7 @@ editor = { enable = function() app.update = editor.update sys.beat(2) + shader.disable(); end, update = function() @@ -141,6 +142,20 @@ editor = { end end, + play=function() + if editor.modified then + msgbox.show("IE MEN!", + {"Hi ha canvis sense guardar.", "Vols guardar-los abans de jugar?"}, + { + {"Cancel", app.pop}, + {"No", function() app.pop() game.enable() end}, + {"Yes", function() app.pop() rooms.save() game.enable() end} + } ) + else + game.enable() + end + end, + picker = { show = function() diff --git a/data/game.lua b/data/game.lua index c4a75be..18da5ce 100644 --- a/data/game.lua +++ b/data/game.lua @@ -2,17 +2,23 @@ game = { enable = function() app.update = game.update - sys.beat(20) + sys.beat(2) + shader.enable(); end, update = function() view.origin(0,0) surf.target(0) + view.clip() score.draw() -- Pintar el mapa i sprites rooms.draw() + sprites.update() + if key.down(key.ESCAPE) then + editor.enable() + end end } \ No newline at end of file diff --git a/data/main.lua b/data/main.lua index 34bc6f6..e36c3f3 100644 --- a/data/main.lua +++ b/data/main.lua @@ -2,6 +2,7 @@ require "app" require "score" require "rooms" require "editor" +require "game" function mini.init() surf_sprites = surf.load("sprites.gif") @@ -10,6 +11,7 @@ function mini.init() pal.trans(0) rooms.init() + shader.init("lynx.glsl") editor.enable() end diff --git a/data/menu.lua b/data/menu.lua index 4f538da..ec82811 100644 --- a/data/menu.lua +++ b/data/menu.lua @@ -15,6 +15,7 @@ menu = { menu.option("FILE") popup.create("FILE", 1, 8) + popup.addOption("FILE", "Play", editor.play) popup.addOption("FILE", "Save", function() rooms.save() editor.modified=false end) popup.addOption("FILE", "Quit", editor.quit) diff --git a/data/rooms.lua b/data/rooms.lua index 7c7debf..b680cdf 100644 --- a/data/rooms.lua +++ b/data/rooms.lua @@ -47,9 +47,6 @@ rooms = { --surf.save(rooms.surf_background, "data/rooms_background.bin") --surf.save(rooms.surf_foreground, "data/rooms_foreground.bin") --surf.save(rooms.surf_items, "data/rooms_items.bin") - - --shader.init("lynx.glsl") - --shader.enable(); end, save = function() @@ -104,7 +101,6 @@ rooms = { --draw.surf(0, 0, 16, 17, 20, 15, 16, 17) end - sprites.update() -- Pintem la rejilla --for y=0,12 do draw.line(0,y*8, 160, y*8, 27) end --for x=0,20 do draw.line(x*8, 0, x*8, 104, 27) end diff --git a/data/rooms_foreground.bin b/data/rooms_foreground.bin index 8a1f60b..9b4868c 100644 Binary files a/data/rooms_foreground.bin and b/data/rooms_foreground.bin differ diff --git a/data/score.lua b/data/score.lua index 9cfa95d..ba4a2d9 100644 --- a/data/score.lua +++ b/data/score.lua @@ -1,6 +1,6 @@ score = { draw = function() - draw.rectf(0,0,160,7,1) + draw.rectf(0,0,160,8,1) end } diff --git a/data/sprites.gif b/data/sprites.gif index b1b938d..f6df32e 100644 Binary files a/data/sprites.gif and b/data/sprites.gif differ diff --git a/data/sprites.lua b/data/sprites.lua index 59ecd36..6d920bf 100644 --- a/data/sprites.lua +++ b/data/sprites.lua @@ -9,14 +9,35 @@ sprites = { pos = { x=24, y=15 }, size= { w=16, h=17 }, bbo = { left=0, top=0, right=0, bottom=0 }, - animation = "hero_walk", + flipped = false, + animation = "hero_stand", current_frame = 1, current_wait = 1 } end, + set_animation=function(sprite, animation) + if sprite.animation ~= animation then + sprite.animation = animation + sprite.current_frame = 1 + sprite.current_wait = 1 + end + end, + update = function() sprites.update_sprite(sprites.hero) + + if key.down(key.LEFT) then + sprites.hero.flipped = true + sprites.set_animation(sprites.hero, "hero_walk") + sprites.hero.pos.x = sprites.hero.pos.x - 1 + elseif key.down(key.RIGHT) then + sprites.hero.flipped = false + sprites.set_animation(sprites.hero, "hero_walk") + sprites.hero.pos.x = sprites.hero.pos.x + 1 + else + sprites.set_animation(sprites.hero, "hero_stand") + end end, update_sprite = function(sprite) @@ -43,6 +64,6 @@ sprites = { draw_sprite = function(sprite) local cycle = animations[sprite.animation].cycle[sprite.current_frame] local frame = animations[sprite.animation].frames[cycle] - draw.surf(frame.frame.x, frame.frame.y, frame.frame.w, frame.frame.h, sprite.pos.x, sprite.pos.y, sprite.size.w, sprite.size.h) + draw.surf(frame.frame.x, frame.frame.y, frame.frame.w, frame.frame.h, sprite.pos.x, sprite.pos.y, sprite.size.w, sprite.size.h, sprite.flipped) end } \ No newline at end of file