マウスのある方向に板が傾くイメージの運動
マウスのある方向に板が傾くイメージの運動
♥0 |
Line 51 |
Modified 2010-02-18 23:10:59 |
MIT License
archived:2017-03-20 16:27:55
ActionScript3 source code
/**
* Copyright cpu_t ( http://wonderfl.net/user/cpu_t )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/xSdh
*/
// マウスのある方向に板が傾くイメージの運動
//
package {
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
public class FlashTest extends Sprite {
private var ball:Shape;
public function FlashTest() {
ball = new Shape();
ball.graphics.beginFill(0xFFC040);
ball.graphics.drawCircle(0, 0, 30);
ball.x = stage.stageWidth * .5;
ball.y = stage.stageHeight * .5;
addChild(ball);
addEventListener(Event.ENTER_FRAME, enterframeHandler);
}
private const slope:Number = 0.002;
private var vx:Number = 0;
private var vy:Number = 0;
private function enterframeHandler(e:Event):void
{
ball.x += vx;
ball.y += vy;
if (ball.x < 0)
{
ball.x *= -1;
vx *= -1;
}
else if (ball.x > stage.stageWidth)
{
ball.x = (ball.x - stage.stageWidth * 2) * -1;
vx *= -1;
}
if (ball.y < 0)
{
ball.y *= -1;
vy *= -1;
}
else if (ball.y > stage.stageHeight)
{
ball.y = (ball.y - stage.stageHeight * 2) * -1;
vy *= -1;
}
vx *= .98;
vy *= .98;
var ax:Number = (mouseX - stage.stageWidth * .5) * slope;
var ay:Number = (mouseY - stage.stageHeight * .5) * slope;
vx += ax;
vy += ay;
}
}
}