LevelData
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Objects;
|
||||
|
||||
namespace Level
|
||||
{
|
||||
@@ -34,7 +35,6 @@ namespace Level
|
||||
// Properties
|
||||
public static LevelBuilder Instance => instance;
|
||||
|
||||
|
||||
// Methods
|
||||
private void Awake()
|
||||
{
|
||||
@@ -89,7 +89,53 @@ namespace Level
|
||||
}
|
||||
|
||||
|
||||
public LayoutCell GetCellAt(Vector2Int layoutPosition)
|
||||
public LevelData CreateLevelData()
|
||||
{
|
||||
LayoutCell.LayoutCellData[][] layoutData = new LayoutCell.LayoutCellData[height][];
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
layoutData[y] = new LayoutCell.LayoutCellData[width];
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
layoutData[y][x] = layout[y][x].cellData;
|
||||
}
|
||||
}
|
||||
|
||||
LevelData levelData = new LevelData();
|
||||
levelData.layout = layoutData;
|
||||
levelData.width = width;
|
||||
levelData.height = height;
|
||||
return levelData;
|
||||
}
|
||||
|
||||
|
||||
public void LoadLevelData(LevelData levelData)
|
||||
{
|
||||
CreateLayout(levelData.width, levelData.height);
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
LayoutCell cell = layout[y][x];
|
||||
cell.cellData = levelData.layout[y][x];
|
||||
cell.UpdateSprites();
|
||||
|
||||
if (cell.cellData.cellContent == LayoutCell.LayoutCellData.CellContent.Crate)
|
||||
{
|
||||
cell.PlaceCrate();
|
||||
}
|
||||
else if (cell.cellData.cellContent == LayoutCell.LayoutCellData.CellContent.Player)
|
||||
{
|
||||
Player.Instance.Teleport(cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public LayoutCell GetCellAtLayout(Vector2Int layoutPosition)
|
||||
{
|
||||
// Check that cell with these indices exists in array
|
||||
// if (0 < layoutPosition.y < height && 0 < layoutPosition.x < width)
|
||||
@@ -109,7 +155,7 @@ namespace Level
|
||||
Vector3Int cellPos = grid.WorldToCell(worldPos);
|
||||
Vector2Int layoutPosition = ((Vector2Int) (cellPos - firstCellPos));
|
||||
|
||||
return GetCellAt(layoutPosition);
|
||||
return GetCellAtLayout(layoutPosition);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user