Advertisement
Guest User

Untitled

a guest
Mar 12th, 2012
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Created with IntelliJ IDEA.
  3.  * User: VirtualMaestro
  4.  * Date: 12.03.12
  5.  * Time: 21:49
  6.  * To change this template use File | Settings | File Templates.
  7.  */
  8. package tests
  9. {
  10.     import flash.display.Sprite;
  11.  
  12.     import nape.dynamics.InteractionFilter;
  13.  
  14.     import nape.geom.GeomPoly;
  15.  
  16.     import nape.geom.Vec2;
  17.  
  18.     import nape.phys.Body;
  19.     import nape.phys.BodyType;
  20.     import nape.phys.Material;
  21.     import nape.shape.Polygon;
  22.  
  23.     [SWF(width=800, height=600, backgroundColor=0xdddddd, frameRate=30)]
  24.     public class TestFiltering extends Sprite
  25.     {
  26.         static public const APP_WIDTH:int = 800;
  27.         static public const APP_HEIGHT:int = 600;
  28.  
  29.         private var _core:InitNape;
  30.         private var _frameRate:Number = 30;
  31.         private var _timeStep:Number = 1 / _frameRate;
  32.  
  33.         public function TestFiltering(initNape:InitNape = null)
  34.         {
  35.             _core = initNape;
  36.  
  37.             if (_core == null)
  38.             {
  39.                 _core = new InitNape(APP_WIDTH, APP_HEIGHT, _frameRate, 10);
  40.                 addChild(_core);
  41.             }
  42.  
  43.             init();
  44.         }
  45.  
  46.         private function init():void
  47.         {
  48.             var bigBoxCollisionGroup:int = 0x000000001;
  49.             var bigBoxCollisionMask:int =  0x000000001;
  50.  
  51.             var triangleCollisionGroup:int = 0x000000011;
  52.             var triangleCollisionMask:int =  0x000000001;
  53.  
  54.             var hexagonCollisionGroup:int = 0x000000001;
  55.             var hexagonCollisionMask:int =  0x000000010;
  56.  
  57.             //
  58.             var bigBox:Body = new Body(BodyType.DYNAMIC, new Vec2(APP_WIDTH/2, APP_HEIGHT-150));
  59.             var bigBoxSize:int = 100;
  60.             bigBox.shapes.add(new Polygon(Polygon.box(bigBoxSize, bigBoxSize), new Material(0.5), new InteractionFilter(bigBoxCollisionGroup, bigBoxCollisionMask)));
  61.             bigBox.space = _core.space();
  62.  
  63.             //
  64.             var triangle:Body = new Body(BodyType.DYNAMIC, new Vec2(APP_WIDTH/2, APP_HEIGHT-300));
  65.             var triangleSize:int = 30;
  66.             var vertices:GeomPoly = new GeomPoly();
  67.             vertices.push(new Vec2(-triangleSize, -triangleSize));
  68.             vertices.push(new Vec2(triangleSize, -triangleSize));
  69.             vertices.push(new Vec2(triangleSize, triangleSize));
  70.             triangle.shapes.add(new Polygon(vertices, new Material(0.5), new InteractionFilter(triangleCollisionGroup, triangleCollisionMask)));
  71.             triangle.align();
  72.             triangle.space = _core.space();
  73.  
  74.             //
  75.             var hexagon:Body = new Body(BodyType.DYNAMIC, new Vec2(APP_WIDTH/2, APP_HEIGHT-400));
  76.             var hexagonSize:int = 50;
  77.             hexagon.shapes.add(new Polygon(Polygon.regular(hexagonSize, hexagonSize, 6), new Material(0.5), new InteractionFilter(hexagonCollisionGroup, hexagonCollisionMask)));
  78.             hexagon.space = _core.space();
  79.  
  80.  
  81.             // Static platform
  82.             var platform:Body = new Body(BodyType.STATIC, new Vec2(APP_WIDTH/2, APP_HEIGHT-50));
  83.             var polygonShape:Polygon = new Polygon(Polygon.box(APP_WIDTH, 50), new Material(0.5), new InteractionFilter(0xffffffff, 0xffffffff));
  84.             platform.shapes.add(polygonShape);
  85.             platform.space = _core.space();
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement