Adding More Tile Functions (Non-building commit).
This commit is contained in:
@@ -100,6 +100,8 @@
|
||||
"mnemonic-id" : "grass",
|
||||
"display-name" : "Grass",
|
||||
"solid": true,
|
||||
"forced-ticc-func": "grass-forced",
|
||||
"random-ticc-func": "grass-random",
|
||||
"color": [124, 252, 0],
|
||||
"pallet": [[126, 252, 5], [122, 238, 0], [124, 248, 12]]
|
||||
},
|
||||
@@ -113,7 +115,9 @@
|
||||
"mnemonic-id" : "vine",
|
||||
"display-name" : "Vine",
|
||||
"solid": false,
|
||||
"color": [32, 139, 34]
|
||||
"color": [32, 139, 34],
|
||||
"forced-ticc-func": "vine-forced",
|
||||
"random-ticc-func": "vine-random"
|
||||
},
|
||||
{
|
||||
"mnemonic-id" : "sand",
|
||||
|
@@ -13,7 +13,6 @@
|
||||
|
||||
namespace CaveGame::Core {
|
||||
using J3ML::LinearAlgebra::Vector2i;
|
||||
|
||||
using TileID = u16;
|
||||
|
||||
struct Tile;
|
||||
@@ -24,6 +23,12 @@ namespace CaveGame::Core {
|
||||
|
||||
void SandGravTiccFunc(const Tile& data, ITileMap* world, int x, int y);
|
||||
void LiquidSettleTiccFunc(const Tile& data, ITileMap* world, int x, int y);
|
||||
void GrassRandomTiccFunc(const Tile& data, ITileMap* world, int x, int y);
|
||||
void GrassForcedTiccFunc(const Tile& data, ITileMap* world, int x, int y);
|
||||
void MossRandomTiccFunc(const Tile& data, ITileMap* world, int x, int y);
|
||||
void MossForcedTiccFunc(const Tile& data, ITileMap* world, int x, int y);
|
||||
void VineRandomTiccFunc(const Tile& data, ITileMap* world, int x, int y);
|
||||
void VineForcedTiccFunc(const Tile& data, ITileMap* world, int x, int y);
|
||||
|
||||
|
||||
static std::map<std::string, TileTiccFunc> ticc_funcs;
|
||||
@@ -124,12 +129,6 @@ namespace CaveGame::Core {
|
||||
uint8_t b;
|
||||
uint8_t g;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*std::unordered_map<std::string, TileTiccFunc> tile_functions {
|
||||
{"check-spread", [](const Tile& data, ITileMap* world, int x, int y){
|
||||
|
||||
|
@@ -305,4 +305,75 @@ namespace CaveGame::Core {
|
||||
|
||||
}
|
||||
|
||||
void MossRandomTiccFunc(const Tile &data, ITileMap *world, int x, int y) {
|
||||
|
||||
}
|
||||
|
||||
void GrassForcedTiccFunc(const Tile &data, ITileMap *world, int x, int y) {
|
||||
|
||||
}
|
||||
|
||||
void GrassRandomTiccFunc(const Tile &data, ITileMap *world, int x, int y) {
|
||||
|
||||
}
|
||||
|
||||
void MossForcedTiccFunc(const Tile &data, ITileMap *world, int x, int y) {
|
||||
|
||||
}
|
||||
|
||||
void VineRandomTiccFunc(const Tile &data, ITileMap *world, int x, int y) {
|
||||
static TileID air = Tiles()["air"].numeric_id;
|
||||
|
||||
|
||||
|
||||
if (DecayCheck(world, x,y, air))
|
||||
return;
|
||||
|
||||
if (SpreadCheck(world, x, y, air))
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void VineForcedTiccFunc(const Tile &data, ITileMap *world, int x, int y) {
|
||||
static TileID air = Tiles()["air"].numeric_id;
|
||||
if (DecayCheck(world, x, y, TileID::AIR))
|
||||
return;
|
||||
}
|
||||
|
||||
bool DecayCheck(ITileMap* world, int x, int y, TileID decays_to) {
|
||||
static TileID vine = Tiles()["vine"].numeric_id;
|
||||
static TileID grass = Tiles()["grass"].numeric_id;
|
||||
static TileID air = Tiles()["air"].numeric_id;
|
||||
|
||||
TileID above = world->GetTile(x, y-1);
|
||||
if (above != vine && above != grass)
|
||||
{
|
||||
DecayTo(world, x, y, air);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VineTile::ShouldSpread(ITileMap* world, int x, int y, TileID spreads_to) const
|
||||
{
|
||||
if (world->GetTile(x, y) == spreads_to)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VineTile::SpreadCheck(ITileMap* world, TileState state, int x, int y, TileID spreads_to)
|
||||
{
|
||||
if (ShouldSpread(world, x, y + 1, spreads_to))
|
||||
{
|
||||
if (world->GetTile(x+1, y+1) == TileID::AIR && world->GetTile(x-1, y+1) == TileID::AIR)
|
||||
{
|
||||
world->SetTile(x, y+1, numeric_id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@@ -92,6 +92,24 @@ namespace CaveGame::Core
|
||||
bool LoadTileMetadata(const std::filesystem::path &path) {
|
||||
|
||||
ticc_funcs.insert({"sand-grav", SandGravTiccFunc});
|
||||
ticc_funcs.insert({"liquid-settle", LiquidSettleTiccFunc});
|
||||
ticc_funcs.insert({"grass-random", GrassRandomTiccFunc});
|
||||
ticc_funcs.insert({"grass-forced", GrassForcedTiccFunc});
|
||||
ticc_funcs.insert({"moss-random", MossRandomTiccFunc});
|
||||
ticc_funcs.insert({"moss-forced", MossForcedTiccFunc});
|
||||
ticc_funcs.insert({"vine-random", VineRandomTiccFunc});
|
||||
ticc_funcs.insert({"vine-forced", VineForcedTiccFunc});
|
||||
//ticc_funcs.insert({"water-solver", })
|
||||
|
||||
// Subgroups for what collides with what. ~Will
|
||||
// Like collision mask? Or tile-reactions (i.e. obsidian and water)
|
||||
|
||||
// Solid means the tile is noncompressible. It is a solid box.
|
||||
// Collides means whether any collision test is even performed. Will be used for cosmetic tiles. Terrain decoration.
|
||||
// Otherwise, i'm thinking you could use an idiom like
|
||||
// Tile collided;
|
||||
// if (collided.tagged("soil")) { ... }
|
||||
|
||||
|
||||
using namespace JJX;
|
||||
std::string content = read_file(path);
|
||||
|
@@ -471,13 +471,6 @@ namespace CaveGame::Core {
|
||||
if (tile.does_random_ticc)
|
||||
tile.random_ticc_func(tile, this, wx, wy);
|
||||
|
||||
|
||||
//if (at == TileID::AIR)
|
||||
// continue;
|
||||
|
||||
//tile = GetByNumeric(at);
|
||||
//if ((tile != nullptr) && (tile->DoesRandomTicc()))
|
||||
// tile->RandomTicc(this, 0, wx, wy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -516,23 +509,4 @@ namespace CaveGame::Core {
|
||||
void World::SetSeed(int seed) {
|
||||
generator.SetSeed(seed);
|
||||
}
|
||||
|
||||
/*Vector2i World::GetChunkCoordinatesAtCell(int x, int y) const {
|
||||
float chunkX = Math::Floor(x / Chunk::ChunkSize);
|
||||
float chunkY = Math::Floor(y / Chunk::ChunkSize);
|
||||
|
||||
return Vector2i(chunkX, chunkY);
|
||||
}
|
||||
|
||||
Vector2i World::GetTileCoordinatesAtCell(int x, int y) const {
|
||||
float tileX = Math::Mod(x, Chunk::ChunkSize);
|
||||
float tileY = Math::Mod(y, Chunk::ChunkSize);
|
||||
|
||||
if (tileX < 0)
|
||||
tileX = Chunk::ChunkSize + tileX;
|
||||
if (tileY < 0)
|
||||
tileY = Chunk::ChunkSize + tileY;
|
||||
|
||||
return Vector2i(tileX, tileY);
|
||||
}*/
|
||||
}
|
||||
|
Reference in New Issue
Block a user