Ejemplo n.º 1
0
        private void initialize()
        {
            //------------------------------------------------------------------------------------------------------------------
            // Purpose: Initialize game
            //
            // 1. Check that FMOD is present and functioning
            // 2. Create sprite instances ...
            //------------------------------------------------------------------------------------------------------------------

            int i = 0;
            int j = 0;
            int k = 0;
            int e = 0;
            int c = 0;

            DrawText(graphicsBuffer, ":: Gridcoin Galaza -- ßeta rev: 1.1 -- 4/22/2015 :: ", 20, 50, 12, FontStyle.Regular, Brushes.Red);

            // Precision regulated  delay
            initDelay();
            DrawText(graphicsBuffer, "Precision regulated delay initialized", 20, 100, 12, FontStyle.Regular, Brushes.White);

            // Update screen
            this.Refresh();

            // FMOD sound engine ...
            try
            {
                FSOUND_Init(44100, 32, 0);

                // Good
                DrawText(graphicsBuffer, "FMOD sound engine initialize", 20, 120, 12, FontStyle.Regular, Brushes.White);

            }
            catch
            {
                // Problems
                DrawText(graphicsBuffer, "FMOD sound engine unable to initialize", 20, 120, 12, FontStyle.Regular, Brushes.White);
            //    sndEngineError = true;
            }

            // Update screen
            this.Refresh();

            // Sound effects & music ...
            if (!sndEngineError)
            {
                try
                {
                    InitSound();

                    // Good
                    DrawText(graphicsBuffer, "FMOD sound engine OK", 20, 140, 12, FontStyle.Regular, Brushes.White);

                }
                catch
                {
                    // Problems
                    DrawText(graphicsBuffer, "FMOD sound engine ERROR", 20, 140, 12, FontStyle.Regular, Brushes.White);
                    sndEngineError = true;
                }

                //- Problems ...
            }
            else
            {
                DrawText(graphicsBuffer, "FMOD sound engine ERROR", 20, 140, 12, FontStyle.Regular, Brushes.White);
            }

            // Update
            this.Refresh();

            // Sample of time in mS
            k = timeGetTime();

            // Load resource images and remove backgrounds and thus a sprite is born
            background[0] = GridcoinGalaza.Properties.Resources.background;
            background[1] = GridcoinGalaza.Properties.Resources.backgroundTop1;
            background[2] = GridcoinGalaza.Properties.Resources.backgroundTop1;
            background[3] = GridcoinGalaza.Properties.Resources.backgroundTop3;
            background[4] = GridcoinGalaza.Properties.Resources.backgroundTop4;
            background[5] = GridcoinGalaza.Properties.Resources.backgroundTop5;

            gameTitle = GridcoinGalaza.Properties.Resources.title;
            keyInstructions = GridcoinGalaza.Properties.Resources.keys;
            star = GridcoinGalaza.Properties.Resources.starA;
            gameTitle.MakeTransparent(Color.Black);
            star.MakeTransparent(Color.Black);
            keyInstructions.MakeTransparent(Color.Red);

            // Invader sprites ...
            createInvaderInstances();

            //:: Backgroud scrolling vectors ::

            // -------------------------------------------------------------------------------------
            // 8 Vectors which sequentially scroll until they reach the vector belows stating y-axis
            // -------------------------------------------------------------------------------------
            // 3 hardcoded attributes for each vector
            // 1. Starting y-axis
            // 2. Ending y-axis ...
            // 3. Degree of incrementation p/frame
            // -------------------------------------------------------------------------------------

            // Loop through all vectors and create instances with specified attributes ...
            for (i = 0; i <= 7; i++)
            {
                // Asign attributes based on vector index
                switch (i)
                {
                    case 0:
                        j = 168; // Starting y-axis
                        e = 188; // Ending y-axis ...
                        c = 2;   // Incrementation weight
                        break;

                    case 1:
                        j = 188;
                        e = 228;
                        c = 4;
                        break;

                    case 2:
                        j = 228;
                        e = 288;
                        c = 6;
                        break;

                    case 3:
                        j = 288;
                        e = 368;
                        c = (i + 1) * 2;
                        break;

                    case 4:
                        j = 368;
                        e = 468;
                        c = (i + 1) * 2;
                        break;

                    case 5:
                        j = 468;
                        e = 588;
                        c = (i + 1) * 2;
                        break;

                    case 6:
                        j = 588;
                        e = 728;
                        c = (i + 1) * 2;
                        break;

                    case 7:
                        j = 728;
                        e = 888;
                        c = (i + 1) * 2;
                        break;
                }

                // Create class instance
                vectorScroll[i] = new clsVectorScroll(0, j, c, e);
            }

            // Background stars
            fetchNewStars();

            // Player's ship
            player = new clsPlayer(0, 0);
            clsShared._clsPlayer = player;

            player.setFirePower(1);

            // Paths ...
            paths = new clsPaths();
            j = timeGetTime();
            DrawText(graphicsBuffer, "Sprites created in: " + Convert.ToString(j - k) + "mS", 20, 160, 12, FontStyle.Regular, Brushes.White);
            DrawText(graphicsBuffer, "Done ...", 20, 180, 12, FontStyle.Regular, Brushes.White);
            this.Refresh();

            processStartmS = timeGetTime();
            regulatedDelay(100);
        }
Ejemplo n.º 2
0
        private void frmGame_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
        {
            //------------------------------------------------------------------------------------------------------------------
            // Purpose: Terminate application -- clean up: dispose of resources
            //------------------------------------------------------------------------------------------------------------------

            // Clean up kill instances
            playerbullet = null;
            vectorScroll = null;
            invaders = null;
            particle = null;
            stars = null;
            player = null;
            paths = null;
            _clsCommon.sndEffects = null;
            bkMusic = null;
            pickup = null;

            // Dump screen buffer ...
            scrnBufferBmp.Dispose();
            graphicsBuffer.Dispose();

            // Save high scores ...
            SaveHighScores();

            // free FMOD sound engine from its duty
            if (!sndEngineError)
            {

               // FSOUND_Close();
            }

            // Dump this instance and terminate
            this.Dispose();
            System.Environment.Exit(0);
        }