Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Character movement #77

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Server/Components/Pages/GamePage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<div class="info-content">
<div @onclick="() => _popup.ShowComponent<EquipmentPopup>(_equipmentPopupParameters)">
<img src="assets/infobutton.svg" />

</div>
</div>
</div>
Expand Down Expand Up @@ -84,7 +85,7 @@
<div class="journal">
<div class="info">
<div class="info-content">
<div @onclick="() => _popup.ShowComponent<JournalPopup>()"></div><img src="assets/infobutton.svg" />
<div @onclick="() => _popup.ShowComponent<JournalPopup>()" ></div><img src="assets/infobutton.svg" />
</div>
</div>

Expand Down Expand Up @@ -129,7 +130,6 @@
</div>
</div>


@code {
private User _user = new();
private readonly ObservableCollection<Item> _equipment = new();
Expand Down
14 changes: 13 additions & 1 deletion Server/Components/Popups/MapPopup.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@
@using Fracture.Server.Modules.MapGenerator.UI
@using Fracture.Server.Modules.MapGenerator.UI.Models

@inject NavigationManager NavigationManager

@page "/map"

<div class="row">
<MapView Map="Map" MapDisplayData="MapDisplayData" Path="null" IsMiniMap="false"></MapView>
<MapView Map="Map" MapDisplayData="MapDisplayData" Path="null" IsMiniMap="false" CharacterX="x" CharacterY="y"></MapView>
@update_map

Check warning on line 11 in Server/Components/Popups/MapPopup.razor

View workflow job for this annotation

GitHub Actions / Checks

Converting method group 'update_map' to non-delegate type 'object'. Did you intend to invoke the method?
</div>

@code {
[Parameter] public required MapData Map { get; set; }
[Parameter] public required MapDisplayData MapDisplayData { get; set; }
int x = MapView.CharacterXX;
int y = MapView.CharacterYY;

private void update_map()
{
NavigationManager.NavigateTo("/map");
}
}
3 changes: 2 additions & 1 deletion Server/Components/UI/PopupContainer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<DynamicComponent Type="@_componentType" Parameters="@_parameters" @ref="Component" />
}
<div>
<button class="closeBtn" @onclick="() => IsVisible = false"><img src="assets/closebutton.svg" /></button>
<button class="closeBtn" @onclick="() => IsVisible=false"><img src="assets/closebutton.svg" /></button>
</div>
</div>

Expand All @@ -23,6 +23,7 @@
StateHasChanged();
}


public DynamicComponent? Component = null;
private Type? _componentType = null;
private IDictionary<string, object>? _parameters;
Expand Down
4 changes: 2 additions & 2 deletions Server/Modules/MapGenerator/Services/MapGeneratorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class MapGeneratorService : IMapGeneratorService
private MapData _mapData = default!;

private readonly float _persistence = 0.5f;
private readonly float _lacunarity = 2f;
private readonly float _lacunarity = 1f;
private readonly int _octaves = 5;
private readonly float _scale = 5f;
private readonly float _scale = 4.5f;

private Random _rnd = new Random();

Expand Down
88 changes: 81 additions & 7 deletions Server/Modules/MapGenerator/UI/MapView.razor
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@using Fracture.Server.Modules.MapGenerator.Models
@using Fracture.Server.Modules.MapGenerator.UI.Models
@using Fracture.Server.Modules.Pathfinding.Models
@using Microsoft.AspNetCore.Components.Web

<div id="map">


<div id="map" tabindex="0" @onkeydown="HandleKeyDown">
@if (Map != null && MapDisplayData != null)
{
<table class="@(IsMiniMap ? "miniMapTable" : "mapTable")">
Expand All @@ -11,26 +14,34 @@
<tr>
@for (int x = 0; x < Map.Grid.GetLength(0); x++)
{
@if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.Position)
@if (x == CharacterXX && y == CharacterYY)
{


<td style='background: @GetTileColor(@Map.Grid[x, y])'>
C
</td>
}
else if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.Position)
{
<td style='background: @GetTileColor(@Map.Grid[x,y])'>
x:@x<br />y:@y
<td style='background: @GetTileColor(@Map.Grid[x, y])'>
x:@x<br/>y:@y
</td>
}
else if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.Noise)
{
<td style="background: @GetTileColor(@Map.Grid[x,y])">
<td style="background: @GetTileColor(@Map.Grid[x, y])">
@Math.Round(Map.Grid[x, y].NoiseValue, 2)
</td>
}
else if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.None)
{
<td style='background: @GetTileColor(@Map.Grid[x,y])'>
<td style='background: @GetTileColor(@Map.Grid[x, y])'>
</td>
}
else if (MapDisplayData.TileInformationDisplay == TileInformationDisplay.Path)
{
<td style='font-size: 16px; background: @GetTileColor(@Map.Grid[x,y])'>
<td style='font-size: 16px; background: @GetTileColor(@Map.Grid[x, y])'>
@GetPathForTile(Map.Grid[x, y])
</td>
}
Expand All @@ -53,7 +64,19 @@

[Parameter]
public bool IsMiniMap { get; set; } = true;

private bool isMoving = false;
public static int CharacterXX { get; set; } = 16;
public static int CharacterYY { get; set; } = 16;
[Parameter] public int CharacterX { get; set; } = CharacterXX;
[Parameter] public int CharacterY { get; set; } = CharacterXX;


private readonly HashSet<string> _blockingColors = new HashSet<string>
{
"#21618C","#2E86C1"
};

private string GetTileColor(Node node)
{
if (MapDisplayData!.ShowColorMap)
Expand Down Expand Up @@ -101,4 +124,55 @@
_ => ""
};
}

private void HandleKeyDown(KeyboardEventArgs e)
{
if (IsMiniMap==false)
{
if (isMoving) return;
isMoving = true;
int newX = CharacterXX;
int newY = CharacterYY;
switch (e.Key)
{
case "ArrowUp":
if (CharacterYY > 0) newY--;;
break;
case "ArrowDown":
if (CharacterYY < Map.Grid.GetLength(1)-1 ) newY++;
break;
case "ArrowLeft":
if (CharacterXX > 0) newX--;
break;
case "ArrowRight":
if (CharacterXX < Map.Grid.GetLength(0)-1 ) newX++;
break;
}

if (CanMoveToTile(newX, newY))
{
CharacterXX = newX;
CharacterYY = newY;
StateHasChanged();
}

Task.Delay(100).ContinueWith(_ =>
{
isMoving = false;
});
}


}

private bool CanMoveToTile(int x, int y)
{
Node targetNode = Map.Grid[x, y];
string tileColor = GetTileColor(targetNode);

return !_blockingColors.Contains(tileColor);
}


}

2 changes: 1 addition & 1 deletion Server/Modules/NoiseGenerator/Services/FalloffGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class FalloffGenerator
private static float Evaluate(float value)
{
const float a = 3;
const float b = 4.2f;
const float b = 5f;

return (float)(Math.Pow(value, a) / (Math.Pow(value, a) + Math.Pow(b - b * value, a)));
}
Expand Down
2 changes: 1 addition & 1 deletion Server/wwwroot/css/game.css
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ body {
scroll-snap-type: y mandatory;
scroll-behavior: smooth;
}
.eqCiolumn span {
.eqColumn span {
font-size: 1.1em;
font-weight: bolder;
}
Expand Down
Loading