Beispiel #1
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);
            }
        }