Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import as3isolib.display.IsoSprite;
- import as3isolib.display.IsoView;
- import as3isolib.display.primitive.IsoBox;
- import as3isolib.display.scene.IsoGrid;
- import as3isolib.display.scene.IsoScene;
- import as3isolib.geom.IsoMath;
- import as3isolib.geom.Pt;
- import as3isolib.graphics.SolidColorFill;
- import as3isolib.graphics.Stroke;
- import eDpLib.events.ProxyEvent;
- import flash.display.Sprite;
- import flash.events.*;
- [SWF(width='800', height='700', backgroundColor='#000000', frameRate='30')]
- public class HabClone extends Sprite
- {
- private static const CELL_SIZE:Number = 40;
- private var grid:IsoGrid;
- private var scene:IsoScene;
- private var view:IsoView;
- private var floor:IsoBox;
- private var lwall:IsoBox;
- private var rwall:IsoBox;
- private var cellover:IsoBox;
- private var player:IsoBox;
- public function HabClone()
- {
- grid = new IsoGrid();
- grid.addEventListener(MouseEvent.MOUSE_MOVE, cellOver);
- grid.setGridSize(6, 6, 1);
- grid.gridlines = new Stroke(1, 0x8E8E5E);
- grid.showOrigin = false;
- grid.cellSize = CELL_SIZE;
- scene = new IsoScene();
- scene.addChild(grid);
- // Create the Room scenery
- CreateRoomScenery();
- // Create cell hover
- CreateCellHover();
- // Create player
- createPlayer();
- scene.render();
- view = new IsoView();
- view.setSize(800, 700);
- view.centerOnPt(new Pt(0, 0, 0));
- view.addScene(scene);
- addChild(view);
- addEventListener(Event.ENTER_FRAME, loop);
- }
- private function loop(event:Event):void
- {
- scene.render();
- }
- private function CreateRoomScenery():void
- {
- // Create Left Wall
- lwall = new IsoBox();
- lwall.setSize(10, CELL_SIZE * 6, CELL_SIZE * 5);
- lwall.stroke = new Stroke(1, 0x000000, 1);
- lwall.fill = new SolidColorFill(0xB6B8C7, 1);
- lwall.moveTo(0 - lwall.width, 0, 0 - lwall.width );
- scene.addChild(lwall);
- // Create Right Wall
- rwall = new IsoBox();
- rwall.setSize((CELL_SIZE * 6) + 10, 10, CELL_SIZE * 5);
- rwall.stroke = new Stroke(1, 0x000000, 1);
- rwall.fill = new SolidColorFill(0xB6B8C7, 1);
- rwall.moveTo(0 - rwall.length, 0 - rwall.length, 0 - rwall.length );
- scene.addChild(rwall);
- // Create the floor
- floor = new IsoBox();
- floor.setSize(CELL_SIZE * 6, CELL_SIZE * 6, 10);
- floor.stroke = new Stroke(1, 0x000000, 0);
- floor.fill = new SolidColorFill(0x989865, 1);
- floor.moveTo(0, 0, 0 - floor.height );
- scene.addChild(floor);
- }
- private function CreateCellHover():void
- {
- // Create cell hover
- cellover = new IsoBox();
- cellover.setSize(CELL_SIZE - 2, CELL_SIZE - 2, 1);
- cellover.fill = new SolidColorFill(0x000000, 0);
- cellover.stroke = new Stroke(2, 0xffffff);
- //cellover.moveTo(CELL_SIZE, CELL_SIZE, 0);
- scene.addChild(cellover);
- }
- private function cellOver(event:ProxyEvent):void
- {
- var me:MouseEvent = MouseEvent(event.targetEvent);
- var p:Pt = new Pt(me.localX, me.localY);
- IsoMath.screenToIso(p);
- cellover.moveTo(
- Math.floor(p.x / CELL_SIZE) * CELL_SIZE,
- Math.floor(p.y / CELL_SIZE) * CELL_SIZE, 0);
- }
- private function createPlayer():void
- {
- // Create cell hover
- player = new IsoBox();
- player.setSize(CELL_SIZE, CELL_SIZE, CELL_SIZE);
- //cellover.moveTo(CELL_SIZE, CELL_SIZE, 0);
- scene.addChild(player);
- }
- private function movePlayer(event:ProxyEvent):void
- {
- var me:MouseEvent = MouseEvent(event.targetEvent);
- var p:Pt = new Pt(me.localX, me.localY);
- IsoMath.screenToIso(p);
- player.moveTo(
- Math.floor(p.x / CELL_SIZE) * CELL_SIZE,
- Math.floor(p.y / CELL_SIZE) * CELL_SIZE, 0);
- }
- }
- }
Add Comment
Please, Sign In to add comment