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

極座標変換でブロック崩し

カーソルで移動
*  スペースで発射
Get Adobe Flash player
by nemu90kWw 15 Mar 2009
// forked from Kay's DisplacementMapFliterで極座標変換
// forked from Kay's 四角いBitmapを極座標変換する
// forked from Kay's 四角いBitmapを三角にする
/*
 *  カーソルで移動
 *  スペースで発射
 */
package
{
	import flash.display.*;
	import flash.geom.*;
	import flash.filters.*;
	import flash.events.*;
	
	[SWF(width="300", height="300", frameRate="30", backgroundColor="0x201828")]
	public class Take12 extends Sprite
	{
		private const SW:Number = stage.stageWidth;
		private const SH:Number = stage.stageHeight;
		private var map:BitmapData;
		
		private var buffer:BitmapData;
		private var screen:Bitmap;
		
		public function Take12():void
		{
			map = new BitmapData(SW,SH,false,0x808080);
			var radius:Number = (SH+SW)/4;
			var stageCenter :Point = new Point(SW/2, SH/2);
			for (var v:int=0; v < SH; v++) {
				for (var h:int=0; h <= SW; h++) {
					var p:Point = new Point(h,v);
					var distance:Number = Point.distance(stageCenter,p);
					var radian:Number = Math.atan2(p.y-stageCenter.y, p.x-stageCenter.x)+Math.PI;
					var target:Point = new Point();
					target.x = radian / (Math.PI*2) * SW;
					target.y = distance / radius * SH;
					var ratioX:Number = (target.x-h) / SW;
					var ratioY:Number = (target.y-v) / SH;
					var colorX:uint = Math.round(ratioX*0x7f)+0x80;
					var colorY:uint = Math.round(ratioY*0x7f)+0x80; 
					var nColor:uint = 0 << 16 | colorX << 8 | colorY;
					map.setPixel(h,v, nColor);
				}
			}
			var xyFilter:DisplacementMapFilter = new DisplacementMapFilter();
			xyFilter.mapBitmap = map;
			xyFilter.mapPoint = new Point(0,0);
			xyFilter.componentX = BitmapDataChannel.GREEN;
			xyFilter.componentY = BitmapDataChannel.BLUE;
			xyFilter.scaleX = SW*2;
			xyFilter.scaleY = SH*2;
			xyFilter.mode = DisplacementMapFilterMode.COLOR;
			xyFilter.color = 0x201828;
			xyFilter.alpha = 1;
			
			stage.quality = StageQuality.LOW;
			
			buffer = new BitmapData(SW,SH,false,0);
			screen = new Bitmap(buffer);
			
			screen.filters = [xyFilter];
			addChild(screen);
			
			init();
			
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, Key.onKeyDownHandler);
			stage.addEventListener(KeyboardEvent.KEY_UP, Key.onKeyUpHandler);
		}
		
		private function onEnterFrame(e:Event):void
		{
			main();
			draw();
		}
		
		private var racket_x:Number, racket_y:Number, racket_vx:Number;
		private var ball_x:Number, ball_y:Number, ball_vx:Number, ball_vy:Number;
		private var ball_wait:Boolean;
		private var blocks:Vector.<Vector.<Boolean>> = new Vector.<Vector.<Boolean>>(6, true);
		
		private function init():void
		{
			racket_x = 225;
			racket_y = 260;
			racket_vx = 0;
			ball_wait = true;
			
			for(var y:int = 0; y < blocks.length; y++)
			{
				blocks[y] = new Vector.<Boolean>(15, true);
				for(var x:int = 0; x < blocks[y].length; x++)
				{
					blocks[y][x] = true;
				}
			}
		}
		
		private function main():void
		{
			if(Key.isLeft) {racket_vx -= 1.8;}
			if(Key.isRight) {racket_vx += 1.8;}
			racket_vx /= 1.3;
			racket_x = MathEx.loop(0, racket_x + racket_vx, SW);
			
			if(ball_wait == true)
			{
				if(Key.isShot)
				{
					ball_vx = (Math.random() * 2 - 1) + racket_vx / 4;
					ball_vy = -3;
					ball_wait = false;
				}
				else {
					ball_x = racket_x;
					ball_y = racket_y - 20;
					return;
				}
			}
			
			ball_x = MathEx.loop(0, ball_x + ball_vx, SW);
			ball_y += ball_vy*2.5;
			
			if(ball_x+4 > racket_x-16 && ball_x-4 < racket_x+16 && ball_y+8 > racket_y && ball_y-8 < racket_y+20)
			{
				ball_y = racket_y-8;
				ball_vy *= -1;
				//ball_vx += (ball_x - racket_x) / 8;
				ball_vx -= (ball_x - racket_x) / 15;
				ball_vx += racket_vx / 8;
			}
			
			if(ball_y < 40+8)
			{
				ball_y = 40+8;
				ball_vy *= -1;
			}
			
			if(ball_y > SH)
			{
				ball_wait = true;
				return;
			}
			
			var hit_7:Boolean = false;
			var hit_9:Boolean = false;
			var hit_1:Boolean = false;
			var hit_3:Boolean = false;
			var clear:Boolean = true;
			
			for(var y:int = 0; y < blocks.length; y++) {
				for(var x:int = 0; x < blocks[y].length; x++) {
					if(blocks[y][x] == true)
					{
						if(hitcheck(ball_x - 4, ball_y - 8, x, y) == true)
						{
							hit_7 = true;
							blocks[y][x] = false;
						}
						if(hitcheck(ball_x + 4, ball_y - 8, x, y) == true)
						{
							hit_9 = true;
							blocks[y][x] = false;
						}
						if(hitcheck(ball_x - 4, ball_y + 8, x, y) == true)
						{
							hit_1 = true;
							blocks[y][x] = false;
						}
						if(hitcheck(ball_x + 4, ball_y + 8, x, y) == true)
						{
							hit_3 = true;
							blocks[y][x] = false;
						}
						clear = false;
					}
				}
			}
			
			if(clear == true)
			{
				init();
				return;
			}
			
			if((hit_7 == true && hit_9 == true)||(hit_1 == true && hit_3 == true))
			{
				ball_vy *= -1;
			}
			else if((hit_7 == true && hit_1 == true)||(hit_9 == true && hit_3 == true))
			{
				ball_vx *= -1;
			}
			else if(hit_7 == true || hit_9 == true || hit_1 == true || hit_3 == true)
			{
				var temp:Number = ball_vx;
				ball_vx = ball_vy;
				ball_vy = temp;
			}
			
			if(ball_vy >= 0 && ball_vy < 2) {ball_vy = 2;}
			if(ball_vy < 0 && ball_vy > -2) {ball_vy = -2;}
		}
		
		private function hitcheck(x:int, y:int, bx:int, by:int):Boolean
		{
			return (x > bx*20 && x < bx*20+20 && y > by*15+40 && y < by*15+15+40);
		}
		
		private function draw():void
		{
			buffer.fillRect(buffer.rect, 0x000000);
			
			buffer.fillRect(new Rectangle(racket_x-16, racket_y, 32, 20), 0xFFFF00);
			buffer.fillRect(new Rectangle(racket_x-16-SW, racket_y, 32, 20), 0xFFFF00);
			buffer.fillRect(new Rectangle(racket_x-16+SW, racket_y, 32, 20), 0xFFFF00);
			
			buffer.fillRect(new Rectangle(ball_x-4, ball_y, 8, 16), 0xFFFF00);
			buffer.fillRect(new Rectangle(ball_x-4-SW, ball_y, 8, 16), 0xFFFF00);
			buffer.fillRect(new Rectangle(ball_x-4+SW, ball_y, 8, 16), 0xFFFF00);
			
			for(var y:int = 0; y < blocks.length; y++) {
				for(var x:int = 0; x < blocks[y].length; x++) {
					if(blocks[y][x] == true) {
						buffer.fillRect(new Rectangle(x*20+1, y*15+1+40, 18, 13), 0xFFFF00);
					}
				}
			}
			
			buffer.fillRect(new Rectangle(0, 0, SW, 40), 0xFFFF00);
		}
	}
}

import flash.events.*;
import flash.ui.*;

class Key
{
	public static var isLeft:Boolean = false;
	public static var isRight:Boolean = false;
	public static var isShot:Boolean = false;
	
	public static function onKeyDownHandler(e:KeyboardEvent):void
	{
		switch(e.keyCode) {
			case Keyboard.LEFT: Key.isLeft = true; break;
			case Keyboard.RIGHT: Key.isRight = true; break;
			case Keyboard.SPACE: Key.isShot = true; break;
		}
	}
	public static function onKeyUpHandler(e:KeyboardEvent):void
	{
		switch(e.keyCode) {
			case Keyboard.LEFT: Key.isLeft = false; break;
			case Keyboard.RIGHT: Key.isRight = false; break;
			case Keyboard.SPACE: Key.isShot = false; break;
		}
	}
}

class MathEx
{
	public static function loop(min:Number, target:Number, max:Number):Number
	{
		var range:Number = max - min;
		if(min < 0 && target < min) {
			target = range - (-target % range);
		}
		target = (target + max) % range + min;
		return target;
	}
}