Пример #1
0
        public static void pressKey(byte key, int x, int y)
        {
            keys[key] = true;

            switch (key)
            {
            case 8:
                if (buffer.Length >= 1)
                {
                    buffer = buffer.Remove(buffer.Length - 1, 1);
                }
                break;

            case (byte)'d':
            case (byte)'D': player1.moveRight = true; break;

            case (byte)'a':
            case (byte)'A': player1.moveLeft = true; break;

            case (byte)'w':
            case (byte)'W':
                if (gameState == EnumStateOfGame.GAME)
                {
                    if (player1.onGround || player1.doubleJump)
                    {
                        player1.jump = true;
                    }
                }
                else
                {
                    menuState--;
                    if (menuState < 0)
                    {
                        menuState = EnumStateofMenu.SCORE;
                    }
                }
                break;

            case (byte)'s':
            case (byte)'S':
                menuState++;
                if (menuState > EnumStateofMenu.SCORE)
                {
                    menuState = 0;
                }
                break;

            case (byte)' ':     //if (player1.kd == 0) { player1.hit = true; } break;
                switch (gameState)
                {
                case EnumStateOfGame.GAME: if (player1.kd == 0)
                    {
                        player1.hit = true;
                    }
                    ; break;

                case EnumStateOfGame.BEGINNING:         //gameState = EnumStateOfGame.GAME; break;
                    switch (menuState)
                    {
                    case EnumStateofMenu.NEW_GAME: gameState = EnumStateOfGame.GAME; break;

                    case EnumStateofMenu.QUIT: Environment.Exit(0); break;

                    case EnumStateofMenu.SCORE: gameState = EnumStateOfGame.TOP_SCORE; break;
                    }
                    break;

                case EnumStateOfGame.DEATH:
                case EnumStateOfGame.END:
                    gameState = EnumStateOfGame.SCORE;
                    //gameState = EnumStateOfGame.BEGINNING;
                    //levels = initLevels(N, ref coins, ref enemies, textures, textureCount);
                    //player1 = new Player((int)levels[0].begin.X, (int)levels[0].begin.Y, texPlayer, countPlayer);
                    break;

                case EnumStateOfGame.SCORE:
                    currScore.name = buffer;
                    SaveScore(currScore);
                    gameState = EnumStateOfGame.BEGINNING;
                    gameState = EnumStateOfGame.BEGINNING;
                    levels    = initLevels(N_levels, ref coins, ref enemies, textures, textureCount);
                    player1   = new Player((int)levels[0].begin.X, (int)levels[0].begin.Y, texPlayer, countPlayer);
                    break;
                }
                break;

            case 27:    // pause = !pause; break;
                switch (gameState)
                {
                case EnumStateOfGame.GAME: gameState = EnumStateOfGame.PAUSE; SystemSounds.Asterisk.Play(); break;

                case EnumStateOfGame.PAUSE: gameState = EnumStateOfGame.GAME; SystemSounds.Beep.Play(); break;

                //case EnumStateOfGame.DEATH: Environment.Exit(0); break;
                //case EnumStateOfGame.END: Environment.Exit(0); break;
                case EnumStateOfGame.BEGINNING: Environment.Exit(0); break;

                case EnumStateOfGame.TOP_SCORE: gameState = EnumStateOfGame.BEGINNING; break;
                }
                break;
            }
        }
Пример #2
0
        //отрисовка игры
        static void DrawGame()
        {
            if (levels[k].ending)
            {
                k++;
                bonus += 150;
                if (k < N_levels)
                {
                    player1.ReturnVectors();
                    player1.X    = (int)levels[k].begin.X;
                    player1.Y    = (int)levels[k].begin.Y;
                    player1.life = 100;
                    X            = 0;
                    Y            = 0;
                }
                else
                {
                    //Environment.Exit(0);
                    gameState = EnumStateOfGame.END;
                    return;
                }
            }


            //myMap.Draw();
            levels[k].Draw();
            foreach (Coin i in coins[k])//arrayOfCoins)
            {
                i.Draw(levels[k]);
            }

            foreach (Enemy i in enemies[k])//arrayOfEnemy)
            {
                if (i.life == 0)
                {
                    continue;
                }
                //if (i is NormalEnemy)
                //{
                //    ((NormalEnemy)i).MoveEnemy(levels[k], player1.X, player1.Y);
                //}
                //else
                //{
                //    i.MoveEnemy(levels[k]);
                //}
                //i.HandlerMovement();
                i.DrawC(levels[k]);
            }

            DrawString((int)X + 50, (int)Y + 700, "LIFE:+" + Convert.ToString(player1.life));
            DrawString((int)X + 50, (int)Y + 675, "COINS:" + Convert.ToString(player1.coins));
            //TimeSpan tmp = time.Elapsed;
            //DrawString((int)X + 50, (int)Y + 6, "TIME:" + Convert.ToString(tmp.Seconds) + "." + Convert.ToString(tmp.Milliseconds));

            //player1.HandlerMovementWithHit(ref enemies[k], ref coins[k]);//(ref arrayOfEnemy, ref arrayOfCoins);
            player1.Draw(levels[k], coins[k], enemies[k]);//(myMap, arrayOfCoins, arrayOfEnemy);

            //пережвижение камеры
            //X
            if (Math.Abs(X - player1.X + WIDTH) < WIDTH / 2 && X + WIDTH < levels[k].Width * Tile.Size)
            {
                while (Math.Abs(X - player1.X + WIDTH) < WIDTH / 2 && X + WIDTH < levels[k].Width * Tile.Size)
                {
                    X += 3;
                }
            }
            if (Math.Abs(X - player1.X) < WIDTH / 2 && X > 0)
            {
                while (Math.Abs(X - player1.X) < WIDTH / 2 && X > 0)
                {
                    X -= 3;
                }
            }

            if (player1.life <= 0 && gameState == EnumStateOfGame.GAME)
            {
                //Environment.Exit(0);
                player1.ZeroingCoord();
                gameState = EnumStateOfGame.DEATH;
                //player1.ZeroingCoord();
            }
        }