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

forked from: forked from: forked from: forked from: forked from: forked from: forked from: forked from: forked from: forked from: forked from: forked from: forked from: forked from: forked from: forked from: forked from: flash on 2010-1-13

Get Adobe Flash player
by Tamanegi_kenshi 28 Mar 2010
/**
 * Copyright Tamanegi_kenshi ( http://wonderfl.net/user/Tamanegi_kenshi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/8eVF
 */

package{

import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Rectangle;

public class test extends Sprite{
	
	private var ball:Ball;
	private var line:Line;
	private var lines:Array;
	private var lineNum:uint=3;
	private var gravity:Number=0.4;
	private var bounce:Number=-0.6;
	
	public function test(){
		init();
		}
		
		private function init():void{
			ball=new Ball(0x000000);
			ball.x=150;
			
			addChild(ball);
			
			
			
			lines=new Array();
			for(var i:uint=0;i<lineNum;i++){
			line=new Line();
			addChild(line);
			lines.push(line);
			}
			
			lines[0].x=100;
			lines[0].y=100;
			lines[0].rotation=30;
			
			lines[1].x=100;
			lines[1].y=300;
			lines[1].rotation=40;
			
			lines[2].x=250;
			lines[2].y=250;
			lines[2].rotation= -30;
			
			
		addEventListener(Event.ENTER_FRAME,on);	
			
			
			}
			
		private function on(e:Event):void{
			
			
			
			ball.vy+=gravity;
			ball.x+=ball.vx;
			ball.y+=ball.vy;
			
			lines[1].x+=5;
			if(lines[1].x>=stage.stageWidth){
				lines[1].x=-50;
			}
			
			lines[2].y+=3;
			if(lines[2].y>=stage.stageHeight){
				lines[2].y=-50;
			}
			
			if(ball.y>stage.stageHeight){
				ball.x=150;
				ball.y=0;
				ball.vx=ball.vy=0;
			}
			
			for(var i:uint=0;i<lineNum;i++){
			checkLine(lines[i]);
			}
			
			
			}
			
			
			
			
			private function checkLine(line:Sprite):void{
				
				var bound:Rectangle=line.getBounds(this);
				if(ball.x>bound.left && ball.x<bound.right){
				
				var angle:Number=line.rotation*Math.PI/180;
				var cos:Number=Math.cos(angle);
				var sin:Number=Math.sin(angle);
				
				var x1:Number=ball.x-line.x;
				var y1:Number=ball.y-line.y;
				
				
				var y2:Number=cos*y1-sin*x1;
				
				
				var vy1:Number=cos*ball.vy-sin*ball.vx;
				
				if(y2>-ball.height/2 && y2<vy1){
					var x2:Number=cos*x1+sin*y1;
					var vx1:Number=cos*ball.vx+sin*ball.vy;
					
					y2=-ball.height/2;
					vy1*=bounce;
				
				
				x1=cos*x2-sin*y2;
				y1=cos*y2+sin*x2;
				ball.vx=cos*vx1-sin*vy1;
				ball.vy=cos*vy1+sin*vx1;
				ball.x=line.x+x1;
				ball.y=line.y+y1;
				
				}
				}
				}
			
	} 
	
	
	
}
import flash.display.Sprite;

class Ball extends Sprite{
	
	public var vx:Number=0;
	public var vy:Number=0;
	
	function Ball(color:uint){
	
	graphics.beginFill(color);
	graphics.drawCircle(0,0,20);
	graphics.endFill();

	}
}

import flash.display.Sprite;

class Line extends Sprite{
	
	function Line(){
		graphics.lineStyle(1);
		graphics.lineTo(150,0);
	}
}