Array Scaling- How do you do it?

For questions about using Classic.

Post » Sun Sep 18, 2011 12:03 pm

Hi there,

I'm currently working on an asteroid exploration game, and I'm using cellular automata with arrays to create procedural cave systems.

I'm having difficulty though scaling an array. What I would like to do is a low resolution pass with my algorithm, then copy that data to a larger array in which the algorithm would then be applied to smooth things out a little, but my solution doesn't seem to be working.

So, basically, I want to take this data in one array

XOO
OOO
OOX
and turn it in to this data in another array

XXXXOOOOOOO
XXXXOOOOOOO
XXXXOOOOOOO
XXXXOOOOOOO
OOOOOOOOOOO
OOOOOOOOOOO
OOOOOOOOOOO
OOOOOOOOOOO
OOOOOOOXXXX
OOOOOOOXXXX
OOOOOOOXXXX
OOOOOOOXXXX


You can find the .cap file here


Is this another time when Construct can't decide whether 0 or 1 is the first number?

B
2
G
2
Posts: 15
Reputation: 680

Post » Sun Sep 18, 2011 2:02 pm

You could calculate the ratio of X to O's in a single line, then expand accordingly. Then do this for every line.

eg: 4:1 then divide the new line size by 5. 4* that are X, 1* that are O.
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Sun Sep 18, 2011 2:25 pm

I suppose I could do it that way...I was just wondering why a simpler way I had created which looped over the smaller array and for each of its cells, populating 16 cells in the larger array with the value in the small array cell wasn't working.




Was hoping for less lines of code, and hopefully less values needing to be stored.
B
2
G
2
Posts: 15
Reputation: 680

Post » Sun Sep 18, 2011 6:28 pm

Right, I've changed it all to for loops, and its still not iterating over the array properly... I have changed the preview image and the .cap file.
B
2
G
2
Posts: 15
Reputation: 680

Post » Sun Sep 18, 2011 6:36 pm

That's alot of nested for loops you use there. I'm not sure but I think they'd work better as actual sub-events for each loop rather than all being in the same one.

Edit: Also, that Repeat 2 times event is triggered every tick. This means in 2 ticks it will perform those actions 4 times. Maybe add a trigger once to the top of the conditions for that, or have it as a function called once (and then on called > repeat 2 times).Jayjay2011-09-18 18:37:49
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Sun Sep 18, 2011 8:49 pm

Augh, I am such a fool!

Sorry guys, just worked out the problem. The tileset was performing the if action on the wrong array, and the scaling was very easy to fix, it needed to be Array1.Value(loop1x*4 - loop2x, loop1y*4- loop2y).

NthSimulacrum2011-09-18 21:12:35
B
2
G
2
Posts: 15
Reputation: 680

Post » Sun Sep 18, 2011 9:55 pm

Here's another way to scale the array by setting the large array by sampling from the small array.

+ System: Trigger once
+ LargeArray: For Each element
-> LargeArray: Set index (LargeArray.CurrentX, LargeArray.CurrentY) to AsteroidArray (int((LargeArray.CurrentX-1)/4)+1, int((LargeArray.CurrentY-1)/4)+1)
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests