Guest User

Untitled

a guest
Jan 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import as3isolib.display.IsoSprite;
  4.     import as3isolib.display.IsoView;
  5.     import as3isolib.display.primitive.IsoBox;
  6.     import as3isolib.display.scene.IsoGrid;
  7.     import as3isolib.display.scene.IsoScene;
  8.     import as3isolib.geom.IsoMath;
  9.     import as3isolib.geom.Pt;
  10.     import as3isolib.graphics.SolidColorFill;
  11.     import as3isolib.graphics.Stroke;
  12.    
  13.     import eDpLib.events.ProxyEvent;
  14.    
  15.     import flash.display.Sprite;
  16.     import flash.events.*;
  17.    
  18.     [SWF(width='800', height='700', backgroundColor='#000000', frameRate='30')]
  19.     public class HabClone extends Sprite
  20.     {
  21.         private static const CELL_SIZE:Number = 40;
  22.        
  23.         private var grid:IsoGrid;
  24.         private var scene:IsoScene;
  25.         private var view:IsoView;
  26.         private var floor:IsoBox;
  27.         private var lwall:IsoBox;
  28.         private var rwall:IsoBox;
  29.         private var cellover:IsoBox;
  30.         private var player:IsoBox;
  31.        
  32.         public function HabClone()
  33.         {
  34.             grid = new IsoGrid();
  35.             grid.addEventListener(MouseEvent.MOUSE_MOVE, cellOver);
  36.             grid.setGridSize(6, 6, 1);
  37.             grid.gridlines = new Stroke(1, 0x8E8E5E);
  38.             grid.showOrigin = false;
  39.             grid.cellSize = CELL_SIZE;
  40.            
  41.             scene = new IsoScene();
  42.             scene.addChild(grid);
  43.            
  44.             // Create the Room scenery
  45.             CreateRoomScenery();
  46.            
  47.             // Create cell hover
  48.             CreateCellHover();
  49.            
  50.             // Create player
  51.             createPlayer();
  52.            
  53.             scene.render();
  54.            
  55.             view = new IsoView();
  56.             view.setSize(800, 700);
  57.             view.centerOnPt(new Pt(0, 0, 0));
  58.             view.addScene(scene);
  59.             addChild(view);
  60.            
  61.             addEventListener(Event.ENTER_FRAME, loop);
  62.         }
  63.        
  64.         private function loop(event:Event):void
  65.         {
  66.             scene.render();
  67.         }
  68.        
  69.         private function CreateRoomScenery():void
  70.         {
  71.             // Create Left Wall
  72.             lwall = new IsoBox();
  73.             lwall.setSize(10, CELL_SIZE * 6, CELL_SIZE * 5);
  74.             lwall.stroke = new Stroke(1, 0x000000, 1);
  75.             lwall.fill = new SolidColorFill(0xB6B8C7, 1);
  76.             lwall.moveTo(0 - lwall.width, 0, 0 - lwall.width );
  77.             scene.addChild(lwall);
  78.            
  79.             // Create Right Wall
  80.             rwall = new IsoBox();
  81.             rwall.setSize((CELL_SIZE * 6) + 10, 10, CELL_SIZE * 5);
  82.             rwall.stroke = new Stroke(1, 0x000000, 1);
  83.             rwall.fill = new SolidColorFill(0xB6B8C7, 1);
  84.             rwall.moveTo(0 - rwall.length, 0 - rwall.length, 0 - rwall.length );
  85.             scene.addChild(rwall);
  86.            
  87.             // Create the floor
  88.             floor = new IsoBox();
  89.             floor.setSize(CELL_SIZE * 6, CELL_SIZE * 6, 10);
  90.             floor.stroke = new Stroke(1, 0x000000, 0);
  91.             floor.fill = new SolidColorFill(0x989865, 1);
  92.             floor.moveTo(0, 0, 0 - floor.height );
  93.             scene.addChild(floor);
  94.         }
  95.        
  96.         private function CreateCellHover():void
  97.         {
  98.             // Create cell hover
  99.             cellover = new IsoBox();
  100.             cellover.setSize(CELL_SIZE - 2, CELL_SIZE - 2, 1);
  101.             cellover.fill = new SolidColorFill(0x000000, 0);
  102.             cellover.stroke = new Stroke(2, 0xffffff);
  103.             //cellover.moveTo(CELL_SIZE, CELL_SIZE, 0);
  104.             scene.addChild(cellover);
  105.         }
  106.        
  107.         private function cellOver(event:ProxyEvent):void
  108.         {
  109.             var me:MouseEvent = MouseEvent(event.targetEvent);
  110.             var p:Pt = new Pt(me.localX, me.localY);
  111.             IsoMath.screenToIso(p);
  112.             cellover.moveTo(
  113.                 Math.floor(p.x / CELL_SIZE) * CELL_SIZE,
  114.                 Math.floor(p.y / CELL_SIZE) * CELL_SIZE, 0);
  115.         }
  116.        
  117.         private function createPlayer():void
  118.         {
  119.             // Create cell hover
  120.             player = new IsoBox();
  121.             player.setSize(CELL_SIZE, CELL_SIZE, CELL_SIZE);
  122.             //cellover.moveTo(CELL_SIZE, CELL_SIZE, 0);
  123.             scene.addChild(player);
  124.         }
  125.        
  126.         private function movePlayer(event:ProxyEvent):void
  127.         {
  128.             var me:MouseEvent = MouseEvent(event.targetEvent);
  129.             var p:Pt = new Pt(me.localX, me.localY);
  130.             IsoMath.screenToIso(p);
  131.             player.moveTo(
  132.                 Math.floor(p.x / CELL_SIZE) * CELL_SIZE,
  133.                 Math.floor(p.y / CELL_SIZE) * CELL_SIZE, 0);
  134.         }
  135.     }
  136. }
Add Comment
Please, Sign In to add comment