ぶもも
玉が動く
ぶもも
♥0 |
Line 66 |
Modified 2011-06-27 19:35:51 |
MIT License
archived:2017-03-20 09:25:36
ActionScript3 source code
/**
* Copyright Kihara ( http://wonderfl.net/user/Kihara )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/zuMd
*/
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
[SWF(backgroundColor = "0x000000", width = 465, height = 465)]
public class ex5_2 extends Sprite
{
private var ball:Array=[];
private var n:int=100;
public function ex5_2()
{
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
for(var i:int=0;i<n;i++){
ball.push(new Ball(Math.random()*30+15,Math.random()*30+15,Math.random()*0xFFFFFF));
ball[i].x = stage.stageWidth/2;
ball[i].y = stage.stageHeight/2;
addChild(ball[i]);
}
addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
private function onEnterFrame(e:Event):void{
for(var i:int=0;i<n;i++){
ball[i].move();
}
}
}
}
import flash.display.Sprite;
class Ball extends Sprite{
private var vx:Number;
private var vy:Number;
private var r:Number=Math.random()*10+5;
private var g:Number=0.98;
private var e:Number=0.9;
public function Ball(_vx:Number,_vy:Number,color:Number){
vx=Math.cos(Math.random()*Math.PI*2/3+Math.PI/6)*_vx;
vy=-Math.sin(Math.random()*Math.PI*2/3+Math.PI/6)*_vy;
graphics.beginFill(color);
graphics.drawCircle(0,0,r);
graphics.endFill();
}
public function move():void{
this.x+=vx;
this.y+=vy;
if(this.x-r < 0){
vx*=-e;
this.x = r;
}
if(this.x+r > this.stage.stageWidth){
vx*=-e;
this.x = this.stage.stageWidth-r;
}
if(this.y-r < 0){
vy*=-e;
this.y=r;
}
if(this.y+r > this.stage.stageHeight){
vy*=-e;
this.y=this.stage.stageHeight-r;
}
vy+=g;
}
}