Skip to content

Commit

Permalink
Merge pull request #16 from Superyodeler/Multiplayer
Browse files Browse the repository at this point in the history
Adds Multiplayer
  • Loading branch information
MarkSuckerberg authored Oct 3, 2023
2 parents 22da09c + d6f229e commit ee3c95e
Show file tree
Hide file tree
Showing 64 changed files with 1,602 additions and 596 deletions.
14 changes: 9 additions & 5 deletions Blocktest/Blocktest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@
<ApplicationIcon>Icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<None Remove="Icon.ico"/>
<None Remove="Icon.bmp"/>
<None Remove="Icon.ico" />
<None Remove="Icon.bmp" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Icon.ico"/>
<EmbeddedResource Include="Icon.bmp"/>
<EmbeddedResource Include="Icon.ico" />
<EmbeddedResource Include="Icon.bmp" />
</ItemGroup>
<PropertyGroup>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LiteNetLib" Version="1.1.0" />
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.*" />
<PackageReference Include="Nopipeline.Task" Version="2.2.*" />
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.*"/>
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
<Target Name="RestoreDotnetTools" BeforeTargets="Restore">
<Message Text="Restoring dotnet tools" Importance="High" />
Expand Down
26 changes: 21 additions & 5 deletions Blocktest/BlocktestGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,51 @@ public class BlocktestGame : Game
{
private GraphicsDeviceManager _graphics;
private Scene? _currentScene;
private bool connect;
private string ip;



/// <inheritdoc />
public BlocktestGame()
{
connect = false;
ip = "";
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
TargetElapsedTime = TimeSpan.FromMilliseconds(16);
}

public BlocktestGame(string newIp)
{
connect = true;
ip = newIp;
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
Window.AllowUserResizing = true;
TargetElapsedTime = TimeSpan.FromMilliseconds(16);
}

/// <inheritdoc />
protected override void Initialize() {
BlockManager.Initialize();
BlockManagerShared.Initialize();
base.Initialize();
}

/// <inheritdoc />
protected override void LoadContent()
{
Drawable.ContentManager = Content;
BlockManager.LoadBlockSprites(Content);
_currentScene = new GameScene(this);
BlockSpritesManager.LoadBlockSprites(Content);
_currentScene = new GameScene(this, connect, ip);
}

/// <inheritdoc />
protected override void Update(GameTime gameTime)
{
_currentScene?.Update(gameTime);

base.Update(gameTime);
}

Expand Down
52 changes: 52 additions & 0 deletions Blocktest/Code/Block System/BlockSprites.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Blocktest.Rendering;

namespace Blocktest
{
/// <summary>
/// Handles sprites for blocks.
/// </summary>
public class BlockSprites
{
/// <summary> Shared block info </summary>
public BlockShared blockShared;

/// <summary> The block's sprite. </summary>
public Drawable blockSprite;

/// <summary> The sprite sheet used for smoothing the block. </summary>
public SpriteSheet spriteSheet;

/* METHODS */

public BlockSprites(BlockShared newBlockShared, ContentManager content)
{
blockShared = newBlockShared;
LoadSprite(content);
}

/// <summary>
/// Called when the block is created by the block sprites manager.
/// </summary>
/// <remarks>
/// DO NOT FORGET TO CALL THE BASE METHOD IF YOU OVERRIDE THIS.
/// </remarks>
public virtual void LoadSprite(ContentManager content)
{
string path = @"Graphics\Blocks\" + blockShared.blockName.ToLower().Replace(" ", "");
try {
blockSprite = new Drawable(path, new Rectangle(1, 1, 10, 10)); //this might need to be expanded in the future in case we decide to make use of the full 12x12 tiles on our spritesheets
/*if (!blockShared.blockSmoothing) {
return;
}*/
spriteSheet = new SpriteSheet(path, 4, 4, 1);
if (spriteSheet.OrderedSprites.Length <= 1) {
Console.WriteLine("Block " + this + " is marked as smoothable, but a sprite sheet could not be found at " + path + "!");
}
}
catch (ContentLoadException) {
blockSprite = new Drawable(@"Graphics\Blocks\error");
Console.WriteLine("Block " + this + " does not have an icon at " + path + "!");
}
}
}
}
31 changes: 31 additions & 0 deletions Blocktest/Code/Block System/BlockSpritesManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Blocktest.Rendering;

namespace Blocktest
{
public class BlockSpritesManager
{
/// <summary> Array which stores all blocksprites instances for referencing as if they were globals. </summary>
private static BlockSprites[] allBlocksSprites;
/// <summary> Array which stores all blocksprites instances for referencing as if they were globals. </summary>
public static BlockSprites[] AllBlocksSprites { get => allBlocksSprites; private set => allBlocksSprites = value; }

/// <summary> List used to store the names of blocks. The indexes are the corresponding block's ID. </summary>
private static string[] blockSpriteNames;
/// <summary> List used to store the names of blocks. The indexes are the corresponding block's ID. </summary>
public static string[] BlockSpriteNames { get => blockSpriteNames; private set => blockSpriteNames = value; }

public static void LoadBlockSprites(ContentManager content)
{
AllBlocksSprites = new BlockSprites[BlockManagerShared.AllBlocks.Length];
BlockSpriteNames = new string[BlockManagerShared.AllBlocks.Length];

for(int i = 0; i < BlockManagerShared.AllBlocks.Length; i++)
{
BlockShared block = BlockManagerShared.AllBlocks[i];
BlockSprites newBlockSprites = new(block, content);
BlockSpriteNames[block.blockID] = block.blockName;
AllBlocksSprites[block.blockID] = newBlockSprites;
}
}
}
}
175 changes: 0 additions & 175 deletions Blocktest/Code/Block System/Tilemap.cs

This file was deleted.

48 changes: 48 additions & 0 deletions Blocktest/Code/Block System/TilemapSprites.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Blocktest.Rendering;
namespace Blocktest
{
/// <summary>
/// Handles drawing <see cref="TilemapShared"/>.
/// </summary>
public class TilemapSprites
{
public TilemapShared tilemap;

/// <summary>
/// Creates a <see cref="Tilemap"/>.
/// </summary>
/// <param name="sizeX">The width of the tilemap in tiles.</param>
/// <param name="sizeY">The height of the tilemap in tiles.</param>
public TilemapSprites(TilemapShared newTilemap)
{
tilemap = newTilemap;
}

/// <summary>
/// Called from the main draw loop, draws each tile in the tilemap.
/// </summary>
/// <remarks>
/// This can almost definitely be optimized, but I'm focused on getting a decent version out
/// quickly so the codebase split causes fewer issues for others.
/// </remark>
/// <param name="spriteBatch">The spritebatch to draw the tilemap tiles' sprite on.</param>
public void DrawAllTiles(SpriteBatch spriteBatch)
{
for(int x = 0; x < tilemap.tilemapSize.X; x++)
{
for(int y = 0; y < tilemap.tilemapSize.Y; y++)
{
TileShared? tile = tilemap.tileGrid[x, y];
BlockSprites blockSprites = BlockSpritesManager.AllBlocksSprites[tile.SourceBlock.blockID];
Drawable sprite = blockSprites.spriteSheet.OrderedSprites[tile.bitmask];
spriteBatch.Draw(sprite.Texture, new Vector2(tile.rectangle.X, tile.rectangle.Y), sprite.Bounds, tile.color);
}
}
/*foreach (TileShared tile in tilemap.allTiles) {
BlockSprites blockSprites = BlockSpritesManager.AllBlocksSprites[tile.SourceBlock.blockID];
Drawable sprite = blockSprites.spriteSheet.OrderedSprites[tile.bitmask];
spriteBatch.Draw(sprite.Texture, new Vector2(tile.rectangle.X, tile.rectangle.Y), sprite.Bounds, tile.color);
}*/
}
}
}
Loading

0 comments on commit ee3c95e

Please sign in to comment.