示例#1
0
        public void GameWin()
        {
            if (this.TimeDelay()) {

                // uložení skóre
                this.SaveScore();

                // screen
                string message	=	String.Format(AppResources.Winner);

                GameCompleteScreen complete	=	new GameCompleteScreen(message);
                complete.Accepted	+=	this.ConfirmGameWin;

                this.Sm.AddScreen(complete, null);

            }
        }
示例#2
0
        private void gameLoop_Tick(object sender, EventArgs e)
        {
            gameMusic.controls.play();                     //play the game music on repeat
            gameMusic.settings.volume = Shadow.gameVolume; //update game volume

            //hero movement
            if (dDown == true && hero.x < this.Width - hero.size)
            {
                hero.MoveRightLeft(5);
            }
            if (aDown == true && hero.x > 0)
            {
                hero.MoveRightLeft(-5);
            }
            if (wDown == true)
            {
                hero.MoveUpDown(-5);
            }
            if (sDown == true)
            {
                hero.MoveUpDown(5);
            }

            //hero movement sounds
            if (heroSoundTimer == 0 && (wDown == true || aDown == true || sDown == true || dDown == true))
            {
                heroFootsteps.Play();
                heroSoundTimer = 100;
            }
            else if (wDown == false && aDown == false && sDown == false && dDown == false)
            {
                heroFootsteps.Stop();
                heroSoundTimer = 0;
            }
            else if (heroSoundTimer > 0)
            {
                heroSoundTimer--;
            }

            #region enemy movement

            #region enemies 1-4

            //enemy movement for enemies 1 and 2 (following a square path starting with up-down)
            if (leftRight == true && moveCount2 == 0)
            {
                moveCount2 = 70;
                moveSpeed2 = -moveSpeed2;
                leftRight  = false;
            }
            else if (moveCount2 == 0)
            {
                moveCount2 = 24;
                leftRight  = true;
            }
            else if (leftRight == true)
            {
                moveEnemies[0].MoveEnemyLeftRight(moveSpeed2);
                moveEnemies[1].MoveEnemyLeftRight(-moveSpeed2);
                moveCount2--;
            }
            else
            {
                moveEnemies[0].MoveEnemyUpDown(moveSpeed2);
                moveEnemies[1].MoveEnemyUpDown(-moveSpeed2);
                moveCount2--;
            }

            //enemy movement for enemies 3 and 4 (following 1 & 2 square path but starting with left-right)
            if (upDown == true && moveCount3 == 0)
            {
                moveCount3 = 24;
                moveSpeed3 = -moveSpeed3;
                upDown     = false;
            }
            else if (moveCount3 == 0)
            {
                moveCount3 = 70;
                upDown     = true;
            }
            else if (upDown == true)
            {
                moveEnemies[2].MoveEnemyUpDown(-moveSpeed3);
                moveEnemies[3].MoveEnemyUpDown(moveSpeed3);
                moveCount3--;
            }
            else
            {
                moveEnemies[2].MoveEnemyLeftRight(moveSpeed3);
                moveEnemies[3].MoveEnemyLeftRight(-moveSpeed3);
                moveCount3--;
            }

            #endregion enemies 1-4

            #region enemies 5 and 6

            //enemy movement for enemy 5 (up and down only)
            if (moveCount == 0)
            {
                moveSpeed = -moveSpeed;
                moveCount = 20;
            }
            else
            {
                moveEnemies[4].MoveEnemyUpDown(moveSpeed);
                moveEnemies[5].MoveEnemyLeftRight(moveSpeed);
                moveCount--;
            }

            #endregion enemies 5 and 6

            #endregion enemy movement

            #region hero collisions

            //hero collision rectangle
            Rectangle heroRec = new Rectangle(hero.x, hero.y, hero.size, hero.size);

            //hero collision with level layout
            foreach (Rectangle r in level1Collision)
            {
                if (heroRec.IntersectsWith(r))
                {
                    if (wDown)
                    {
                        hero.Stop("w");
                    }
                    if (aDown)
                    {
                        hero.Stop("a");
                    }
                    if (sDown)
                    {
                        hero.Stop("s");
                    }
                    if (dDown)
                    {
                        hero.Stop("d");
                    }
                }
            }

            #region enemy collisions

            //hero collision with stationary enemy sight radius
            for (int i = 0; i < stationaryEnemies.Count; i++)
            {
                Rectangle enemy = new Rectangle(stationaryEnemies[i].x - radius, stationaryEnemies[i].y - radius, stationaryEnemies[i].size + radius * 2, stationaryEnemies[i].size + radius * 2);
                if (enemies.Count < enemyCount)
                {
                    enemies.Add(enemy);
                }

                if (heroRec.IntersectsWith(enemy))
                {
                    gameLoop.Enabled = false;
                    gameMusic.controls.stop(); //stop the game music

                    //switch to level failed screen
                    Form f = this.FindForm();
                    f.Controls.Remove(this);

                    LevelFailedScreen lf = new LevelFailedScreen();
                    f.Controls.Add(lf);

                    lf.Location = new Point((f.Width - lf.Width) / 2, (f.Height - lf.Height) / 2); //center the screen
                }
            }

            //hero collision with move enemy sight radius
            for (int i = 0; i < moveEnemies.Count; i++)
            {
                Rectangle enemy = new Rectangle(moveEnemies[i].x - radius, moveEnemies[i].y - radius, moveEnemies[i].size + radius * 2, moveEnemies[i].size + radius * 2);

                if (enemies.Count < enemyCount)
                {
                    enemies.Add(enemy);
                }

                if (heroRec.IntersectsWith(enemy))
                {
                    gameLoop.Enabled = false;
                    gameMusic.controls.stop(); //stop the game music

                    //switch to level failed screen
                    Form f = this.FindForm();
                    f.Controls.Remove(this);

                    LevelFailedScreen lf = new LevelFailedScreen();
                    f.Controls.Add(lf);

                    lf.Location = new Point((f.Width - lf.Width) / 2, (f.Height - lf.Height) / 2); //center the screen
                }
            }

            #endregion enemy collisions

            //hero collision with key
            if (heroRec.IntersectsWith(key))
            {
                keyCollected = true;
                gameMusic.controls.pause();      //pause the game music
                keyPickupSound.Play();           //play key pickup sound

                key = new Rectangle(0, 0, 0, 0); //get rid of the key collision

                Thread.Sleep(1000);              //pause for a second

                gameMusic.controls.play();       //resume game music
            }

            //hero collision with finish area
            //game complete!
            if (heroRec.IntersectsWith(finish))
            {
                gameLoop.Enabled = false;
                gameMusic.controls.stop(); //stop the game music

                Form f = this.FindForm();
                f.Controls.Remove(this);

                GameCompleteScreen gcs = new GameCompleteScreen();
                f.Controls.Add(gcs);

                gcs.Location = new Point((f.Width - gcs.Width) / 2, (f.Height - gcs.Height) / 2); //center the screen
            }

            #endregion hero collisions

            Refresh();

            enemies.Clear(); //clear enemy rectangle list (nessecary for enemy sight graphics to update properly)
        }