示例#1
0
        public static PlayerShip getInstance()
        {
            if (instance == null)
            {
                instance = new PlayerShip(5);
            }

            return(instance);
        }
示例#2
0
        public PowerUp(char[] image, PlayerShip ship)
        {
            double tempPosX = Program.rnd.NextDouble();

            if (tempPosX < 0.1)
            {
                tempPosX += 0.1;
            }
            else
            if (tempPosX > 0.9)
            {
                tempPosX -= 0.1;
            }

            position.X         = tempPosX;
            position.Y         = 0;
            previousPosition.X = tempPosX - 1;
            previousPosition.Y = 0;
            velocity.X         = 0;
            velocity.Y         = 0.002;
            maxVelocity        = 0.01;
            size       = 0.0125 * 3;
            this.image = image;

            double value = Program.rnd.NextDouble();

            if (value < 0.2)
            {
                shape = 'S';
            }
            else if (value < 0.5)
            {
                if (ship.getMultipleBullets() < 5)
                {
                    shape = 'M';
                }
                else
                {
                    shape = 'P';
                }
            }
            else if (value < 0.8)
            {
                shape = 'F';
            }
            else if (value <= 1)
            {
                shape = 'P';
            }
        }
示例#3
0
        static public List <Bullet> Fire(MovingObject ship)
        {
            List <Bullet> backFire = new List <Bullet>();

            if (ship.GetType() == typeof(PlayerShip))
            {
                PlayerShip pShip          = (PlayerShip)ship;
                Position   bulletPosition = new Position(ship.getPosition(), 0, 0 - (ship.getSize() + 0.0125) / 2);
                int        bulletCount    = pShip.getMultipleBullets();

                if (bulletCount >= 1)
                {
                    backFire.Add(new Bullet(bulletPosition, new Velocity(0, -0.01), pShip.getPower(), '|'));
                }
                if (bulletCount >= 2)
                {
                    backFire.Add(new Bullet(bulletPosition, new Velocity(-0.007, -0.007), pShip.getPower(), '\\'));
                }
                if (bulletCount >= 3)
                {
                    backFire.Add(new Bullet(bulletPosition, new Velocity(0.007, -0.007), pShip.getPower(), '/'));
                }
                if (bulletCount >= 4)
                {
                    backFire.Add(new Bullet(bulletPosition, new Velocity(0.01, 0), pShip.getPower(), '¯'));
                }
                if (bulletCount >= 5)
                {
                    backFire.Add(new Bullet(bulletPosition, new Velocity(-0.01, 0), pShip.getPower(), '¯'));
                }
            }
            else
            {
                EnemyShip pShip          = (EnemyShip)ship;
                Position  bulletPosition = new Position(ship.getPosition(), 0, (ship.getSize() + 0.0125) / 2);
                backFire.Add(new Bullet(bulletPosition, new Velocity(0, 0.01), 1, '|'));
            }

            return(backFire);
        }
示例#4
0
        static Task keyboardListener()
        {
            ConsoleKeyInfo cki;
            PlayerShip     ship = (PlayerShip)playerShipList[0];

            while (true)
            {
                while (Console.KeyAvailable == false)
                {
                    Thread.Sleep(10);
                }

                lock (keyboardLock)
                {
                    cki = Console.ReadKey(true);
                    if (cki.Key == ConsoleKey.LeftArrow || cki.Key == ConsoleKey.A)
                    {
                        if (playerXMovement > -1)
                        {
                            playerXMovement--;
                        }
                    }
                    if (cki.Key == ConsoleKey.RightArrow || cki.Key == ConsoleKey.D)
                    {
                        if (playerXMovement < 1)
                        {
                            playerXMovement++;
                        }
                    }
                    if (cki.Key == ConsoleKey.UpArrow || cki.Key == ConsoleKey.W)
                    {
                        if (playerYMovement > -1 && gameStart)
                        {
                            playerYMovement--;
                        }

                        if (!gameStart)
                        {
                            menu.selectUp();
                        }
                    }
                    if (cki.Key == ConsoleKey.DownArrow || cki.Key == ConsoleKey.S)
                    {
                        if (playerYMovement < 1 && gameStart)
                        {
                            playerYMovement++;
                        }

                        if (!gameStart)
                        {
                            menu.selectDown();
                        }
                    }
                    if (cki.Key == ConsoleKey.Spacebar || cki.Key == ConsoleKey.Enter)
                    {
                        if (togglePlayerFire)
                        {
                            togglePlayerFire = false;
                        }
                        else
                        {
                            togglePlayerFire = true;
                        }

                        if (!gameStart)
                        {
                            menu.select();
                        }
                    }
                    if (cki.Key == ConsoleKey.Escape)
                    {
                        playerDead = false;

                        if (gameStart)
                        {
                            gameStart = false;
                        }
                        else
                        {
                            gameRunning = false;
                        }
                    }
                }
            }
        }
示例#5
0
        static void calculatePlayerMovement()
        {
            PlayerShip mObj = (PlayerShip)playerShipList[0];

            if (playerXMovement == -1)
            {
                mObj.moveLeft();
            }
            if (playerXMovement == 1)
            {
                mObj.moveRight();
            }
            if (playerYMovement == -1)
            {
                mObj.moveUp();
            }
            if (playerYMovement == 1)
            {
                mObj.moveDown();
            }

            double x     = mObj.getPosition().X;
            double y     = mObj.getPosition().Y;
            double xVel  = mObj.getVelocity().X;
            double yVel  = mObj.getVelocity().Y;
            double speed = mObj.getSpeed();

            mObj.setPreviousPosition(x, y);

            double newX = x + xVel;
            double newY = y + yVel;

            mObj.setVelocity(xVel * 0.9, yVel * 0.9);

            if (xVel < 0.002 && xVel > -0.002)
            {
                xVel = 0;
            }
            if (yVel < 0.002 && yVel > -0.002)
            {
                yVel = 0;
            }

            if (newX < 0)
            {
                newX = 0;
            }
            else if (newX > 1)
            {
                newX = 1;
            }
            if (newY < 0)
            {
                newY = 0;
            }
            else if (newY > 1)
            {
                newY = 1;
            }

            mObj.setPosition(newX, newY);

            for (int i = 1; i < playerShipList.Count; i++)
            {
                x = playerShipList[i].getPosition().X;
                y = playerShipList[i].getPosition().Y;

                playerShipList[i].setPreviousPosition(x, y);

                double velX = playerShipList[i].getVelocity().X;
                double velY = playerShipList[i].getVelocity().Y;

                newX = x + velX;
                newY = y + velY;

                playerShipList[i].setPosition(newX, newY);
            }

            if (powerUp != null)
            {
                x = powerUp.getPosition().X;
                y = powerUp.getPosition().Y;

                powerUp.setPreviousPosition(x, y);

                double velX = powerUp.getVelocity().X;
                double velY = powerUp.getVelocity().Y;

                newX = x + velX;
                newY = y + velY;

                powerUp.setPosition(newX, newY);
            }
        }
示例#6
0
 public static PlayerShip getReset()
 {
     instance = new PlayerShip(5);
     return(instance);
 }