Ejemplo n.º 1
0
 public override bool ConsiderCollision(HitboxEntity entity)
 {
     if (entity is Fireball)
     {
         return(false);
     }
     return(base.ConsiderCollision(entity));
 }
Ejemplo n.º 2
0
        public override void OnCollision(HitboxEntity entity)
        {
            if (entity.EntityType == EntityType.Enemy)
            {
                int playerDamage = this.Player.GetBuff(BuffTypes.Damage) * 10;
                entity.Damage(damageConstant, playerDamage);

                if (entity is Enemy enemy)
                {
                    var damageOverTime = this.Player.GetBuff(BuffTypes.DOT) * 1;
                    enemy.Health.Regen.Value = -damageOverTime * 5f;
                    if (damageOverTime > 0)
                    {
                        enemy.DamageOverTime();
                    }
                }

                var lifestealAmount = this.Player.GetBuff(BuffTypes.Lifesteal) * 0.05f;
                this.Player.Health.Current.Value += (damageConstant + playerDamage) * lifestealAmount;

                var scene = SceneWithMap.CurrentScene;
                scene.AddScrollingMessage(new ScrollingTextMessage(
                                              (damageConstant + playerDamage).ToString(),
                                              entity.Position.X,
                                              entity.Position.Y,
                                              RGBA.Red
                                              ));
            }

            if (entity is Item item)
            {
                this.Player.SetBuff(item.buffType);

                //remove item after taking it
                var scene = SceneWithMap.CurrentScene;
                var map   = scene.map;
                map.RemoveEntity(entity);
            }

            if (entity is Flies fly)
            {
                var scene = SceneWithMap.CurrentScene;
                scene.map.RemoveEntity(fly);

                this.Player.Health.Current.Value += 10;
            }
        }
Ejemplo n.º 3
0
        public override void OnCollision(HitboxEntity entity)
        {
            if (entity is PlayerHitbox playerHitbox)
            {
                if (EventManager.CurrentTime - LastAttacked < 1000)
                {
                    return;
                }
                this.LastAttacked = EventManager.CurrentTime;

                int defenseMultiplier = playerHitbox.Player.GetBuff(Buffs.BuffTypes.Defense);
                playerHitbox.Player.Damage(2, -defenseMultiplier);

                var scene = SceneWithMap.CurrentScene;
                scene.AddScrollingMessage(new ScrollingTextMessage("-1", entity.Position.X, entity.Position.Y, RGBA.Purple));
            }
        }
Ejemplo n.º 4
0
        public (float x, float y) GetMapBorderCollisions(HitboxEntity entity)
        {
            float x = 0;
            float y = 0;

            if (entity.RealLeft < 125)
            {
                x = -entity.RealLeft + 125;
            }
            if (entity.RealTop < 200)
            {
                y = -entity.RealTop + 200;
            }
            if (entity.RealRight >= Map.Size_X - 125)
            {
                x = -(entity.RealRight - (Map.Size_X - 125));
            }
            if (entity.RealBottom >= Map.Size_Y - 150)
            {
                y = -(entity.RealBottom - (Map.Size_Y - 150));
            }

            return(x, y);
        }
Ejemplo n.º 5
0
        public (float x, float y) GetMaximumColllisions(HitboxEntity entity)
        {
            (float maxX, float maxY) = GetMapBorderCollisions(entity);

            if (maxX != 0 || maxY != 0)
            {
                return(maxX, maxY);
            }

            var entities = this._mapEntities.ToList();

            for (int i = 0; i < entities.Count; i++)
            {
                var otherEntity = entities[i];
                if (otherEntity == entity)
                {
                    continue;
                }
                var other = otherEntity as HitboxEntity;
                if (other == null)
                {
                    continue;
                }

                if (!other.ConsiderCollision(entity) && !entity.ConsiderCollision(other))
                {
                    continue;
                }

                float x          = 0;
                float y          = 0;
                bool  xCollision = false;
                bool  yCollision = false;

                // Border collisions.
                if (entity.RealLeft > other.RealLeft && entity.RealLeft < other.RealRight)
                {
                    x          = other.RealRight - entity.RealLeft;
                    xCollision = true;
                }
                if (entity.RealRight > other.RealLeft && entity.RealRight < other.RealRight)
                {
                    x          = other.RealLeft - entity.RealRight;
                    xCollision = true;
                }
                if (entity.RealTop < other.RealBottom && entity.RealTop > other.RealTop)
                {
                    y          = other.RealBottom - entity.RealTop;
                    yCollision = true;
                }
                if (entity.RealBottom > other.RealTop && entity.RealBottom < other.RealBottom)
                {
                    y          = other.RealTop - entity.RealBottom;
                    yCollision = true;
                }

                // Is the other inside our hitbox?
                if (!(yCollision || xCollision))
                {
                    if (entity.RealLeft < other.RealLeft && entity.RealRight > other.RealRight)
                    {
                        x          = -1;
                        xCollision = true;
                    }
                    if (entity.RealTop < other.RealTop && entity.RealBottom > other.RealBottom)
                    {
                        y          = -1;
                        yCollision = true;
                    }
                }

                // Swallowing collisions
                if (yCollision && !xCollision && entity.RealLeft < other.RealLeft && entity.RealRight > other.RealRight)
                {
                    xCollision = true;
                }
                if (xCollision && !yCollision && entity.RealTop < other.RealTop && entity.RealBottom > other.RealBottom)
                {
                    yCollision = true;
                }

                if (xCollision && yCollision)
                {
                    if (Math.Abs(x) > Math.Abs(maxX))
                    {
                        maxX = x;
                    }
                    if (Math.Abs(y) > Math.Abs(maxY))
                    {
                        maxY = y;
                    }
                    entity.OnCollision(other);
                    other.OnCollision(entity);
                }
            }

            if (Math.Abs(maxX) < Math.Abs(maxY))
            {
                maxY = 0;
            }
            else
            {
                maxX = 0;
            }
            return(maxX, maxY);
        }