( Index )
Month

Brief Information about the June '07 CSIG Meeting

Balloons 1.2

C++ Version 7 and Visual Studio 2005

Written by B. Arnold

Balloons

Welcome to the CSIG, a Special Interest Group of the ACGNJ. The subject for this month is a discussion about Windows Sound and Graphics using the latest Microsoft C++ compiler.

The subject for this month is an advanced version of the Balloons program discussed in the September meeting last year. At that time there was no provision for mouse input. Now there is.

This game is suitable for small children ages 1 to 4 years. When the game starts, 35 colored balloons are presented on the screen. The target balloon has an X in the center. Pressing the space bar will explode the indicated balloon with a "pop" sound. When all the balloons are exploded, a smiley face appears with a different sound effect.

This latest version of the program additionally allows the player to use the mouse to "pop" any balloon on the screen. The program must know which balloon has been selected. It also keeps track of the elapsed time and displays it at the end of the game.

The program may be compiled using the C++ .Net compiler included with Visual Studio 2005 as well as the free (!!!) C++ Express compiler. Additionally, since C++ has many similarities with C# or C-Sharp, these compilers may also be used with modifications to the source files. Microsoft provides a C-Sharp compiler with Visual Studio 2005 as well as the free (!!!) C-Sharp Express compiler. Be sure to bring questions about the code and the language.


The programs are normally quite small, about 100 KB, but require a Windows computer that has the following software installed:

Microsoft .NET Framework Version 2.0

This is a large package, about 24 Megs. Most people running updated versions of WinXP will already have it on their computer. If not, it may be downloaded from Microsoft.

Here's the download address for the Microsoft Framework:
Microsoft Software
Or, just look for: Microsoft .NET Framework Version 2.0 Redistributable Package (x86)

There are a number of ways to refer to this compiler and code.

The beginning of the evening (starting at 7:30pm) will be a RANDOM ACCESS discussion. The main presentation will discuss the program.

Our download site has code and programs from most of our meetings. ( Source Code Files )

Sample Code - VC7

Sample Code
===========
// Paint the screen.   Paint the screen.   Paint the screen.
    private: System::Void Form1_OnPaint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e)
        {
            int topBalloon = -1;
            Rectangle windowRect = ClientRectangle;

            if (firstime)
            {
                Form1_InitBalloonArray(windowRect);
                firstime = false;
            }
            Graphics ^g = e->Graphics;

            for (int i = 0; i < MAXBALLOONS; i++)
            {
                if (pBaloonCenter[i]->X < 0) continue;

                SolidBrush^ balloonBrush = gcnew SolidBrush(*pBaloonColor[i]);
                g->FillEllipse(balloonBrush,
                    (*pBaloonCenter[i]).X - *pBalloonRadius[i],
                    (*pBaloonCenter[i]).Y - *pBalloonRadius[i],
                    2 * (*pBalloonRadius[i]),
                    2 * (*pBalloonRadius[i]));
                g->DrawEllipse(Pens::Black,
                    (*pBaloonCenter[i]).X - *pBalloonRadius[i],
                    (*pBaloonCenter[i]).Y - *pBalloonRadius[i],
                    2 * (*pBalloonRadius[i]),
                    2 * (*pBalloonRadius[i]));
                // ~balloonBrush();  or balloonBrush->Dispose();
                topBalloon = i;
            }

            if (-1 != topBalloon)       // Put a X in the center of the top balloon.
            {
                Pen ^ myBlackPen = gcnew Pen(Color::Black, 10);
                myBlackPen->StartCap = System::Drawing::Drawing2D::LineCap::Round;
                myBlackPen->EndCap = System::Drawing::Drawing2D::LineCap::Round;

                Pen ^ myWhitePen = gcnew Pen(Color::White, 5);
                myWhitePen->StartCap = System::Drawing::Drawing2D::LineCap::Round;
                myWhitePen->EndCap = System::Drawing::Drawing2D::LineCap::Round;

                g->DrawLine(myBlackPen,
                    (*pBaloonCenter[topBalloon]).X - 10, (*pBaloonCenter[topBalloon]).Y - 10,
                    (*pBaloonCenter[topBalloon]).X + 10, (*pBaloonCenter[topBalloon]).Y + 10);
                g->DrawLine(myBlackPen,
                    (*pBaloonCenter[topBalloon]).X - 10, (*pBaloonCenter[topBalloon]).Y + 10,
                    (*pBaloonCenter[topBalloon]).X + 10, (*pBaloonCenter[topBalloon]).Y - 10);
                g->DrawLine(myWhitePen,
                    (*pBaloonCenter[topBalloon]).X - 10, (*pBaloonCenter[topBalloon]).Y - 10,
                    (*pBaloonCenter[topBalloon]).X + 10, (*pBaloonCenter[topBalloon]).Y + 10);
                g->DrawLine(myWhitePen,
                    (*pBaloonCenter[topBalloon]).X - 10, (*pBaloonCenter[topBalloon]).Y + 10,
                    (*pBaloonCenter[topBalloon]).X + 10, (*pBaloonCenter[topBalloon]).Y - 10);
                //myBlackPen->Dispose();
                //myWhitePen->Dispose();
            }
        }

"Random Access" questions start at 7:30 Tuesday night.

SOURCE CODE

Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page