forked from: forked from: Checkmate vol.5 Amateur 実験用
/**
* Copyright uwi ( http://wonderfl.net/user/uwi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/lxVY
*/
// forked from uwi's forked from: Checkmate vol.5 Amateur
// forked from checkmate's Checkmate vol.5 Amateur
package {
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import flash.net.*;
import flash.system.*;
import jp.progression.commands.*;
import jp.progression.commands.lists.*;
import jp.progression.commands.display.*;
import jp.progression.commands.net.*;
import jp.progression.commands.tweens.*;
import jp.progression.events.*;
import flash.text.*;
import caurina.transitions.*;
public class Amateur extends Sprite {
public static var GRAPHICS_URL:String = "http://swf.wonderfl.net/static/assets/checkmate05/wancoAmateur.swf";
public var stayMotion:MovieClip;
public var jumpMotion:MovieClip;
public var highJumpMotion:MovieClip;
public var walkMotion:MovieClip;
public var runMotion:MovieClip;
public var squatMotion:MovieClip;
public var questionMotion:MovieClip;
public var exclamationMotion:MovieClip;
public var heartMotion:MovieClip;
public var poutMotion:MovieClip;
public var starMotion:MovieClip;
public var singMotion:MovieClip;
public var sleepMotion:MovieClip;
public var wakeMotion:MovieClip;
public function Amateur(){
super();
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
var com:SerialList = new SerialList();
com.addCommand(
new LoadSWF( new URLRequest( GRAPHICS_URL ) ),
function():void {
var loader:Loader = Loader( this.latestData );
var domain:ApplicationDomain = loader.contentLoaderInfo.applicationDomain;
stayMotion = new ( domain.getDefinition( "StayMotion" ) as Class );
jumpMotion = new ( domain.getDefinition( "JumpMotion" ) as Class );
highJumpMotion = new ( domain.getDefinition( "HighJumpMotion" ) as Class );
walkMotion = new ( domain.getDefinition( "WalkMotion" ) as Class );
runMotion = new ( domain.getDefinition( "RunMotion" ) as Class );
squatMotion = new ( domain.getDefinition( "SquatMotion" ) as Class );
questionMotion = new ( domain.getDefinition( "QuestionMotion" ) as Class );
exclamationMotion = new ( domain.getDefinition( "ExclamationMotion" ) as Class );
heartMotion = new ( domain.getDefinition( "HeartMotion" ) as Class );
poutMotion = new ( domain.getDefinition( "PoutMotion" ) as Class );
starMotion = new ( domain.getDefinition( "StarMotion" ) as Class );
singMotion = new ( domain.getDefinition( "SingMotion" ) as Class );
sleepMotion = new ( domain.getDefinition( "SleepMotion" ) as Class );
wakeMotion = new ( domain.getDefinition( "WakeMotion" ) as Class );
}
);
com.addEventListener(ExecuteEvent.EXECUTE_COMPLETE,onLoadSWF);
com.execute();
_tf = new TextField();
addChild(_tf);
_tf.width = 200;
_tf.height = 465;
}
private var _tf : TextField;
private function onLoadSWF(e:Event):void {
var motionList:Array = [
stayMotion,
jumpMotion,
highJumpMotion,
walkMotion,
runMotion,
squatMotion,
questionMotion,
exclamationMotion,
heartMotion,
poutMotion,
starMotion,
singMotion,
sleepMotion,
wakeMotion
];
_motion = new MovieClip();
addChild(_motion);
_mc = motionList[4];
_motion.addChild(motionList[4]);
_motion.x = 465 / 2;
_motion.y = 370;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
_d = new Disc();
addChild(_d);
_d.x = 465 / 2;
_d.y = 100;
_d.z = -200;
_vxz = 9.0;
_vy = 0.3;
_dir = 0.0;
_omega = 50;
_state = 1;
}
private var _d : Disc;
private var _vxz : Number;
private var _vy : Number;
private var _dir : Number;
private var _omega : Number;
private var _mc : MovieClip;
private var _motion : MovieClip;
private function onEnterFrame(e : Event) : void
{
if(_state == 1){
moveDisc();
moveWanko(_d.x, _d.z);
dirWanko(_d.x, _d.z);
if(_d.y >= 350 &&
(_motion.x - _d.x) * (_motion.x - _d.x) +
(_motion.x - _d.x) * (_motion.z - _d.z)
< 30 * 30){
_state = 2;
}
}else if(_state == 2){
moveWanko(465 / 2, 0);
var at : Number = dirWanko(465 / 2, 0);
_d.x = _motion.x + 30 * Math.cos(at);
_d.z = _motion.z + 30 * Math.sin(at);
_d.rotationY = 0;
_d.rotationX = -75;
_d.y = 350;
_d.y += [0, 6, 0, -6, -6, 6][_mc.currentFrame];
}
// Z-sort
if(getChildAt(1).z < getChildAt(2).z){
swapChildrenAt(1, 2);
}
}
private function moveDisc() : void
{
var T : Number = 0.1;
var mu : Number = Math.pow(0.95, T);
var omu : Number = Math.pow(0.7, T);
var G : Number = 9.8;
var theta : Number = Math.atan(_vy / _vxz) / Math.PI * 180;
var v2 : Number = _vy * _vy + _vxz * _vxz;
var L : Number = (1.0 - 1 / _omega) * _vxz / Math.sqrt(v2);
_omega *= omu;
_d.rotationY += _omega;
if(_omega < 1.0)_omega = 1.0;
_vxz *= mu;
_vy += (L - 1.0) * G * T * T;
_vy *= mu;
if(_d.y < 350){
_d.x += _vxz * Math.sin(_dir) * T * 10;
_d.z += _vxz * Math.cos(_dir) * T * 10;
_d.y -= _vy * T * 10;
_dir += 0.01;
}
}
private var _state : int;
private function dirWanko(tx : Number, tz : Number) : Number
{
var at : Number = Math.atan2(tz - _motion.z, tx - _motion.x);
var t : Number = ((Math.PI / 2 + 2 * Math.PI / 20 * 2.5) + 2 * Math.PI + at) % (2 * Math.PI);
// _tf.text = "" + _t + "\t" + int(t / (Math.PI * 2) * 20) + "\n";
_mc.wc2.wc3.gotoAndStop(int(t / (Math.PI * 2) * 20));
return at;
}
private var _prevX : Number;
private var _prevZ : Number;
private function moveWanko(tx : Number, tz : Number) : void
{
var mdr : Number = Math.sqrt(
(tx - _motion.x) * (tx - _motion.x) +
(tz - _motion.z) * (tz - _motion.z)
);
_tf.text = "" + mdr;
var dx : Number, dz : Number;
if(mdr > 10){
dx = (tx - _motion.x) / mdr;
dz = (tz - _motion.z) / mdr;
if(_prevX * dx + _prevZ * dz < Math.cos(10 * Math.PI / 180)){
// 角度変化の上限
var sgn : Number = _prevX * dz - _prevZ * dx;
var nc : Number = Math.cos(10 * Math.PI / 180);
var ns : Number = Math.sin(10 * Math.PI / 180);
var nz : Number = _prevZ * nc + _prevX * ns * (sgn > 0 ? -1 : 1);
var nx : Number = _prevX * nc + _prevZ * ns * (sgn > 0 ? 1 : -1);
dx = nx;
dz = nz;
}
}else{
dx = 0;
dz = 0;
}
_motion.x += dx * 7;
_motion.z += dz * 7;
}
/*
private function clickHandler(e:Event):void {
var motion:MovieClip = e.currentTarget as MovieClip;
// motion.gotoAndPlay(1);
motion.gotoAndStop(3);
// A way of rolling.
_tf.appendText("" + motion.wc2.wc3.currentFrame);
_u++;
motion.wc2.wc3.gotoAndStop(_u);
}
*/
}
}
import flash.display.*;
import flash.geom.*;
class Disc extends Sprite
{
private const R : Number = 30;
public function Disc()
{
var mat : Matrix = new Matrix();
mat.scale(1/1638*R*2, 1/1638*R*2);
var g : Graphics = this.graphics;
g.lineStyle(1, 0x000000);
g.beginGradientFill(GradientType.RADIAL, [0x00ee00, 0x005500], [1, 1], [225, 255], mat);
g.drawCircle(0, 0, R);
g.endFill();
// g.beginGradientFill(GradientType.RADIAL, [0x00ee00, 0x005500], [1, 1], [200, 255], mat);
g.beginFill(0x00ee00);
g.drawCircle(0, 0, 0.9 * R);
g.endFill();
g.beginFill(0x00ff00);
g.drawCircle(0, 0, 0.5 * R);
g.moveTo(0, 0);
g.lineTo(0, 0.5 * R);
this.rotationX = -90;
makeBound(16);
}
private function makeBound(n : int) : void
{
var L : Number = R * Math.sin(Math.PI / n);
for(var i : int = 0;i < n;i++){
var theta : Number = Math.PI * 2 / n * i;
var s : Shape = new Shape();
var g : Graphics = s.graphics;
g.lineStyle(1, 0x005500 + 0x001100 * (i % 2));
g.beginFill(0x005500 + 0x001100 * (i % 2));
g.drawRect(-L, 0, 2 * L, 3);
g.endFill();
s.x = R * Math.cos(theta);
s.y = R * Math.sin(theta);
s.rotationX = 90;
s.rotationZ = 90+theta / Math.PI * 180;
addChild(s);
}
}
}