Asteroid.hx
There isn’t as many interesting code to point out by now since we’ve covered most of them in the previous two posts. However, let’s take a look at something:
1 2 3 4 5 6 7 8 9 |
public function new() { super(); // Bouncy! elasticity = 1; // Smooth rotations antialiasing = true; } |
Note that FlxObject has variables such as elasticity that helps with the in-built physics. Do check the API for more info on what other variables or functions that you can use. 😀
1 2 3 4 5 6 7 8 9 10 11 |
override public function update():Void { if (justTouched(FlxObject.ANY)) { angularVelocity = (Math.abs(velocity.x) + Math.abs(velocity.y)); } FlxSpriteUtil.screenWrap(this); super.update(); } |
Also note that while the asteroids bounce off each other quite convincingly, their rotation is not part of the physics. As such, there’s the piece of code above that handles the rotation whenever an asteroid collides with something.
This wraps up the FlxTeroids demo project study tutorial. I apologise if the contents of this series are not satisfactory — In upcoming tutorials I’ll cover parts of HaxeFlixel that isn’t already available elsewhere.