flash on 2012-3-13
操作方法、工夫した点、解説したい内容、こだわったところや参考文献のURL等を書いてください
書かない場合、クラス宣言までのコメント文から自動抽出します
♥0 |
Line 118 |
Modified 2012-03-13 06:07:40 |
MIT License
archived:2017-03-20 19:50:16
ActionScript3 source code
/**
* Copyright medadotter ( http://wonderfl.net/user/medadotter )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/cCe2
*/
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.filters.BlurFilter;
/**
* これだけでも弾幕っぽいNE!
* @author DT
*/
[SWF(backgroundColor="0")]
public class STGMain extends Sprite {
private var bullets:Vector.<Bullet> = new Vector.<Bullet>();
private var numBullets:uint = 50;
private var beginX:Number = stage.stageWidth / 2;
private var beginY:Number = stage.stageHeight / 2;
private var frames:int = 0;
private var angle:Number = 0;
static private const speed:Number = 3;
public function STGMain() {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void {
angle += 0.1;
if (frames == 0) {
var bullet:Bullet = makeBullet();
addChild(bullet);
bullets.push(bullet);
}
for (var i:int = bullets.length - 1; i >= 0 ; i--) {
bullets[i].update();
if (!bullets[i].onArea()) removeBullet(i);
}
++frames;
frames %= 4;
}
private function removeBullet(i:int):void {
removeChild(bullets[i]);
bullets.splice(i, 1);
}
private function refreshBullet(bullet:Bullet):Bullet {
var color:uint = Math.random() * 0xffffff;
var radius:Number = Math.random() * 15 + 5;
bullet.color = color;
bullet.radius = radius;
bullet.x = beginX;
bullet.y = beginY;
bullet.velocity.x = speed * Math.cos(angle);
bullet.velocity.y = speed * Math.sin(angle);
return bullet;
}
private function makeBullet():Bullet {
return refreshBullet(new Bullet());
}
}
}
import flash.display.Sprite;
import flash.geom.Point;
class Bullet extends Sprite {
private var _position:Point = new Point();
private var _velocity:Point = new Point();
private var _radius:Number;
private var _color:uint;
public function Bullet(radius:Number = 40, color:uint = 0xff0000,x:Number = 0,y:Number=0) {
this.radius = radius;
this.color = color;
this.x = x;
this.y = y;
draw();
}
public function update():void {
x += velocity.x;
y += velocity.y;
}
public function onArea():Boolean {
if (x + radius >= 0 && x - radius <= stage.stageWidth &&
y + radius >= 0 && y - radius <= stage.stageHeight) return true;
return false;
}
private function draw():void {
graphics.clear();
graphics.beginFill(color);
graphics.drawCircle(0, 0, radius);
graphics.endFill();
}
override public function set x(value:Number):void {
position.x = value;
super.x = position.x;
}
override public function set y(value:Number):void {
position.y = value;
super.y = position.y;
}
public function get position():Point {
return _position;
}
public function set position(value:Point):void {
_position = value;
}
public function get velocity():Point {
return _velocity;
}
public function set velocity(value:Point):void {
_velocity = value;
}
public function get radius():Number {
return _radius;
}
public function set radius(value:Number):void {
_radius = value;
draw();
}
public function get color():uint {
return _color;
}
public function set color(value:uint):void {
_color = value;
draw();
}
}