2018-11-24 22:34:16 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using OpenDiablo2.Common;
|
2018-11-27 23:09:10 -05:00
|
|
|
|
using OpenDiablo2.Common.Enums;
|
2018-11-24 22:34:16 -05:00
|
|
|
|
using OpenDiablo2.Common.Interfaces;
|
|
|
|
|
|
|
|
|
|
namespace OpenDiablo2.Core.Map_Engine
|
|
|
|
|
{
|
|
|
|
|
public sealed class MapEngine : IMapEngine
|
|
|
|
|
{
|
|
|
|
|
private readonly IGameState gameState;
|
|
|
|
|
private readonly IRenderWindow renderWindow;
|
|
|
|
|
private readonly IResourceManager resourceManager;
|
|
|
|
|
|
|
|
|
|
private PointF cameraLocation = new PointF();
|
|
|
|
|
public PointF CameraLocation
|
|
|
|
|
{
|
|
|
|
|
get => cameraLocation;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (cameraLocation == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
cameraLocation = value;
|
2018-11-25 01:51:21 -05:00
|
|
|
|
cOffX = (int)((cameraLocation.X - cameraLocation.Y) * (cellSizeX / 2));
|
|
|
|
|
cOffY = (int)((cameraLocation.X + cameraLocation.Y) * (cellSizeY / 2));
|
2018-11-24 22:34:16 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ISprite loadingSprite;
|
2018-11-25 01:51:21 -05:00
|
|
|
|
private int cOffX, cOffY;
|
2018-11-24 23:49:56 -05:00
|
|
|
|
//private ISprite[] tempMapCell;
|
2018-11-24 22:34:16 -05:00
|
|
|
|
|
|
|
|
|
private const int
|
|
|
|
|
cellSizeX = 160,
|
|
|
|
|
cellSizeY = 80,
|
2018-11-28 19:28:41 -05:00
|
|
|
|
renderCellsX = (800 / cellSizeX),
|
|
|
|
|
renderCellsY = (600 / cellSizeY);
|
2018-11-24 22:34:16 -05:00
|
|
|
|
|
|
|
|
|
public MapEngine(
|
|
|
|
|
IGameState gameState,
|
|
|
|
|
IRenderWindow renderWindow,
|
|
|
|
|
IResourceManager resourceManager
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
this.gameState = gameState;
|
|
|
|
|
this.renderWindow = renderWindow;
|
|
|
|
|
this.resourceManager = resourceManager;
|
|
|
|
|
|
|
|
|
|
loadingSprite = renderWindow.LoadSprite(ResourcePaths.LoadingScreen, Palettes.Loading, new Point(300, 400));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void NotifyMapChanged()
|
|
|
|
|
{
|
|
|
|
|
LoadNewMapData();
|
2018-11-28 19:28:41 -05:00
|
|
|
|
CameraLocation = new PointF(0, 0);
|
2018-11-24 22:34:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadNewMapData()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Render()
|
|
|
|
|
{
|
2018-11-28 19:28:41 -05:00
|
|
|
|
var cx = -(cameraLocation.X - Math.Truncate(cameraLocation.X));
|
|
|
|
|
var cy = -(cameraLocation.Y - Math.Truncate(cameraLocation.Y));
|
|
|
|
|
|
|
|
|
|
for (int ty = -5; ty <= 9; ty++)
|
2018-11-25 18:37:53 -05:00
|
|
|
|
{
|
2018-11-28 19:28:41 -05:00
|
|
|
|
for (int tx = -5; tx <= 9; tx++)
|
2018-11-25 18:37:53 -05:00
|
|
|
|
{
|
2018-11-28 19:28:41 -05:00
|
|
|
|
var ax = tx + Math.Truncate(cameraLocation.X);
|
|
|
|
|
var ay = ty + Math.Truncate(cameraLocation.Y);
|
2018-11-25 14:15:13 -05:00
|
|
|
|
|
2018-11-28 19:28:41 -05:00
|
|
|
|
var px = (tx - ty) * (cellSizeX / 2);
|
|
|
|
|
var py = (tx + ty) * (cellSizeY / 2);
|
2018-11-27 23:09:10 -05:00
|
|
|
|
|
2018-11-28 19:28:41 -05:00
|
|
|
|
var ox = (cx - cy) * (cellSizeX / 2);
|
|
|
|
|
var oy = (cx + cy) * (cellSizeY / 2);
|
2018-11-25 14:15:13 -05:00
|
|
|
|
|
|
|
|
|
|
2018-11-28 19:28:41 -05:00
|
|
|
|
foreach (var cellInfo in gameState.GetMapCellInfo((int)ax, (int)ay, eRenderCellType.Floor))
|
|
|
|
|
renderWindow.DrawMapCell(cellInfo, 320 + (int)px + (int)ox, 210 + (int)py + (int)oy);
|
2018-11-25 14:15:13 -05:00
|
|
|
|
|
2018-11-28 19:28:41 -05:00
|
|
|
|
foreach (var cellInfo in gameState.GetMapCellInfo((int)ax, (int)ay, eRenderCellType.WallLower))
|
|
|
|
|
renderWindow.DrawMapCell(cellInfo, 320 + (int)px + (int)ox, 210 + (int)py + (int)oy);
|
2018-11-25 14:15:13 -05:00
|
|
|
|
|
2018-11-28 19:28:41 -05:00
|
|
|
|
foreach (var cellInfo in gameState.GetMapCellInfo((int)ax, (int)ay, eRenderCellType.WallUpper))
|
|
|
|
|
renderWindow.DrawMapCell(cellInfo, 320 + (int)px + (int)ox, 210 + (int)py + (int)oy);
|
2018-11-25 14:15:13 -05:00
|
|
|
|
|
2018-11-28 19:28:41 -05:00
|
|
|
|
foreach (var cellInfo in gameState.GetMapCellInfo((int)ax, (int)ay, eRenderCellType.Roof))
|
|
|
|
|
renderWindow.DrawMapCell(cellInfo, 320 + (int)px + (int)ox, 210 + (int)py + (int)oy);
|
2018-11-25 18:37:53 -05:00
|
|
|
|
|
2018-11-28 19:28:41 -05:00
|
|
|
|
}
|
2018-11-25 18:37:53 -05:00
|
|
|
|
}
|
2018-11-27 23:09:10 -05:00
|
|
|
|
|
2018-11-25 18:37:53 -05:00
|
|
|
|
}
|
2018-11-24 23:49:56 -05:00
|
|
|
|
|
2018-11-27 23:09:10 -05:00
|
|
|
|
|
2018-11-24 22:34:16 -05:00
|
|
|
|
public void Update(long ms)
|
|
|
|
|
{
|
2018-11-27 00:56:54 -05:00
|
|
|
|
}
|
2018-11-27 23:09:10 -05:00
|
|
|
|
|
|
|
|
|
|
2018-11-24 22:34:16 -05:00
|
|
|
|
}
|
|
|
|
|
}
|