public void Update(GameTime gameTime, float elapsed)
        {
            // Y-movement
            if (IsMovingDown)
            {
                CollisionRect.SetNewLocation(CollisionRect.TopLeft + new Vector2(0, Velocity * elapsed));
                MovedDownDistance += Velocity * elapsed;
                if (MovedDownDistance >= HEIGHT)
                {
                    MovedDownDistance = 0f;
                    IsMovingDown      = false;

                    // Perform one X-movement to get away from the edge of the screen to prevent turning around again
                    CollisionRect.SetNewLocation(CollisionRect.TopLeft + new Vector2((float)FaceDirection * Velocity * elapsed, 0));
                }
            }
            else
            {
                // X-movement
                CollisionRect.SetNewLocation(CollisionRect.TopLeft + new Vector2((float)FaceDirection * Velocity * elapsed, 0));
            }

            #region Shooting
            ShootDelay.Update(gameTime);
            if (ShootDelay.IsDone)
            {
                ShootDelay.Reset();
                if (Maths.Chance(ShootChance))
                {
                    Level.Instance.Projectiles.Add(new Projectile(CollisionRect.CenterLoc, null));
                }
            }
            #endregion
        }
Beispiel #2
0
        public void Update(GameTime gameTime, float elapsed)
        {
            CollisionRect.SetNewLocation(CollisionRect.TopLeft + new Vector2(MoveDir * Velocity * elapsed, 0));

            if ((MoveDir > 0 && CollisionRect.Left > Engine.Instance.Width) ||
                (MoveDir < 0 && CollisionRect.Right < 0))
            {
                IsDisposed = true;
            }
        }
Beispiel #3
0
        public void Update(GameTime gameTime, float elapsed)
        {
            // Move
            CollisionRect.SetNewLocation(CollisionRect.TopLeft + Velocity * MoveDir * elapsed);

            #region Check collision

            // Collision with walls
            foreach (Wall w in Level.Instance.Walls)
            {
                if (w.Collides(CollisionRect))
                {
                    IsDisposed = true;
                    Engine.Instance.Audio.PlaySound("enemyHit");
                    return;
                }
            }

            if (Owner == null)
            {
                // Outside screen
                if (CollisionRect.Top > Engine.Instance.Height)
                {
                    IsDisposed = true;
                    return;
                }

                // Collision with player(s)
                foreach (Player p in Level.Instance.Players)
                {
                    if (p.CollisionRect.Intersects(CollisionRect))
                    {
                        p.TakeDamage();
                        IsDisposed = true;
                        Level.Instance.Projectiles.Remove(this);
                        Engine.Instance.Audio.PlaySound("enemyHit");
                        return;
                    }
                }
            }
            else
            {
                // Outside screen
                if (CollisionRect.Bottom < 0)
                {
                    IsDisposed = true;
                    return;
                }

                // Collision with enemies
                foreach (Enemy e in Level.Instance.Enemies)
                {
                    if (e.CollisionRect.Intersects(CollisionRect))
                    {
                        Owner.Score += e.TakeDamage();
                        IsDisposed   = true;
                        Engine.Instance.Audio.PlaySound("enemyHit");
                        return;
                    }
                }

                // Collision with bonus enemy
                if (Level.Instance.BonusEnemy != null)
                {
                    if ((Level.Instance.BonusEnemy.CollisionRect.Intersects(CollisionRect)))
                    {
                        Level.Instance.BonusEnemy.IsDisposed = true;
                        Owner.Score += 300;
                        IsDisposed   = true;
                        Engine.Instance.Audio.PlaySound("bonusHit");
                        return;
                    }
                }
            }
            #endregion
        }