JohnJensen on DeviantArthttps://www.deviantart.com/johnjensen/art/Fruit-Circle-Physics-285849160JohnJensen

Deviation Actions

JohnJensen's avatar

Fruit Circle Physics!

By
Published:
17.4K Views

Description

Before anyone says anything - yeah, I know some of them aren't fruits. :|

ALRIGHT:

So I found this spritesheet by ~Ails and I thought I was gonna make some sort of RPG game outta it, but then I found mysef playing around with ball physics and these fruits. :lol: And so I just added more features, and boom...the result became this.

Features:
* click to add a fruit/ball
* make fruits fly around!
* watch the epic motion blur/movement fading effect as the fruits fly around
* toggle different rendering modes, such as rotated sprites (BitmapData.draw + Matrix), still sprites (BitmapData.copyPixels) and the movement fading (BitmapData.merge with multiplier 86 on a white 0xFFFFFFFF 640x430 bitmapData) and you can also show the collision circles
* change appearance of fruits (make all the same, randomize)
* and something I've never done before...save a screenshot directly from the Flash onto your computer! I've seen it be done before, so I researched it, and found out you could use the FileReference class to prompt a user to save a file to the user's computer, and then encode a PNG using PNGEncoder.

Algorithm optimization?
The algorithm is not optimized in any way, I simply looped through each circle twice, so if we have 100 circles, it's gonna do 10,000 checks (O(n^2)). I chose not to investigate ways to speed up the engine, as this is simply a toy and not some kind of big project that'll be needing great performance. But: I tried splitting up the stage into 10x10 small boxes, and for every box it'd only check collision inside those boxes, but I found the system to be acting weird when leaving a box, so inbetween each box there was a gap where the circles would fall, but it might be fixed if I would check for neighboring boxes.. but oh well, let's leave it as is, poor O(n^2) ;)

Also, if your computer starts to lag, simply just click 'Remove all', that should hopefully fix everything.

Enjoy!


EDIT #1 (19 feb 2012)
* Added so that when you aim, a blue line with a ball at the point the circle touches the ground (like in Skyward Sword =0) will show you the path the fruit will fly until it hits the ground if not hit by any other fruits. (Making a path which includes what'll happen when the fruit flys around and touches other fruits will kill your computer... :paranoid: unless...I split up everything into small boxes, and-- well..no I'm not going to look into that :shakefist:)
* Fixed a bug where if you turned fruits off, then fruits on again the collision circles will still be shown.
Image size
640x480px 39.1 KB
© 2012 - 2024 JohnJensen
Comments55
Join the community to add your comment. Already a deviant? Log In
JavaThePsychopath's avatar
Lol, spam add 10 and then click fire all xD