0 Members and 3 Guests are viewing this topic.
Here is a small preview of my game.
As for the string, I know is a local joke here, but never cared to read what is really about...
platform.apilevel = '1.0'----------------- CONSTANTS -----------------object = {} -- C = Cobble, D = Door, G = Grass, L = Log, S = Dirt, W = Wood, X = Black, / = RoofL, | = RoofR, @ = Window, # = Leaf, ~ = Water, ` = Shop, ' = Postobject["C"] = image.new(...)object["D"] = image.new(...)object["1"] = object["D"]object["2"] = object["D"]object["G"] = image.new(...)object["S"] = image.new(...)object["W"] = image.new(...)object["X"] = image.new(...)object["/"] = image.new(...)object["|"] = image.new(...)object["@"] = image.new(...)object["`"] = image.new(...)object["~"] = image.new(...)object["'"] = image.new(...)frontObject = {} -- L = Log, # = Leaf, frontObject["L"] = image.new(...)frontObject["#"] = image.new(...)
--------------------------------------------------------------------------------function on.paint(gc)-------------------------------------------------------------------------------- Doors() sprites(gc, object) -- Background gc:drawImage(Person,(Xcoord-1)*BlockSize,(Ycoord-1)*BlockSize) sprites(gc, frontObject) -- Foreground end --------------------------------------------------------------------------------function sprites(gc, table)-------------------------------------------------------------------------------- for i = 1, #Map do -- length of table -> 10 for ii = 1, #Map[i] do -- length of row -> 10 sprite = string.sub(Map[i],ii,ii) if table[sprite] then gc:drawImage(table[sprite], BlockSize*(ii-1), BlockSize*(i-1)) end end endend
platform.apilevel = '1.0'----------------- CONSTANTS ------------------- Since the images never change, I've moved them at the beginning in order to have them as global constants.-- To store them, I've used a table, in where the key (what goes inside the brackets) matches the ASCII used for the sprites. This will greatly simplify the code when you look in the map for an specific sprite.object = {} -- C = Cobble, D = Door, G = Grass, L = Log, S = Dirt, W = Wood, X = Black, / = RoofL, | = RoofR, @ = Window, # = Leaf, ~ = Water, ` = Shop, ' = Postobject["C"] = image.new(...)object["D"] = image.new(...)object["1"] = object["D"] -- This is just a reference to the sprite aboveobject["2"] = object["D"] -- Same as aboveobject["G"] = image.new(...)...object["'"] = image.new(...)-- Also, I've separated the items that will be painted on the front in another blockfrontObject = {} -- L = Log, # = Leaf, frontObject["L"] = image.new(...)frontObject["#"] = image.new(...)
--------------------------------------------------------------------------------function on.paint(gc)-------------------------------------------------------------------------------- Doors() sprites(gc, object) -- Function for painting Background sprites, needs parameter "gc" for Graphic Content functions gc:drawImage(Person,(Xcoord-1)*BlockSize,(Ycoord-1)*BlockSize) -- Character sprite sprites(gc, frontObject) -- Function for painting Foreground sprites, needs parameter "gc" for Graphic Content functions end --------------------------------------------------------------------------------function sprites(gc, table)-------------------------------------------------------------------------------- for i = 1, #Map do -- length of table -> 10 for ii = 1, #Map[i] do -- length of row -> 10 temp = string.sub(Map[i],ii,ii) if table[temp] then -- Checks if key exists in the table before painting gc:drawImage(table[temp], BlockSize*(ii-1), BlockSize*(i-1)) end end endend