Murga-Projects Forums

Full Version: Tile based game engine for murgaLua
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello again,

I read the excellent document "Tile Based Games" from Tonypa this night again and asked me, if anyone has started to port this ideas to murgaLua ?
Are there pure lua-engines available ? I found "C with Lua" mixtures only.
I have already done some work for my NXT-Simulator this year, but now I'd like to
rewrite it from scratch in a better way...

My problem is currently the OO thinking with Lua Big Grin
Can anybody give me some ideas or links, how to do it with Lua ?

Thanks
Bye
Christian
Hi,

I've prepared a lot of code for the simple Mindstorms NXT Simulation (Robot Simulator)...
Is it OK to add this as an zipped archive to this thread ?
It should be a base of discussion for all my problems, exploring murgaLua-Graphics
and basic GUI-Design...

Daily I'm rengineer the wheel... but there already exists solutions

Bye
Christian
Feel free, or e-mail it to me at john@murga.org and I'll attach it.

JohnMurga Wrote:
Feel free, or e-mail it to me at john@murga.org and I'll attach it.


Hi John,
my new code to too ugly and buggy...
I attach old code from may, just showing the idea of Mindstorms NXT simulation ;-(

Give me one more month and I send you the new code...

Bye
Christian

Hi,
last night I started new map design with the following code:

Code:
--[[
    Tile object signatures for ASCII-MAP

    floor            = '_'
    wall            = '#'
    water              = 'W'
    tree               = 'T'
    light source          = 'L'
    sound source        = 'S'
    enemy              = 'E'
    door               = 'D'
    friend               = 'F'
    NXT              = 'N'

--]]

    local i,y;
    y=20;
    map={}
    for i=1,y do
        map[i]={}
    end


    map[1]= {'#','#','#','#','#','#','#','#','#','D','#','#','#','#','#','#','#','#','#','#' };

    map[2]= {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','#' };

    map[3]= {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','#' };

    map[4]= {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','#' };

    map[5]= {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','#' };

    map[6]= {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','#' };

    map[7]= {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','#' };

    map[8]= {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','#' };

    map[9]= {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','#' };

    map[10]={'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','# '};

    map[11]={'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','# '};

    map[12]={'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','# '};

    map[13]={'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','# '};

    map[14]={'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','# '};

    map[15]={'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','# '};

    map[16]={'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','# '};

    map[17]={'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','# '};

    map[18]={'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','# '};

    map[19]={'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','# '};

    map[20]={'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','# '};

-- end

Is this useful or any better ideas ?
Bye
Christian

It seems a little redundant. You initially set each index of map to an empty string, and then set them all over again. You could remove the 'for' loop entirely and get the same result.

You might also be able to set up the map table as a single declaration (omitting the individual "map[num]=" declarations), but I don't recall ever doing that to say for sure.
Odd thing...
I made a table with a single "map={...}" declaration, and it seems to work, but not as I expected.
Having each table entry enclosed in curly brackets apparently makes each entry a table within the map table. I don't know if this is what you wanted, but I had never thought about the possibilities of this type of setup.

Code:
map={
    {'#','#','#','#','#','#','#','#','#','D','#','#','#','#','#','#','#','#','# ','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_ ','# '},
    {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','# ','# '}
}
fourth_table=map[4]
print(fourth_table[2]) -- a floor tile

Hi Mikshaw,
your're right, but I want to access map with simple construct like:

tile=map[x][y]

That's better for human eyes Big Grin

Bye
Christian


mikshaw Wrote:
Odd thing...
I made a table with a single "map={...}" declaration, and it seems to work, but not as I expected.
Having each table entry enclosed in curly brackets apparently makes each entry a table within the map table. I don't know if this is what you wanted, but I had never thought about the possibilities of this type of setup.

Code:
map={
    {'#','#','#','#','#','#','#','#','#','D','#','#','#','#','#','#','#','#' ,'#','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','#' },
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','# '},
    {'#','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' ,'_','# '},
    {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' ,'#','# '}
}
fourth_table=map[4]
print(fourth_table[2]) -- a floor tile

Quote:
tile=map[x][y]

Ahhhh. Thank you.
I was trying to figure out how to directly access the nested table, but that syntax didn't occur to me.
The closest I got was something like map[x[y]] before the bulky solution worked and I quit looking =o)

mikshaw Wrote:

Quote:
tile=map[x][y]

Ahhhh. Thank you.
I was trying to figure out how to directly access the nested table, but that syntax didn't occur to me.
The closest I got was something like map[x[y]] before the bulky solution worked and I quit looking =o)


Hi,
with this functions, it is easy to access all map arrays...
Some usefull stuff

Code:
function MapShow()
local x,y;
    for y=1,20 do
        for x=1,#map[y] do
            if (nil~=map[x][y]) then
                print("Tile="..map[x][y].." x="..x.." y="..y);
            end
        end
    end
end

function TileObject()

end

function WindowGetSize()
local x,y;
    x=1;
    while(nil~=map[x]) do x=x+1 end
    x=x-1;
    y=1;
    while(nil~=map[x][y]) do y=y+1 end
    y=y-1;
    y=y*TileSizeY;
    x=x*TileSizeX;
    
    return x,y;
end

--[[
***** MAP WINDOW *****
--]]
TileSizeX=30;
TileSizeY=30;

MapCreate(x,y);
MapShow();
x,y=WindowGetSize()
print("WindowsSize x="..x.." y="..y);


Bye
Christian

Reference URL's