Example #1
0
        //You must have an Update.
        //Always read in deltaTime, and only deltaTime (it's the time that's passed since the last frame)
        //Use deltaTime for things like changing velocity or changing position from velocity
        //This is where you do anything that you want to happen every frame.
        //There is a chance that your system won't need to do anything in update. Still have it.
        public override void Update(float deltaTime)
        {
            foreach (Entity e in getApplicableEntities())
            {
                HealthComponent healthComp = ( HealthComponent )e.getComponent(GlobalVars.HEALTH_COMPONENT_NAME);
                if (healthComp.isDead())
                {
                    //Tell the death handler
                    deathHandler.handleDeath(e);
                }

                if (!healthComp.hasFullHealth())
                {
                    if (healthComp.timeSinceRecharge >= healthComp.rechargeTime)
                    {
                        healthComp.addToHealth(healthComp.rechargeAmt);
                        healthComp.timeSinceRecharge = 0;
                    }
                    else
                    {
                        healthComp.timeSinceRecharge += deltaTime;
                    }
                }

                if (healthComp.health > healthComp.maxHealth)
                {
                    healthComp.restoreHealth();
                }

                if (healthComp.invincibleTimer > 0)
                {
                    healthComp.invincibleTimer -= deltaTime;
                    if (healthComp.invincibleTimer < 0)
                    {
                        healthComp.removeInvincible();
                    }
                }
            }

            deathHandler.update(deltaTime);
        }