Skip to content

Commit

Permalink
Merge pull request #23 from blocktest-game/misc-fixes
Browse files Browse the repository at this point in the history
Misc Bugfixes and Tweaks
  • Loading branch information
MarkSuckerberg authored Aug 22, 2024
2 parents 49a3dd2 + 96b4918 commit 8211ce3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
4 changes: 4 additions & 0 deletions Blocktest/BlocktestGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public void SetScene(IScene newScene) {

/// <inheritdoc />
protected override void Initialize() {
_graphics.PreferredBackBufferHeight = 720;
_graphics.PreferredBackBufferWidth = 1280;
_graphics.ApplyChanges();

BlockManagerShared.Initialize();
base.Initialize();
}
Expand Down
3 changes: 2 additions & 1 deletion Blocktest/Code/Block System/RenderableTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class RenderableTile : TileShared {
public RenderableTile(TileShared tile, bool background) : base(tile.SourceBlock,
tile.Transform.Position / GlobalsShared.GridSize) {
Renderable = new Renderable(Transform, background ? Layer.BackgroundBlocks : Layer.ForegroundBlocks,
BlockSpritesManager.AllBlocksSprites[tile.SourceBlock.BlockUid].BlockSprite, tile.Color);
BlockSpritesManager.AllBlocksSprites[tile.SourceBlock.BlockUid].BlockSprite,
background ? Color.Gray : Color.White);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Blocktest/Code/Rendering/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public sealed class Camera {
private readonly Color _backgroundColor;
private readonly Vector2 _size;

public readonly List<Renderable> RenderedComponents = new();
public readonly HashSet<Renderable> RenderedComponents = [];
public readonly RenderTarget2D RenderTarget;
public Vector2 Position;

Expand All @@ -23,7 +23,7 @@ public void Draw(GraphicsDevice graphics, SpriteBatch spriteBatch) {
graphics.SetRenderTarget(RenderTarget);
graphics.Clear(_backgroundColor);

spriteBatch.Begin();
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.PointClamp);

foreach (Renderable component in RenderedComponents) {
if (component.Appearance == null) {
Expand Down
4 changes: 4 additions & 0 deletions Blocktest/Code/Rendering/Drawable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ public void Draw(RenderContext context, Rectangle dest, Color color) {
}

public Point Size => Bounds.Size;

public override int GetHashCode() {
return HashCode.Combine(Bounds, Texture);
}
}
9 changes: 5 additions & 4 deletions Blocktest/Code/Scenes/GameScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public GameScene(BlocktestGame game, bool doConnect, IPEndPoint? ip) {
_spriteBatch = new SpriteBatch(game.GraphicsDevice);
_game = game;

_camera = new Camera(Vector2.Zero, new Vector2(512, 256), game.GraphicsDevice);
_camera = new Camera(Vector2.Zero, new Vector2(640, 360), game.GraphicsDevice);

_backgroundTilemapSprites = new RenderableTilemap(_worldState.Foreground, _camera);
_foregroundTilemapSprites = new RenderableTilemap(_worldState.Background, _camera);
Expand Down Expand Up @@ -79,14 +79,14 @@ public void Draw(GameTime gameTime, GraphicsDevice graphicsDevice) {
graphicsDevice.Clear(Color.CornflowerBlue);
_camera.Draw(graphicsDevice, _spriteBatch);

const bool pixelPerfect = false;
const bool pixelPerfect = true;

Rectangle destinationRectangle = pixelPerfect ? GetPixelPerfectRect() : GetFitRect();
_camera.RenderLocation = destinationRectangle;

graphicsDevice.Clear(Color.Black);

_spriteBatch.Begin(samplerState: pixelPerfect ? SamplerState.PointClamp : null);
_spriteBatch.Begin(samplerState: SamplerState.PointClamp);
_spriteBatch.Draw(_camera.RenderTarget, destinationRectangle, Color.White);

float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
Expand Down Expand Up @@ -165,7 +165,8 @@ private void HandleInput() {

if (currentMouseState.LeftButton != ButtonState.Pressed &&
currentMouseState.RightButton != ButtonState.Pressed ||
!_camera.RenderLocation.Contains(currentMouseState.Position)) {
!_camera.RenderLocation.Contains(currentMouseState.Position) ||
_gameDesktop.IsMouseOverGUI) {
return;
}

Expand Down
9 changes: 0 additions & 9 deletions Shared/Code/Block System/TileShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ namespace Shared.Code.Block_System;
public class TileShared : INetSerializable {
public readonly Transform Transform;

/// <summary>
/// Color of the tile.
/// </summary>
public Color Color = Color.White;

/// <summary>
/// The type of block this tile is.
/// </summary>
Expand All @@ -33,15 +28,11 @@ public TileShared(BlockShared newBlock, Vector2Int position) {
}

public void Serialize(NetDataWriter writer) {
writer.Put(Color.R);
writer.Put(Color.G);
writer.Put(Color.B);
writer.Put(Transform);
writer.Put(SourceBlock.BlockUid);
}

public void Deserialize(NetDataReader reader) {
Color = new Color(reader.GetByte(), reader.GetByte(), reader.GetByte());
Transform.Deserialize(reader);
SourceBlock = BlockManagerShared.AllBlocks[reader.GetString()];
}
Expand Down

0 comments on commit 8211ce3

Please sign in to comment.