Exemplo n.º 1
0
        // prepareCollisions
        private void prepareCollisions()
        {
            string levelUid = LevelSystem.currentLevelUid;
            Dictionary <int, Dictionary <int, List <Metamer> > > levelMetamerGrid;
            Dictionary <int, List <Metamer> > gridX;
            List <Metamer> gridY;

            // Query the world using the screen's AABB
            _physicsSystem.getWorld(levelUid).QueryAABB((Fixture fixture) =>
            {
                // Skip certain collisions
                int entityId = (int)fixture.Body.UserData;
                if (_entityManager.getComponent(levelUid, entityId, ComponentType.IgnoreTreeCollision) != null)
                {
                    return(true);
                }

                AABB aabb;
                Transform transform;
                fixture.Body.GetTransform(out transform);
                fixture.Shape.ComputeAABB(out aabb, ref transform, 0);
                int Ax = getPlantGridX(aabb.LowerBound.X);
                int Ay = getPlantGridY(aabb.LowerBound.Y);
                int Bx = getPlantGridX(aabb.UpperBound.X) + 1;
                int By = getPlantGridY(aabb.UpperBound.Y) + 1;
                if (_metamerGrid.TryGetValue(levelUid, out levelMetamerGrid))
                {
                    for (int i = Ax; i < Bx; i++)
                    {
                        for (int j = Ay; j < By; j++)
                        {
                            if (levelMetamerGrid.TryGetValue(i, out gridX) && gridX.TryGetValue(j, out gridY))
                            {
                                for (int n = 0; n < gridY.Count; n++)
                                {
                                    Metamer metamer = gridY[n];
                                    if (metamer.numFixturesToTest < Metamer.MAX_FIXTURES_TO_TEST)
                                    {
                                        metamer.fixturesToTest[metamer.numFixturesToTest] = fixture;
                                        metamer.numFixturesToTest++;
                                    }
                                }
                            }
                        }
                    }
                }

                return(true);
            },
                                                        ref treeAABB);
        }
Exemplo n.º 2
0
        // prepareCollisions
        private void prepareCollisions()
        {
            // Query the world using the screen's AABB
            _physicsSystem.getWorld(LevelSystem.currentLevelUid).QueryAABB((Fixture fixture) =>
            {
                // Skip certain collisions
                //UserData data = fixtureProxy.fixture.GetBody().GetUserData() as UserData;
                //if (data.actorType == ActorType.WALL_GROUP || data.actorType == ActorType.GROUND)
                //    return true;

                AABB aabb;
                Transform transform;
                fixture.Body.GetTransform(out transform);
                fixture.Shape.ComputeAABB(out aabb, ref transform, 0);
                int Ax = getFluidGridX(aabb.LowerBound.X);
                int Ay = getFluidGridY(aabb.LowerBound.Y);
                int Bx = getFluidGridX(aabb.UpperBound.X) + 1;
                int By = getFluidGridY(aabb.UpperBound.Y) + 1;
                for (int i = Ax; i < Bx; i++)
                {
                    for (int j = Ay; j < By; j++)
                    {
                        if (fluidGrid.TryGetValue(i, out _collisionGridX) && _collisionGridX.TryGetValue(j, out _collisionGridY))
                        {
                            for (int n = 0; n < _collisionGridY.Count; n++)
                            {
                                Particle particle = liquid[_collisionGridY[n]];
                                if (particle.numFixturesToTest < Particle.MAX_FIXTURES_TO_TEST)
                                {
                                    particle.fixturesToTest[particle.numFixturesToTest] = fixture;
                                    particle.numFixturesToTest++;
                                }
                            }
                        }
                    }
                }

                return(true);
            },
                                                                           ref simulationAABB);
        }