Beispiel #1
0
        public static void enemyShot(EnemyShip ship)
        {
            Vector      bulletPosition = new Vector(ship.getPosition(), 0, (ship.getSize() + 0.0125) / 2);
            EnemyBullet bullet         = new EnemyBullet(bulletPosition, new Vector(0, 0.01), 1);

            bullet.setStrategy(ScreenView.MSStraight);
            enemyBulletList.Add(bullet);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        // drawing moving object here ---------------------------------------------------------
        static void drawMovingObject(MovingObject mObj)
        {
            double x  = mObj.getPosition().X;
            double y  = mObj.getPosition().Y;
            double pX = mObj.getPreviousPosition().X;
            double pY = mObj.getPreviousPosition().Y;

            if (x == pX && y == pY)
            {
                return;
            }

            double size               = screenWidth * mObj.getSize();
            double XstartingPoint     = Math.Round(screenWidth * x - size / 2, MidpointRounding.AwayFromZero);
            double YstartingPoint     = Math.Round(screenHeight * y - size / 2, MidpointRounding.AwayFromZero);
            double prevXstartingPoint = Math.Round(screenWidth * pX - size / 2, MidpointRounding.AwayFromZero);
            double prevYstartingPoint = Math.Round(screenHeight * pY - size / 2, MidpointRounding.AwayFromZero);
            int    drawingX           = (int)XstartingPoint;
            int    drawingY           = (int)YstartingPoint;
            int    previousDrawingX   = (int)prevXstartingPoint;
            int    previousDrawingY   = (int)prevYstartingPoint;

            if (drawingX == previousDrawingX && drawingY == previousDrawingY)
            {
                return;
            }

            if (mObj.GetType() == typeof(Bullet))
            {
                Bullet b = (Bullet)mObj;

                if (drawingX > 0 && drawingY > 0 && drawingX < screenWidth - 1 && drawingY < screenWidth - 1)
                {
                    Console.SetCursorPosition(drawingX, drawingY);
                    Console.Write(b.getShape());
                }

                if (previousDrawingX > 0 && previousDrawingY > 0 && previousDrawingX < screenWidth - 1 && previousDrawingY < screenWidth - 1)
                {
                    Console.SetCursorPosition(previousDrawingX, previousDrawingY);
                    Console.Write(" ");
                }
            }
            else if (mObj.GetType() == typeof(SceneryObject) && mObj.getImage() == null)
            {
                SceneryObject sb = (SceneryObject)mObj;

                if (drawingX > 0 && drawingY > 0 && drawingX < screenWidth - 1 && drawingY < screenWidth - 1)
                {
                    Console.SetCursorPosition(drawingX, drawingY);
                    Console.Write(sb.getShape());
                }

                if (previousDrawingX > 0 && previousDrawingY > 0 && previousDrawingX < screenWidth - 1 && previousDrawingY < screenWidth - 1)
                {
                    Console.SetCursorPosition(previousDrawingX, previousDrawingY);
                    Console.Write(" ");
                }
            }
            else
            {
                EnemyShip ship = null;
                if (mObj.GetType() == typeof(EnemyShip))
                {
                    ship = (EnemyShip)mObj;
                }

                char[] skin = mObj.getImage();
                for (int i = 0; i < (int)size; i++)
                {
                    drawingX = (int)XstartingPoint + i;
                    if (drawingX <= 0 || drawingX >= screenWidth - 1)
                    {
                        continue;
                    }

                    for (int j = 0; j < (int)size; j++)
                    {
                        drawingY = (int)YstartingPoint + j;
                        if (drawingY <= 0 || drawingY >= screenHeight - 1)
                        {
                            continue;
                        }

                        Console.SetCursorPosition(drawingX, drawingY);
                        if (ship != null && i == (int)(size / 2) && j == (int)(size / 2))
                        {
                            if (ship.getHitpoints() <= 9)
                            {
                                Console.Write(ship.getHitpoints());
                            }
                            else
                            {
                                Console.Write('*');
                            }
                        }
                        else if (mObj.GetType() == typeof(PowerUp) && i == (int)(size / 2) && j == (int)(size / 2))
                        {
                            Console.Write(((PowerUp)mObj).getShape());
                        }
                        else
                        {
                            Console.Write(skin[j * (int)size + i]);
                        }
                    }
                }

                int drawnXDown = (int)Math.Round(screenWidth * x - size / 2, MidpointRounding.AwayFromZero);
                int drawnXUp   = (int)Math.Round(screenWidth * x + size / 2, MidpointRounding.AwayFromZero);
                int drawnYDown = (int)Math.Round(screenHeight * y - size / 2, MidpointRounding.AwayFromZero);
                int drawnYUp   = (int)Math.Round(screenHeight * y + size / 2, MidpointRounding.AwayFromZero);

                for (int i = 0; i < (int)size; i++)
                {
                    previousDrawingX = (int)prevXstartingPoint + i;
                    if (previousDrawingX <= 0 || previousDrawingX >= screenWidth - 1)
                    {
                        continue;
                    }

                    for (int j = 0; j < (int)size; j++)
                    {
                        previousDrawingY = (int)prevYstartingPoint + j;
                        if (previousDrawingY <= 0 || previousDrawingY >= screenHeight - 1)
                        {
                            continue;
                        }

                        if (previousDrawingX < drawnXDown || previousDrawingX >= drawnXUp ||
                            previousDrawingY < drawnYDown || previousDrawingY >= drawnYUp)
                        {
                            Console.SetCursorPosition(previousDrawingX, previousDrawingY);
                            Console.Write(" ");
                        }
                    }
                }
            }
        }