Sell this.

Really I'm serious this could be a very innovative game on the Indie scene. I personally like it better than Towers of Goo(or whatever its called ), plus free advertising for construct

24 posts
• Page **2** of **3** • 1, **2**, 3

Thanks for all the positive feedback!

I will indeed sell this, if it turns out well enough (and I'll definitely send a percentage back to Construct). That's an awfully long way off, though.

So far, I'm spending a lot of time on the maths (eg, figuring out the mean or median of the swarm to cause clumping). If anyone has any tips on that stuff, I'm all ears - I get the feeling there might be a more elegant way of working. For example, to get the mean X of the swarm, I do a For Each loop on each object, adding each X value to a variable. I increment another variable that so I know when the loop has added up all the objects; using that, I trigger an event that divides the variable containing the X coords by the number of objects. So far, I haven't worked out how to measure dispersion or find the standard deviation.

Fortunately, I'm living with two engineers at the moment, and they're helping with the physics. I'll post anything we come up with that seems useful. I've almost finished a method of having attraction between physics objects proportional to their distance from each other (which is good for a gravity-like effect). It isn't at all difficult, especially compared to some of the stuff I've seen posted, but maybe it'll do some good for non-maths guys like me.

I will indeed sell this, if it turns out well enough (and I'll definitely send a percentage back to Construct). That's an awfully long way off, though.

So far, I'm spending a lot of time on the maths (eg, figuring out the mean or median of the swarm to cause clumping). If anyone has any tips on that stuff, I'm all ears - I get the feeling there might be a more elegant way of working. For example, to get the mean X of the swarm, I do a For Each loop on each object, adding each X value to a variable. I increment another variable that so I know when the loop has added up all the objects; using that, I trigger an event that divides the variable containing the X coords by the number of objects. So far, I haven't worked out how to measure dispersion or find the standard deviation.

Fortunately, I'm living with two engineers at the moment, and they're helping with the physics. I'll post anything we come up with that seems useful. I've almost finished a method of having attraction between physics objects proportional to their distance from each other (which is good for a gravity-like effect). It isn't at all difficult, especially compared to some of the stuff I've seen posted, but maybe it'll do some good for non-maths guys like me.

**Posts:**113**Reputation:**2,101

B

5
S

2
G

4
It sounds like you're on the right track for calculating the mean X - but you can possibly simplify it simply by dividing by the count when the for-each has finished, like:

+ Always

-> Set x_sum to 0

-> Set y_sum to 0

+ For each swarm_object

-> Add swarm_object.x to x_sum

-> Add swarm_object.y to y_sum

+ Always

-> Set mean_x to x_sum / swarm_object.count

-> Set mean_y to y_sum / swarm_object.count

Remembering events and actions are read in top to bottom order, this leaves you with the mean x and y in mean_x and mean_y.

+ Always

-> Set x_sum to 0

-> Set y_sum to 0

+ For each swarm_object

-> Add swarm_object.x to x_sum

-> Add swarm_object.y to y_sum

+ Always

-> Set mean_x to x_sum / swarm_object.count

-> Set mean_y to y_sum / swarm_object.count

Remembering events and actions are read in top to bottom order, this leaves you with the mean x and y in mean_x and mean_y.

**Posts:**22,952**Reputation:**178,600

Scirra Founder

B

359
S

214
G

72
This is a very sweet game. I'm very tempted to make a couple more levels just so I can play it some more.

As far as calculating standard deviation:

+ variance = 0

+ for each:

- variance_x = variance_x + (mean_x - current_object.x)^2

+ std_dev_x = sqrt(variance_x)

That will give you a*true* standard deviation. But it also requires going through the loop a second time. I think it would be faster to just calculate an approximate standard deviation:

+ Always

-> Set x_sum to 0

-> Set y_sum to 0

-> old_mean_x = mean_x

+ For each swarm_object

-> Add swarm_object.x to x_sum

-> Add swarm_object.y to y_sum

-> variance_x = variance_x + (old_mean_x - current_object.x)^2

+ Always

-> Set mean_x to x_sum / swarm_object.count

-> Set mean_y to y_sum / swarm_object.count

-> std_dev_x = sqrt(variance_x)

(Sorry for mixing syntaxes but I just had time for a quick post.)

If you want a better approximation for the standard deviation maybe adjust old_mean_x by taking into consideration which direction the swarm is traveling and shifting old_mean_x in that direction. (or maybe just shifting it towards the current mouse position) but I think the approximation I showed would be good enough.

As far as calculating standard deviation:

+ variance = 0

+ for each:

- variance_x = variance_x + (mean_x - current_object.x)^2

+ std_dev_x = sqrt(variance_x)

That will give you a

+ Always

-> Set x_sum to 0

-> Set y_sum to 0

-> old_mean_x = mean_x

+ For each swarm_object

-> Add swarm_object.x to x_sum

-> Add swarm_object.y to y_sum

-> variance_x = variance_x + (old_mean_x - current_object.x)^2

+ Always

-> Set mean_x to x_sum / swarm_object.count

-> Set mean_y to y_sum / swarm_object.count

-> std_dev_x = sqrt(variance_x)

(Sorry for mixing syntaxes but I just had time for a quick post.)

If you want a better approximation for the standard deviation maybe adjust old_mean_x by taking into consideration which direction the swarm is traveling and shifting old_mean_x in that direction. (or maybe just shifting it towards the current mouse position) but I think the approximation I showed would be good enough.

**Posts:**271**Reputation:**2,017

B

3
S

2
G

4
**Posts:**271**Reputation:**2,017

B

3
S

2
G

4
Events are highly optimised. Events which operate on just a handful of instances often run in negligable time (with a few exceptions, like RTS movement's 'move to' actions, which run a fairly CPU-intensive pathfinding search). To get events to be the cause of your application's slowdown, generally you'd have to make something which repeats tens of thousands of times per tick. That could be a for-each, or an action applying to a *lot* of instances, etc. Also read up on how the CPU and GPU work in parallel in Optimisation Tips.

**Posts:**22,952**Reputation:**178,600

Scirra Founder

B

359
S

214
G

72
24 posts
• Page **2** of **3** • 1, **2**, 3

Return to Your tutorials & example files

## Who is online |

Users browsing this forum: No registered users and 0 guests |