public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        var data = new ExplosionComponent
        {
            Prefab = conversionSystem.GetPrimaryEntity(PrefabGO)
        };

        dstManager.AddComponentData(entity, data);
    }
Exemplo n.º 2
0
 public override void HitByExplosion(ExplosionComponent explosion)
 {
     if (broken)
     {
         return;
     }
     Explode();
     SetBroken(true);
 }
Exemplo n.º 3
0
        public void Execute(Entity e, int index,
                            ref PhysicsVelocity physicsVelocity, ref LocalToWorld localToWorld, ref BulletCollisionComponent bulletCollision)
        {
            if (bulletCollision.Exploded)
            {
                return;
            }
            RaycastInput input = new RaycastInput
            {
                Start  = localToWorld.Position,
                End    = localToWorld.Forward,
                Filter = new CollisionFilter()
                {
                    // MaskBits is "A bitmask which describes which layers a collider belongs too"
                    //CategoryBits is "A bitmask which describes which layers this collider should interact with"
                    BelongsTo    = ~0u,
                    CollidesWith = ~0u,
                    GroupIndex   = 0
                }
            };

            bulletCollision.Raycasting = _World.CollisionWorld.CastRay(input, out RaycastHit hit);
            if (bulletCollision.Raycasting)
            {
                bulletCollision.Exploded     = true;
                bulletCollision.CastDistance = math.distance(localToWorld.Position, hit.Position);
                if (bulletCollision.CastDistance < .5f)
                {
                    if (hit.RigidBodyIndex == -1)
                    {
                        return;
                    }
                    var collisionEntity = _World.Bodies[hit.RigidBodyIndex].Entity;
                    if (!HealthComponents.Exists(collisionEntity))
                    {
                        return;
                    }
                    var    healthComponent    = HealthComponents[collisionEntity];
                    var    explosionComponent = ExplosionComponents[collisionEntity];
                    Health health             = new Health
                    {
                        Value = healthComponent.Value - 10
                    };
                    CommandBuffer.SetComponent(collisionEntity, health);

                    ExplosionComponent exposion = new ExplosionComponent
                    {
                        Prefab   = explosionComponent.Prefab,
                        Position = TranslationComponents[collisionEntity].Value
                    };
                    CommandBuffer.SetComponent(collisionEntity, exposion);
                    CommandBuffer.DestroyEntity(e);//Destroy Bullet
                }
            }
        }
Exemplo n.º 4
0
        // handleParticleInfluence -- Handles interaction between entities and particles
        public void handleParticleInfluence(string levelUid, Particle particle)
        {
            for (int i = 0; i < particle.entityInfluenceCount; i++)
            {
                int entityId = particle.entitiesToInfluence[i];
                ParticleInfluenceComponent particleInfluenceComponent = _entityManager.getComponent(levelUid, entityId, ComponentType.ParticleInfluence) as ParticleInfluenceComponent;

                particleInfluenceComponent.particleCount++;
                if (particleInfluenceComponent.type == ParticleInfluenceType.Physical)
                {
                    // Physical body influences -- body-to-particle influences are usually already handled by resolveCollisions()
                    PhysicsComponent physicsComponent = _entityManager.getComponent(levelUid, entityId, ComponentType.Physics) as PhysicsComponent;

                    physicsComponent.body.ApplyLinearImpulse(particle.oldPosition - particle.position, particle.oldPosition);
                }
                else if (particleInfluenceComponent.type == ParticleInfluenceType.Dynamite)
                {
                    // Dynamite influence
                    PhysicsComponent physicsComponent = _entityManager.getComponent(levelUid, entityId, ComponentType.Physics) as PhysicsComponent;
                    Vector2          bodyVelocity     = physicsComponent.body.LinearVelocity;

                    physicsComponent.body.LinearVelocity  = bodyVelocity * 0.98f + particle.velocity;
                    physicsComponent.body.AngularVelocity = physicsComponent.body.AngularVelocity * 0.98f;
                    particle.velocity += bodyVelocity * 0.003f;
                }
                else if (particleInfluenceComponent.type == ParticleInfluenceType.Character)
                {
                    // Character influence
                    PhysicsComponent physicsComponent = _entityManager.getComponent(levelUid, entityId, ComponentType.Physics) as PhysicsComponent;
                    Vector2          bodyVelocity     = physicsComponent.body.LinearVelocity;

                    physicsComponent.body.LinearVelocity = bodyVelocity * 0.95f + particle.velocity;
                    particle.velocity += bodyVelocity * 0.003f;
                }
                else if (particleInfluenceComponent.type == ParticleInfluenceType.Explosion)
                {
                    ExplosionComponent explosionComponent = _entityManager.getComponent(levelUid, entityId, ComponentType.Explosion) as ExplosionComponent;
                    Vector2            relative;
                    float   distanceSq;
                    Vector2 force;

                    relative   = particle.position - explosionComponent.position;
                    distanceSq = relative.LengthSquared();
                    relative.Normalize();
                    force              = relative * (explosionComponent.strength / Math.Max(distanceSq, 1f));
                    particle.velocity += force * 0.0055f;
                }
            }
        }
Exemplo n.º 5
0
        public override void Update(GameTime gametime)
        {
            List <Entity> explosions = world.GetEntities(new[] { typeof(ExplosionComponent) });

            foreach (Entity explosion in explosions)
            {
                ExplosionComponent ec = (ExplosionComponent)explosion.components[typeof(ExplosionComponent)];
                ec.elapsedTime += gametime.ElapsedGameTime.Milliseconds;
                if (ec.elapsedTime > ec.maxLife)
                {
                    world.RemoveEntity(explosion);
                    continue;
                }
            }
        }
        private void Explode(Vector3 worldPosition)
        {
            if (CustomNetworkManager.IsServer == false)
            {
                return;
            }

            Vector3Int worldTilePosition = worldPosition.CutToInt();

            if (useExplosionPrefab)
            {
                GameObject         explosionObject = Spawn.ServerPrefab(explosionPrefab, worldPosition).GameObject;
                ExplosionComponent explosion       = explosionObject.GetComponent <ExplosionComponent>();
                explosion.Explode(MatrixManager.AtPoint(worldTilePosition, true).Matrix);
                return;
            }

            Explosion.StartExplosion(worldTilePosition, explosionStrength);
        }
Exemplo n.º 7
0
        private void _createExplosion(IEntity source)
        {
            if (!source.HasComponent <ViewComponent>())
            {
                return;
            }

            var viewComponent = source.GetComponent <ViewComponent>();
            var go            = viewComponent.View.gameObject;
            var startPosition = go.transform.position;

            var explosionComponent = new ExplosionComponent()
            {
                startPosition = startPosition
            };
            var entity = _pool.CreateEntity();

            entity.AddComponent(explosionComponent);
            entity.AddComponent(new ViewComponent());

            MainThreadDispatcher.StartCoroutine(_removeExplosion(entity));
        }
Exemplo n.º 8
0
 public virtual void HitByExplosion(ExplosionComponent explosion)
 {
     Explode(); // create one more explosion
     Destroy(); // destroy
 }
Exemplo n.º 9
0
 public override void HitByExplosion(ExplosionComponent explosion)
 {
     // don't create explosion
 }
Exemplo n.º 10
0
 public override void HitByExplosion(ExplosionComponent explosion)
 {
     base.HitByExplosion(explosion);
     GameLevel.instance.OnKillEnemy(this);
 }
Exemplo n.º 11
0
 public override void HitByExplosion(ExplosionComponent explosion)
 {
     base.HitByExplosion(explosion);
     ammo = 0;
     nextRocket.Explode();
 }
Exemplo n.º 12
0
 public override void HitByExplosion(ExplosionComponent explosion)
 {
     base.HitByExplosion(explosion);
     ammo = 0;
     nextRocket.Explode();
 }
Exemplo n.º 13
0
        public bool BeginContact(Contact contact)
        {
            string          levelUid          = LevelSystem.currentLevelUid;
            List <int>      levelGoalEntities = _entityManager.getEntitiesPosessing(levelUid, ComponentType.RegionGoal);
            List <int>      explosionEntities = _entityManager.getEntitiesPosessing(levelUid, ComponentType.Explosion);
            LevelSystem     levelSystem       = (LevelSystem)_systemManager.getSystem(SystemType.Level);
            ExplosionSystem explosionSystem   = (ExplosionSystem)_systemManager.getSystem(SystemType.Explosion);
            int             playerId          = PlayerSystem.PLAYER_ID;

            // See if player is touching a level goal
            if (levelGoalEntities.Count > 0)
            {
                int entityA = (int)contact.FixtureA.Body.UserData;
                int entityB = (int)contact.FixtureB.Body.UserData;

                if (entityA == playerId)
                {
                    if (levelGoalEntities.Contains(entityB))
                    {
                        levelSystem.completeRegionGoal(entityB);
                    }
                }
                else if (entityB == playerId)
                {
                    if (levelGoalEntities.Contains(entityA))
                    {
                        levelSystem.completeRegionGoal(entityA);
                    }
                }
            }

            // Explosions
            if (explosionEntities.Count > 0)
            {
                int                   entityA            = (int)contact.FixtureA.Body.UserData;
                int                   entityB            = (int)contact.FixtureB.Body.UserData;
                IComponent            component          = null;
                ExplosionComponent    explosionComponent = null;
                Fixture               targetFixture      = null;
                FixedArray2 <Vector2> points;

                if (_entityManager.tryGetComponent(levelUid, entityA, ComponentType.Explosion, out component))
                {
                    targetFixture = contact.FixtureB;
                }
                else if (_entityManager.tryGetComponent(levelUid, entityB, ComponentType.Explosion, out component))
                {
                    targetFixture = contact.FixtureA;
                }

                if (targetFixture != null && component != null)
                {
                    DestructibleGeometryComponent destructibleGeometryComponent = (DestructibleGeometryComponent)_entityManager.getComponent(levelUid, (int)targetFixture.Body.UserData, ComponentType.DestructibleGeometry);
                    Vector2 contactNormal;
                    Vector2 relative;
                    Vector2 force;
                    float   distance;

                    //contact.GetWorldManifold(out worldManifold);
                    contact.GetWorldManifold(out contactNormal, out points);
                    explosionComponent = (ExplosionComponent)component;
                    relative           = (targetFixture.Shape.Center + targetFixture.Body.Position) - explosionComponent.position;
                    distance           = Math.Max(relative.Length(), 0.1f);
                    force = relative * (1 / distance) * explosionComponent.strength;

                    if (destructibleGeometryComponent != null)
                    {
                        // Break fixture off from body
                        explosionSystem.breakFixture(targetFixture, force, 180);
                        return(false);
                    }
                    else
                    {
                        // Apply generic explosion force
                        targetFixture.Body.ApplyForce(force, points[0]);
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 14
0
 public override void HitByExplosion(ExplosionComponent explosion)
 {
     // don't create explosion
 }
Exemplo n.º 15
0
 public override void HitByExplosion(ExplosionComponent explosion)
 {
     if (broken) return;
     Explode();
     SetBroken(true);
 }
Exemplo n.º 16
0
 public virtual void HitByExplosion(ExplosionComponent explosion)
 {
     Explode();         // create one more explosion
     Destroy();         // destroy
 }
Exemplo n.º 17
0
 public override void HitByExplosion(ExplosionComponent explosion)
 {
     base.HitByExplosion(explosion);
     GameLevel.instance.OnKillEnemy(this);
 }
Exemplo n.º 18
0
        // draw
        public void draw(GameTime gameTime)
        {
            string      levelUid                        = LevelSystem.currentLevelUid;
            FluidSystem fluidSystem                     = (FluidSystem)_systemManager.getSystem(SystemType.Fluid);
            List <int>  primitiveRenderEntities         = _entityManager.getEntitiesPosessing(levelUid, ComponentType.PrimitivesRender);
            List <int>  ropeEntities                    = _entityManager.getEntitiesPosessing(levelUid, ComponentType.Rope);
            List <int>  characterRenderEntities         = _entityManager.getEntitiesPosessing(levelUid, ComponentType.CharacterRender);
            List <int>  characterMovementEntities       = _entityManager.getEntitiesPosessing(levelUid, ComponentType.CharacterMovement);
            List <int>  treeEntities                    = _entityManager.getEntitiesPosessing(levelUid, ComponentType.Tree);
            List <int>  aimEntities                     = _entityManager.getEntitiesPosessing(levelUid, ComponentType.Aim);
            List <int>  explosionEntities               = _entityManager.getEntitiesPosessing(levelUid, ComponentType.Explosion);
            List <RopeGrabComponent> ropeGrabComponents = _entityManager.getComponents <RopeGrabComponent>(levelUid, ComponentType.RopeGrab);
            List <TooltipComponent>  tooltipComponents  = _entityManager.getComponents <TooltipComponent>(levelUid, ComponentType.Tooltip);
            Vector2 screenCenter                        = _cameraSystem.screenCenter;

            // Temporary debug draw
            if (LoderGame.debug)
            {
                Vector2 debugOffset = new Vector2(0f, 5f);
                _graphicsDevice.SetRenderTarget(_debugFluid);
                _graphicsDevice.Clear(Color.Black);
                _spriteBatch.Begin();

                // Cells
                foreach (KeyValuePair <int, Dictionary <int, List <int> > > row1Pair in fluidSystem.fluidGrid)
                {
                    foreach (KeyValuePair <int, List <int> > row2Pair in row1Pair.Value)
                    {
                        int     gridSize = (int)(FluidSystem.CELL_SPACING * scale) - 1;
                        Vector2 position = new Vector2((float)row1Pair.Key * FluidSystem.CELL_SPACING, (float)row2Pair.Key * FluidSystem.CELL_SPACING);
                        _spriteBatch.Draw(_pixel, (position - debugOffset) * scale + _halfScreen, new Rectangle(0, 0, gridSize, gridSize), Color.DarkBlue, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
                    }
                }

                // Particle pressures
                for (int i = 0; i < FluidSystem.MAX_PARTICLES; i++)
                {
                    Particle particle = fluidSystem.liquid[i];
                    _spriteBatch.Draw(_pixel, (particle.position - debugOffset) * scale + _halfScreen, new Rectangle(0, 0, 16, 16), Color.Red * 0.5f, 0f, new Vector2(8, 8), Math.Abs(particle.pressure) / FluidSystem.MAX_PRESSURE, SpriteEffects.None, 0f);
                }

                // Particle near pressures
                for (int i = 0; i < FluidSystem.MAX_PARTICLES; i++)
                {
                    Particle particle = fluidSystem.liquid[i];
                    _spriteBatch.Draw(_pixel, (particle.position - debugOffset) * scale + _halfScreen, new Rectangle(0, 0, 16, 16), Color.Orange * 0.5f, 0f, new Vector2(8, 8), Math.Abs(particle.pressureNear) / FluidSystem.MAX_PRESSURE_NEAR, SpriteEffects.None, 0f);
                }

                // Particle positions
                for (int i = 0; i < FluidSystem.MAX_PARTICLES; i++)
                {
                    Particle particle = fluidSystem.liquid[i];
                    Color    color    = particle.active ? Color.White : Color.DarkGray;
                    _spriteBatch.Draw(_pixel, (particle.position - debugOffset) * scale + _halfScreen, new Rectangle(0, 0, 4, 4), color, 0, new Vector2(2, 2), 1, SpriteEffects.None, 0);
                }

                // Simulation AABB
                Vector2[] vertices = new Vector2[4];
                vertices[0] = fluidSystem.simulationAABB.LowerBound;
                vertices[1] = new Vector2(fluidSystem.simulationAABB.UpperBound.X, fluidSystem.simulationAABB.LowerBound.Y);
                vertices[2] = fluidSystem.simulationAABB.UpperBound;
                vertices[3] = new Vector2(fluidSystem.simulationAABB.LowerBound.X, fluidSystem.simulationAABB.UpperBound.Y);
                for (int i = 0; i < 4; i++)
                {
                    Vector2   a        = vertices[i];
                    Vector2   b        = vertices[i == 3 ? 0 : i + 1];
                    Vector2   relative = b - a;
                    float     angle    = (float)Math.Atan2(relative.Y, relative.X);
                    Rectangle rect     = new Rectangle(0, 0, (int)(relative.Length() * scale), 2);
                    _spriteBatch.Draw(_pixel, (a - debugOffset) * scale + _halfScreen, rect, Color.Lime, angle, new Vector2(0, 1), 1f, SpriteEffects.None, 0);
                }

                _spriteBatch.End();
                _graphicsDevice.SetRenderTarget(null);
            }

            // Begin drawing a source for post effects under the player's level
            _graphicsDevice.SetRenderTarget(_postSourceUnder);
            _graphicsDevice.Clear(Color.Black);

            // Draw background
            if (_backgroundRenderer.background != null)
            {
                _spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
                _backgroundRenderer.drawFirstHalf();
                _spriteBatch.End();
            }

            // Begin ordered drawing
            _spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
            _halfScreen       = new Vector2(_graphicsDevice.Viewport.Width, _graphicsDevice.Viewport.Height) / 2;
            _viewMatrix       = Matrix.CreateTranslation(new Vector3(-screenCenter, 0)) * Matrix.CreateScale(new Vector3(_scale, -_scale, 1f));
            _projectionMatrix = Matrix.CreateOrthographic(_graphicsDevice.Viewport.Width, _graphicsDevice.Viewport.Height, 0, 1);
            _primitivesEffect.Parameters["view"].SetValue(_viewMatrix);
            _primitivesEffect.Parameters["projection"].SetValue(_projectionMatrix);

            // Primitive rendering
            for (int i = 0; i < primitiveRenderEntities.Count; i++)
            {
                int entityId = primitiveRenderEntities[i];
                PrimitivesRenderComponent primitiveRenderComponent = (PrimitivesRenderComponent)_entityManager.getComponent(levelUid, entityId, ComponentType.PrimitivesRender);

                for (int j = 0; j < primitiveRenderComponent.primitiveRenderObjects.Count; j++)
                {
                    PrimitiveRenderObject primitiveRenderObject = primitiveRenderComponent.primitiveRenderObjects[j];
                    PhysicsComponent      physicsComponent      = (PhysicsComponent)_entityManager.getComponent(levelUid, entityId, ComponentType.Physics);
                    IComponent            component;

                    // Update world matrix
                    if (physicsComponent != null)
                    {
                        primitiveRenderObject.worldMatrix = primitiveRenderObject.originMatrix * Matrix.CreateRotationZ(physicsComponent.body.Rotation) * Matrix.CreateTranslation(new Vector3(physicsComponent.body.Position, 0));
                    }
                    else if (_entityManager.tryGetComponent(levelUid, entityId, ComponentType.FollowMetamer, out component))
                    {
                        FollowMetamerComponent followMetamerComponent = component as FollowMetamerComponent;
                        primitiveRenderObject.worldMatrix = primitiveRenderObject.originMatrix * Matrix.CreateRotationZ(followMetamerComponent.metamer.currentAngle + StasisMathHelper.halfPi) * Matrix.CreateTranslation(new Vector3(followMetamerComponent.metamer.position, 0));
                    }

                    // Update vertices
                    primitiveRenderObject.updateVertices();

                    addRenderablePrimitive(primitiveRenderObject);
                }
            }

            // Rope rendering
            for (int i = 0; i < ropeEntities.Count; i++)
            {
                int           entityId      = ropeEntities[i];
                RopeComponent ropeComponent = _entityManager.getComponent(levelUid, entityId, ComponentType.Rope) as RopeComponent;
                RopeNode      current       = ropeComponent.ropeNodeHead;
                RopeNode      head          = current;
                RopeNode      tail          = head.tail;
                Vector2       position;
                float         muIncrement = 1f / (float)ropeComponent.interpolationCount;

                while (current != null)
                {
                    float mu = 0f;
                    for (int j = 0; j < ropeComponent.interpolationCount; j++)
                    {
                        Texture2D texture = current.ropeNodeTextures[j].texture;
                        Vector2   a;
                        Vector2   b = current.body.GetWorldPoint(new Vector2(current.halfLength, 0));
                        Vector2   c = current.body.GetWorldPoint(new Vector2(-current.halfLength, 0));
                        Vector2   d;

                        // Determine a's position
                        if (current.previous == null)
                        {
                            a = b + (b - c);
                        }
                        else
                        {
                            a = current.previous.body.GetWorldPoint(new Vector2(current.halfLength, 0));
                        }

                        // Determine d's position
                        if (current.next == null)
                        {
                            d = c + (c - b);
                        }
                        else
                        {
                            d = current.next.body.GetWorldPoint(new Vector2(-current.halfLength, 0));
                        }

                        StasisMathHelper.interpolate(ref a, ref b, ref c, ref d, mu, out position);
                        _spriteBatch.Draw(texture, (position - screenCenter) * _scale + _halfScreen, texture.Bounds, Color.White, current.body.Rotation + current.ropeNodeTextures[j].angleOffset, current.ropeNodeTextures[j].center, 1f, SpriteEffects.None, 0.1f);

                        mu += muIncrement;
                    }

                    current = current.next;
                }
            }

            // Character rendering
            for (int i = 0; i < characterRenderEntities.Count; i++)
            {
                PhysicsComponent         physicsComponent         = (PhysicsComponent)_entityManager.getComponent(levelUid, characterRenderEntities[i], ComponentType.Physics);
                CharacterRenderComponent characterRenderComponent = _entityManager.getComponent(levelUid, characterRenderEntities[i], ComponentType.CharacterRender) as CharacterRenderComponent;
                Vector2   offset;
                Texture2D texture = _animationManager.getTexture(characterRenderComponent.character, characterRenderComponent.animation, characterRenderComponent.currentFrame, out offset);

                _spriteBatch.Draw(texture, (physicsComponent.body.Position - screenCenter) * _scale + _halfScreen, texture.Bounds, Color.White, 0, offset, 1f, SpriteEffects.None, 0.05f);
            }

            /*
             * for (int i = 0; i < characterMovementEntities.Count; i++)
             * {
             *  PhysicsComponent physicsComponent = (PhysicsComponent)_entityManager.getComponent(levelUid, characterMovementEntities[i], ComponentType.Physics);
             *  CharacterMovementComponent characterMovementComponent = (CharacterMovementComponent)_entityManager.getComponent(levelUid, characterMovementEntities[i], ComponentType.CharacterMovement);
             *  Vector2 movementUnitVector = characterMovementComponent.movementUnitVector;
             *  Rectangle source = new Rectangle(0, 0, (int)(movementUnitVector.Length() * _scale), 2);
             *  float angle = (float)Math.Atan2(movementUnitVector.Y, movementUnitVector.X);
             *
             *  _spriteBatch.Draw(_pixel, (physicsComponent.body.Position - screenCenter) * _scale + _halfScreen, source, Color.Yellow, angle, new Vector2(0, 1), 1f, SpriteEffects.None, 0);
             * }*/

            // Tree
            _primitivesEffect.Parameters["world"].SetValue(Matrix.Identity);
            for (int i = 0; i < treeEntities.Count; i++)
            {
                TreeComponent treeComponent = _entityManager.getComponent(levelUid, treeEntities[i], ComponentType.Tree) as TreeComponent;

                if (treeComponent.tree.active)
                {
                    addRenderablePrimitive(treeComponent.tree);
                    treeComponent.tree.rootMetamer.draw(this);
                }
            }

            drawRenderablePrimitives();

            // Rope grab components (TEMPORARY)
            for (int i = 0; i < ropeGrabComponents.Count; i++)
            {
                foreach (KeyValuePair <Body, RevoluteJoint> pair in ropeGrabComponents[i].joints)
                {
                    Vector2 pointA   = pair.Value.BodyA.Position;
                    Vector2 pointB   = pair.Value.BodyB.Position;
                    Vector2 relative = pointB - pointA;
                    float   angle    = (float)Math.Atan2(relative.Y, relative.X);

                    _spriteBatch.Draw(_pixel, (pointA - screenCenter) * _scale + _halfScreen, new Rectangle(0, 0, (int)(relative.Length() * _scale), 2), Color.Green, angle, new Vector2(0, 1), 1f, SpriteEffects.None, 0f);
                }
            }

            // Draw explosions (TEMPORARY)
            for (int i = 0; i < explosionEntities.Count; i++)
            {
                ExplosionComponent explosionComponent = (ExplosionComponent)_entityManager.getComponent(levelUid, explosionEntities[i], ComponentType.Explosion);
                _spriteBatch.Draw(_circle, (explosionComponent.position - screenCenter) * _scale + _halfScreen, _circle.Bounds, Color.Red, 0f, new Vector2(_circle.Width, _circle.Height) / 2f, ((explosionComponent.radius * _scale) / (_circle.Width / 2f)), SpriteEffects.None, 0f);
            }

            // Aim components
            for (int i = 0; i < aimEntities.Count; i++)
            {
                AimComponent aimComponent  = (AimComponent)_entityManager.getComponent(levelUid, aimEntities[i], ComponentType.Aim);
                Vector2      worldPosition = (_entityManager.getComponent(levelUid, aimEntities[i], ComponentType.WorldPosition) as WorldPositionComponent).position;
                float        length        = aimComponent.length;

                _spriteBatch.Draw(_reticle, (worldPosition - screenCenter + new Vector2((float)Math.Cos(aimComponent.angle), (float)Math.Sin(aimComponent.angle)) * length) * _scale + _halfScreen, _reticle.Bounds, Color.Red, aimComponent.angle, new Vector2(_reticle.Width, _reticle.Height) / 2f, 1f, SpriteEffects.None, 0f);
            }

            _spriteBatch.End();

            // Begin drawing source for post effects over the player's layer
            _graphicsDevice.SetRenderTarget(_postSourceOver);
            _graphicsDevice.Clear(Color.Transparent);
            _spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);

            // Draw background's second half
            if (_backgroundRenderer.background != null)
            {
                _backgroundRenderer.drawSecondHalf();
            }

            // Draw tooltips
            for (int i = 0; i < tooltipComponents.Count; i++)
            {
                TooltipComponent tooltip = tooltipComponents[i];

                if (tooltip.draw)
                {
                    Vector2 tooltipPosition = (tooltip.position - screenCenter) * _scale + _halfScreen - new Vector2(0, 50f);

                    _spriteBatch.DrawString(_tooltipFont, tooltip.message, tooltipPosition + new Vector2(2, 2), Color.Black, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0001f);
                    _spriteBatch.DrawString(_tooltipFont, tooltip.message, tooltipPosition, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
                    tooltip.draw = false;
                }
            }

            _spriteBatch.End();
            _graphicsDevice.SetRenderTarget(null);
            _graphicsDevice.Clear(Color.Transparent);


            // Render fluid
            _graphicsDevice.SetRenderTarget(_fluidRenderTarget);
            _graphicsDevice.Clear(Color.Transparent);
            spriteBatch.Begin();
            int limit = fluidSystem.numActiveParticles;

            for (int i = 0; i < limit; i++)
            {
                // Current particle
                Particle particle = fluidSystem.liquid[fluidSystem.activeParticles[i]];
                Color    color    = new Color(1, particle.velocity.X < 0 ? -particle.velocity.X : particle.velocity.X, particle.velocity.Y < 0 ? -particle.velocity.Y : particle.velocity.Y);
                spriteBatch.Draw(_fluidParticleTexture, (particle.position - _cameraSystem.screenCenter) * scale + _halfScreen, _fluidParticleTexture.Bounds, color, 0, new Vector2(16, 16), 1, SpriteEffects.None, 0);
            }
            spriteBatch.End();
            _graphicsDevice.SetRenderTarget(_renderedFluid);
            _graphicsDevice.Clear(Color.Transparent);

            // Draw post-processed render target to screen
            _graphicsDevice.Textures[1] = _postSourceUnder;
            _fluidEffect.Parameters["renderSize"].SetValue(new Vector2(_renderedFluid.Width, _renderedFluid.Height));
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, _fluidEffect);
            spriteBatch.Draw(_fluidRenderTarget, Vector2.Zero, Color.DarkBlue);
            spriteBatch.End();
            _graphicsDevice.SetRenderTarget(null);

            // Draw post source under and over
            _spriteBatch.Begin();
            _spriteBatch.Draw(_postSourceUnder, _postSourceUnder.Bounds, Color.White);
            _spriteBatch.End();

            // Draw fluid
            if (fluidSystem != null)
            {
                _spriteBatch.Begin();
                _spriteBatch.Draw(_renderedFluid, _renderedFluid.Bounds, Color.White);
                _spriteBatch.End();
            }

            _spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
            _spriteBatch.Draw(_postSourceOver, _postSourceOver.Bounds, Color.White);
            _spriteBatch.End();

            // Particle debug
            if (LoderGame.debug)
            {
                _spriteBatch.Begin();
                _spriteBatch.Draw(_debugFluid, Vector2.Zero, _debugFluid.Bounds, Color.White, 0f, Vector2.Zero, _enlargeDebugFuild ? 1f : 0.25f, SpriteEffects.None, 0f);
                _spriteBatch.End();

                /*
                 * _spriteBatch.Begin();
                 * int limit = fluidSystem.numActiveParticles;
                 * for (int i = 0; i < limit; i++)
                 * {
                 *  // Current particle
                 *  Particle particle = fluidSystem.liquid[fluidSystem.activeParticles[i]];
                 *  spriteBatch.Draw(_pixel, (particle.position - _cameraSystem.screenCenter) * scale + _halfScreen, new Rectangle(0, 0, 2, 2), Color.White, 0, new Vector2(1, 1), 1, SpriteEffects.None, 0);
                 * }
                 * _spriteBatch.End();
                 */
            }

            // AI Wander Behavior debug
            if (LoderGame.debug)
            {
                AIBehaviorSystem aiBehaviorSystem       = _systemManager.getSystem(SystemType.AIBehavior) as AIBehaviorSystem;
                List <int>       wanderBehaviorEntities = _entityManager.getEntitiesPosessing(levelUid, ComponentType.AIWanderBehavior);

                for (int i = 0; i < wanderBehaviorEntities.Count; i++)
                {
                    AIWanderBehaviorComponent wanderComponent     = _entityManager.getComponent(levelUid, wanderBehaviorEntities[i], ComponentType.AIWanderBehavior) as AIWanderBehaviorComponent;
                    List <WaypointsComponent> waypointsComponents = _entityManager.getComponents <WaypointsComponent>(levelUid, ComponentType.Waypoints);

                    if (waypointsComponents.Count > 0)
                    {
                        WaypointsComponent waypointsComponent = aiBehaviorSystem.getWaypointsComponent(wanderComponent.waypointsUid, waypointsComponents);
                        Vector2            waypointPosition   = waypointsComponent.waypoints[wanderComponent.currentWaypointIndex];

                        _spriteBatch.Begin();
                        _spriteBatch.Draw(_circle, (waypointPosition - screenCenter) * _scale + _halfScreen, _circle.Bounds, Color.Red, 0f, new Vector2(_circle.Width, _circle.Height) / 2f, 0.02f, SpriteEffects.None, 0f);
                        _spriteBatch.End();
                    }
                }
            }
        }