Exemple #1
0
 public Game1(cpSpace space)
 {
     spc = space;
     spc.SetGravity(new cpVect(0, 1f));
     spc.AddDefaultCollisionHandler().preSolveFunc = new Func <cpArbiter, cpSpace, object, bool> ((arg1, arg2, arg3) => { Console.WriteLine("ij"); return(true); });
     spc.AddDefaultCollisionHandler().beginFunc    = new Func <cpArbiter, cpSpace, object, bool> ((arg1, arg2, arg3) => { Console.WriteLine("ij"); return(true); });
 }
Exemple #2
0
        public void Start(int worldSize)
        {
            lock (UpdateLock)
            {
                _worldSize = worldSize;

                _space = new cpSpace {
                    CollisionEnabled = true
                };
                _space.SetGravity(cpVect.Zero);

                var boxBody = cpBody.NewStatic();

                var leftShape   = new cpSegmentShape(boxBody, new cpVect(-worldSize, -worldSize), new cpVect(-worldSize, worldSize), 5);
                var topShape    = new cpSegmentShape(boxBody, new cpVect(-worldSize, worldSize), new cpVect(worldSize, worldSize), 5);
                var rightShape  = new cpSegmentShape(boxBody, new cpVect(worldSize, worldSize), new cpVect(worldSize, -worldSize), 5);
                var bottomShape = new cpSegmentShape(boxBody, new cpVect(worldSize, -worldSize), new cpVect(-worldSize, -worldSize), 5);

                leftShape.SetCollisionType(GenerateCollisionType <cpSpace>());
                topShape.SetCollisionType(GenerateCollisionType <cpSpace>());
                rightShape.SetCollisionType(GenerateCollisionType <cpSpace>());
                bottomShape.SetCollisionType(GenerateCollisionType <cpSpace>());

                _space.AddShape(leftShape);
                _space.AddShape(topShape);
                _space.AddShape(rightShape);
                _space.AddShape(bottomShape);

                var defaultCollisionHandler = _space.AddDefaultCollisionHandler();
                defaultCollisionHandler.preSolveFunc = (arbiter, space, userData) => false;

                var playerCollisionHandler = _space.AddCollisionHandler(GenerateCollisionType <PlayerBlob>(), GenerateCollisionType <PlayerBlob>());
                playerCollisionHandler.preSolveFunc = OnPreSolve;

                _reindexStatic = true;
            }
        }