Ejemplo n.º 1
0
        public override void Update(GameTime gameTime, Levels.Level level)
        {
            _timeFromCreation += gameTime.ElapsedGameTime;

            if (level.Map.Collides(CollisionRect, false, true))
            {
                level.RemoveEntity(this);
                return;
            }

            if (HitEntity != null)
            {
                SoundManager.PlaySound("onfire");
                if (gameTime.TotalGameTime > _entHitTime + _maxHitTime)
                {
                    level.RemoveEntity(this);
                }

                return;
            }

            var timeFactor = gameTime.ElapsedGameTime.TotalMilliseconds / 1000;

            Position += CurrentDirection * (float)timeFactor * Speed;

            foreach (var ent in level.CollidesWith(CollisionRect).Distinct())
            {
                if (ent != this && ent != Parent && ent.Health != null)
                {
                    _entHitTime = gameTime.TotalGameTime;
                    HitEntity   = ent;

                    var direction = VectorHelper.AngleToV2(Angle, 5);
                    direction = new Vector2(-direction.Y, direction.X);

                    ent.Hit(this, gameTime, level, direction);
                    if (HitEntity != null)
                    {
                        OverlapEntities = false;
                        Position        = ent.CenterPosition;
                        Angle           = 0;
                        return;
                    }
                    else
                    {
                        _timeFromCreation = TimeSpan.Zero;
                    }
                }
            }

            if (_timeFromCreation > MaxFlyTime)
            {
                level.RemoveEntity(this);
            }
        }
Ejemplo n.º 2
0
 public override void Update(GameTime gameTime, Levels.Level level)
 {
     foreach (Entity en in level.CollidesWith(this.CollisionRect))
     {
         //TODO: Remove en is Player
         if (Teleportable.Split(';').Contains(en.Category))
         {
             level.GoToDungeon(en, Dungeon);
         }
     }
     //base.Update(gameTime, level);
 }
Ejemplo n.º 3
0
 public override void Update(Microsoft.Xna.Framework.GameTime gameTime, Levels.Level level)
 {
     foreach (var ent in level.CollidesWith(CollisionRect).Where(e => !e.IsDead).Distinct())
     {
         if (Parent == null)
         {
             if (ent.Health != null && ent.Health.Quantity < ent.Health.Maximum)
             {
                 ent.Health.Quantity += PickupCount;
                 level.RemoveEntity(this);
             }
             return;
         }
     }
     base.Update(gameTime, level);
 }
Ejemplo n.º 4
0
        public override void Update(GameTime gameTime, Levels.Level level)
        {
            var col = CollisionRect;
            var ent = level.CollidesWith(new Rectangle(
                                             x: (int)(col.X + CurrentDirection.X * 8),
                                             y: (int)(col.Y + CurrentDirection.Y * 8),
                                             width: col.Width,
                                             height: col.Height)).FirstOrDefault(e => e != this);

            if (ent != null)
            {
                ent.Hit(this, gameTime, level, CurrentDirection);
            }

            base.Update(gameTime, level);
        }
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime, Levels.Level level)
        {
            if (GameStateManager.CurrentState.ContainersUsed.Contains(_id))
            {
                level.RemoveEntity(this);
                return;
            }

            if (level.CollidesWith(CollisionRect).Where(e => e.Category == "Player" && !e.IsDead).Any())
            {
                if (Parent == null)
                {
                    foreach (var p in LevelCollection.CurrentPlayers)
                    {
                        p.Health.Maximum += PickupCount;
                        p.Health.Fill();
                    }
                    level.RemoveEntity(this);
                    GameStateManager.CurrentState.ContainersUsed.Add(_id);
                    return;
                }
            }
            base.Update(gameTime, level);
        }
Ejemplo n.º 6
0
        public override void Update(GameTime gameTime, Levels.Level level)
        {
            if (CurrentDirection != Vector2.Zero)
            {
                Angle = (float)(Math.Atan2(-CurrentDirection.X, CurrentDirection.Y) + _spriteAngle);
            }

            _timeFromCreation += gameTime.ElapsedGameTime;

            if (level.Map.Collides(CollisionRect, false, true) && CurrentDirection != Vector2.Zero)
            {
                if (level.Map.IsOutsideBorders(CollisionRect))
                {
                    level.RemoveEntity(this);
                }
                else
                {
                    Dettach(level, removeFromLevel: Parent == null || Parent.Category != "Player");
                }
                return;
            }

            if (HitEntity != null)
            {
                if (gameTime.TotalGameTime > _entHitTime + _maxHitTime || !level.ContainsEntity(HitEntity))
                {
                    Dettach(level, HitEntity.Arrows == null || HitEntity.Health <= 0);
                }
                else
                {
                    Position = HitEntity.CenterPosition - _hitLocation;
                }

                return;
            }

            if (Parent != null)
            {
                var timeFactor = gameTime.ElapsedGameTime.TotalMilliseconds / 1000;
                Position += CurrentDirection * (float)timeFactor * Speed;
            }

            foreach (var ent in level.CollidesWith(CollisionRect).Distinct())
            {
                if (Parent == null)
                {
                    if (ent.Arrows != null && ent.Arrows.Quantity < ent.Arrows.Maximum)
                    {
                        ent.Arrows.Quantity += PickupCount;
                        level.RemoveEntity(this);
                    }
                    return;
                }

                if (ent != this && ent != Parent && ent.Health != null)
                {
                    _entHitTime = gameTime.TotalGameTime;
                    HitEntity   = ent;

                    var direction = VectorHelper.AngleToV2(Angle, 5);
                    direction = new Vector2(-direction.Y, direction.X);

                    ent.Hit(this, gameTime, level, direction);
                    _hitLocation = ent.CenterPosition - Position - CurrentDirection;
                    return;
                }
            }
        }