Computer Science Canada 2D Arrays: Connecting Grass Tiles |
Author: | TheXploder [ Tue Feb 10, 2004 10:04 pm ] | ||||
Post subject: | 2D Arrays: Connecting Grass Tiles | ||||
I created an array with the size of 10x10
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:
but It doesn't seem to work right... |
Author: | Andy [ Tue Feb 10, 2004 10:16 pm ] |
Post 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 |
Author: | TheXploder [ Tue Feb 10, 2004 10:20 pm ] |
Post 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 |
Author: | Andy [ Tue Feb 10, 2004 10:24 pm ] |
Post subject: | |
o well, just reandomize those then... and for the other ones, just make it ur plain grass... |
Author: | TheXploder [ Tue Feb 10, 2004 10:39 pm ] | ||||||
Post 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:
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:
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:
|
Author: | Dan [ Tue Feb 10, 2004 10:51 pm ] |
Post 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. |
Author: | TheXploder [ Wed Feb 11, 2004 12:21 am ] | ||
Post subject: | |||
Cool, it works Thanx Dan. I wrote this:
|
Author: | TheXploder [ Thu Feb 12, 2004 1:53 pm ] | ||
Post 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
|
Author: | TheXploder [ Thu Feb 12, 2004 5:06 pm ] | ||
Post 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.
|