Skip to content

Commit

Permalink
Merge pull request #6 from triplezeta/previewtest
Browse files Browse the repository at this point in the history
adds a placement preview for building
  • Loading branch information
MarkSuckerberg authored Aug 23, 2023
2 parents b984da2 + 856c090 commit 3f90002
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Blocktest/BlocktestGame.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Blocktest.Rendering;
using Blocktest.Rendering;
using Microsoft.Xna.Framework.Input;

namespace Blocktest
Expand All @@ -9,9 +9,9 @@ public class BlocktestGame : Game
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
bool latch = false; //latch for button pressing
private bool latchBlockSelect = false;
private bool latchBlockSelect = false; //same but for block selection
bool buildMode = true; //true for build, false for destroy
private int blockSelected = 0;
private int blockSelected = 0; //ID of the block to place


/// <inheritdoc />
Expand Down Expand Up @@ -61,6 +61,7 @@ protected override void Update(GameTime gameTime)
Exit();
}

//press E to toggle build/destroy
if (Keyboard.GetState().IsKeyUp(Keys.E))
{
latch = false;
Expand All @@ -70,8 +71,11 @@ protected override void Update(GameTime gameTime)
buildMode = !buildMode;
latch = true;
}

//for block placement
MouseState currentState = Mouse.GetState();

//Q changes which block you have selected
if (Keyboard.GetState().IsKeyUp(Keys.Q))
{
latchBlockSelect = false;
Expand All @@ -86,7 +90,8 @@ protected override void Update(GameTime gameTime)

latchBlockSelect = true;
}


//build and destroy mode
if (buildMode)
{
if(currentState.LeftButton == ButtonState.Pressed)
Expand Down Expand Up @@ -125,6 +130,13 @@ protected override void Draw(GameTime gameTime)
_spriteBatch.Begin();
Globals.BackgroundTilemap.Draw(_spriteBatch);
Globals.ForegroundTilemap.Draw(_spriteBatch);
// placement preview
if(buildMode)
_spriteBatch.Draw(BlockManager.AllBlocks[blockSelected].blockSprite.Texture,
new Vector2Int(Mouse.GetState().X - (Mouse.GetState().X % 8),
(Mouse.GetState().Y - Mouse.GetState().Y % 8)),
new Rectangle(1, 1, 10, 10), Color.DimGray);

_spriteBatch.End();

base.Draw(gameTime);
Expand Down

0 comments on commit 3f90002

Please sign in to comment.