グラディウスV / Gradius V!!!
A or D: rotate lasers
Up/Down/Right/Left: move
T: change follow mode
M: mouse mode (warning, lag!)
+/-: change rotate speed
SPACE: HSV color laser
/**
* Copyright zob ( http://wonderfl.net/user/zob )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/zMMT
*/
package
{
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.display.Sprite;
import flash.net.*;
import flash.filters.*;
import flash.geom.*;
import flash.ui.*;
import flash.system.*;
import flash.utils.*;
import net.hires.debug.Stats;
import frocessing.color.ColorHSV;
[SWF(width=465,height=465,backgroundColor=0x000000,frameRate=60)]
public class gradiusVmini extends Sprite
{
private var tbmpd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
private var bmpd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
private var bmp:Bitmap = new Bitmap(bmpd);
private var ebmpd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
private var panel:Sprite = new Sprite();
private var gShip:GShip = new GShip(panel, bmpd, stage.stageWidth/2, stage.stageHeight/2);
private var hips:Vector.<Dot> = new Vector.<Dot>();
private var maxhips:int = 1000;
private var counter2:int = 0;
private var gtime:int = 1;
private var gsum:int = 3;
private var cT:ColorTransform = new ColorTransform(1,1,1,0.9);
private var blurEffect:BlurFilter = new BlurFilter(2,2,2);
private var glowEffect:GlowFilter = new GlowFilter(0xFF0000AA, 3, 10, 10, 1, 3);
//private var tracer:TRC = new TRC();
private var shipBmpd:BitmapData;
private var enemyBmpd:BitmapData;
private var ballBmpd:BitmapData;
private var vcolor:ColorHSV = new ColorHSV(0);
private var varyColor:Boolean = false;
public function gradiusVmini()
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, init);
loader.load(new URLRequest("http://assets.wonderfl.net/images/related_images/a/ab/ab4a/ab4afc6ce6b79cbc40cbf6cf019a604c031f437a"), new LoaderContext(true));
}
private function init(e:Event):void
{
addChild(new Bitmap(new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x000022)));
var bitmapData:BitmapData = Bitmap(e.target.content).bitmapData;
shipBmpd = new BitmapData(27, 15, true, 0x0);
shipBmpd.copyPixels(bitmapData, new Rectangle(0,0,27,15), new Point());
enemyBmpd = new BitmapData(16, 15, true, 0x0);
enemyBmpd.copyPixels(bitmapData, new Rectangle(27,0,27,15), new Point());
ballBmpd = new BitmapData(9, 15, true, 0x0);
ballBmpd.copyPixels(bitmapData, new Rectangle(44,0,9,15), new Point());
addChild(new Bitmap(ebmpd));
addChild(bmp);
addChild(panel);
addChild(new Stats());
panel.filters = [glowEffect]
stage.addEventListener(KeyboardEvent.KEY_DOWN, onkeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onkeyUp);
stage.addEventListener(Event.ENTER_FRAME, processing);
}
private function onkeyDown(e:KeyboardEvent):void
{
switch(e.keyCode)
{
case Keyboard.DOWN:
gShip.m_moveDown = true;
break;
case Keyboard.UP:
gShip.m_moveUp = true;
break;
case Keyboard.LEFT:
gShip.m_moveLeft = true;
break;
case Keyboard.RIGHT:
gShip.m_moveRight = true;
break;
case 65:
gShip.m_rotateLeft = true;
break;
case 68:
gShip.m_rotateRight = true;
break;
case 84:
gShip.toggleFollowMode();
break;
case 72:
gShip.toggleHold();
break;
case 77:
gShip.toggleMouseMode();
break;
case 109:
gShip.decreaseEnergyBallsRotateSpeed();
break;
case 107:
gShip.increaseEnergyBallsRotateSpeed();
break;
case Keyboard.SPACE:
varyColor = !varyColor;
if(!varyColor) {glowEffect.color = 0xFF0000AA; panel.filters = [glowEffect];}
break;
}
trace(e.keyCode);
}
private function onkeyUp(e:KeyboardEvent):void
{
switch(e.keyCode)
{
case Keyboard.DOWN:
gShip.m_moveDown = false;
break;
case Keyboard.UP:
gShip.m_moveUp = false;
break;
case Keyboard.LEFT:
gShip.m_moveLeft = false;
break;
case Keyboard.RIGHT:
gShip.m_moveRight = false;
break;
case 65:
gShip.m_rotateLeft = false;
break;
case 68:
gShip.m_rotateRight = false;
break;
}
}
private function processing(e:Event):void
{
var i:int = 0;
bmpd.lock();
panel.graphics.clear();
if(varyColor)
{
vcolor.h = getTimer()/360;
panel.graphics.lineStyle(0.1, vcolor.value);
glowEffect.color = vcolor.value;
panel.filters = [glowEffect];
} else
panel.graphics.lineStyle(0.1, 0xFF77CCFF);
gShip.updateMouse(mouseX, mouseY);
gShip.update();
gShip.paint();
// Enemies
//////////////////////////////////////////////////////////////////////////////////////////////////
if(counter2%gtime==0)
{
var gm:int = 0;
var rand:Number = 0;
while(gm<gsum && hips.length<maxhips)
{
rand = Math.random()*(2*Math.PI);
hips.push(new Dot(stage.stageWidth/2+250*Math.cos(rand),stage.stageHeight/2+250*Math.sin(rand)));
gm++;
}
counter2%=gtime;
}
counter2++;
ebmpd.fillRect(ebmpd.rect, 0x0);
var hlen:Number = 0;
var hvx:Number = 0;
var hvy:Number = 0;
for(i=0;i<hips.length;i++)
{
hvx = hips[i].x - gShip.m_pos.x;
hvy = hips[i].y - gShip.m_pos.y;
hlen = Math.sqrt(hvx*hvx+hvy*hvy);
if(hlen>10 && !touched(bmpd, hips[i]))
{
hips[i].x -= hvx/hlen;
hips[i].y -= hvy/hlen;
ebmpd.copyPixels(enemyBmpd, enemyBmpd.rect, new Point(hips[i].x - enemyBmpd.width/2, hips[i].y - enemyBmpd.height/2), null, null, true);
} else {
hips.splice(i,1);
i--;
}
}
for(i = 0; i < gShip.m_energyBalls.length; i++)
{
ebmpd.copyPixels(ballBmpd, ballBmpd.rect, new Point(gShip.m_energyBalls[i].m_pos.x - ballBmpd.width/2, gShip.m_energyBalls[i].m_pos.y - ballBmpd.height/2), null, null, true);
}
ebmpd.copyPixels(shipBmpd, shipBmpd.rect, new Point(gShip.m_pos.x - shipBmpd.width/2, gShip.m_pos.y - shipBmpd.height/2), null, null, true);
bmpd.colorTransform(bmpd.rect, cT);
bmpd.applyFilter(bmpd, bmpd.rect, new Point(), blurEffect);
bmpd.draw(panel);
bmpd.unlock();
}
private function touched(target:BitmapData, thisDot:Dot):Boolean
{
var tx:int = Math.round(thisDot.x);
var ty:int = Math.round(thisDot.y);
for(var i:int = -7; i<7; i++)
{
if(target.getPixel32(tx,ty+i)==0xFF77CCFF) return true;
if(target.getPixel32(tx+i,ty)==0xFF77CCFF) return true;
}
return false;
}
}
}
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.display.Sprite;
import flash.net.*;
import flash.filters.*;
import flash.geom.*;
import flash.ui.*;
class EnergyBall
{
private var m_bmpd:BitmapData;
private var m_panel:Sprite;
public var m_pos:Dot;
private var m_ship:GShip;
private var m_bpf:int = 1;
private var m_bltSpeed:int = 10;
private var m_blts:Vector.<Dot> = new Vector.<Dot>();
private var m_reducer:int = 1;
private var m_counter:int = 0;
private var P0:Point = new Point();
private var P1:Point = new Point();
private var P2:Point = new Point();
private var P3:Point = new Point();
private var PA:Point = new Point();
private var PB:Point = new Point();
private var dx:Number = 0;
private var dy:Number = 0;
private var Pc_1:Point = new Point();
private var Pc_2:Point = new Point();
private var Pc_3:Point = new Point();
private var Pc_4:Point = new Point();
private var Pa_1:Point = new Point();
private var Pa_2:Point = new Point();
private var Pa_3:Point = new Point();
public function EnergyBall(mPanel:Sprite, mBmpd:BitmapData, px:Number, py:Number, mShip:GShip)
{
m_ship = mShip;
m_panel = mPanel;
m_bmpd = mBmpd;
m_pos = new Dot(px, py);
}
public function update():void
{
if(m_counter%m_bpf==0)
{
var vx:Number = m_ship.m_drt.x;
var vy:Number = m_ship.m_drt.y;
var len:Number = Math.sqrt(vx*vx+vy*vy);
var currRad:Number = Math.atan2(vy, vx);
var lastRad:Number = Math.atan2(m_ship.m_lastdrt.y, m_ship.m_lastdrt.x);
var radDist:Number = (lastRad-currRad)/Math.PI*180;
if(radDist>180)
{
radDist-=360;
}
if(radDist<-180)
{
radDist+=360;
}
if(m_ship.m_mouseMode && (radDist>0||radDist<0))//mouse mode is dangerous
{
var sum:int = radDist;
var cSum:int;
while(radDist>0 && radDist >=m_reducer)
{
radDist-=m_reducer;
cSum = m_bltSpeed*(sum-radDist)/sum;
lastRad-=m_reducer*Math.PI/180;
m_blts.push(new Dot(m_pos.x-Math.cos(lastRad)*cSum, m_pos.y-Math.sin(lastRad)*cSum));
m_blts[m_blts.length-1].vx = Math.cos(lastRad);
m_blts[m_blts.length-1].vy = Math.sin(lastRad);
}
while(radDist<0 && radDist <=-m_reducer)
{
radDist+=m_reducer;
cSum = m_bltSpeed*(sum-radDist)/sum;
lastRad+=m_reducer*Math.PI/180;
m_blts.push(new Dot(m_pos.x-Math.cos(lastRad)*cSum, m_pos.y-Math.sin(lastRad)*cSum));
m_blts[m_blts.length-1].vx = Math.cos(lastRad);
m_blts[m_blts.length-1].vy = Math.sin(lastRad);
}
}
/**/
m_blts.push(new Dot(m_pos.x-(vx/len)*m_bltSpeed, m_pos.y-(vy/len)*m_bltSpeed));
var ci:int = m_blts.length-1;
m_blts[ci].vx = vx/len;
m_blts[ci].vy = vy/len;
m_counter = 0;
m_ship.m_lastdrt.val_p_(vx, vy);
}
m_counter++;
var i:int = 0;
for(; i<m_blts.length; i++)
{
if(m_blts[i].x <0-(m_reducer+1)*m_bltSpeed || m_blts[i].x >global.STAGE_WIDTH+(m_reducer+1)*m_bltSpeed || m_blts[i].y <0-(m_reducer+1)*m_bltSpeed || m_blts[i].y >global.STAGE_HEIGHT+(m_reducer+1)*m_bltSpeed)
{
m_blts.splice(i,1);
i--;
} else {
m_blts[i].x += m_blts[i].vx*m_bltSpeed;
m_blts[i].y += m_blts[i].vy*m_bltSpeed;
}
}
}
public function paint():void
{
var i:int = 0;
var xc1:Number = 0;
var yc1:Number = 0;
var xc2:Number = 0;
var yc2:Number = 0;
var xc3:Number = 0;
var yc3:Number = 0;
var len1:Number = 0;
var len2:Number = 0;
var len3:Number = 0;
var k1:Number = 0;
var k2:Number = 0;
var xm1:Number = 0;
var ym1:Number = 0;
var xm2:Number = 0;
var ym2:Number = 0;
var ctrl1_x:Number = 0;
var ctrl1_y:Number = 0;
var ctrl2_x:Number = 0;
var ctrl2_y:Number = 0;
var x1x0:Number = 0;
var y1y0:Number = 0;
var x2x1:Number = 0;
var y2y1:Number = 0;
var x3x2:Number = 0;
var y3y2:Number = 0;
var smooth_value:Number = 1;
for(i=1; i<m_blts.length-2; i++)
{
xc1 = (m_blts[i-1].x + m_blts[i].x) / 2.0;
yc1 = (m_blts[i-1].y + m_blts[i].y) / 2.0;
xc2 = (m_blts[i].x + m_blts[i+1].x) / 2.0;
yc2 = (m_blts[i].y + m_blts[i+1].y) / 2.0;
xc3 = (m_blts[i+1].x + m_blts[i+2].x) / 2.0;
yc3 = (m_blts[i+1].y + m_blts[i+2].y) / 2.0;
x1x0 = m_blts[i].x-m_blts[i-1].x;
y1y0 = m_blts[i].y-m_blts[i-1].y;
x2x1 = m_blts[i+1].x-m_blts[i].x;
y2y1 = m_blts[i+1].y-m_blts[i].y;
x3x2 = m_blts[i+2].x-m_blts[i+1].x;
y3y2 = m_blts[i+2].y-m_blts[i+1].y;
len1 = Math.sqrt((x1x0) * (x1x0) + (y1y0) * (y1y0));
len2 = Math.sqrt((x2x1) * (x2x1) + (y2y1) * (y2y1));
len3 = Math.sqrt((x3x2) * (x3x2) + (y3y2) * (y3y2));
k1 = len1 / (len1 + len2);
k2 = len2 / (len2 + len3);
xm1 = xc1 + (xc2 - xc1) * k1;
ym1 = yc1 + (yc2 - yc1) * k1;
xm2 = xc2 + (xc3 - xc2) * k2;
ym2 = yc2 + (yc3 - yc2) * k2;
ctrl1_x = xm1 + (xc2 - xm1) * smooth_value + m_blts[i].x - xm1;
ctrl1_y = ym1 + (yc2 - ym1) * smooth_value + m_blts[i].y - ym1;
ctrl2_x = xm2 + (xc2 - xm2) * smooth_value + m_blts[i+1].x - xm2;
ctrl2_y = ym2 + (yc2 - ym2) * smooth_value + m_blts[i+1].y - ym2;
GGraphic.cubic_bezier(m_bmpd, m_blts[i].x, m_blts[i].y, ctrl1_x,ctrl1_y, ctrl2_x,ctrl2_y, m_blts[i+1].x,m_blts[i+1].y, 0xFF77CCFF);
drawCubicBezier(m_blts[i].x, m_blts[i].y, ctrl1_x,ctrl1_y, ctrl2_x,ctrl2_y, m_blts[i+1].x,m_blts[i+1].y)
}
/**/
}
private function drawCubicBezier(p1x:Number, p1y:Number, c1x:Number, c1y:Number, c2x:Number, c2y:Number, p2x:Number, p2y:Number):void
{
P0.x = p1x;
P0.y = p1y;
P1.x = c1x;
P1.y = c1y;
P2.x = c2x;
P2.y = c2y;
P3.x = p2x;
P3.y = p2y;
getPointOnSegment(PA, P0, P1, 3/4);
getPointOnSegment(PB, P3, P2, 3/4);
dx = (P3.x - P0.x)/16;
dy = (P3.y - P0.y)/16;
getPointOnSegment(Pc_1, P0, P1, 3/8);
getPointOnSegment(Pc_2, PA, PB, 3/8);
Pc_2.x -= dx;
Pc_2.y -= dy;
getPointOnSegment(Pc_3, PB, PA, 3/8);
Pc_3.x += dx;
Pc_3.y += dy;
getPointOnSegment(Pc_4, P3, P2, 3/8);
getMiddle(Pa_1, Pc_1, Pc_2);
getMiddle(Pa_2, PA, PB);
getMiddle(Pa_3, Pc_3, Pc_4);
with(m_panel.graphics)
{
moveTo(P0.x, P0.y);
curveTo(Pc_1.x, Pc_1.y, Pa_1.x, Pa_1.y);
curveTo(Pc_2.x, Pc_2.y, Pa_2.x, Pa_2.y);
curveTo(Pc_3.x, Pc_3.y, Pa_3.x, Pa_3.y);
curveTo(Pc_4.x, Pc_4.y, P3.x, P3.y);
}
}
private function getMiddle(p:Point, p1:Point, p2:Point):void
{
p.x = (p1.x + p2.x)/2;
p.y = (p1.y + p2.y)/2;
}
private function getPointOnSegment(p:Point, p1:Point, p2:Point, tT:Number):void
{
p.x = p1.x + tT*(p2.x - p1.x);
p.y = p1.y + tT*(p2.y - p1.y);
}
}
class GShip
{
public var m_pos:Dot;
private var m_lastpos:Dot;
private var m_totalBalls:int = 4;
private var m_radian:Number = 0;
private var m_radius:Number = 20;
private var m_energyPathLength:int = 32;
private var m_energyPathAverage:int = m_energyPathLength/m_totalBalls;
private var m_energyPath:Vector.<EnergyPath> = new Vector.<EnergyPath>();
public var m_energyBalls:Vector.<EnergyBall> = new Vector.<EnergyBall>();
private var m_energyBall:EnergyBall;
private var m_bmpd:BitmapData;
private var m_panel:Sprite;
private var m_moveSpeed:int = 3;
public var m_moveUp:Boolean = false;
public var m_moveDown:Boolean = false;
public var m_moveLeft:Boolean = false;
public var m_moveRight:Boolean = false;
public var m_rotateLeft:Boolean = false;
public var m_rotateRight:Boolean = false;
public var m_drt:Dot;
public var m_lastdrt:Dot;
private var m_hold:Boolean = false;
private var m_totalModes:int = 3;
private var m_followMode:int = 0;
public var m_mouseMode:Boolean = false;
private var m_energyBallsRotateSpeed:int = 10;
private var m_energyBallsRotateSpeedLimit:int = 20;
public function GShip(mPanel:Sprite, mBmpd:BitmapData, px:Number, py:Number)
{
var i:int;
m_panel = mPanel;
m_bmpd = mBmpd;
m_pos = new Dot(px, py);
m_lastpos = new Dot(px, py);
m_drt = new Dot(100, 0);
m_lastdrt = new Dot(100, 0);
for(i = 0; i<m_energyPathLength; i++)
{
m_energyPath.push(new EnergyPath(px, py));
}
for(i = 0; i<m_totalBalls; i++)
{
m_energyBalls.push(new EnergyBall(mPanel, mBmpd, px, py, this));
}
}
public function updateMouse(px:Number, py:Number):void
{
if(m_mouseMode)
{
m_drt.x = px-m_pos.x;
m_drt.y = py-m_pos.y;
}
}
public function toggleHold():void
{
m_hold = !m_hold;
}
public function toggleFollowMode():void
{
m_followMode++;
if(m_followMode>=m_totalModes)
{
m_followMode = 0;
}
}
public function toggleMouseMode():void
{
m_mouseMode = !m_mouseMode;
}
public function decreaseEnergyBallsRotateSpeed():void
{
m_energyBallsRotateSpeed--;
if(m_energyBallsRotateSpeed<=0)
m_energyBallsRotateSpeed = m_energyBallsRotateSpeedLimit;
}
public function increaseEnergyBallsRotateSpeed():void
{
m_energyBallsRotateSpeed++;
if(m_energyBallsRotateSpeed>=m_energyBallsRotateSpeedLimit)
m_energyBallsRotateSpeed = 1;
}
public function update():void
{
var i:int;
if(!m_mouseMode && (m_rotateLeft || m_rotateRight))
{
var radius:Number;
var tempX:Number;
if(m_rotateLeft)
{
radius= -8*Math.PI/180;
}
if(m_rotateRight)
{
radius= 8*Math.PI/180;
}
tempX = m_drt.x;
m_drt.x = m_drt.x * Math.cos(radius) - m_drt.y * Math.sin(radius);
m_drt.y = tempX * Math.sin(radius) + m_drt.y * Math.cos(radius);
}
/**/
if(m_moveUp || m_moveDown || m_moveLeft || m_moveRight)
{
m_lastpos.val_(m_pos);
if(m_moveUp)
{
m_pos.add_( 0, -m_moveSpeed);
}
if(m_moveDown)
{
m_pos.add_( 0, m_moveSpeed);
}
if(m_moveLeft)
{
m_pos.add_(-m_moveSpeed, 0);
}
if(m_moveRight)
{
m_pos.add_( m_moveSpeed, 0);
}
if(m_followMode==0)
{
if(m_hold)
{
var dx:Number = m_pos.x - m_lastpos.x;
var dy:Number = m_pos.y - m_lastpos.y;
for(i = 0; i<m_energyPathLength; i++)
{
m_energyPath[i].m_lastpos.add_(dx, dy);
m_energyPath[i].m_pos.add_(dx, dy);
}
} else {
m_energyPath[0].m_lastpos.val_(m_energyPath[0].m_pos);
m_energyPath[0].m_pos.val_(m_lastpos);
for(i = 1; i<m_energyPathLength; i++)
{
m_energyPath[i].m_lastpos.val_(m_energyPath[i].m_pos);
m_energyPath[i].m_pos.val_(m_energyPath[i-1].m_lastpos);
}
}
for(i = 0; i< m_totalBalls; i++)
{
m_energyBalls[i].m_pos.val_(m_energyPath[(i+1)*m_energyPathAverage-1].m_pos);
}
}
/**/
}
if(m_followMode==1)
{
m_radian +=m_energyBallsRotateSpeed*Math.PI/180;
m_energyPath[0].m_lastpos.val_(m_energyPath[0].m_pos);
m_energyPath[0].m_pos.val_p_(m_pos.x+m_radius*Math.cos(m_radian),m_pos.y+m_radius*Math.sin(m_radian));
for(i = 1; i<m_energyPathLength; i++)
{
m_energyPath[i].m_lastpos.val_(m_energyPath[i].m_pos);
m_energyPath[i].m_pos.val_(m_energyPath[i-1].m_lastpos);
}
for(i = 0; i< m_totalBalls; i++)
{
m_energyBalls[i].m_pos.val_(m_energyPath[(i+1)*m_energyPathAverage-1].m_pos);
}
}
if(m_followMode==2)
{
m_radian += m_energyBallsRotateSpeed*Math.PI/180;
var temprad:Number = 0;
for(i = 1; i<m_energyPathLength; i++)
{
temprad = m_radian+i*Math.PI/180*360/m_energyPathLength;
m_energyPath[i].m_pos.val_p_(m_pos.x+m_radius*Math.cos(temprad),m_pos.y+m_radius*Math.sin(temprad));
m_energyPath[i].m_lastpos.val_(m_energyPath[i].m_pos);
}
for(i = 0; i< m_totalBalls; i++)
{
m_energyBalls[i].m_pos.val_(m_energyPath[(i+1)*m_energyPathAverage-1].m_pos);
}
}
for(i = 0; i< m_totalBalls; i++)
{
m_energyBalls[i].update();
}
}
public function paint():void
{
var i:int;
GGraphic.dp(m_bmpd, m_pos.x+m_drt.x, m_pos.y+m_drt.y, 0xFFFF6666);
for(i = 0; i< m_totalBalls; i++)
{
m_energyBalls[i].paint();
}
}
}
class GGraphic
{
public function GGraphic()
{
}
public static function dp(target:BitmapData, px:int, py:int, color:uint):void
{
lineFast(target, px-5, py-5, px+5, py+5, color);
lineFast(target, px-5, py+5, px+5, py-5, color);
}
public static function lineFast(target:BitmapData, x0:int, y0:int, x1:int, y1:int, color:uint):void
{
var pix :uint = color;
var dy :int = y1 - y0;
var dx :int = x1 - x0;
var stepx :int;
var stepy :int;
var fraction :int;
if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; }
if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; }
dy <<= 1;
dx <<= 1;
target.setPixel32(x0, y0, pix);
if (dx > dy)
{
fraction = dy - (dx >> 1);
while (x0 != x1)
{
if (fraction >= 0)
{
y0 += stepy;
fraction -= dx;
}
x0 += stepx;
fraction += dy;
target.setPixel32(x0, y0, pix);
}
} else {
fraction = dx - (dy >> 1);
while (y0 != y1)
{
if (fraction >= 0)
{
x0 += stepx;
fraction -= dy;
}
y0 += stepy;
fraction += dx;
target.setPixel32(x0, y0, pix);
}
}
}
public static function cubic_bezier(target:BitmapData, x1:int, y1:int, x2:int, y2:int, x3:int, y3:int, x4:int, y4:int, color:uint ):void
{
var N_SEG:int = 5;//20;
var i:int;
var j:int;
var pts:Vector.<Dot> = new Vector.<Dot>();
var t:Number = 0;
var a:Number = 0;
var b:Number = 0;
var c:Number = 0;
var d:Number = 0;
var x:Number = 0;
var y:Number = 0;
for (i=0; i <= N_SEG; ++i)
{
t = i / N_SEG;
a = Math.pow((1.0 - t), 3.0);
b = 3.0 * t * Math.pow((1.0 - t), 2.0);
c = 3.0 * Math.pow(t, 2.0) * (1.0 - t);
d = Math.pow(t, 3.0);
x = a * x1 + b * x2 + c * x3 + d * x4;
y = a * y1 + b * y2 + c * y3 + d * y4;
pts.push(new Dot(x,y));
}
for (i=0; i < N_SEG; ++i)
{
j = i + 1;
lineFast(target, pts[i].x, pts[i].y, pts[j].x, pts[j].y, color );
}
}
}
class Dot
{
public var x:Number = 0;
public var y:Number = 0;
public var tx:Number = 0;
public var ty:Number = 0;
public var vx:Number = 0;
public var vy:Number = 0;
public var angle:Number = 0;
public var size:Number = 0;
public var speed:Number = 0;
public var m:Number = 0;
public var rad:Number = 0;
public function Dot(px:Number,py:Number)
{
x = px;
y = py;
tx = x;
ty = y;
}
public function val_(p:Dot):Dot
{
x = p.x;
y = p.y;
return this;
}
public function val_p_(px:Number, py:Number):Dot
{
x = px;
y = py;
return this;
}
public function add_(px:Number, py:Number):Dot
{
x += px;
y += py;
return this;
}
}
class EnergyPath
{
public var m_pos:Dot;
public var m_lastpos:Dot;
public function EnergyPath(px:Number, py:Number)
{
m_pos = new Dot(px, py);
m_lastpos = new Dot(px, py);
}
}
class global
{
public static var STAGE_WIDTH:Number = 465;
public static var STAGE_HEIGHT:Number = 465;
public function global() {}
}