Ejemplo n.º 1
0
 public void ProjectileDied(Projectile projectile)
 {
     if (projectile is SwordProjectile)
     {
         _swordProjectile = null;
     }
 }
Ejemplo n.º 2
0
        public override void Update(float dTime)
        {
            base.Update(dTime);

            float speed = Speed;

            if (_dashEndTime > Game.ElapsedTime)
            {
                speed *= DashMultiplier;
            }
            if (_spaceListener.IsPressed && _dashEndTime + DashCooldown < Game.ElapsedTime)
            {
                _dashEndTime = Game.ElapsedTime + DashTime;
            }

            if (Keyboard.IsKeyPressed(Keyboard.Key.D))
            {
                if (Game.ElapsedTime - lastDPressed < 0.15 && !isDPressed && _dashEndTime + DashCooldown < Game.ElapsedTime)
                {
                    _dashEndTime = Game.ElapsedTime + DashTime;
                }
                isDPressed   = true;
                lastDPressed = Game.ElapsedTime;
            }
            else
            {
                isDPressed = false;
            }
            if (Keyboard.IsKeyPressed(Keyboard.Key.A))
            {
                if (Game.ElapsedTime - lastAPressed < 0.15 && !isAPressed && _dashEndTime + DashCooldown < Game.ElapsedTime)
                {
                    _dashEndTime = Game.ElapsedTime + DashTime;
                }
                isAPressed   = true;
                lastAPressed = Game.ElapsedTime;
            }
            else
            {
                isAPressed = false;
            }
            if (Keyboard.IsKeyPressed(Keyboard.Key.W))
            {
                if (Game.ElapsedTime - lastWPressed < 0.15 && !isWPressed && _dashEndTime + DashCooldown < Game.ElapsedTime)
                {
                    _dashEndTime = Game.ElapsedTime + DashTime;
                }
                isWPressed   = true;
                lastWPressed = Game.ElapsedTime;
            }
            else
            {
                isWPressed = false;
            }
            if (Keyboard.IsKeyPressed(Keyboard.Key.S))
            {
                if (Game.ElapsedTime - lastSPressed < 0.15 && !isSPressed && _dashEndTime + DashCooldown < Game.ElapsedTime)
                {
                    _dashEndTime = Game.ElapsedTime + DashTime;
                }
                isSPressed   = true;
                lastSPressed = Game.ElapsedTime;
            }
            else
            {
                isSPressed = false;
            }
            Vector2 direction = GetDirection();

            direction.X *= speed * dTime;
            direction.Y *= speed * dTime;

            if (Math.Abs(direction.X) > float.Epsilon && Math.Abs(direction.Y) > float.Epsilon)
            {
                direction = direction / (float)Math.Sqrt(2);
            }

            Position = CollisionHelper.FindAccessablePoint(this, Position + direction);

            if (Mouse.IsButtonPressed(Mouse.Button.Left) && _swordProjectile == null)
            {
                _swordProjectile = new SwordProjectile(this, Position.AngleTo(Game.MousePosition), 0.2f);
                Game.Entities.Add(_swordProjectile);
            }

            if (_1ButtonListener.IsPressed)
            {
                FireballProjectile projectile = new FireballProjectile(this, (Game.MousePosition - Position).Normalize() * 75);
                Game.Entities.Add(projectile);
            }
        }