Skip to content

Commit

Permalink
Fixes error from singleplayer player location not being instantiated
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkSuckerberg committed Nov 3, 2023
1 parent b675563 commit 0db4824
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions Blocktest/Code/Scenes/GameScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Myra.Graphics2D.UI;
using Shared.Code;
using Shared.Code.Block_System;
using Shared.Code.Components;
using Shared.Code.Packets;
namespace Blocktest.Scenes;

Expand All @@ -21,18 +22,16 @@ public sealed class GameScene : IScene {
private readonly RenderableTilemap _foregroundTilemapSprites;
private readonly FrameCounter _frameCounter = new();
private readonly BlocktestGame _game;
private readonly Desktop _gameDesktop;
private readonly GameUI _gameUi;
private readonly Client _networkingClient;
private readonly SpriteBatch _spriteBatch;

private readonly WorldState _worldState = new();
public int BlockSelected = 1; //ID of the block to place

public bool BuildMode { get; private set; } = true; //true for build, false for destroy

private KeyboardState _previousKeyboardState;
private readonly Desktop _gameDesktop;
private readonly GameUI _gameUi;

public int BlockSelected = 1; //ID of the block to place

public GameScene(BlocktestGame game, bool doConnect, IPEndPoint? ip) {
_connect = doConnect;
_spriteBatch = new SpriteBatch(game.GraphicsDevice);
Expand All @@ -48,16 +47,24 @@ public GameScene(BlocktestGame game, bool doConnect, IPEndPoint? ip) {

_gameUi = new GameUI(this);
_gameDesktop = new Desktop { Root = _gameUi };

if (_connect && ip != null) {
_networkingClient.Connect(ip);
return;
}

//Add player to world in singleplayer
Transform newTransform = new(new Vector2Int(256, 128));
Renderable newRenderable = new(newTransform, Layer.Player, Drawable.ErrorDrawable, Color.Orange);
_worldState.PlayerPositions.Add(0, newTransform);
_camera.RenderedComponents.Add(newRenderable);

WorldDownload testDownload = WorldDownload.Default();
testDownload.Process(_worldState);
}

public bool BuildMode { get; private set; } = true; //true for build, false for destroy

public void Update(GameTime gameTime) {
if (_connect) {
_networkingClient.Update();
Expand Down Expand Up @@ -87,7 +94,7 @@ public void Draw(GameTime gameTime, GraphicsDevice graphicsDevice) {
_frameCounter.Update(deltaTime);

_spriteBatch.End();

_gameDesktop.Render();
}

Expand Down Expand Up @@ -117,7 +124,7 @@ private void HandleInput() {
//Q changes which block you have selected
if (currentKeyboardState.IsKeyDown(Keys.Q) &&
_previousKeyboardState.IsKeyUp(Keys.Q)) {

BlockSelected = (BlockSelected + 1) % BlockManagerShared.AllBlocks.Count;
_gameUi.BlockSelector.SelectedIndex = BlockSelected;
}
Expand Down Expand Up @@ -227,7 +234,7 @@ private Rectangle GetFitRect() {

return new Rectangle(x, y, width, height);
}

public void SetBuildMode(bool buildMode) {
BuildMode = buildMode;
}
Expand Down

0 comments on commit 0db4824

Please sign in to comment.