Hmmm.. let's both think about that, it shouldn't be that hard if each map block has a fixed width and height, say 14 width 13 height as you have in your exemple ?Davidobot wrote:Now that is another problem, I will now need a remove function?!Ranguna259 wrote:infinite well.. don't forget to optimize it so it will discard maps as you move forward or backward and reload them once you get close to them again because if you don't there'll be a massive impact on the performanceDavidobot wrote:Thank you!
Works perfectly! Infinite worlds, here I come!
Combining 2D Arrays?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Combining 2D Arrays?
Re: Combining 2D Arrays?
Lets just say it's 60x100. So removing shouldn't be that much of a problem, but that means after removing you will need to save it somewhere, I already have a table serializer.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
personal page and a raycaster
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Combining 2D Arrays?
Actualy it wont be easy, removing vars from a table is actually a delicate matter but luckly I've already done something like this, I just gotta search for my code, I'm going to have dinner now so I'll post back in an hour or so.Davidobot wrote:Lets just say it's 60x100. So removing shouldn't be that much of a problem, but that means after removing you will need to save it somewhere, I already have a table serializer.
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Combining 2D Arrays?
Oh great I can't code anything unless I know how you manage you tables and player coordinates so take a look at the code in this page which is this one:
And try to make it so that it removes a mapblock from the mainmap when the player moves forward ir backward to a new mapblock. Here's a a representation:
Code: Select all
local input = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p' }
local remove = { f=true, g=true, j=true, n=true, o=true, p=true }
local n=#input
for i=1,n do
if remove[input[i]] then
input[i]=nil
end
end
local j=0
for i=1,n do
if input[i]~=nil then
j=j+1
input[j]=input[i]
end
end
for i=j+1,n do
input[i]=nil
end
Re: Combining 2D Arrays?
Here is the .love file I am working on. The map combining is located under states/gameState.lua at the very bottom. BTW the map can get very big.
- Attachments
-
- AoB.love
- Development Build
- (237.71 KiB) Downloaded 54 times
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
personal page and a raycaster
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Combining 2D Arrays?
Ok I'm gonna look into it, but basicly what you want is something like a random generated map right ? like minecraft or terraria ?
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Combining 2D Arrays?
Here ya go, now all you need to do is to implement this to your code:
EDIT: When the code discards mapblocks make it save them in a file they can be restored when the player approaches them again, or not if you want the map to be totally random generated even if the player has already past throught a mapblock.
Code: Select all
print('back remover')
mapa = {
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4, 1 },
{ 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
{ 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
{ 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
}
mapb = {
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4, 1 },
{ 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
{ 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
{ 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
}
for i=1,#mapb do
for ii=1, #mapb[i] do
table.insert(mapa[i],mapb[i][ii])
end
end
print('two maps')
for i=1, #mapa do
print(unpack(mapa[i]))
end
--back remover
local remove = 14 --mapblock width in this exemple
local n = #mapa --length of the table
local nn = #mapa[1] --length of the table
for i=1,#mapa do
for ii=1,remove do
mapa[i][ii]=nil
end
end
print('\none map with nil garbedge')
for i=1, #mapa do
print(unpack(mapa[i]))
end
local j=0
local jj=0
for i=1,n do
j=j+1
for ii=15,nn do
jj=jj+1
mapa[j][jj]=mapa[i][ii]
end
jj=0
end
print('\none map with number garbedge')
for i=1, #mapa do
print(unpack(mapa[i]))
end
for i=1,n do
for ii=nn-13,nn do
mapa[i][ii]=nil
end
end
print('\none map')
for i=1, #mapa do
print(unpack(mapa[i]))
end
print('\nfront remover')
mapa =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 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
}
for i=1,#mapb do
for ii=1, #mapb[i] do
table.insert(mapa[i],mapb[i][ii])
end
end
print('two maps')
for i=1, #mapa do
print(unpack(mapa[i]))
end
--front remover
local remove = #mapa[1] --end of mainmap in this exemple
local n = #mapa --length of the table
local nn = #mapa[1] --length of the table
for i=1,#mapa do
for ii=15,remove do --15=mapblock width + 1 (width of the mapblocks that are before the last one)
mapa[i][ii]=nil
end
end
print('\none map')
for i=1, #mapa do
print(unpack(mapa[i]))
end
Who is online
Users browsing this forum: Google [Bot], secretsue92 and 98 guests