Skip to content
This repository has been archived by the owner on Sep 18, 2022. It is now read-only.

Commit

Permalink
Updated Tileset
Browse files Browse the repository at this point in the history
  • Loading branch information
craftersmine committed Mar 18, 2019
1 parent e815188 commit ba6488c
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions craftersmine.EtherEngine.Core/Objects/Tileset.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -9,28 +10,59 @@ namespace craftersmine.EtherEngine.Core
{
public sealed class Tileset : GameObject
{
public bool[,] Tiles;
private List<Tile> _tiles = new List<Tile>();
private Dictionary<string, Tile> _tilesPresets = new Dictionary<string, Tile>();

public TextureSet TilesTextures { get; private set; }
public int TileWidth { get; private set; }
public int TileHeight { get; private set; }
public TileOnUpdateAction TileOnUpdateAction { get; set; }

public Tileset(Texture tileTexture, int tileWidth, int tileHeight, int tilesAlongX, int tilesAlongY)
public Tileset(TextureSet tilesTextures, int tileWidth, int tileHeight)
{
Texture = tileTexture;
Tiles = new bool[tilesAlongX, tilesAlongY];
for (int x = 0; x < tilesAlongX; x++)
for (int y = 0; y < tilesAlongY; y++)
Tiles[x, y] = false;
TilesTextures = tilesTextures;
}

public override void OnUpdate()
{
//TiledImage.
foreach (Tile tile in _tiles)
{
TileOnUpdateAction?.Invoke(tile);
}
}

public void AddTile(int x, int y)
public Tile CheckTile(int x, int y)
{
throw new NotImplementedException("[WIP] CheckTile is not implemented yet");
}

public void AddTile(string tilePresetId, int x, int y)
{
try
{
Tile clonedTile = _tilesPresets[tilePresetId].Clone<Tile>();
clonedTile.TilesetX = x;
clonedTile.TilesetY = y;
_tiles.Add(clonedTile);
}
catch { }
}

/// <summary>
/// Tries to add preset of tile and returns true if success, otherwise false
/// </summary>
/// <param name="tile"></param>
/// <returns></returns>
public bool AddTilePreset(Tile tile)
{
if (!_tilesPresets.ContainsKey(tile.TileId))
{
_tilesPresets.Add(tile.TileId, tile);
return true;
}
else return false;
}
}

public delegate void TileOnUpdateAction(Tile updatingTile);
}

0 comments on commit ba6488c

Please sign in to comment.