예제 #1
0
        public void Draw(ScreenCanvas screenCanvas, int iPictX, int iPictY)
        {
            const int iWriteTop     = 100;
            const int iLetterWidth  = 200;
            const int iLetterHeight = iLetterWidth * 2;
            String    strScore;

            // Draw Score + Ships left justified
            strScore = iScore.ToString("000000") + " ";
            if (iShips > 10)
            {
                strScore += "^x" + (iShips - 1);
            }
            else
            {
                for (int i = 0; i < iShips - 1; i++)
                {
                    strScore += "^";
                }
            }
            TextDraw.DrawText(screenCanvas, strScore, TextDraw.Justify.LEFT,
                              iWriteTop, iLetterWidth, iLetterHeight, iPictX, iPictY);

            // Draw HiScore Centered
            strScore = iHiScore.ToString("000000");
            TextDraw.DrawText(screenCanvas, strScore, TextDraw.Justify.CENTER,
                              iWriteTop, iLetterWidth, iLetterHeight, iPictX, iPictY);
        }
예제 #2
0
        public static void DrawText(ScreenCanvas screenCanvas, string strText,
                                    Justify justification, int iTopLoc,
                                    int iLetterWidth, int iLetterHeight,
                                    int iPictX, int iPictY)
        {
            int iPrintStart;

            switch (justification)
            {
            case Justify.LEFT:
                iPrintStart = 100;
                break;

            case Justify.CENTER:
                iPrintStart = (int)((iMaxX - strText.Length * iLetterWidth) / 2.0);
                break;

            case Justify.RIGHT:
                iPrintStart = iMaxX - 100 - strText.Length * iLetterWidth;
                break;

            default:
                return;
            }

            for (int i = 0; i < strText.Length; i++)
            {
                TextDraw.DrawLetter(screenCanvas, strText[i],
                                    (int)((iPrintStart + i * iLetterWidth) / (double)iMaxX * iPictX),
                                    (int)(iTopLoc / (double)iMaxY * iPictY),
                                    (int)(iLetterWidth / (double)iMaxX * iPictX),
                                    (int)(iLetterHeight / (double)iMaxY * iPictY));
            }
        }
예제 #3
0
        public void DrawScreen(ScreenCanvas screenCanvas, int iPictX, int iPictY)
        {
            // Flip back and forth between "Game Over" and "Asteroids"
            if ((iLetterSize > 1000) || (iLetterSize < 40))
            {
                iIncrement = -iIncrement;
                if (iLetterSize < 40)
                {
                    if (strTitle == "GAME OVER")
                    {
                        strTitle = "ASTEROIDS";
                    }
                    else
                    {
                        strTitle = "GAME OVER";
                    }
                }
            }
            iLetterSize += iIncrement;
            TextDraw.DrawText(screenCanvas, strTitle, TextDraw.Justify.CENTER,
                              iMaxY / 2 - iLetterSize, iLetterSize, iLetterSize * 2, iPictX, iPictY);

            // Draw copyright notice
            const int iTitleWidth  = 200;
            const int iTitleHeight = iTitleWidth * 2;

            TextDraw.DrawText(screenCanvas, strCopyright, TextDraw.Justify.CENTER,
                              iMaxY - iTitleWidth * 3, iTitleWidth, iTitleHeight, iPictX, iPictY);

            // Draw the asteroid belt
            asteroids.Move();
            asteroids.Draw(screenCanvas, iPictX, iPictY);
        }
예제 #4
0
        public void DrawScreen(ScreenCanvas sc, int iPictX, int iPictY, ref Score score)
        {
            Point ptCheck = new Point(0);

            if (paused)
            {
                // Pause flashes on and off
                if (iPauseTimer > PAUSE_INTERVAL / 2)
                {
                    TextDraw.DrawText(sc, "PAUSE", TextDraw.Justify.CENTER,
                                      iMaxY / 3, 200, 400, iPictX, iPictY);
                }
                if (--iPauseTimer < 0)
                {
                    iPauseTimer = PAUSE_INTERVAL;
                }
            }
            else // Do all game processing if game is not paused
            {
                // If no ship displaying, after explosions are done
                // get a new one - or end the game
                if (!ship.IsAlive() && (explosions.Count() == 0))
                {
                    if (!score.HasReserveShips())
                    {
                        // Game over
                        inProcess = false;
                    }
                    else
                    {
                        if (asteroids.IsCenterSafe())
                        {
                            score.GetNewShip();
                            ship = new Ship(true);
                        }
                    }
                }

                // Create a new asteroid belt if
                // no explosions and no asteroids
                if ((explosions.Count() == 0) && (asteroids.Count() == 0))
                {
                    asteroids = new AsteroidBelt(++iLevel);
                }

                // Move all objects
                ship.Move();
                foreach (Bullet bullet in shipBullets)
                {
                    bullet.Move();
                }
                asteroids.Move();
                explosions.Move();

                // Check bullets for collisions
                foreach (Bullet bullet in shipBullets)
                {
                    if (bullet.AcquireLoc(ref ptCheck) && CheckPointInAsteroid(ptCheck, ref score))
                    {
                        explosions.AddExplosion(ptCheck);
                        bullet.Disable();
                    }
                }

                // Check ship for collisions
                if (ship.IsAlive())
                {
                    foreach (Point ptInShip in ship.pointsTransformed)
                    {
                        ptCheck.X = ptInShip.X + ship.GetCurrLoc().X;
                        ptCheck.Y = ptInShip.Y + ship.GetCurrLoc().Y;
                        if (CheckPointInAsteroid(ptCheck, ref score))
                        {
                            ExplodeShip();
                            break;
                        }
                    }
                }
            }

            // Draw all objects
            ship.Draw(sc, iPictX, iPictY);
            foreach (Bullet bullet in shipBullets)
            {
                bullet.Draw(sc, iPictX, iPictY);
            }

            asteroids.Draw(sc, iPictX, iPictY);
            explosions.Draw(sc, iPictX, iPictY);

            // Draw the score
            score.Draw(sc, iPictX, iPictY);
        }