1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-08 19:27:18 -05:00
OpenDiablo2/OpenDiablo2.Core/Map Engine/MapEngine.cs

108 lines
3.4 KiB
C#
Raw Normal View History

using System;
using System.Drawing;
using OpenDiablo2.Common;
2018-11-27 23:09:10 -05:00
using OpenDiablo2.Common.Enums;
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;
cOffX = (int)((cameraLocation.X - cameraLocation.Y) * (cellSizeX / 2));
cOffY = (int)((cameraLocation.X + cameraLocation.Y) * (cellSizeY / 2));
}
}
private ISprite loadingSprite;
private int cOffX, cOffY;
2018-11-24 23:49:56 -05:00
//private ISprite[] tempMapCell;
private const int
cellSizeX = 160,
cellSizeY = 80,
renderCellsX = (800 / cellSizeX),
renderCellsY = (600 / cellSizeY);
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();
CameraLocation = new PointF(0, 0);
}
private void LoadNewMapData()
{
}
public void Render()
{
var cx = -(cameraLocation.X - Math.Truncate(cameraLocation.X));
var cy = -(cameraLocation.Y - Math.Truncate(cameraLocation.Y));
for (int ty = -5; ty <= 9; ty++)
{
for (int tx = -5; tx <= 9; tx++)
{
var ax = tx + Math.Truncate(cameraLocation.X);
var ay = ty + Math.Truncate(cameraLocation.Y);
2018-11-25 14:15:13 -05:00
var px = (tx - ty) * (cellSizeX / 2);
var py = (tx + ty) * (cellSizeY / 2);
2018-11-27 23:09:10 -05:00
var ox = (cx - cy) * (cellSizeX / 2);
var oy = (cx + cy) * (cellSizeY / 2);
2018-11-25 14:15:13 -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
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
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
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-27 23:09:10 -05:00
}
2018-11-24 23:49:56 -05:00
2018-11-27 23:09:10 -05:00
public void Update(long ms)
{
}
2018-11-27 23:09:10 -05:00
}
}