new super basic tiles
2
MyGame/.vscode/launch.json
vendored
|
@ -10,7 +10,7 @@
|
|||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
// If you have changed target frameworks, make sure to update the program path.
|
||||
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/MyGame.dll",
|
||||
"program": "${workspaceFolder}/bin/Debug/net5.0/MyGame.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||
|
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 199 B |
Before Width: | Height: | Size: 909 B After Width: | Height: | Size: 199 B |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 198 B |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 276 B |
BIN
MyGame/Content/tiles/tile05.png
Normal file
After Width: | Height: | Size: 203 B |
BIN
MyGame/Content/tiles/tile06.png
Normal file
After Width: | Height: | Size: 191 B |
BIN
MyGame/Content/walls/wall01.png
Normal file
After Width: | Height: | Size: 192 B |
BIN
MyGame/Content/walls/wall02.png
Normal file
After Width: | Height: | Size: 223 B |
BIN
MyGame/Content/walls/wall03.png
Normal file
After Width: | Height: | Size: 201 B |
BIN
MyGame/Content/walls/wall04.png
Normal file
After Width: | Height: | Size: 232 B |
BIN
MyGame/Content/walls/wall05.png
Normal file
After Width: | Height: | Size: 339 B |
|
@ -42,8 +42,9 @@ namespace MyGame
|
|||
private List<Tile> _map = new List<Tile>();
|
||||
private List<Wall> _mapWalls = new List<Wall>();
|
||||
private Tile _selectedTile = new Tile { X = 1, Y = 1 };
|
||||
private Wall _selectedWall = new Wall { X = 1, Y = 1 };
|
||||
|
||||
private int _tileSize = 30;
|
||||
private int _tileSize = 60;
|
||||
HubConnection connection;
|
||||
private Desktop _desktop;
|
||||
private int _currentTileId = 1;
|
||||
|
@ -62,7 +63,7 @@ namespace MyGame
|
|||
IsMouseVisible = true;
|
||||
Window.AllowUserResizing = true;
|
||||
connection = new HubConnectionBuilder()
|
||||
.WithUrl("http://localhost:5000/ChatHub")
|
||||
.WithUrl("http://hub.michelescandura.com:5000/ChatHub")
|
||||
.Build();
|
||||
connection.On<string, string>("ReceiveMessage", (user, message) =>
|
||||
{
|
||||
|
@ -373,6 +374,58 @@ namespace MyGame
|
|||
_viewportCenter = new Vector3(_viewportCenter.X + mouseState.Position.X - oldMouseState.Position.X, _viewportCenter.Y + mouseState.Position.Y - oldMouseState.Position.Y, 0);
|
||||
}
|
||||
|
||||
_selectedTile.X = (mouseState.Position.X - (int)_viewportCenter.X) / _tileSize;
|
||||
_selectedTile.Y = (mouseState.Position.Y - (int)_viewportCenter.Y) / _tileSize;
|
||||
|
||||
System.Console.WriteLine($"mouse {mouseState.Position.X} - {mouseState.Position.Y}");
|
||||
System.Console.WriteLine($"topleft {_selectedTile.X * _tileSize} - {_selectedTile.Y * _tileSize}");
|
||||
|
||||
var leftWall = PointInTriangle(mouseState.Position,
|
||||
new Point(_selectedTile.X * _tileSize, _selectedTile.Y * _tileSize),
|
||||
new Point(_selectedTile.X * _tileSize, _selectedTile.Y * _tileSize + _tileSize),
|
||||
new Point(_selectedTile.X * _tileSize + _tileSize / 2, _selectedTile.Y * _tileSize+ _tileSize/2));
|
||||
|
||||
var rightWall = PointInTriangle(mouseState.Position,
|
||||
new Point(_selectedTile.X * _tileSize + _tileSize, _selectedTile.Y * _tileSize),
|
||||
new Point(_selectedTile.X * _tileSize + _tileSize, _selectedTile.Y * _tileSize + _tileSize),
|
||||
new Point(_selectedTile.X * _tileSize + _tileSize / 2, _selectedTile.Y * _tileSize+ _tileSize/2));
|
||||
|
||||
var topWall = PointInTriangle(mouseState.Position,
|
||||
new Point(_selectedTile.X * _tileSize, _selectedTile.Y * _tileSize),
|
||||
new Point(_selectedTile.X * _tileSize + _tileSize, _selectedTile.Y * _tileSize),
|
||||
new Point(_selectedTile.X * _tileSize + _tileSize / 2, _selectedTile.Y * _tileSize+ _tileSize/2));
|
||||
|
||||
var bottomtWall = PointInTriangle(mouseState.Position,
|
||||
new Point(_selectedTile.X * _tileSize, _selectedTile.Y * _tileSize + _tileSize),
|
||||
new Point(_selectedTile.X * _tileSize + _tileSize, _selectedTile.Y * _tileSize + _tileSize),
|
||||
new Point(_selectedTile.X * _tileSize + _tileSize / 2, _selectedTile.Y * _tileSize+ _tileSize/2));
|
||||
|
||||
if (leftWall)
|
||||
{
|
||||
_selectedWall.X = _selectedTile.X;
|
||||
_selectedWall.Y = _selectedTile.Y;
|
||||
_selectedWall.Rotation = 1;
|
||||
}
|
||||
else if (rightWall)
|
||||
{
|
||||
_selectedWall.X = _selectedTile.X + 1;
|
||||
_selectedWall.Y = _selectedTile.Y;
|
||||
_selectedWall.Rotation = 1;
|
||||
}
|
||||
else if (topWall)
|
||||
{
|
||||
_selectedWall.X = _selectedTile.X;
|
||||
_selectedWall.Y = _selectedTile.Y;
|
||||
_selectedWall.Rotation = 0;
|
||||
}
|
||||
else if (bottomtWall)
|
||||
{
|
||||
_selectedWall.X = _selectedTile.X ;
|
||||
_selectedWall.Y = _selectedTile.Y+1;
|
||||
_selectedWall.Rotation = 0;
|
||||
}
|
||||
|
||||
System.Console.WriteLine($"{_selectedWall.X} - {_selectedWall.Y} - {_selectedWall.Rotation}");
|
||||
foreach (var key in newState.GetPressedKeys())
|
||||
{
|
||||
|
||||
|
@ -433,7 +486,7 @@ namespace MyGame
|
|||
else
|
||||
{
|
||||
_map.Add(new Tile { X = _selectedTile.X, Y = _selectedTile.Y, ID = tileId });
|
||||
connection?.InvokeAsync("SendMessage", $"{_selectedTile.X}:{_selectedTile.Y}", tileId.ToString(),_session);
|
||||
connection?.InvokeAsync("SendMessage", $"{_selectedTile.X}:{_selectedTile.Y}", tileId.ToString(), _session);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -521,13 +574,38 @@ namespace MyGame
|
|||
|
||||
}
|
||||
|
||||
_spriteBatch.DrawRectangle(new Rectangle(_selectedTile.X * _tileSize, _selectedTile.Y * _tileSize, _tileSize, _tileSize), Color.Blue, 3);
|
||||
// _spriteBatch.DrawRectangle(new Rectangle(_selectedTile.X * _tileSize, _selectedTile.Y * _tileSize, _tileSize, _tileSize), Color.Blue, 3);
|
||||
|
||||
|
||||
var startWall = new Vector2(_selectedWall.X * _tileSize, _selectedWall.Y * _tileSize);
|
||||
|
||||
_spriteBatch.DrawLine(startWall, _tileSize, MathHelper.ToRadians(90 * _selectedWall.Rotation), Color.Red, 2);
|
||||
|
||||
_spriteBatch.End();
|
||||
|
||||
_desktop?.Render();
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
|
||||
private float Sign(Point p1, Point p2, Point p3)
|
||||
{
|
||||
return (p1.X - p3.X) * (p2.Y - p3.Y) - (p2.X - p3.X) * (p1.Y - p3.Y);
|
||||
}
|
||||
|
||||
private bool PointInTriangle(Point pt, Point v1, Point v2, Point v3)
|
||||
{
|
||||
float d1, d2, d3;
|
||||
bool has_neg, has_pos;
|
||||
|
||||
d1 = Sign(pt, v1, v2);
|
||||
d2 = Sign(pt, v2, v3);
|
||||
d3 = Sign(pt, v3, v1);
|
||||
|
||||
has_neg = (d1 < 0) || (d2 < 0) || (d3 < 0);
|
||||
has_pos = (d1 > 0) || (d2 > 0) || (d3 > 0);
|
||||
|
||||
return !(has_neg && has_pos);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ExtensionMethods
|
||||
|
@ -546,5 +624,7 @@ namespace MyGame
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<PublishReadyToRun>false</PublishReadyToRun>
|
||||
<TieredCompilation>false</TieredCompilation>
|
||||
<PublishTrimmed>false</PublishTrimmed>
|
||||
<TrimMode>link</TrimMode>
|
||||
<_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) --verbose</_ExtraTrimmerArgs>
|
||||
</PropertyGroup>
|
||||
<Target Name="EnsureAllAssembliesAreLinked" BeforeTargets="PrepareForILLink">
|
||||
<ItemGroup>
|
||||
<ManagedAssemblyToLink>
|
||||
<TrimMode>link</TrimMode>
|
||||
</ManagedAssemblyToLink>
|
||||
<TrimmerRootAssembly Include="$(TargetName)" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
<PropertyGroup>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<ApplicationIcon>Icon.ico</ApplicationIcon>
|
||||
|
|