removed placement inside player
This commit is contained in:
parent
73daa75c5f
commit
fe5706e65f
|
|
@ -43,5 +43,6 @@ public class EventService
|
|||
EventPublisher.Publish(EventType.MouseWheel, e);
|
||||
}
|
||||
}
|
||||
EventPublisher.Publish(EventType.Tick, new SDL_Event());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,4 +10,5 @@ public enum EventType
|
|||
KeyUp,
|
||||
WindowResize,
|
||||
MouseWheel,
|
||||
Tick,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,12 +21,16 @@ public class Place
|
|||
{
|
||||
return;
|
||||
}
|
||||
if (PlayerEntity.HasCollisionWithAnyPlayer(packet.Target))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (ctx.GameState.World.HasChunkAt(packet.Target))
|
||||
{
|
||||
var chunk = ctx.GameState.World.GetChunkAt(packet.Target);
|
||||
var tile = chunk.GetTileAt(packet.Target);
|
||||
var tileId = tile.Id;
|
||||
if (tileId != 0 || player.Inventory.Hotbar[packet.Slot]?.Count <= 0)
|
||||
if (tileId != 0 || player.Inventory.Hotbar[packet.Slot] == null || player.Inventory.Hotbar[packet.Slot]?.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,4 +90,35 @@ public class PlayerEntity
|
|||
}
|
||||
} while (hasCollision);
|
||||
}
|
||||
|
||||
public static bool HasCollisionWithAnyPlayer(Vector2 pos)
|
||||
{
|
||||
var ctx = Context.Get();
|
||||
var ts = Constants.TileSize;
|
||||
var tilePos = new Vector2(pos.X - pos.X % ts, pos.Y - pos.Y % ts);
|
||||
return ctx.GameState.Players.Any(
|
||||
player =>
|
||||
{
|
||||
var playerPos = player.Position;
|
||||
var playerSize = new Vector2(14, 28);
|
||||
var playerRect = new SDL_Rect
|
||||
{
|
||||
x = (int)playerPos.X,
|
||||
y = (int)playerPos.Y - 5,
|
||||
w = (int)playerSize.X,
|
||||
h = (int)playerSize.Y
|
||||
};
|
||||
var tileRect = new SDL_Rect
|
||||
{
|
||||
x = (int)tilePos.X,
|
||||
y = 24 + (int)tilePos.Y,
|
||||
w = 16,
|
||||
h = 16
|
||||
};
|
||||
Console.WriteLine("playerRect: " + playerRect.x + ", " + playerRect.y + ", " + playerRect.w + ", " + playerRect.h);
|
||||
Console.WriteLine("tileRect: " + tileRect.x + ", " + tileRect.y + ", " + tileRect.w + ", " + tileRect.h);
|
||||
return SDL_HasIntersection(ref playerRect, ref tileRect) == SDL_bool.SDL_TRUE;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ namespace Mine2d.game.frontend.events;
|
|||
|
||||
public class PlayerBreakInput
|
||||
{
|
||||
[EventListener(EventType.MouseMotion)]
|
||||
public static void OnBreak(SDL_Event e)
|
||||
private static Vector2 mousePos;
|
||||
|
||||
[EventListener(EventType.Tick)]
|
||||
public static void OnTick()
|
||||
{
|
||||
var ctx = Context.Get();
|
||||
var mousePos = new Vector2(e.motion.x, e.motion.y);
|
||||
ctx.FrontendGameState.MousePosition = mousePos;
|
||||
if (ctx.GameState.Players.Find(player => player.Id == ctx.FrontendGameState.PlayerGuid)?.Mining
|
||||
!= Vector2.Zero)
|
||||
|
|
@ -26,6 +27,13 @@ public class PlayerBreakInput
|
|||
Source = BreakSource.Move
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[EventListener(EventType.MouseMotion)]
|
||||
public static void OnBreak(SDL_Event e)
|
||||
{
|
||||
mousePos = new Vector2(e.motion.x, e.motion.y);
|
||||
}
|
||||
|
||||
[EventListener(EventType.MouseButtonDown)]
|
||||
|
|
|
|||
Loading…
Reference in New Issue