コード例 #1
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));
            }
        }
コード例 #2
0
 public void Draw(ScreenCanvas sc, int iPictX, int iPictY)
 {
     foreach (Explosion explosion in explosions)
     {
         explosion.Draw(sc, iPictX, iPictY);
     }
 }
コード例 #3
0
ファイル: Score.cs プロジェクト: timdetering/CSharpAsteroids
        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);
        }
コード例 #4
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);
        }
コード例 #5
0
 public void Draw(ScreenCanvas sc, int iPictX, int iPictY)
 {
     foreach (Asteroid asteroid in asteroids)
     {
         asteroid.Draw(sc, iPictX, iPictY);
     }
 }
コード例 #6
0
ファイル: Bullet.cs プロジェクト: timdetering/CSharpAsteroids
 public new void Draw(ScreenCanvas sc, int iPictX, int iPictY)
 {
     // only draw things that are not available
     if (!Available())
     {
         base.Draw(sc, iPictX, iPictY, GetRandomFireColor());
     }
 }
コード例 #7
0
 public new void Draw(ScreenCanvas sc, int iPictX, int iPictY)
 {
     // only draw things that are not available
     if (aSize != ASTEROID_SIZE.DNE)
     {
         //Rotate(rotateSpeed);
         base.Draw(sc, iPictX, iPictY);
     }
 }
コード例 #8
0
 protected void DrawPolyToSC(ArrayList alPoly, ScreenCanvas sc, int iPictX, int iPictY,
                             System.Drawing.Pen penColor)
 {
     Point[] ptsPoly = new Point[alPoly.Count];
     for (int i = 0; i < alPoly.Count; i++)
     {
         ptsPoly[i].X = (int)((currLoc.X + ((Point)alPoly[i]).X) / (double)iMaxX * iPictX);
         ptsPoly[i].Y = (int)((currLoc.Y + ((Point)alPoly[i]).Y) / (double)iMaxY * iPictY);
     }
     sc.AddPolygon(ptsPoly, penColor);
 }
コード例 #9
0
        public override void Draw(ScreenCanvas sc, int iPictX, int iPictY)
        {
            for (int i = 0; i < NUM_EXP_POINTS; i++)
            {
                Point ptDraw = new Point((int)(ptPoints[i].X / (double)iMaxX * iPictX),
                                         (int)(ptPoints[i].Y / (double)iMaxY * iPictY));

                Point ptDraw2 = new Point(ptDraw.X + 1, ptDraw.Y + 1);

                sc.AddLine(ptDraw, ptDraw2, GetRandomFireColor());
            }
        }
コード例 #10
0
        private void frmAsteroids_Activated(object sender, EventArgs e)
        {
            if (gameStatus == Modes.PREP)
            {
                screenCanvas = new ScreenCanvas();
                score        = new Score();
                gameStatus   = Modes.TITLE;
                currTitle    = new TitleScreen();
                currTitle.InitTitleScreen();

                // Timers for flipping display and playing sounds
                SetFlipTimer();
                SetSoundsTimer();

                // Handle the game
                do
                {
                    Application.DoEvents();
                    Thread.Sleep(0);
                } while (gameStatus != Modes.EXIT);
            }
        }
コード例 #11
0
 public new void Draw(ScreenCanvas sc, int iPictX, int iPictY)
 {
     switch (state)
     {
     case SHIP_STATE.ALIVE:
         base.Draw(sc, iPictX, iPictY);
         if (bThrustOn)
         {
             // We have points transformed
             // so...  we know where the bottom of the ship is
             ArrayList alPoly = new ArrayList();
             alPoly.Capacity = 3;
             alPoly.Add(pointsTransformed[iPointThrust1]);
             alPoly.Add(pointsTransformed[iPointThrust2]);
             int iThrustSize = rndGen.Next(200) + 100; // random thrust effect
             alPoly.Add(new Point((((Point)pointsTransformed[iPointThrust1]).X + ((Point)pointsTransformed[iPointThrust2]).X) / 2 + (int)(iThrustSize * Math.Sin(radians)),
                                  (((Point)pointsTransformed[iPointThrust1]).Y + ((Point)pointsTransformed[iPointThrust2]).Y) / 2 + (int)(-iThrustSize * Math.Cos(radians))));
             // Draw thrust directly to ScreenCanvas
             // it's not really part of the ship object
             DrawPolyToSC(alPoly, sc, iPictX, iPictY, GetRandomFireColor());
         }
         break;
     }
 }
コード例 #12
0
        static private void DrawLetter(ScreenCanvas screenCanvas, char chDraw,
                                       int letterLeft, int letterTop, int letterWidth, int letterHeight)
        {
            int newLeft    = (int)(letterLeft + letterWidth * .2);
            int newTop     = (int)(letterTop + letterHeight * .1);
            int halfRight  = (newLeft + letterLeft + letterWidth) / 2;
            int halfDown   = (newTop + letterTop + letterHeight) / 2;
            int rightSide  = letterLeft + letterWidth;
            int bottomSide = letterTop + letterHeight;

            switch (chDraw)
            {
            case '^':/* Ship */
                int pointInUp    = (int)(bottomSide - letterHeight * .2);
                int pointInLeft  = (int)(newLeft + letterWidth * .25);
                int pointInRight = (int)(rightSide - letterWidth * .25);
                screenCanvas.AddLine(new Point(halfRight, newTop), new Point(rightSide, bottomSide));
                screenCanvas.AddLineTo(new Point(pointInRight, pointInUp));
                screenCanvas.AddLineTo(new Point(pointInLeft, pointInUp));
                screenCanvas.AddLineTo(new Point(newLeft, bottomSide));
                screenCanvas.AddLineTo(new Point(halfRight, newTop));
                break;

            case 'O':
            case '0':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(rightSide, newTop));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                screenCanvas.AddLineTo(new Point(newLeft, bottomSide));
                screenCanvas.AddLineTo(new Point(newLeft, newTop));
                break;

            case '1':
            case 'I':
                screenCanvas.AddLine(new Point(halfRight, newTop), new Point(halfRight, bottomSide));
                break;

            case '2':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(rightSide, newTop));
                screenCanvas.AddLineTo(new Point(rightSide, halfDown));
                screenCanvas.AddLineTo(new Point(newLeft, halfDown));
                screenCanvas.AddLineTo(new Point(newLeft, bottomSide));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                break;

            case '3':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(rightSide, newTop));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                screenCanvas.AddLineTo(new Point(newLeft, bottomSide));
                screenCanvas.AddLine(new Point(newLeft, halfDown), new Point(rightSide, halfDown));
                break;

            case '4':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(newLeft, halfDown));
                screenCanvas.AddLineTo(new Point(rightSide, halfDown));
                screenCanvas.AddLine(new Point(rightSide, newTop), new Point(rightSide, bottomSide));
                break;

            case '5':
            case 'S':
                screenCanvas.AddLine(new Point(rightSide, newTop), new Point(newLeft, newTop));
                screenCanvas.AddLineTo(new Point(newLeft, halfDown));
                screenCanvas.AddLineTo(new Point(rightSide, halfDown));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                screenCanvas.AddLineTo(new Point(newLeft, bottomSide));
                break;

            case '6':
                screenCanvas.AddLine(new Point(rightSide, newTop), new Point(newLeft, newTop));
                screenCanvas.AddLineTo(new Point(newLeft, bottomSide));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                screenCanvas.AddLineTo(new Point(rightSide, halfDown));
                screenCanvas.AddLineTo(new Point(newLeft, halfDown));
                break;

            case '7':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(rightSide, newTop));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                break;

            case '8':
            case 'B':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(rightSide, newTop));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                screenCanvas.AddLineTo(new Point(newLeft, bottomSide));
                screenCanvas.AddLineTo(new Point(newLeft, newTop));
                screenCanvas.AddLine(new Point(newLeft, halfDown), new Point(rightSide, halfDown));
                break;

            case '9':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(rightSide, newTop));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                screenCanvas.AddLineTo(new Point(newLeft, bottomSide));
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(newLeft, halfDown));
                screenCanvas.AddLineTo(new Point(rightSide, halfDown));
                break;

            case 'x':
                screenCanvas.AddLine(new Point(newLeft, halfDown), new Point(rightSide, bottomSide));
                screenCanvas.AddLine(new Point(rightSide, halfDown), new Point(newLeft, bottomSide));
                break;

            case 'A':
                screenCanvas.AddLine(new Point(newLeft, bottomSide), new Point(newLeft, halfDown));
                screenCanvas.AddLineTo(new Point(halfRight, newTop));
                screenCanvas.AddLineTo(new Point(rightSide, halfDown));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                screenCanvas.AddLine(new Point(newLeft, halfDown), new Point(rightSide, halfDown));
                break;

            // case 'B' handled by '8'
            case 'C':
                screenCanvas.AddLine(new Point(rightSide, newTop), new Point(newLeft, newTop));
                screenCanvas.AddLineTo(new Point(newLeft, bottomSide));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                break;

            case 'D':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(halfRight, newTop));
                screenCanvas.AddLineTo(new Point(rightSide, halfDown));
                screenCanvas.AddLineTo(new Point(halfRight, bottomSide));
                screenCanvas.AddLineTo(new Point(newLeft, bottomSide));
                screenCanvas.AddLineTo(new Point(newLeft, newTop));
                break;

            case 'E':
                screenCanvas.AddLine(new Point(rightSide, newTop), new Point(newLeft, newTop));
                screenCanvas.AddLineTo(new Point(newLeft, bottomSide));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                screenCanvas.AddLine(new Point(newLeft, halfDown), new Point(rightSide, halfDown));
                break;

            case 'F':
                screenCanvas.AddLine(new Point(rightSide, newTop), new Point(newLeft, newTop));
                screenCanvas.AddLineTo(new Point(newLeft, bottomSide));
                screenCanvas.AddLine(new Point(newLeft, halfDown), new Point(rightSide, halfDown));
                break;

            case 'G':
                screenCanvas.AddLine(new Point(rightSide, newTop), new Point(newLeft, newTop));
                screenCanvas.AddLineTo(new Point(newLeft, bottomSide));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                screenCanvas.AddLineTo(new Point(rightSide, halfDown));
                screenCanvas.AddLineTo(new Point(halfRight, halfDown));
                break;

            case 'H':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(newLeft, bottomSide));
                screenCanvas.AddLine(new Point(rightSide, newTop), new Point(rightSide, bottomSide));
                screenCanvas.AddLine(new Point(newLeft, halfDown), new Point(rightSide, halfDown));
                // case 'I' handled by '1'
                break;

            case 'J':
                screenCanvas.AddLine(new Point(rightSide, newTop), new Point(rightSide, bottomSide));
                screenCanvas.AddLineTo(new Point(halfRight, bottomSide));
                screenCanvas.AddLineTo(new Point(newLeft, halfDown));
                break;

            case 'K':
                screenCanvas.AddLine(new Point(newLeft, bottomSide), new Point(newLeft, newTop));
                screenCanvas.AddLine(new Point(rightSide, newTop), new Point(newLeft, halfDown));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                break;

            case 'L':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(newLeft, bottomSide));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                break;

            case 'M':
                screenCanvas.AddLine(new Point(newLeft, bottomSide), new Point(newLeft, newTop));
                screenCanvas.AddLineTo(new Point(halfRight, halfDown));
                screenCanvas.AddLineTo(new Point(rightSide, newTop));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                break;

            case 'N':
                screenCanvas.AddLine(new Point(newLeft, bottomSide), new Point(newLeft, newTop));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                screenCanvas.AddLineTo(new Point(rightSide, newTop));
                break;

            // case 'O' handled by '0'
            case 'P':
                screenCanvas.AddLine(new Point(newLeft, bottomSide), new Point(newLeft, newTop));
                screenCanvas.AddLineTo(new Point(rightSide, newTop));
                screenCanvas.AddLineTo(new Point(rightSide, halfDown));
                screenCanvas.AddLineTo(new Point(newLeft, halfDown));
                break;

            case 'Q':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(rightSide, newTop));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                screenCanvas.AddLineTo(new Point(newLeft, bottomSide));
                screenCanvas.AddLineTo(new Point(newLeft, newTop));
                screenCanvas.AddLine(new Point(halfRight, halfDown), new Point(rightSide, bottomSide));
                break;

            case 'R':
                screenCanvas.AddLine(new Point(newLeft, bottomSide), new Point(newLeft, newTop));
                screenCanvas.AddLineTo(new Point(rightSide, newTop));
                screenCanvas.AddLineTo(new Point(rightSide, halfDown));
                screenCanvas.AddLineTo(new Point(newLeft, halfDown));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                break;

            // case 'S' handled by '5'
            case 'T':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(rightSide, newTop));
                screenCanvas.AddLine(new Point(halfRight, newTop), new Point(halfRight, bottomSide));
                break;

            case 'U':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(newLeft, bottomSide));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                screenCanvas.AddLineTo(new Point(rightSide, newTop));
                break;

            case 'V':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(halfRight, bottomSide));
                screenCanvas.AddLineTo(new Point(rightSide, newTop));
                break;

            case 'W':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(newLeft, bottomSide));
                screenCanvas.AddLineTo(new Point(halfRight, halfDown));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                screenCanvas.AddLineTo(new Point(rightSide, newTop));
                break;

            case 'X':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(rightSide, bottomSide));
                screenCanvas.AddLine(new Point(rightSide, newTop), new Point(newLeft, bottomSide));
                break;

            case 'Y':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(halfRight, halfDown));
                screenCanvas.AddLineTo(new Point(rightSide, newTop));
                screenCanvas.AddLine(new Point(halfRight, halfDown), new Point(halfRight, bottomSide));
                break;

            case 'Z':
                screenCanvas.AddLine(new Point(newLeft, newTop), new Point(rightSide, newTop));
                screenCanvas.AddLineTo(new Point(newLeft, bottomSide));
                screenCanvas.AddLineTo(new Point(rightSide, bottomSide));
                break;
            }
        }
コード例 #13
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);
        }
コード例 #14
0
 public virtual void Draw(ScreenCanvas sc, int iPictX, int iPictY, System.Drawing.Pen penColor)
 {
     DrawPolyToSC(pointsTransformed, sc, iPictX, iPictY, penColor);
 }
コード例 #15
0
 public virtual void Draw(ScreenCanvas sc, int iPictX, int iPictY)
 {
     DrawPolyToSC(pointsTransformed, sc, iPictX, iPictY, Pens.White);
 }