예제 #1
0
        public GameScreen(ref SpriteBatch sb, ref Player p, TextureMap eMap, 
            TextureMap lMap, TextureMap bMap, params string[] bgNames)
        {
            max_time = 100;
            enemyTimer = 0;
            bg2pos = new Vector2(0.0f, -800.0f);
            SB = sb;
            PlayerShip = p;
            pressedPause = false;
            Backgrounds = new List<TextureMap>();
            DrawableEntities = new List<GameEntity>();
            foreach (string bg in bgNames)
            {
                Backgrounds.Add(new TextureMap(Constants.content.Load<Texture2D>(bg), 1, 1));
            }

            enemyMap = eMap;
            laserMap = lMap;
            bossMap = bMap;

            r = new Random();
            veltemp = Vector2.Zero;
            for (int i = 0; i < 5; ++i)
            {
                veltemp.Y = r.Next(1, 5);
                Constants.mEnemyManager.addEnemy(new Enemy(
                    new Vector2(r.Next(100, Constants.graphics.PreferredBackBufferWidth - 100), 0.0f),
                    veltemp, enemyMap, laserMap, Enemy.ENEMY_TYPE.SIDEWINDER));
            }
        }
예제 #2
0
        public GameWorld(Form form)
        {
            mainWindow = form;
            MessageBox.Show("Hra bude spuštěna", "Zpráva hry");
            timer.Interval = 100;
            mainWindow.Paint += MainWindow_Paint;
            timer.Tick += UpdateGame;
            timer.Start();

            Player player = new Player(this);
            listOfGameObjects.Add(player);
            Enemy enemy = new Enemy(this, "Graphics\\Nepritel1.bmp");
            listOfGameObjects.Add(enemy);

            mainWindow.KeyDown += MainWindow_KeyDown;

            enemyGenerator.Interval = 2000;
            enemyGenerator.Tick += EnemyGenerator_Tick;
            enemyGenerator.Start();
        }
예제 #3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            if (gameLevelChange == true && pause ==false)
            {
                if (soundOnce == true)
                {
                    SoundPlayer.soundBank.PlayCue("SP0000");
                    soundOnce = false;
                }
                currentKeystate = Keyboard.GetState();
                if (currentKeystate.IsKeyDown(Keys.Enter))
                {
                    soundOnce = true;
                    gameLevelChange = false;
                    playerSprite.Visible = true;
                    playerSprite.life++;
                    spriteManager = new SpriteManager();
                    spriteManager.Add(gameBackground);
                    LoadGraphicsContent(true);
                    SoundPlayer.soundBank.PlayCue("menu_select3 2");
                }
            }

                if (gameMenu.select == SELECT_NOT)
                {
                    if (pause == true)
                        gameStatus = 1;
                    else if (showHighScore == true)
                        gameStatus = 2;
                    else
                        gameStatus = 0;
                    prevKeystate = gameMenu.Update(gameTime, currentKeystate, gameStatus);
                }
                else if (gameMenu.select == SELECT_PLAY)
                {

                    spriteManager = new SpriteManager();
                    playerSprite = new Player();
                    gameStarted = true;
                    maxAlien = 5;
                    Player.immune = false;
                    gameLevel = 1;

                    LoadGraphicsContent(true);
                    spriteManager.UpdateSprites(gameTime);

                    playerScore = 0;
                    gameMenu.select = SELECT_RESUME;
                    pause = false;

                }
                else if (gameMenu.select == SELECT_EXIT)
                {
                    this.Exit();
                }
                else if (gameMenu.select == SELECT_RESUME)
                {

                    pause = false;
                }
                else if (gameMenu.select == SELECT_HIGHSCORE)
                {
                    showHighScore = true;

                }
                else if (gameMenu.select == SELECT_HELP)
                {
                    showHelp = true;
                }

                currentKeystate = Keyboard.GetState();

                if (gameStarted == true )
                {
                    if (currentKeystate.IsKeyDown(Keys.Escape) && prevKeystate.IsKeyDown(Keys.Escape) == false)
                    {
                        if (playerSprite.life > 0)
                        {
                            gameMenu.select = SELECT_NOT;
                            gameMenu.downInc = -60;
                            pause = true;
                            SoundPlayer.soundBank.PlayCue("menu_select3 2");
                        }

                    }
                }
                if (showHighScore == true)
                {
                    if (currentKeystate.IsKeyDown(Keys.Enter) && prevKeystate.IsKeyDown(Keys.Enter) == false)
                    {
                        showHighScore = false;
                        gameMenu.select = SELECT_NOT;
                        SoundPlayer.soundBank.PlayCue("menu_select3 2");

                    }
                }
                if(showHelp== true)
                {
                    if (currentKeystate.IsKeyDown(Keys.Enter) && prevKeystate.IsKeyDown(Keys.Enter) == false)
                    {
                        showHelp = false;
                        gameMenu.select = SELECT_NOT;
                        SoundPlayer.soundBank.PlayCue("menu_select3 2");

                    }
                }
                prevKeystate = currentKeystate;

                if (pause == false && gameMenu.select > 0 && showHighScore == false&&showHelp==false)
                {

                    if (playerScore >= 500 && gameLevel == 1)
                    {
                        gameLevel = 2;
                        gameBackground.Load(content, @"Textures\back");

                        maxAlien = 5;

                        playerSprite.Visible = false;

                        gameLevelChange = true;

                    }
                    if (playerScore >= 1500 && gameLevel == 2)
                    {
                        gameLevel = 3;

                        maxAlien = 4 ;
                        playerSprite.Visible = false;
                        gameBackground = new Sprite();
                        gameBackground.Load(content, @"Textures\back_level3");

                        gameLevelChange = true;
                    }
                    if (playerScore >= 2000&& gameLevel == 3)
                      {
                          gameLevel = 4;

                          maxAlien = 4;
                          playerSprite.Visible = false;
                          gameBackground = new Sprite();
                          gameBackground.Load(content, @"Textures\back");

                          gameLevelChange = true;

                       }
                       if (playerScore >= 3000 && gameLevel == 4)
                       {
                           gameLevel = 5;

                           maxAlien = 4;
                           playerSprite.Visible = false;
                           gameBackground = new Sprite();
                           gameBackground.Load(content, @"Textures\back_level3");

                           gameLevelChange = true;

                       }

                    KeyboardState curState;
                    curState = Keyboard.GetState();
                    if (playerSprite.life <= 0)
                    {
                        if (curState.IsKeyDown(Keys.Enter))
                        {
                            Player.immune = false;
                            playerSprite.life = 3;
                            gameMenu.downInc = 0;
                            gameMenu.select = 0;
                            gameStarted = false;

                        }
                    }

                    if (gameMenu.select > 0)
                    {
                        spriteManager.UpdateSprites(gameTime);
                        base.Update(gameTime);
                    }

                }
        }