Example #1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            switch (gameState)
            {
            case GameState.GameLogin:

                spriteBatch.Begin();

                spriteBatch.Draw(backgroundTexture, backgroundRect, Color.Black);

                for (int i = 0; i < loginTextboxs.Count; i++)
                {
                    loginTextboxs[i].Draw(spriteBatch, backgroundTexture);
                }

                for (int i = 0; i < loginLabels.Count; i++)
                {
                    loginLabels[i].Draw(spriteBatch);
                }

                for (int i = 0; i < loginButtons.Count; i++)
                {
                    loginButtons[i].DrawButton(spriteBatch);
                }

                if (userTaken)
                {
                    spriteBatch.DrawString(buttonFont, "The username enterned for the new account is invalid, please try again.", new Vector2(60, 670), Color.White);
                }
                else if (isAccountInvalid)
                {
                    spriteBatch.DrawString(buttonFont, "The current information is invalid, please try again.", new Vector2(170, 670), Color.White);
                }

                spriteBatch.End();

                break;

            case GameState.MainMenu:

                spriteBatch.Begin();

                spriteBatch.Draw(backgroundTexture, backgroundRect, Color.Black);

                for (int i = 0; i < mainMenuButtons.Count; i++)
                {
                    mainMenuButtons[i].DrawButton(spriteBatch);
                }

                spriteBatch.DrawString(buttonFont, "Current User: " + currentUser, currentUserPos, Color.White);

                spriteBatch.End();

                break;

            case GameState.Game:
            case GameState.MapCreator:

                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, camera.GetTransformation());

                //Draws all the tiles
                foreach (Tile tile in tilesInView)
                {
                    tile.Draw(spriteBatch);
                }

                if (gameState == GameState.Game)
                {
                    player.Draw(spriteBatch, backgroundTexture);
                }

                foreach (Enemy enemy in enemiesInView)
                {
                    enemy.Draw(spriteBatch, backgroundTexture);
                }

                foreach (Projectile projectile in projectiles)
                {
                    projectile.Draw(spriteBatch);
                }

                spriteBatch.End();

                if (gameState == GameState.MapCreator)
                {
                    spriteBatch.Begin();

                    mapCreatorLabels[0].Draw(spriteBatch);

                    spriteBatch.End();
                }

                break;

            case GameState.Pause:
                break;

            case GameState.MapCreatorHelp:

                spriteBatch.Begin();

                DrawCreatorHelp();

                spriteBatch.End();

                break;

            case GameState.StartMapCreator:

                spriteBatch.Begin();

                spriteBatch.Draw(backgroundTexture, backgroundRect, Color.Black);

                for (int i = 0; i < mapCreatorStartLabel.Count - 1; i++)
                {
                    mapCreatorStartLabel[i].Draw(spriteBatch);
                }

                for (int i = 0; i < startMapCreatorTextboxs.Count; i++)
                {
                    startMapCreatorTextboxs[i].Draw(spriteBatch, backgroundTexture);
                }

                for (int i = 0; i < startMapCreatorButtons.Count; i++)
                {
                    startMapCreatorButtons[i].DrawButton(spriteBatch);
                }

                if (invalidMapSize)
                {
                    mapCreatorStartLabel[2].Draw(spriteBatch);
                }

                spriteBatch.End();

                break;
            }

            base.Draw(gameTime);
        }
        protected override void Update(GameTime gameTime)
        {
            gameTimePublic = gameTime;

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            penumbra.Transform = playerCam.GetTransformation();

            if (runOnce)
            {
                worlds[0].initialize();

                ToolBelt.Initialize();

                runOnce = false;
            }


            if (kb.IsKeyDown(Keys.Q))
            {
                renderSize += 10;
            }
            else if (kb.IsKeyDown(Keys.E))
            {
                playerCam.SetZoom(3f);
                renderSize = 600;
            }

            Zoom();

            kb    = Keyboard.GetState();
            mouse = Mouse.GetState();

            worlds[0].Update();
            Player.Update();
            ToolBelt.Update();

            playerCam.LookAt(Player.rec);

            // TODO: Add your update logic here

            if (kb.IsKeyDown(Keys.R) && kbPre.IsKeyUp(Keys.R))
            {
                if (penumbra.Visible == false)
                {
                    penumbra.Visible = true;
                }
                else
                {
                    penumbra.Visible = false;
                }
            }

            frames++;
            mousePre = mouse;
            kbPre    = kb;
            base.Update(gameTime);
        }
Example #3
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            //Draw the background to the screen
            spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearClamp, null, null);
            spriteBatch.Draw(world.Background.Texture, world.Background.GetBounds, Color.White);
            spriteBatch.End();

            //Draw the game with a camera as long as the game is in play mode
            if (World.worldState == World.States.play || World.worldState == World.States.zoom || World.worldState == World.States.finished)
            {
                //Draw the world with the camera
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, cam.GetTransformation());
                world.Draw(spriteBatch);
                spriteBatch.End();
            }
            else
            {
                //Draw the world without the camera
                spriteBatch.Begin();
                world.Draw(spriteBatch);
                spriteBatch.End();
            }

            base.Draw(gameTime);
        }