In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

100行でゲームっぽいもの

【 あそびかた 】
黒ニコちゃんマークを罠にはめてやっつけよう!
マウスの左ボタンを押しながら円を書くと罠を設置できます。
罠は大きいほど作動までの時間が長くなります。
黒ニコちゃんを3匹逃すとゲームオーバーです。
Get Adobe Flash player
by a24 30 Jan 2009
//
// 【 あそびかた 】
// 黒ニコちゃんマークを罠にはめてやっつけよう!
// マウスの左ボタンを押しながら円を書くと罠を設置できます。
// 罠は大きいほど作動までの時間が長くなります。
// 黒ニコちゃんを3匹逃すとゲームオーバーです。
//
package {
	import flash.display.*;
	import flash.events.*;
	import flash.geom.Point;
	import flash.text.*;
	import flash.utils.Timer;
	import caurina.transitions.Tweener;
	[ SWF( width = "465" , height = "465" , backgroundColor = "0xFFFFFF" , frameRate = "48" ) ]
	public class MouseGame extends MovieClip {
		private var _startPoint : Point;
		private var _nextPoint : Point;
		private var _baseDistance : Number = 10;
		private var _sp : Sprite = new Sprite;
		private var _tf : TextField = new TextField();
		private var _pointArray : Array;
		private var _drawPointArray : Array;
		private var _enemyArray : Array = new Array();
		private var _time : int = 3000;
		private var _how : String = "黒マークが入るようにマウスで円を書いてね。\nSCORE : ";
		private var _score : int = 0;
		private var _life : String = " 匹  残機 : \u263A\u263A\u263A";
		public function MouseGame() {
			var _redzone : Shape = new Shape();
			_redzone.graphics.beginFill( 0xFF3333 , 0.2 );
			_redzone.graphics.drawRect( 435 , 0 , 30 , 465 );
			_tf.wordWrap = true;
			_tf.selectable = false;
			_tf.width = _tf.height = 445;
			_tf.x = _tf.y = 10;
			_tf.text = _how + _score + _life;
			addChild( _tf );
			addChild( _sp );
			addChild( _redzone );
			stage.addEventListener( MouseEvent.MOUSE_DOWN , mouseDownHandler );
			var _timer : Timer = new Timer( _time , 1 );
			_timer.addEventListener( TimerEvent.TIMER , createEnemy );
			_timer.start();
		} private function createEnemy( e:TimerEvent ):void {
			var _enemy : TextField = new TextField();
			_enemy.defaultTextFormat =  new TextFormat( "MS ゴシック" , 24 );
			_enemyArray.push( _enemy );
			_enemy.selectable = false;
			_enemy.width = _enemy.height = 24;
			_enemy.y = 465 * Math.random();
			_enemy.text = "\u263B";
			addChild( _enemy );
			Tweener.addTween( _enemy , { x : 465 , y : 465 * Math.random() , time : 2 * Math.random() + 2 , transition : "linear", onComplete : function():void { _life = _life.replace("\u263A" , "");
				if ( _life.search( /\u263A/ ) == -1 ) { _life = " 匹  残機 : \n\nGAME OVER!!\n\nもう一度遊びたいときは、ページを更新してね。";
					stage.removeEventListener( MouseEvent.MOUSE_DOWN , mouseDownHandler ); }
				_tf.text = _how + _score + _life;
				} } );
			if ( _time > 1500 ) _time -= 100;
			var _timer : Timer = new Timer( _time , 1 );
			_timer.addEventListener( TimerEvent.TIMER , createEnemy );
			_timer.start();
		} private function mouseDownHandler( e:MouseEvent ):void {
			_pointArray = new Array();
			_drawPointArray = new Array();
			_startPoint = new Point( stage.mouseX , stage.mouseY );
			_pointArray.push( _startPoint );
			_sp.graphics.clear();
			_sp.graphics.lineStyle( 2 , 0x33CCFF , 1.0 );
			_sp.graphics.moveTo( _startPoint.x , _startPoint.y );
			stage.addEventListener( MouseEvent.MOUSE_MOVE , mouseMoveHandler );
			stage.addEventListener( MouseEvent.MOUSE_UP , mouseUpHander );
		} private function mouseMoveHandler( e:MouseEvent ):void {
			_nextPoint = new Point(  stage.mouseX , stage.mouseY );
			var _distance : Number = Point.distance( _startPoint , _nextPoint );
			if ( Math.abs( _distance ) > _baseDistance ) { if ( _pointArray.length > 2 && _drawPointArray.length == 0 ) for ( var i : int = 0; i < _pointArray.length - 1; i ++ ) { if ( isCross( _pointArray[ i ] , _pointArray[ i + 1 ] , _startPoint , _nextPoint ) ) { _drawPointArray.push( crossPoint( _pointArray[ i ] , _pointArray[ i + 1 ] , _startPoint , _nextPoint ) );
							for ( var j : int = i + 1; j < _pointArray.length - ( i - 1 ); j ++ ) _drawPointArray.push( _pointArray[ j ] );
							break;
				} } _sp.graphics.lineTo( _nextPoint.x , _nextPoint.y );
				_startPoint = new Point( stage.mouseX , stage.mouseY );
				_pointArray.push( _startPoint );
		} } private function mouseUpHander( e:MouseEvent ):void {
			_sp.graphics.clear();
			if ( _drawPointArray.length != 0 ) { stage.removeEventListener( MouseEvent.MOUSE_DOWN , mouseDownHandler );
				_sp.graphics.beginFill( 0x3399FF , 0.5 );
				_sp.graphics.moveTo( _drawPointArray[ 0 ].x , _drawPointArray[ 0 ].y );
				for ( var i : int = 1; i < _drawPointArray.length - 1; i ++ ) _sp.graphics.lineTo( _drawPointArray[ i ].x , _drawPointArray[ i ].y );
				var _bar : Sprite = new Sprite();
				_bar.x = 20;
				_bar.graphics.beginFill( 0xFFCC00 , 1.0 );
				_bar.graphics.drawRect( 0 , 425 , _sp.width * _sp.height / 200 , 20 );
				addChild( _bar );
				Tweener.addTween( _bar , { width : 0 , time : _bar.width / 150 , transition : "linear" , onComplete : function():void { if ( _life.search( /\u263A/ ) != -1 ) stage.addEventListener( MouseEvent.MOUSE_DOWN , mouseDownHandler );
					for ( var j : int = 0; j < _enemyArray.length; j ++ ) if ( _sp.hitTestPoint( _enemyArray[ j ].x , _enemyArray[ j ].y , true ) || _sp.hitTestPoint( _enemyArray[ j ].x + _enemyArray[ j ].width , _enemyArray[ j ].y , true ) || _sp.hitTestPoint( _enemyArray[ j ].x + _enemyArray[ j ].width , _enemyArray[ j ].y + _enemyArray[ j ].height , true ) || _sp.hitTestPoint( _enemyArray[ j ].x , _enemyArray[ j ].y + _enemyArray[ j ].height , true ) ) { Tweener.addTween( _enemyArray[ j ] , { x : _enemyArray[ j ].x , y : 465 , time : ( 465 - _enemyArray[ j ].y ) / 300 , transition : "linear" } );
							_score ++;
							_tf.text = _how + _score + _life;
					} _sp.graphics.clear();
				} } );
			} stage.removeEventListener( MouseEvent.MOUSE_MOVE , mouseMoveHandler );
			stage.removeEventListener( MouseEvent.MOUSE_UP , mouseUpHander );
		} public function crossPoint( _pt1:Point , _pt2:Point , _pt3:Point , _pt4:Point ):Point {
			if (( _pt4.x - _pt3.x ) * ( _pt2.y - _pt1.y ) - ( _pt4.y - _pt3.y ) * ( _pt2.x - _pt1.x ) == 0) return null;
			return new Point( _pt1.x + ( _pt2.x - _pt1.x ) * ( ( _pt4.x - _pt3.x ) * ( _pt3.y - _pt1.y ) - ( _pt4.y - _pt3.y ) * ( _pt3.x - _pt1.x ) ) / ( ( _pt4.x - _pt3.x ) * ( _pt2.y - _pt1.y ) - ( _pt4.y - _pt3.y ) * ( _pt2.x - _pt1.x ) ) , _pt1.y + ( _pt2.y - _pt1.y ) * ( ( _pt4.x - _pt3.x ) * ( _pt3.y - _pt1.y ) - ( _pt4.y - _pt3.y ) * ( _pt3.x - _pt1.x ) ) / ( ( _pt4.x - _pt3.x ) * ( _pt2.y - _pt1.y ) - ( _pt4.y - _pt3.y ) * ( _pt2.x - _pt1.x ) ) );
        } public function isCross( _pt1:Point , _pt2:Point , _pt3:Point , _pt4:Point ):Boolean {
			var p:Point = crossPoint( _pt1 , _pt2 , _pt3 , _pt4 );
			return ( p != null && (p.x - _pt3.x) * (p.x - _pt4.x) + (p.y - _pt3.y) * (p.y - _pt4.y) < 0) && ((p.x - _pt1.x) * (p.x - _pt2.x) + (p.y - _pt1.y) * (p.y - _pt2.y) < 0);
} } }