Esempio n. 1
0
        /// <summary>
        /// Helper setup start game state
        /// </summary>
        private void InitGame()
        {
            //show modeless box
            _HelpBox      = new frmInfos();
            this.Location = new Point(10, 10);
            _HelpBox.Show();

            //set helpbox location
            _HelpBox.Location = new Point(this.Location.X + this.Width + 10, 10);

            //preset flag
            _bGameStart = false;
            _bGameOver  = false;
            _bGamePause = false;
            _bWelcome   = true;

            //reset state
            _UserInfo  = new UserInfo();
            _gameLevel = eGameLevel.Easy;
            this.Focus();

            //add main ship
            MakeAShip(0, ClientSize);

            //add one rock
            Point     center  = new Point(_rnd.Next(ClientRectangle.Width), _rnd.Next(ClientRectangle.Height));
            ShapeRock newRock = new ShapeRock(center, (ShapeRock.RockSize)_rnd.Next(3));

            _lstRock.Add(newRock);

            //call make color function
            //make a random known color every second
            MakeColor(1000);

            //make rock based on selected level
            //add asteroids on canvas based on game level
            _gr = CreateGraphics();
            MakeAsteroid((int)_gameLevel, _gr.VisibleClipBounds.Size);

            //play opening sound
            _SoundFolder    = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "Sound"));
            _soundOpening   = _SoundFolder + "\\opening.wav";
            _soundExplosion = _SoundFolder + "\\explosion-012.wav";
            _soundGameOver  = _SoundFolder + "\\Yunas-Theme.wav";
            _soundGotHit    = _SoundFolder + "\\explosion.wav";
            _soundLazer     = _SoundFolder + "\\lazer.wav";

            PlaySound(_soundOpening);

            //load images
            //LoadImages();

            //play hot sound
            PlaySound(_soundOpening);

            // Helper to load existing high score
            LoadFile();
        }
Esempio n. 2
0
        /// <summary>
        /// Child function of async method that create a random rock in specific time
        /// </summary>
        /// <param name="time">input time</param>
        /// <param name="size"></param>
        private void MakeARock(int time, SizeF size)
        {
            //delay inside method, use stopwatch to get exact timing
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            while (sw.ElapsedMilliseconds < time)
            {
                ;
            }

            //random location
            PointF center = new PointF((float)(_rnd.NextDouble() * size.Width), (float)(_rnd.NextDouble() * size.Height));

            lock (_oLock)
            {
                ShapeRock newRock = new ShapeRock(center, (ShapeRock.RockSize)_rnd.Next(1, 4));
                _lstRock.Add(newRock);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Helper to update score everytime bullet hit the rock
        /// </summary>
        /// <param name="rock">input rock</param>
        private void UpdateScore(ShapeRock rock)
        {
            //use rock instance property to update
            _UserInfo._CurrentScore += rock.RScore;

            //if current score mul by 10K -> award player a life
            if ((int)_UserInfo._CurrentScore / AWARD_LIFE > _UserInfo._AwardsTimes)
            {
                _UserInfo._AwardsTimes++;
                _UserInfo._Life++;
            }

            //increase level when user get 20k, and 100k
            if (_UserInfo._AwardsTimes == (int)_MediumScore / 10000)
            {
                _gameLevel = eGameLevel.Medium;
            }

            if (_UserInfo._AwardsTimes == (int)_HardScore / 10000)
            {
                _gameLevel = eGameLevel.Hard;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Helper to break down the input rock by size
        /// </summary>
        /// <param name="rockOG">input rock</param>
        private void BreakDownRock(ShapeRock rockOG)
        {
            //clear the current collection, make sure no repeatition
            _lstBrokenRock.Clear();

            //if this rock is big, break it to 3 smaller rocks
            if (rockOG._rockSize == ShapeRock.RockSize.Big)
            {
                //count
                for (int i = 0; i < 3; ++i)
                {
                    //make a new rock
                    ShapeRock rock = new ShapeRock(rockOG.Location, ShapeRock.RockSize.Medium);

                    //make all the broken rocks same direction, use QUADRANT
                    //use sign of original rock
                    float fX_OG = (float)Math.Ceiling(rockOG._fXSpeed);
                    float fY_OG = (float)Math.Ceiling(rockOG._fYSpeed);

                    //check sign of orignal rock, if make the smaller ones same sign
                    if (rockOG._fXSpeed >= 0)
                    {
                        rock._fXSpeed = (float)(fX_OG + _rnd.NextDouble() * fX_OG);
                    }
                    else
                    {
                        rock._fXSpeed = -(float)(fX_OG + _rnd.NextDouble() * fX_OG);
                    }

                    //check sign of orignal rock, if make the smaller ones same sign
                    if (rockOG._fYSpeed >= 0)
                    {
                        rock._fYSpeed = (float)(fY_OG + _rnd.NextDouble() * fY_OG);
                    }
                    else
                    {
                        rock._fYSpeed = -(float)(fY_OG + _rnd.NextDouble() * fY_OG);
                    }

                    //set the rock increment
                    rock._fRotationIncrement = (float)(_rnd.NextDouble() * 5.0 - 2.5);

                    //set this rock active
                    rock.IsMarkedForDeath = false;

                    //use lock?
                    lock (_oLock)
                    {
                        //add new rock to the sub list, combine to main list later
                        _lstBrokenRock.Add(rock);
                    }
                }
            }

            //if this rock is medium, break it to 2 smaller rocks
            else if (rockOG._rockSize == ShapeRock.RockSize.Medium)
            {
                //count
                for (int i = 0; i < 2; ++i)
                {
                    //make a new rock
                    ShapeRock rock = new ShapeRock(rockOG.Location, ShapeRock.RockSize.Small);

                    //make all the broken rocks same direction, use QUADRANT
                    //use sign of original rock
                    float fX_OG = (float)Math.Ceiling(rockOG._fXSpeed);
                    float fY_OG = (float)Math.Ceiling(rockOG._fYSpeed);

                    //check sign of orignal rock, if make the smaller ones same sign
                    if (rockOG._fXSpeed >= 0)
                    {
                        rock._fXSpeed = (float)(fX_OG + _rnd.NextDouble() * fX_OG);
                    }
                    else
                    {
                        rock._fXSpeed = -(float)(fX_OG + _rnd.NextDouble() * fX_OG);
                    }

                    //check sign of orignal rock, if make the smaller ones same sign
                    if (rockOG._fYSpeed >= 0)
                    {
                        rock._fYSpeed = (float)(fY_OG + _rnd.NextDouble() * fY_OG);
                    }
                    else
                    {
                        rock._fYSpeed = -(float)(fY_OG + _rnd.NextDouble() * fY_OG);
                    }

                    //set the rock increment
                    rock._fRotationIncrement = (float)(_rnd.NextDouble() * 5.0 - 2.5);

                    //set this rock active
                    rock.IsMarkedForDeath = false;

                    lock (_oLock)
                    {
                        //add new rock to the sub list, combine to main list later
                        _lstBrokenRock.Add(rock);
                    }
                }
            }
        }