2D Arrays: Connecting Grass Tiles
Author |
Message |
TheXploder
|
Posted: Tue Feb 10, 2004 10:04 pm Post subject: 2D Arrays: Connecting Grass Tiles |
|
|
I created an array with the size of 10x10
code: |
0000000000
0000000000
0000000000
0001110000
0001110000
0001110000
0000000000
0000000000
0000000000
0000000000
|
now for any 1 there is a random posibility that it is plain grass or bushy grass now I don't want the bushy to apper beside a '0' but for the plain grass it shoudn't matter, so I wanna check that beside every bushy grass there is plain grass...
I have this to check the array:
code: |
for col : 1 .. 10
for decreasing row : 10 .. 1
if map (col, row) = 1 then
randint (gTileRand, 1, 1)
if gTileRand = 0 then
objIsoBlock (x + row + col, y + row - col, gTileRand)
end if
if gTileRand = 1 then
gTileRand := 4
if row > 0 and row < 10 and col > 0 and col < 10 then
if map (col, row + 1) = 1 then
objIsoBlock (x + row + col, y + row - col, gTileRand)
elsif map (col-1, row) = 1 then
objIsoBlock (x + row + col, y + row - col, gTileRand)
end if
end if
end if
end if
if map (col, row) = 0 then
openObj (0 + newX (x + row + col), -4 + newY (y + row - col), 4)
end if
end for
end for
|
but It doesn't seem to work right... |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Andy
|
Posted: Tue Feb 10, 2004 10:16 pm Post subject: (No subject) |
|
|
well y dont u just check whether if a 1 is surrounded by all 1s, and if it is, make it ur bushy grass |
|
|
|
|
|
TheXploder
|
Posted: Tue Feb 10, 2004 10:20 pm Post subject: (No subject) |
|
|
Oh I c but I need '1' to be both for plain grass and bushy grass, that's my only mind problem..
P.S: Dodge I have a packadge for you, so can you add me to MSN it's:
thexploder@hotmail.com |
|
|
|
|
|
Andy
|
Posted: Tue Feb 10, 2004 10:24 pm Post subject: (No subject) |
|
|
o well, just reandomize those then... and for the other ones, just make it ur plain grass... |
|
|
|
|
|
TheXploder
|
Posted: Tue Feb 10, 2004 10:39 pm Post subject: (No subject) |
|
|
ok, let's say this is a mountain represented by a '1' so then I randomly place either a plain grass tile or a bushy grass tile on top of the mountain, and I don't want bushy tiles to be at the edge of a mountain...
so when the array is like this:
code: |
0000000000
0000000000
0000000000
0000000000
0001110000
0001110000
0001110000
0000000000
0000000000
0000000000
|
plain grass tiles can be anywhre as the '1' but bushy grass tiles are only allwoed to appear surrounded by plain grass tiles.
so let's say 2 is a bushy grass tile but I won't use 2's in my real code this is just to see what might happen:
code: |
0000000000
0000000000
0000000000
0000000000
0002110000
0001220000
0002210000
0000000000
0000000000
0000000000
|
so now I would like to get rid of the 2's that are not completely surrounded by '1's ao I want to just keep the '2' that are in the middle:
code: |
0000000000
0000000000
0000000000
0000000000
0001110000
0001210000
0001110000
0000000000
0000000000
0000000000
|
|
|
|
|
|
|
Dan
|
Posted: Tue Feb 10, 2004 10:51 pm Post subject: (No subject) |
|
|
well the easy way whould be to do somting like
if array[i][ii] = 1 then
if array[i][ii+1] = 1 and array[i][ii-1] and array[i-1][ii] = 1 and array[i+1][ii] = 1 and array[i+1][ii+1] = 1 and array[i+1][ii-1] = 1 and array[i-1][ii+1] = 1 and array[i-1][ii-1] = 1 then
%randomly pic 1 or 2
else
%pic 1
end if
end if
but this will have isues when it is on the eages of the screen so u will have to facter that in as well. i think recursion could be used to do this better but this is esayer i think. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
TheXploder
|
Posted: Wed Feb 11, 2004 12:21 am Post subject: (No subject) |
|
|
Cool, it works Thanx Dan.
I wrote this:
code: |
for col : 1 .. 10
for decreasing row : 10 .. 1
if map (col, row) = 1 then
if TypeAtMountain = 0 then
objIsoBlock (x + row + col, y + row - col, TypeAtMountain)
end if
if map (col, row + 1) = 1 and map (col, row - 1) = 1 and map (col + 1, row) = 1 and map (col - 1, row) = 1 and map (col - 1, row - 1) = 1 and map (col + 1, row + 1) = 1 and map (col - 1,
row + 1) = 1 then
objIsoBlock (x + row + col, y + row - col, TypeAtMountain)
else
objIsoBlock (x + row + col, y + row - col, normalType)
end if
end if
if map (col, row) = 0 then
openObj (0 + newX (x + row + col), -4 + newY (y + row - col), 4)
end if
end for
end for
|
|
|
|
|
|
|
TheXploder
|
Posted: Thu Feb 12, 2004 1:53 pm Post subject: (No subject) |
|
|
here is a new code, now that I check that the plain grass is at least surrounded by '1's I also want to connect the bushy grass with the plain grass, the connection works between the grass to the right or to the left or to the top or bottom. But when its to the left and up or to the right and up or down left, or down right the connection doesn't work...
this is my code so fahr
code: |
for col : 1 .. 10
for decreasing row : 10 .. 1
if map (col, row) = 1 then
if TypeAtMountain = 0 then
objIsoBlock (x + row + col, y + row - col, TypeAtMountain)
end if
if map (col, row + 1) = 1 and map (col, row - 1) = 1 and map (col + 1, row) = 1 and map (col - 1, row) = 1 and map (col - 1, row - 1) = 1 and map (col + 1, row + 1) = 1 and map (col - 1,
row + 1) = 1 and map (col + 1, row - 1) = 1 then
objIsoBlock (x + row + col, y + row - col, TypeAtMountain)
elsif map (col, row + 1) = 0 then
objIsoBlock (x + row + col, y + row - col, UpRightMountain)
elsif map (col, row - 1) = 0 then
objIsoBlock (x + row + col, y + row - col, DownRightMountain)
elsif map (col - 1, row) = 0 then
objIsoBlock (x + row + col, y + row - col, UpLeftMountain)
elsif map (col + 1, row) = 0 then
objIsoBlock (x + row + col, y + row - col, DownLeftMountain)
elsif map (col + 1, row + 1) = 0 then
objIsoBlock (x + row + col, y + row - col, 10)
else
objIsoBlock (x + row + col, y + row - col, normalType)
end if
end if
if map (col, row) = 0 then
openObj (0 + newX (x + row + col), -4 + newY (y + row - col), 4)
end if
end for
end for
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
TheXploder
|
Posted: Thu Feb 12, 2004 5:06 pm Post subject: (No subject) |
|
|
see what the problem is?
I'll make an example using some numbers but in reality it'll need to have only '0' as 0 level in height (plain) and '1' as level 1 in height (mountain):
1 = bushy grass mountain.
2 = connection between plain and byshy grass, mountain, to the left..
3 = connection between plain and byshy grass, mountain, to the right..
4 = connection between plain and byshy grass, mountain, to the top..
5 = connection between plain and byshy grass, mountain, to the bottom..
6 = Doesn't work.
7 = Doesn't work.
8 = Doesn't work.
9 = Doesn't work.
code: |
0000000000
0000000000
0000000000
0064447000
0021113000
0021113000
0095558000
0000000000
0000000000
0000000000
|
|
|
|
|
|
|
|
|