Ejemplo n.º 1
0
        public PlayerHUD(GameObject parent)
        {
            health = parent.GetComponent <Health>();
            gun    = parent.GetComponent <Gun>();

            health.OnDamageTaken += HealthChanged;
            gun.OnAmmoChange     += GunChange;
            gun.OnWeaponChange   += GunChange;
            gun.OnReloadProgress += UpdateReloadBar;

            healthBarWidget.SetProgress(health.GetPercentage());
            WidgetManager.AddWidget(healthBarWidget);
            WidgetManager.AddWidget(healthBarBackground);

            currentGunWidget = gunIcons[typeof(PistolBullet)];
            var iconEnd = currentGunWidget.GetScreenEndPoint();

            ammoDisplayWidget = new TextWidget(new Vector2(iconEnd.X + 0.01f, currentGunWidget.position.Y));
            WidgetManager.AddWidget(ammoDisplayWidget);

            float barSize = iconEnd.X - currentGunWidget.position.X;

            reloadBarWidget = new ProgressBarWidget(new Vector2(currentGunWidget.position.X, iconEnd.Y + 0.01f), new Vector2(barSize, 0))
            {
                Texture = SpriteContainer.Instance.GetImage("reloadTime"), SourceRectangle = new Rectangle(0, 0, 80, 4)
            };
            reloadBarWidget.SetProgress(0);
            WidgetManager.AddWidget(reloadBarWidget);

            GunChange(gun);
        }
Ejemplo n.º 2
0
 private void UpdateReloadBar(Gun gun)
 {
     reloadBarWidget.SetProgress(gun.GetReloadLeft());
 }