How do I pick furthest cell with specific data in the array

Get help using Construct 2

Post » Sat May 07, 2016 7:12 pm


Working on level generator and I am looking for a way to pick furthest as well as nearest specific data in array from a selected point. Any clue how to get this done? thanks
My professional Royalty Free Music at Scirra Assets Store
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
Posts: 1,987
Reputation: 20,203

Post » Sat May 07, 2016 7:27 pm

You could do it with a second array we'll call "list" and has a size of (0,3,1).

So you'd first loop over your array and check if any spot is equal to that certain value. If it is then make the list one longer and store the distance, and the current x and y in the array.

After that use the sort action on list and the first value will be the closest and the last will be the furthest.

Every tick
--- set list size to (0,3,1)

Array: for each xy
Array: current value=certainValue
--- list push 0 front
--- set list at (0,0) to distance(X,y, array.curx, array.cury)
--- set list at (0,1) to array.curx
--- set list at (0,2) to array.cury

Every tick
--- list: sort

Then the closest X and y would be:,1),2)

And the furthest:,1),2)
Posts: 5,493
Reputation: 81,674

Return to How do I....?

Who is online

Users browsing this forum: zenox98 and 25 guests