Пример #1
0
        /*protected override void CheckCollision(Vector2 playerPosition)
         * {
         *  Vector2 origo = position + new Vector2((float)Math.Cos(angle) * (length / 2), (float)Math.Sin(angle) * (width / 2));
         *  test = Vector2.Zero;
         *  if (MathFunctions.getDistanceTo(origo, playerPosition) <= (length/2))
         *  {
         *      float checkAngle;
         *      Vector2 checkHit;
         *      checkAngle = MathFunctions.getAngleTo(Vector2.Zero, velocity) + MathFunctions.getAngleTo(origo, playerPosition);
         *      checkHit = new Vector2((float)Math.Cos(MathHelper.ToRadians(checkAngle))*(length*0.45f),(float)Math.Sin(MathHelper.ToRadians(checkAngle))*(width*0.45f));
         *      test = origo + checkHit;
         *      //if (checkHit.Length() <= MathFunctions.getDistanceTo(origo, playerPosition))
         *      if (checkHit.Length() >= MathFunctions.getDistanceTo(origo, playerPosition))
         *      {
         *          //setAlive(false);
         *      }
         *  }
         * }
         * ^*/
        protected override void CheckCollision(PlayerCharacter player)
        {
            origo      = position + new Vector2((float)Math.Cos(angle) * (length / 2), (float)Math.Sin(angle) * (length / 2));
            checkAngle = MathHelper.ToRadians(MathFunctions.getAngleTo(origo, player.getPosition()) - MathHelper.ToDegrees(angle));
            float distance = ((width / 2) * (length / 2)) / (float)Math.Sqrt((Math.Pow((length / 2) * Math.Sin(checkAngle), 2)) + (Math.Pow((width / 2) * Math.Cos(checkAngle), 2)));

            test = origo + new Vector2((float)Math.Cos(checkAngle - angle) * distance, (float)Math.Sin(checkAngle - angle) * distance);
            if (MathFunctions.getDistanceTo(origo, player.getPosition()) <= distance && player.getAlive() == true)
            {
                setAlive(false);
                player.takeHit();
            }
        }
Пример #2
0
        public override void Update(MainLoop mainLoop)
        {
            if (Input.IsKeyPressed(Keys.Escape))
            {
                if (enemy.getAlive() == true && player.getAlive() == true)
                {
                    pauseMenu.ToggleActive();
                }
            }

            if (pauseMenu.GetActive() == false)
            {
                if (Input.IsKeyPressed(Keys.Z))
                {
                    canShoot = true;
                }

                shootInterval--;

                if (enemy.getAlive() == false || player.getAlive() == false)
                {
                    endTimer--;
                    if (player.getAlive() == false)
                    {
                        playerBulletList.Clear();
                    }
                    if (enemy.getAlive() == false)
                    {
                        player.resetHit();
                    }
                }
                //UPDATES
                if (enemy.getAlive() == true)
                {
                    enemy.Update();
                }
                if (player.getAlive() == true)
                {
                    player.Update();
                }
                FXManager.Update();
                CommonData.UpdateData(player.getPosition().X, player.getPosition().Y);
                for (int i = bulletList.Count() - 1; i >= 0; i--)
                {
                    BulletBase bullet = bulletList[i];
                    bullet.Update(player);
                    if (enemy.getAlive() == false)
                    {
                        bullet.setAlive(false);
                    }
                    if (bullet.getAlive() == false)
                    {
                        bulletList.Remove(bullet);
                    }
                }
                for (int i = playerBulletList.Count() - 1; i >= 0; i--)
                {
                    PlayerBullet bullet = playerBulletList[i];
                    bullet.Update();
                    if (bullet.getAlive() == false)
                    {
                        playerBulletList.Remove(bullet);
                    }
                }
                //INPUTS
                if (Input.IsKeyPressed(Keys.X) && bombs > 0 && player.getAlive() == true)
                {
                    ClearBullets();
                    player.resetHit();
                    flashAlpha = 1;
                    bombs--;
                }
                if (Input.IsKeyDown(Keys.Z) && shootInterval <= 0 && canShoot == true && player.getAlive() == true)
                {
                    playerBulletList.Add(new PlayerBullet(new Vector2(player.getPosition().X - 27, player.getPosition().Y - 10)));
                    playerBulletList.Add(new PlayerBullet(new Vector2(player.getPosition().X - 9, player.getPosition().Y - 30)));
                    playerBulletList.Add(new PlayerBullet(new Vector2(player.getPosition().X + 9, player.getPosition().Y - 30)));
                    playerBulletList.Add(new PlayerBullet(new Vector2(player.getPosition().X + 27, player.getPosition().Y - 10)));
                    shootInterval = 5;
                }
                //ENDING
                if (endTimer == 0)
                {
                    if (player.getAlive() == true)
                    {
                        ScoreManager.SetScore(scene, bombs + 1);
                    }
                    pauseMenu.ToggleActive();
                }

                Console.WriteLine(bulletList.Count);
            }
            else
            {
                //PAUSEMENU
                pauseMenu.Update();
            }
            base.Update(mainLoop);
        }