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: scroll

Movement - Arrow Key(カーソルキー)
一回、画面をクリックしないとキーが反応しないかも
Get Adobe Flash player
by saocha 05 Nov 2009
    Embed
// forked from rsakane's scroll
package
{
/*
 * Movement - Arrow Key(カーソルキー)
 * 一回、画面をクリックしないとキーが反応しないかも
 */
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	
	public class Main extends Sprite
	{
		private var player:Player;
		private var blocks:Array = new Array();
		private var cx:int = 0;
		private var cy:int = 0;
		
		public function Main()
		{
			for (var y:int = Map.MAP.length - 1; y >= 0; y--)
			{
				for (var x:int = 0; x < Map.MAP[0].length; x++)
				{
					if (Map.MAP[y][x])
					{
						var block:Block = new Block();
						block.cx = x * 40;
						block.cy = y * 40;
						addChild(block);
						blocks.push(block);
					}
				}
			}
			
			player = new Player();
			addChild(player);
			
			stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
			stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
			
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		private function onEnterFrame(event:Event):void
		{
			cy += (player.cy - 240 - cy) / 20;
			cx += (player.cx - 240 - cx) / 20;
			
			player.move();
			
			player.x = player.cx - cx;
			player.y = player.cy - cy;
			
			for (var i:int = 0; i < blocks.length; i++)
			{
				blocks[i].y = blocks[i].cy - cy;
				blocks[i].x = blocks[i].cx - cx;
			}	
		}
		
		private function onKeyDown(event:KeyboardEvent):void
		{
			if (event.keyCode == 37) player.moveLeft();
			if (event.keyCode == 39) player.moveRight();
			if (event.keyCode == 38) player.moveTop();
			if (event.keyCode == 40) player.moveBottom();
		}
		
		private function onKeyUp(event:KeyboardEvent):void
		{
			player.stop();
		}
	}
}

import flash.display.Sprite;
import flash.geom.Matrix;

class Player extends Sprite
{
	public var cx:Number = 440;
	public var cy:Number = 400;
	private var vx:Number = 0;
	private var vy:Number = 0;
	
	public function Player()
	{
		graphics.lineStyle(1.0, 0x0);
		graphics.moveTo(20, 0);
		graphics.lineTo(20, 40);
		graphics.moveTo(0, 20);
		graphics.lineTo(40, 20);
	}
	
	public function moveLeft():void
	{
		vx = -5;
	}
	
	public function moveRight():void
	{
		vx = 5;
	}
	
	public function moveTop():void
	{
		vy = -5;
	}
	
	public function moveBottom():void
	{
		vy = 5;
	}
	
	public function move():void
	{
		cx += vx;
		cy += vy;
	}
	
	public function stop():void
	{
		vx = 0;
		vy = 0;
	}
}

class Block extends Sprite
{
	public static const SIZE:int = 40;
	public var cx:int = 0;
	public var cy:int = 0;
	
	public function Block()
	{
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox(40, 40, 45 * Math.PI / 180);
		graphics.beginGradientFill("linear", [0xF08a00, 0xcc7700], [1.0, 1.0], [0, 255], matrix);
		graphics.moveTo(0, 0);
		graphics.lineTo(10, -10);
		graphics.lineTo(50, -10);
		graphics.lineTo(50, 30);
		graphics.lineTo(40, 40);
		graphics.endFill();
		
		
		graphics.lineStyle(1.0, 0xcc7700);
		graphics.beginGradientFill("radial", [0xffa020, 0xF08a00], [1.0, 1.0], [0, 255], matrix);
		graphics.drawRect(0, 0, 40, 40);
		graphics.endFill();
	}
}

class Map
{
	public static const BLOCK:int = 1;
	public static const MAP:Array =
	[
		[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
		[0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0],
		[0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0],
		[0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0],
		[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
		[0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,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