コード例 #1
0
        private void PullEntities(SingularityComponent component)
        {
            var singularityCoords = component.Owner.Transform.Coordinates;
            // TODO: Maybe if we have named fixtures needs to pull out the outer circle collider (inner will be for deleting).
            var entitiesToPull = EntityManager.GetEntitiesInRange(singularityCoords, component.Level * 10);

            foreach (var entity in entitiesToPull)
            {
                if (!entity.TryGetComponent <PhysicsComponent>(out var collidableComponent) || collidableComponent.BodyType == BodyType.Static)
                {
                    continue;
                }
                if (entity.HasComponent <GhostComponent>())
                {
                    continue;
                }
                if (singularityCoords.EntityId != entity.Transform.Coordinates.EntityId)
                {
                    continue;
                }
                var vec = (singularityCoords - entity.Transform.Coordinates).Position;
                if (vec == Vector2.Zero)
                {
                    continue;
                }

                var speed = 10 / vec.Length * component.Level;

                collidableComponent.ApplyLinearImpulse(vec.Normalized * speed);
            }
        }
コード例 #2
0
        private void DestroyTiles(SingularityComponent component)
        {
            if (!component.Owner.TryGetComponent(out PhysicsComponent? physicsComponent))
            {
                return;
            }
            var worldBox = physicsComponent.GetWorldAABB();

            foreach (var grid in _mapManager.FindGridsIntersecting(component.Owner.Transform.MapID, worldBox))
            {
                foreach (var tile in grid.GetTilesIntersecting(worldBox))
                {
                    grid.SetTile(tile.GridIndices, Tile.Empty);
                }
            }
        }
コード例 #3
0
        private void MoveSingulo(SingularityComponent singularity, PhysicsComponent physics)
        {
            if (singularity.Level <= 1)
            {
                return;
            }
            // TODO: Could try gradual changes instead but for now just try to replicate

            var pushVector = new Vector2(_robustRandom.Next(-10, 10), _robustRandom.Next(-10, 10));

            if (pushVector == Vector2.Zero)
            {
                return;
            }

            physics.LinearVelocity = Vector2.Zero;
            physics.LinearVelocity = pushVector.Normalized * 2;
        }