forked from: forked from: forked from: forked from: forked from: forked from: ボール
forked from forked from: forked from: forked from: forked from: forked from: ボール (diff: 9)
ActionScript3 source code
/**
* Copyright 084 ( http://wonderfl.net/user/084 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/yzDr
*/
// forked from 084's forked from: forked from: forked from: forked from: forked from: ボール
// forked from 084's forked from: forked from: forked from: forked from: ボール
// forked from 084's forked from: forked from: forked from: ボール
// forked from 084's forked from: forked from: ボール
// forked from 084's forked from: ボール
// forked from 084's ボール
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
public class Test extends Sprite
{
private var ball:Ball;
private var vx:Number;
private var vy:Number;
public function Test():void
{
vx = 0;
vy = 0;
ball = new Ball(100);
ball.x = stage.stageWidth / 2;
ball.y = stage.stageHeight / 2;
addChild(ball);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(KeyboardEvent.KEY_DOWN , onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP , onKeyUp );
}
private function onEnterFrame(e:Event):void
{
ball.x += vx;
ball.y += vy;
var hanbunW:uint = ball.width/2;
var hanbunH:uint = ball.height/2;
if(ball.x - hanbunW > stage.stageWidth)
{
ball.x = 0 - hanbunW;
}
else if(ball.x + hanbunW < 0)
{
ball.x = stage.stageWidth + hanbunW;
}
if(ball.y + hanbunH < 0)
{
ball.y = stage.stageHeight + hanbunH;
}
else if(ball.y - hanbunH > stage.stageHeight)
{
ball.y = 0 - hanbunH;
}
}
private function onKeyDown(e:KeyboardEvent):void
{
if (e.keyCode == Keyboard.LEFT)
{
vx = -10;
}
else if (e.keyCode == Keyboard.RIGHT)
{
vx = 10;
}
if (e.keyCode == Keyboard.UP)
{
vy = -10;
}
else if (e.keyCode == Keyboard.DOWN)
{
vy = 10;
}
}
private function onKeyUp(e:KeyboardEvent):void
{
if (e.keyCode == Keyboard.RIGHT || e.keyCode == Keyboard.LEFT)
{
vx = 0;
}
else if (e.keyCode == Keyboard.UP || e.keyCode == Keyboard.DOWN)
{
vy = 0;
}
}
}
}
import flash.display.Sprite;
class Ball extends Sprite
{
private var hankei:Number;
private var iro:uint;
public function Ball(hanikei:Number = 10, iro:uint = 0x666666)
{
this.hankei = hanikei;
this.iro = iro;
init();
}
private function init():void
{
graphics.beginFill(iro);
graphics.drawCircle(0, 0, hankei);
graphics.endFill();
}
}
