Exemplo n.º 1
0
 protected override void Draw(GameTime gameTime)
 {
     graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
     spriteBatch.Begin(transformMatrix: viewportAdapter.GetScaleMatrix(),
                       samplerState: SamplerState.PointClamp);
     level.Draw(spriteBatch);
     base.Draw(gameTime);
     spriteBatch.End();
 }
Exemplo n.º 2
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);

            this.spriteBatch.Begin(SpriteSortMode.FrontToBack, transformMatrix: ScalingViewportAdapter.GetScaleMatrix(this.GraphicsDevice));

            SceneManager.Draw(this.spriteBatch);

            this.spriteBatch.End();
        }
Exemplo n.º 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)
 {
     graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
     spriteBatch.Begin(transformMatrix: viewPortAdapter.GetScaleMatrix(),
                       samplerState: SamplerState.PointClamp);
     level.Draw(spriteBatch);
     if (gameState == GameState.Started)
     {
         spriteBatch.DrawString(font, "Pulsa <ENTER> para comenzar",
                                new Vector2(8, 40), Color.White);
     }
     if (gameState == GameState.Died)
     {
         spriteBatch.DrawString(font, "Game Over",
                                new Vector2(52, 40), Color.White);
         spriteBatch.DrawString(font, "Pulsa Enter para volver a jugar",
                                new Vector2(8, 50), Color.White);
     }
     spriteBatch.End();
     base.Draw(gameTime);
 }
Exemplo n.º 4
0
        public void Draw(GameTime gameTime)
        {
            // Begin
            _sb.Begin(samplerState: SamplerState.PointClamp, sortMode: SpriteSortMode.FrontToBack,
                      blendState: BlendState.AlphaBlend, transformMatrix: _viewportAdapter.GetScaleMatrix());

            // Draw Entities
            foreach (int entityId in ActiveEntities)
            {
                var renderForm = _renderFormMapper.Get(entityId);
                var transform  = _transform2DMapper.Get(entityId);

                if (string.Compare("Ammo", renderForm.Name) == 0)
                {
                    var animatedSprite = _animatedSpriteMapper.Get(entityId);
                    RenderAmmo(animatedSprite, transform);
                }
            }
            // End
            _sb.End();
        }
Exemplo n.º 5
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 (IsActive)
            {
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                {
                    Exit();
                }

                //ensuring that both the keyboard and the mousebuttons are only pressed once per frame
                previousMs = ms;
                ms         = Mouse.GetState();

                previousKS = ks;
                ks         = Keyboard.GetState();

                //creating the saving form and also hooking its closed event to the
                //savelevel method in the the game class
                saveMenu             = new SaveMenu();
                saveMenu.FormClosed += SaveLevel;

                mousePosition = new Vector2(ms.X, ms.Y);

                //converting the mouse's coordinates to world coordinates
                scalingMousePosition = Vector2.Transform(mousePosition, Matrix.Invert(viewportAdapter.GetScaleMatrix()));
                //SingleButtonPress();
                // TODO: Add your update logic here
                if (tileState == TileState.Player)
                {
                    if (ks.IsKeyDown(Keys.D1) && previousKS.IsKeyUp(Keys.D1))
                    {
                        tileState = TileState.Tile1;
                    }

                    if (ks.IsKeyDown(Keys.D2) && previousKS.IsKeyUp(Keys.D2))
                    {
                        tileState = TileState.Tile2;
                    }

                    if (ks.IsKeyDown(Keys.D3) && previousKS.IsKeyUp(Keys.D3))
                    {
                        tileState = TileState.Tile3;
                    }

                    //if the user clicks the left ouse button then
                    //add the player character at that location
                    if (ms.LeftButton == ButtonState.Pressed && previousMs.LeftButton == ButtonState.Released)
                    {
                        for (int y = 0; y < mapGrid.GetLength(1); y++)
                        {
                            for (int x = 0; x < mapGrid.GetLength(0); x++)
                            {
                                if (mapGrid[x, y] == "4")
                                {
                                    mapGrid[x, y] = "0";
                                }
                            }
                        }

                        mapGrid[(int)scalingMousePosition.X / texture["player"].Width, (int)scalingMousePosition.Y / texture["player"].Height] = "4";
                    }
                }

                //if the user wants to add a tile
                if (tileState == TileState.Tile1)
                {
                    if (ks.IsKeyDown(Keys.P) && previousKS.IsKeyUp(Keys.P))
                    {
                        tileState = TileState.Player;
                    }

                    if (ks.IsKeyDown(Keys.D2) && previousKS.IsKeyUp(Keys.D2))
                    {
                        tileState = TileState.Tile2;
                    }

                    if (ks.IsKeyDown(Keys.D3) && previousKS.IsKeyUp(Keys.D3))
                    {
                        tileState = TileState.Tile3;
                    }

                    if (ms.LeftButton == ButtonState.Pressed && previousMs.LeftButton == ButtonState.Released)
                    {
                        int xPos = (int)Math.Floor((double)ms.X / texture["tile1"].Width) * texture["tile1"].Width;
                        int yPos = (int)Math.Floor((double)ms.Y / texture["tile1"].Height) * texture["tile1"].Height;

                        tile1Positions.Add(new Vector2(xPos, yPos));
                        mapGrid[(int)scalingMousePosition.X / texture["tile1"].Width, (int)scalingMousePosition.Y / texture["tile1"].Height] = "1";
                    }
                }

                if (tileState == TileState.Tile2)
                {
                    if (ks.IsKeyDown(Keys.P) && previousKS.IsKeyUp(Keys.P))
                    {
                        tileState = TileState.Player;
                    }

                    if (ks.IsKeyDown(Keys.D1) && previousKS.IsKeyUp(Keys.D1))
                    {
                        tileState = TileState.Tile1;
                    }

                    if (ks.IsKeyDown(Keys.D3) && previousKS.IsKeyUp(Keys.D3))
                    {
                        tileState = TileState.Tile3;
                    }

                    if (ms.LeftButton == ButtonState.Pressed && previousMs.LeftButton == ButtonState.Released)
                    {
                        int xPos = (int)Math.Floor((double)ms.X / texture["tile2"].Width) * texture["tile2"].Width;
                        int yPos = (int)Math.Floor((double)ms.Y / texture["tile2"].Height) * texture["tile2"].Height;

                        tile1Positions.Add(new Vector2(xPos, yPos));
                        mapGrid[(int)scalingMousePosition.X / texture["tile2"].Width, (int)scalingMousePosition.Y / texture["tile2"].Height] = "2";
                    }
                }

                if (tileState == TileState.Tile3)
                {
                    if (ks.IsKeyDown(Keys.P) && previousKS.IsKeyUp(Keys.P))
                    {
                        tileState = TileState.Player;
                    }

                    if (ks.IsKeyDown(Keys.D2) && previousKS.IsKeyUp(Keys.D2))
                    {
                        tileState = TileState.Tile2;
                    }

                    if (ks.IsKeyDown(Keys.D1) && previousKS.IsKeyUp(Keys.D1))
                    {
                        tileState = TileState.Tile1;
                    }

                    if (ms.LeftButton == ButtonState.Pressed && previousMs.LeftButton == ButtonState.Released)
                    {
                        int xPos = (int)Math.Floor((double)ms.X / texture["tile1"].Width) * texture["tile1"].Width;
                        int yPos = (int)Math.Floor((double)ms.Y / texture["tile1"].Height) * texture["tile1"].Height;

                        tile1Positions.Add(new Vector2(xPos, yPos));
                        mapGrid[(int)scalingMousePosition.X / texture["tile1"].Width, (int)scalingMousePosition.Y / texture["tile1"].Height] = "3";
                    }
                }

                if (this.IsActive)
                {
                    //user wants to save the map
                    if (ks.IsKeyDown(Keys.S) && previousKS.IsKeyUp(Keys.S))
                    {
                        saveMenu.Show();
                        saveMenu.TopMost = true;
                    }
                }
            }
            base.Update(gameTime);
        }