Skip to content

Commit

Permalink
separate images/anims/maps into dedicated files.
Browse files Browse the repository at this point in the history
  • Loading branch information
r043v committed Mar 17, 2012
1 parent 7b648c6 commit 822315d
Show file tree
Hide file tree
Showing 8 changed files with 738 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ LDLIBS=lua/src/liblua.a -lm `pkg-config --libs $(PKGS)`

all: load81

load81: load81.o editor.o framebuffer.o lua/src/liblua.a
load81: load81.o editor.o framebuffer.o gdl.o lua/src/liblua.a
editor.o: editor.c editor.h framebuffer.h
framebuffer.o: framebuffer.c framebuffer.h bitfont.h
gdl.o: gdl.c gdl.h framebuffer.h
load81.o: load81.c framebuffer.h editor.h load81.h

lua/src/liblua.a:
Expand Down
15 changes: 9 additions & 6 deletions examples/falldown.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
-- falldown, lua edition \o/
-- © 2k12 r043v/dph


-- init function, launched at start
function setup()
-- game option
game = { map = { data = {}, sizey = 6000, speed = 450, scroll = 0, bg = {255,0,255}, tile = { size = { x=50, y=50 }, color = { {255,0,0},{0,255,0},{0,0,255},{255,255,0},{0,255,255} } } },
hero = { isFall=1, color = {255,0,0}, size = { x=32, y=32 }, pos = { x=0, y=0 } },
screen = { size = { x=0, y=0 }, fps = 30 },
screen = { size = { x=0, y=0 }, fps = 60 },
}

-- init hero position
Expand All @@ -32,7 +31,9 @@ function setup()

-- generate a random map
generateMap()


setFPS(60)

-- get ready for action!
end

Expand All @@ -44,7 +45,7 @@ end
function draw()
-- clear screen
background(game.map.bg[1],game.map.bg[2],game.map.bg[3]);

-- detect speed change and change current map/hero speed
if game.map.oldSpeed ~= game.speed or game.hero.oldSpeed ~= hero.speed then
game.map.oldSpeed = game.map.speed
Expand Down Expand Up @@ -92,7 +93,7 @@ function draw()
end

-- blit the map
drawMap();
zdrawMap();

-- blit hero²
fill(game.hero.color[1],game.hero.color[2],game.hero.color[3],1);
Expand Down Expand Up @@ -130,6 +131,8 @@ function draw()

-- some debug
-- fill(0,255,0,1)
-- text(100,40,string.format("tick %d",getTick()))
-- text(100,70,string.format("image size %d %d",game.testSizex, game.testSizey))
-- text(100,100,string.format("scroll %d",game.map.scroll))
-- text(100,130,string.format("screen %d*%d => %d*%d",WIDTH,HEIGHT,game.screen.size.x,game.screen.size.y))
-- text(100,160,string.format("speed %d px/s current %d frame %d ratio %f",game.map.speed,game.map.currentSpeed,game.screen.frameFlip,game.map.speedRatio))
Expand Down Expand Up @@ -188,7 +191,7 @@ function generateMap()
end
end

function drawMap()
function zdrawMap()
-- compute y start tile position, pixels -> tiles
local starty = math.floor(game.map.scroll/game.map.tile.size.y)+1

Expand Down
82 changes: 82 additions & 0 deletions examples/map.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
function setup()
game = { }
setFPS(60)
game.tileset = loadImage("examples/map/tileset.bmp");

game.mymap = newMap(
{
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
},game.tileset,21,16,16,40,40)

setMapOutZone(game.mymap,100,100,320,240);

game.scrollway_v = SCROLL_DOWN;
game.scrollway_h = SCROLL_RIGHT;
game.scrollway = mapScrollGetWay(game.scrollway_v,game.scrollway_h);
game.animtest = newAnim(game.tileset,16,21,300,0);
setMapAnimatedTile(game.mymap,6,game.animtest)

-- get ready for action!
end

-- loop function
function draw()
-- clear screen
background(255,255,255);
drawMap(game.mymap)
up,down,left,right = mapScroll(game.mymap,game.scrollway,1);

if game.scrollway_v == SCROLL_DOWN then
if down == 1 then game.scrollway_v = SCROLL_UP end
else
if up == 1 then game.scrollway_v = SCROLL_DOWN end
end

if game.scrollway_h == SCROLL_LEFT then
if left == 1 then game.scrollway_h = SCROLL_RIGHT end
else
if right == 1 then game.scrollway_h = SCROLL_LEFT end
end

game.scrollway = mapScrollGetWay(game.scrollway_v,game.scrollway_h);

end
Binary file added examples/map/tileset.bmp
Binary file not shown.
Loading

0 comments on commit 822315d

Please sign in to comment.