flash on 2013-4-24
♥0 |
Line 42 |
Modified 2013-04-24 07:03:16 |
MIT License
archived:2017-03-20 15:31:18
ActionScript3 source code
/**
* Copyright cjcat2266 ( http://wonderfl.net/user/cjcat2266 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/qaP9
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
public class Main extends Sprite
{
// problem inputs
private static const PLANET_RADIUS :Number = 100.0;
private static const MAX_MISSILE_HEIGHT:Number = 50.0;
// simulation phase
private static const PHASE_AIM :uint = 0;
private static const PHASE_SHOOT:uint = 1;
private var phase_:uint = PHASE_AIM;
// object positions
private var planet_:Point;
private var turret_:Point;
private var target_:Point;
// simulation variables
private var turretAngle_:Number;
private var time_ :Number;
public function Main()
{
stage.addEventListener(Event.ENTER_FRAME, render);
stage.addEventListener(MouseEvent.CLICK, onClick);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function render(e:Event):void
{
// get planet position
planet_ = new Point(0.5 * stage.stageWidth, 0.5 * stage.stageHeight);
// draw planet at the center of the stage
graphics.lineStyle(0, 0x000000);
graphics.drawCircle(planet_.x, planet_.y, PLANET_RADIUS);
}
private function onClick(e:MouseEvent):void
{
// early out
if (phase_ != PHASE_AIM)
return;
time_ = 0.0;
phase_ = PHASE_SHOOT;
}
private function onMouseMove(e:MouseEvent):void
{
// calculate closest point on the planet
}
}
}