Partner, Software Development/General Manager at Persuasive Games. In his role, Mr. Quarto is responsible for software development and testing, as well as studio management and strategy. Then, if you want to see how the ball move and bounce, you can use your keyboard and move it with the arrows keys.
Main idea behind this example is to introduce some physic criteria and forces. Every thing you do to move the ball is basically to apply a force to the ball. There are also external things like gravity, or friction.
Play a bit with the ball, if you like it, let's start with ActionScript.
restitution = 0.7; resistence = 0.997; acceleration_x = 0; acceleration_y = 0; gravity = 0.2; particleCount = 0; this.onEnterFrame = function() { generateParticles(); this.swapDepths(_parent.getNextHighestDepth()) acceleration_y += gravity; acceleration_y *= resistence; acceleration_x *= resistence; checkColision(); _x += acceleration_x; _y += acceleration_y; }; function accelerate(x, y) { acceleration_x += x; acceleration_y += y; } function checkColision() { if (_x+acceleration_x+(_width/2)>=_parent.rightLimit) { if (_x+(_width/2)<_parent.rightLimit) { _x = _parent.rightLimit-(_width/2)-0.1; } else { acceleration_x *= -1*restitution; } } if (_x+acceleration_x-(_width/2)<=_parent.leftLimit) { if (_x-(_width/2)>_parent.leftLimit) { _x = _parent.leftLimit+(_width/2)+0.1; } else { acceleration_x *= -1*restitution; } } if (_y+acceleration_y+(_width/2)>=_parent.bottomLimit) { if (_y+(_width/2)<_parent.bottomLimit) { _y = _parent.bottomLimit-(_width/2)-0.1; } else { acceleration_y *= -1*restitution; } } if (_y+acceleration_y-(_width/2)<=_parent.topLimit) { if (_y-(_width/2)>_parent.topLimit) { _y = _parent.topLimit+(_width/2)+0.1; } else { acceleration_y *= -1*restitution; } } } function generateParticles() { _parent.attachMovie("circleParticle","particle"+particleCount,_parent.getNextHighestDepth(),{_x:_x, _y:_y}); particleCount++; }
function init() { leftLimit = 0; rightLimit = Stage.width; bottomLimit = Stage.height; topLimit = 0; } function createBall() { this.attachMovie("circle","myCircle",_root.getNextHighestDepth(),{_x:(rightLimit-leftLimit)/2, _y:(bottomLimit-topLimit)/2}); } init(); createBall(); this.onEnterFrame = function() { //Wind angle = Math.atan2(_ymouse-myCircle._y, _xmouse-myCircle._x); distance = Math.sqrt(Math.pow(_xmouse-myCircle._x, 2)+Math.pow(_ymouse-myCircle._y, 2))/10; myCircle.accelerate(-Math.cos(angle)/distance,-Math.sin(angle)/distance); //Keyboard detection if (Key.isDown(Key.RIGHT)) { myCircle.accelerate(0.4,0); } if (Key.isDown(Key.LEFT)) { myCircle.accelerate(-0.4,0); } if (Key.isDown(Key.UP)) { myCircle.accelerate(0,-0.4); } if (Key.isDown(Key.DOWN)) { myCircle.accelerate(0,0.4); } };
this.onEnterFrame = function() { distance=Math.sqrt((Math.pow(_alpha-0,2))+(Math.pow(_alpha-0,2)))/5; _alpha-=distance _xscale-=distance/4 _yscale-=distance/4 if(_alpha<1){ this.removeMovieClip() } }