Example #1
0
        public static SceneryObject randomSceneryObject()
        {
            double        tempPosY     = ScreenView.rnd.NextDouble();
            SceneryObject randomObject = new SceneryObject(tempPosY, 0);

            return(randomObject);
        }
Example #2
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(" ");
                        }
                    }
                }
            }
        }