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

flash on 2011-3-20

Get Adobe Flash player
by kb10uy 20 Mar 2011
    Embed
/**
 * Copyright kb10uy ( http://wonderfl.net/user/kb10uy )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/olBt
 */

package 
{
	import flash.display.Sprite;
	[SWF (backgroundColor="0xFFFFFF",frameRate="60",width="640",height="480")]
	public class Main extends Sprite
	{
		public function Main():void {
		main = this; initalize();
		}
	}
	
}
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.text.*;
const winx:int = 640;
const winy:int = 480;
var main:Sprite;
var screen:BitmapData = new BitmapData(winx,winy,false,0);
var ball:Ball = new Ball;
var bs:Rectangle = new Rectangle((winx) / 2, 350, 80, 16);
var bs_left:int = new int;
var bs_right:int = new int;
var bs_top:int = 350;
var bs_bottom:int = 350 + 16
var brblock:Array=[
	[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
	[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
	[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
	[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
	[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
];
var Crear:Boolean = false; 
var scoreField:TextField = new TextField();
var scff:TextFormat = new TextFormat();
var score:int = 0;
var combo:int = 0;


ball.setting(winx/2-(16/2), 60, 0, 5, 0xFF0000);
var resetr:Rectangle = new Rectangle(0, 0, winx, winy);

function initalize():void {
	main.addChild(new Bitmap(screen));	
	main.addEventListener(Event.ENTER_FRAME, update);
	scff.color = 0xFFFFFF;
	scff.font = "_typewriter";
	scff.size = 24;
	scoreField.defaultTextFormat = scff;
	scoreField.x = 0; scoreField.y = 0; scoreField.width = 320;
	main.addChild(scoreField);
}

function update(event:Event):void {
	screen.fillRect(resetr, 0);
	ball.update(0+(16/2),0+(16/2),winx-(16/2), winy-(16/2));
	ball.draw(screen, 16, 16, true);
	bs.x = main.stage.mouseX - 40;
	bs_left = main.stage.mouseX - 40;
	bs_right = main.stage.mouseX + 40;
	bscheck();
	scoreField.text = "SCORE:" + String(score)+" COMBO:"+String(combo);
	screen.fillRect(bs, 0xFFFFFF);
	blockdraw();
	if (Crear) { newgame();}
}

class Ball {
	public var pos:Vector3D=new Vector3D;
	public var addvec:Vector3D=new Vector3D;
	public var col:uint=new uint;
	public function setting(x:Number, y:Number, adx:Number, ady:Number, c:uint):void {
		pos.x = x; pos.y = y; addvec.x = adx; addvec.y = ady; col = c;
	}
	public function update(lxmin:Number, lymin:Number, lxmax:Number, lymax:Number):void {
		
		if ((pos.x <= lxmin) || (pos.x >= lxmax)) {
			addvec.x = -addvec.x;
		}
		if ((pos.y <= lymin) || (pos.y >= lymax)) {
			addvec.y = -addvec.y;
		}
		
		pos.x = pos.x+addvec.x; pos.y = pos.y+addvec.y;
	}
	public function draw(sc:BitmapData, w:Number, h:Number, censet:Boolean=true):void {
		if (censet) {
			var b_rect:Rectangle = new Rectangle(pos.x-(w/2),pos.y-(h/2),w,h);
			sc.fillRect(b_rect,col);
		} else {
			var b2_rect:Rectangle = new Rectangle(pos.x,pos.y,w,h);
			sc.fillRect(b2_rect, col);
		}
	}

}

function bscheck():void {
	if (ball.pos.y>=bs_bottom){return}
	if (ball.pos.y + 8 >= bs_top) {
		combo = 0;
		if ((bs_left <= ball.pos.x + 8) && (bs_right >= ball.pos.x + 8)) {
			ball.addvec.x = (ball.pos.x - main.stage.mouseX) / 8;//4の数値を変えると難易度が変化します
			if (ball.addvec.x >= 5) { ball.addvec.x = 5;}
			ball.addvec.y = -(6 - ball.addvec.x);//6は変えないほうがいい(たてと横の加速合わせて7ピクセル分)
			if ((ball.addvec.x >= 4) || (ball.addvec.y >= 4)) {
				ball.addvec.x = 2.25; ball.addvec.y = 2.25;
			}
		}
	}
}

var i:int = 0;
var j:int = 0;
var bc:uint = 0x000000;
var brr:Rectangle=new Rectangle(10,10,30,14)
function blockdraw():void {
	Crear = true;
	for ( i = 0; i < 20; i++) 
	{
		for ( j = 0; j < 5; j++) 
		{
			if (brblock[j][i] == 1) {
				brr.x = (i * 32 + 1);
				brr.y = (j * 16 + 1)+64;
				bc = 0xFF00FF;
				Crear = false;
				screen.fillRect(brr, bc);
				if (((ball.pos.y <= brr.y + 15)&&(ball.pos.y+16>=brr.y))||((ball.pos.y+16 <= brr.y)&&(ball.pos.y>=brr.y-15))) {
					if ((ball.pos.x >= brr.x) && (ball.pos.x + 8 <= brr.x + 32)) {
						brblock[j][i] = 0;
						score += 10;
						combo++;
						score += combo * (combo * 5);
						ball.addvec.y = -ball.addvec.y;
					}
				}
			}
		}
	}
}

function newgame():void {
	brblock = [
	[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
	[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
	[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
	[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
	[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
	];

}