forked from: 手抜き3Dダンジョン(ミニマップ付き)
// forked from rsakane's 手抜き3Dダンジョン(ミニマップ付き)
package
{
import flash.display.Sprite;
import flash.utils.ByteArray;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.events.MouseEvent;
[SWF(width="465", height="465", frameRate="30", backgroundColor="0x393939")]
public class Main extends Sprite
{
private var px:int = 5;
private var py:int = 4;
private var SIZE:int = 12;
private var pos:Array = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
[1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1],
[1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1],
[1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1],
[1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1],
[1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1],
[1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1],
[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 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]];
public function Main()
{
var forwardButton:Sprite = new Sprite();
forwardButton.x = 210;
forwardButton.y = 360;
forwardButton.graphics.beginFill(0xFBE1F9);
forwardButton.graphics.drawEllipse(-22, -6, 67, 38);
forwardButton.buttonMode = true;
forwardButton.graphics.endFill();
forwardButton.addEventListener(MouseEvent.CLICK, forward);
createTextField(forwardButton, "↑");
addChild(forwardButton);
var backButton:Sprite = new Sprite();
backButton.x = 210;
backButton.y = 430;
backButton.graphics.beginFill(0xFBE1F9);
backButton.graphics.drawEllipse(-22, -6, 67, 38);
backButton.buttonMode = true;
backButton.graphics.endFill();
backButton.addEventListener(MouseEvent.CLICK, back);
createTextField(backButton, "↓");
addChild(backButton);
var leftButton:Sprite = new Sprite();
leftButton.x = 150;
leftButton.y = 395;
leftButton.graphics.beginFill(0xFBE1F9);
leftButton.graphics.drawEllipse(-22, -6, 67, 38);
leftButton.buttonMode = true;
leftButton.graphics.endFill();
leftButton.addEventListener(MouseEvent.CLICK, left);
createTextField(leftButton, "←");
addChild(leftButton);
var rightButton:Sprite = new Sprite();
rightButton.x = 270;
rightButton.y = 395;
rightButton.graphics.beginFill(0xFBE1F9);
rightButton.graphics.drawEllipse(-22, -6, 67, 38);
rightButton.buttonMode = true;
rightButton.graphics.endFill();
rightButton.addEventListener(MouseEvent.CLICK, right);
createTextField(rightButton, "→");
addChild(rightButton);
draw();
}
private function createTextField(parent:Sprite = null, text:String = "", x:int = 0, y:int = 0):TextField
{
var tf:TextField = new TextField();
tf.x = x, tf.y = y;
tf.defaultTextFormat = new TextFormat("_typeWriter", 17, 0x393939);
tf.text = text;
tf.selectable = false;
tf.autoSize = TextFieldAutoSize.LEFT;
if (parent) parent.addChild(tf);
else this.addChild(tf);
return tf;
}
private function forward(event:MouseEvent = null):void
{
if (!pos[py - 1][px]) py--;
draw();
}
private function back(event:MouseEvent = null):void
{
if (!pos[py + 1][px]) py++;
draw();
}
private function left(event:MouseEvent = null):void
{
var tmp:Array = clone(pos);
for (var y:int = 0; y < SIZE; y++)
{
for (var x:int = 0; x < SIZE; x++)
{
pos[x][SIZE - y - 1] = tmp[y][x];
}
}
var t:int = py;
py = px;
px = SIZE - t - 1;
draw();
}
private function right(event:MouseEvent = null):void
{
var tmp:Array = clone(pos);
for (var y:int = 0; y < SIZE; y++)
{
for (var x:int = 0; x < SIZE; x++)
{
pos[SIZE - x - 1][y] = tmp[y][x];
}
}
var t:int = px;
px = py;
py = SIZE - t - 1;
draw();
}
public static function clone(arg:*):*
{
var b:ByteArray = new ByteArray();
b.writeObject(arg);
b.position = 0;
return b.readObject();
}
private function draw():void
{
graphics.clear();
fillRect2(0, 0, 350, 350, 0x222222);
fillRect2(0, 0, 350, 125, 0xEECEA5);
fillRect2(0, 225, 350, 125, 0xEECEA5);
if (pos[py - 2][px - 2])
{
fillRect2(0, 125, 40, 100, 0xAA8A61);
}
if (pos[py - 2][px - 1])
{
fillRect2(40, 125, 90, 100, 0xAA8A61);
}
if (pos[py - 2][px])
{
fillRect2(130, 125, 90, 100, 0xAA8A61);
}
if (pos[py - 2][px + 1])
{
fillRect2(220, 125, 90, 100, 0xAA8A61);
}
if (pos[py - 2][px + 2])
{
fillRect2(310, 125, 40, 100, 0xAA8A61);
}
if (pos[py - 1][px - 2])
{
fillRect([0, 100], [40, 125], [0, 250], [40, 225], 0xCCAC83);
}
if (pos[py - 1][px + 2])
{
fillRect([310, 125], [350, 100], [310, 225], [350, 265], 0xCCAC83);
}
if (pos[py - 1][px - 1])
{
fillRect([50, 50], [130, 125], [50, 300], [130, 225], 0xCCAC83);
//fillRect([50, 50], [125, 125], [50, 300], [125, 225], 0xCCAC83);
fillRect2(0, 50, 50, 250, 0xDAC2A5);
}
if (pos[py - 1][px + 1])
{
fillRect([220, 125], [300, 50], [220, 225], [300, 300], 0xCCAC83);
//fillRect([225, 125], [300, 50], [225, 225], [300, 300], 0xCCAC83);
fillRect2(300, 50, 50, 250, 0xDAC2A5);
}
if (pos[py - 1][px])
{
fillRect2(0, 50, 350, 250, 0x93744F);
}
if (pos[py][px - 1])
{
fillRect([0, 0], [50, 50], [0, 350], [50, 300], 0xCCAC87);
}
if (pos[py][px + 1])
{
fillRect([300, 50], [350, 0], [300, 300], [350, 350], 0xCCAC87);
}
for (var yy:int = -5; yy <= 5; yy++)
{
for (var xx:int = -5; xx <= 5; xx++)
{
var color:int = 0x0000FF;
if (yy == 0 && xx == 0) color = 0xFF0000;
else if (0 <= py + yy && py + yy < SIZE && 0 <= px + xx && px + xx < SIZE)
{
if (pos[py + yy][px + xx]) color = 0x0;
else color = 0xFFFFFF;
}
graphics.beginFill(color);
graphics.drawRect(350 + (xx + 5) * 10, (yy + 5) * 10, 10, 10);
graphics.endFill();
}
}
}
private function fillRect(tl:Array, tr:Array, bl:Array, br:Array, color:int):void
{
graphics.beginFill(color);
graphics.moveTo(tl[0], tl[1]);
graphics.lineTo(tr[0], tr[1]);
graphics.lineTo(br[0], br[1]);
graphics.lineTo(bl[0], bl[1]);
graphics.lineTo(tl[0], tl[1]);
graphics.endFill();
}
private function fillRect2(x:int, y:int, width:int, height:int, color:int):void
{
graphics.beginFill(color);
graphics.drawRect(x, y, width, height);
graphics.endFill();
}
}
}