/// <summary>
 /// Damages Player
 /// </summary>
 /// <param name="amount">Amount of Damage to inflict</param>
 public bool Damage(ushort amount)
 {
     if (Health == 0)
     {
         return(false); // Already Dead
     }
     if (!isInvincible)
     {
         isInvincible = true;
         if (amount >= Health)
         {
             Die();
         }
         // Stop ignoring HealthPotions,
         Physics2D.IgnoreLayerCollision(gameObject.layer, (int)Mathf.Log(healthPotionLayer.value, 2), false);
         Health = (ushort)Mathf.Clamp(Health - amount, 0, Health);
         PopupFactory.CreateDamageUI(transform.position, amount, playerRenderer, Color.red, 50);
         healthChangeEvent?.Invoke(Health, maxHealth, (short)-amount);
         // Tween to Red
         LeanTween.value(gameObject, col => playerRenderer.SetSpriteColor(col), Color.white, Color.red, (invincibilityFrames / 60f) / 6f)
         .setLoopPingPong(3).setOnComplete(() => isInvincible = false);
         // Shake Screen
         ScreenShake.Instance.Shake(0.5f, 0.2f);
         // Stun Player
         MovementManager.Stun(0.2f);
         return(true);
     }
     return(false);
 }
예제 #2
0
        /// <summary>
        /// Show popups for each rectangle, using the now configured painter.
        /// </summary>
        private void showPopups(Rectangle[] rects, Rectangle bds, Rectangle visible, JComponent comp, JScrollPane view)
        {
            bool shown = false;

            for (int i = 0; i < rects.Length; i++)
            {
                Rectangle sect = rects[i];
                sect.translate(-bds.x, -bds.y);
                ImgComp part = painter.getPartial(sect, bds.x + rects[i].x < visible.x);
                Point   pos  = new Point(bds.x + rects[i].x, bds.y + rects[i].y);
                SwingUtilities.convertPointToScreen(pos, comp);
                if (comp is JList)
                {
                    //XXX off by one somewhere, only with JLists - where?
                    pos.y--;
                }
                if (pos.x > 0)
                {                 //Mac OS will reposition off-screen popups to x=0,
                    //so don't try to show them
                    popups[i] = PopupFactory.getPopup(view, part, pos.x, pos.y);
                    popups[i].show();
                    shown = true;
                }
            }
            if (shown)
            {
                setHideComponent(comp, view);
            }
            else
            {
                setHideComponent(null, null);                 //clear references
            }
        }
예제 #3
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
         DontDestroyOnLoad(instance);
     }
     else
     {
         Destroy(this);
     }
 }
예제 #4
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
         DontDestroyOnLoad(instance);
     }
     else
     {
         Destroy(this);
     }
     SetPopupDictionary();
 }
예제 #5
0
        //-------------------------------------------------------------------------

        public MainForm(InfoCollection infoCollection)
        {
            _infoCollection = infoCollection;

            _popups = PopupFactory.CreatePopups(this, infoCollection).ToList();

            InitialiseForms();
            SetupEvents();

            InitializeComponent();

            InitialiseMainForm();
        }
 /// <summary>
 /// Heals Player
 /// </summary>
 /// <param name="amount">Amount of Healing to inflict</param>
 public bool Heal(ushort amount)
 {
     if (Health == maxHealth)
     {
         return(false);
     }
     Health = (ushort)Mathf.Clamp(Health + amount, Health, maxHealth);
     if (Health == maxHealth)
     {
         // Ignore HealthPotions, since Health is full
         Physics2D.IgnoreLayerCollision(gameObject.layer, (int)Mathf.Log(healthPotionLayer.value, 2), true);
     }
     healthChangeEvent?.Invoke(Health, maxHealth, (short)amount);
     PopupFactory.CreateDamageUI(transform.position, amount, playerRenderer, Color.green, 50);
     return(true);
 }
예제 #7
0
 /// <summary>
 /// Damages this Enemy
 /// </summary>
 /// <param name="amount">Amount of Damage to inflict</param>
 /// <returns>True if Damage was inflicted</returns>
 public bool Damage(ushort amount)
 {
     if (Health == 0)
     {
         return(false); // Already Dead. Hit while animating death
     }
     if (amount >= Health)
     {
         Health = 0;
         Die();
     }
     else
     {
         Health -= amount;
     }
     enemyRenderer.SetSpriteColor(Color.red);
     PopupFactory.CreateDamageUI(transform.position, amount, enemyRenderer, Color.red);
     StartCoroutine(CoroutineMethods.RunDelayed(() => enemyRenderer.SetSpriteColor(Color.white), .1f));
     return(true);
 }