Example #1
0
        //You must have an Update.
        public override void Update(float deltaTime)
        {
            foreach (Entity e in getApplicableEntities())
            {
                PushableComponent pushComp = ( PushableComponent )e.getComponent(GlobalVars.PUSHABLE_COMPONENT_NAME);

                if (!pushComp.dontSlow && !pushComp.wasPushedLastFrame)
                {
                    VelocityComponent velComp = ( VelocityComponent )e.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);

                    if (Math.Abs(velComp.x) > slowRate)
                    {
                        if (velComp.x < 0)
                        {
                            velComp.x += slowRate;
                        }
                        else
                        {
                            velComp.x -= slowRate;
                        }
                    }
                    else if (velComp.x != 0)
                    {
                        velComp.x = 0;
                    }
                }

                if (pushComp.wasPushedLastFrame)
                {
                    pushComp.wasPushedLastFrame = false;
                }
            }
        }
Example #2
0
        public void manageSpeedyTimer(float deltaTime)
        {
            List <Entity> toRemove = new List <Entity>();

            foreach (Entity e in speedyTimers.Keys.ToList())
            {
                if (!(e.hasComponent(GlobalVars.VELOCITY_COMPONENT_NAME)))
                {
                    return;
                }

                VelocityComponent velComp = ( VelocityComponent )e.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);
                speedyTimers[e] -= deltaTime;
                if (speedyTimers[e] <= 0 || Math.Abs(velComp.x) < GlobalVars.SPEEDY_SPEED)
                {
                    //If it's not in the air, stop horizontal movement.
                    velComp.setVelocity(0, velComp.y);

                    toRemove.Add(e);

                    if (e is Player)
                    {
                        playerSpeedyEnabled = false;
                        if (!(e.hasComponent(GlobalVars.PLAYER_INPUT_COMPONENT_NAME)))
                        {
                            e.addComponent(new PlayerInputComponent(level.getPlayer()));
                        }
                    }

                    if (e.hasComponent(GlobalVars.PUSHABLE_COMPONENT_NAME))
                    {
                        PushableComponent pushComp = ( PushableComponent )e.getComponent(GlobalVars.PUSHABLE_COMPONENT_NAME);
                        pushComp.dontSlow = false;
                    }
                }
            }

            foreach (Entity remEnt in toRemove)
            {
                speedyTimers.Remove(remEnt);
            }
        }
Example #3
0
        //Handle any pushing that needs to be done when moved
        public void handlePushWithMovement(PositionComponent posComp, float newX, float newY, bool movementBlocked)
        {
            if (!(posComp.myEntity.hasComponent(GlobalVars.PUSHABLE_COMPONENT_NAME)))
            {
                return;
            }

            if (newX != posComp.x)
            {
                PushableComponent pushComp = ( PushableComponent )posComp.myEntity.getComponent(GlobalVars.PUSHABLE_COMPONENT_NAME);
                if (movementBlocked)
                {
                    if (newX < posComp.x)     //left
                    {
                        if (pushComp.horizMovementStopped == 0)
                        {
                            pushComp.horizMovementStopped = 1;
                        }
                        else if (pushComp.horizMovementStopped == 2)
                        {
                            pushComp.horizMovementStopped = 3;
                        }
                    }
                    if (newX > posComp.x)     //right
                    {
                        if (pushComp.horizMovementStopped == 0)
                        {
                            pushComp.horizMovementStopped = 2;
                        }
                        else if (pushComp.horizMovementStopped == 1)
                        {
                            pushComp.horizMovementStopped = 3;
                        }
                    }
                }
                else
                {
                    if (newX < posComp.x)
                    {
                        if (pushComp.horizMovementStopped == 3)
                        {
                            pushComp.horizMovementStopped = 2;
                        }
                        else if (pushComp.horizMovementStopped == 1)
                        {
                            pushComp.horizMovementStopped = 0;
                        }
                    }
                    if (newX > posComp.x)
                    {
                        if (pushComp.horizMovementStopped == 3)
                        {
                            pushComp.horizMovementStopped = 1;
                        }
                        else if (pushComp.horizMovementStopped == 2)
                        {
                            pushComp.horizMovementStopped = 0;
                        }
                    }
                }
            }
            if (newY != posComp.y)
            {
                PushableComponent pushComp = ( PushableComponent )posComp.myEntity.getComponent(GlobalVars.PUSHABLE_COMPONENT_NAME);
                if (movementBlocked)
                {
                    if (newY < posComp.y)     //up
                    {
                        if (pushComp.vertMovementStopped == 0)
                        {
                            pushComp.vertMovementStopped = 1;
                        }
                        else if (pushComp.vertMovementStopped == 2)
                        {
                            pushComp.vertMovementStopped = 3;
                        }
                    }
                    if (newY > posComp.y)     //right
                    {
                        if (pushComp.vertMovementStopped == 0)
                        {
                            pushComp.vertMovementStopped = 2;
                        }
                        else if (pushComp.vertMovementStopped == 1)
                        {
                            pushComp.vertMovementStopped = 3;
                        }
                    }
                }
                else
                {
                    if (newY < posComp.y)
                    {
                        if (pushComp.vertMovementStopped == 3)
                        {
                            pushComp.vertMovementStopped = 2;
                        }
                        else if (pushComp.vertMovementStopped == 1)
                        {
                            pushComp.vertMovementStopped = 0;
                        }
                    }
                    if (newY > posComp.y)
                    {
                        if (pushComp.vertMovementStopped == 3)
                        {
                            pushComp.vertMovementStopped = 1;
                        }
                        else if (pushComp.vertMovementStopped == 2)
                        {
                            pushComp.vertMovementStopped = 0;
                        }
                    }
                }
            }
        }