I'm overriding Timedelta, and it... seems good.

Post your own tutorials, guides and demos.

Post » Thu Jan 01, 2009 3:11 am

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 :lol:
B
21
S
14
G
5
Posts: 106
Reputation: 3,416

Post » Thu Jan 01, 2009 11:39 am

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. :)
B
5
S
2
G
4
Posts: 113
Reputation: 2,101

Post » Thu Jan 01, 2009 3:51 pm

sweet idea! looking forward for the finished game :)
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Thu Jan 01, 2009 6:19 pm

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Thu Jan 01, 2009 9:28 pm

That's a much better method. Thanks Ashley!
B
5
S
2
G
4
Posts: 113
Reputation: 2,101

Post » Sat Jan 03, 2009 2:38 am

Interesting game looks like it could be a lot of fun...
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Tue Jan 06, 2009 2:54 pm

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

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.
B
3
S
2
G
4
Posts: 271
Reputation: 2,017

Post » Tue Jan 06, 2009 3:05 pm

If you have less than 1000 objects, I think the performance impact of looping twice would be negligable.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Tue Jan 06, 2009 7:35 pm

Good to know, thanks. (I always wonder how people know that stuff.)
B
3
S
2
G
4
Posts: 271
Reputation: 2,017

Post » Wed Jan 07, 2009 1:38 am

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

PreviousNext

Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests