04-21-2013, 05:49 AM
If it works, why not? Still, I'd prefer if the whole explosion method was moved into the cChunkMap + cChunk, so that it can manipulate blocks directly.
|
Explosions and TNT block and entity
|
|
04-21-2013, 05:49 AM
If it works, why not? Still, I'd prefer if the whole explosion method was moved into the cChunkMap + cChunk, so that it can manipulate blocks directly.
04-21-2013, 06:04 AM
ok so for some reason i can't edit the World.cpp so i'l just post the changes i made here. you may choose for yourself if you want to implent it or not
![]()
if (GetBlock(a_BlockX, a_BlockY, a_BlockZ) != 9)
{
for (int x = 0; x < ExplosionSizeInt; x++)
{
for (int y = 0; y < ExplosionSizeInt; y++)
{
for (int z = 0; z < ExplosionSizeInt; z++)
{
DigBlock(a_BlockX + x, a_BlockY + y, a_BlockZ + z);
DigBlock(a_BlockX + x, a_BlockY - y, a_BlockZ + z);
DigBlock(a_BlockX - x, a_BlockY - y, a_BlockZ - z);
DigBlock(a_BlockX - x, a_BlockY + y, a_BlockZ - z);
DigBlock(a_BlockX + x, a_BlockY + y, a_BlockZ - z);
DigBlock(a_BlockX + x, a_BlockY - y, a_BlockZ - z);
DigBlock(a_BlockX - x, a_BlockY + y, a_BlockZ + z);
DigBlock(a_BlockX - x, a_BlockY - y, a_BlockZ + z);
BlocksAffected.push_back(Vector3i(a_BlockX + x, a_BlockY + y, a_BlockZ + z));
BlocksAffected.push_back(Vector3i(a_BlockX + x, a_BlockY - y, a_BlockZ + z));
BlocksAffected.push_back(Vector3i(a_BlockX - x, a_BlockY - y, a_BlockZ - z));
BlocksAffected.push_back(Vector3i(a_BlockX - x, a_BlockY + y, a_BlockZ - z));
BlocksAffected.push_back(Vector3i(a_BlockX + x, a_BlockY + y, a_BlockZ - z));
BlocksAffected.push_back(Vector3i(a_BlockX + x, a_BlockY - y, a_BlockZ - z));
BlocksAffected.push_back(Vector3i(a_BlockX - x, a_BlockY + y, a_BlockZ + z));
BlocksAffected.push_back(Vector3i(a_BlockX - x, a_BlockY - y, a_BlockZ + z));
}
}
}
}
04-21-2013, 06:14 AM
Bad idea: comparing to a number, instead of a named constant. If you come back to this code in a month, you won't know that 9 is "water"
Even worse: You're checking only one value used for water, you need to check two: E_BLOCK_WATER and E_BLOCK_STATIONARY_WATER. Now, how about lava? Obsidian? Bedrock? Before you start writing a huge IF condition, let me suggest writing a switch block instead, with the block destroying in its default branch
04-21-2013, 06:19 AM
i already tried to make it ignore both water blocks but it didn't realy work. i tried
if (GetBlock(a_BlockX, a_BlockY, a_BlockZ) != 8,9) //should be E_BLOCK_ETC nowand if (GetBlock(a_BlockX, a_BlockY, a_BlockZ) != 8||9) //should be E_BLOCK_ETC nowthat was what i found on google for the obsydian and bedrock stuff. i don't think the explosion will be IN a obsydian/bedrock block
If you want to do it as an IF statement:
BLOCKTYPE BlockType = GetBlock(a_BlockX, a_BlockY, a_BlockZ); if ((BlockType == E_BLOCK_WATER) || (BlockType == E_BLOCK_STATIONARY_WATER) || (BlockType == ...)) If you want to do it more intelligently, do a switch:
switch (GetBlock(a_BlockX, a_BlockY, a_BlockZ)
{
case E_BLOCK_STATIONARY_WATER:
case E_BLOCK_WATER:
{
// TNT in these blocks doesn't do environmental damage
break;
}
default:
{
// Destroy the neighboring blocks:
for (int y = 0; y < ExplosionSizeInt; y++) ...
}
}
04-21-2013, 12:31 PM
Yeah, I was going to rewrite to use chunk (maybe cBlockArea) and to actually create rays of explosions that attempts to destroy the blocks depending on their resistance. It was kind of a big task to make it on the first try (I am also working on the physics for entities which is another big task hehe
), so that's why i decided just to implement it as a simple cube as first step
05-04-2013, 10:50 PM
TNT flows with water
its pretty cool
05-05-2013, 01:28 AM
yeah, and the idea is that will also collide with other entities once we implement entity on entity collision
05-05-2013, 01:32 AM
:O thats awsome
05-05-2013, 02:51 AM
mmmm, i was thinking: shouldn't explosion be its own class? cExplosion...
|
|
« Next Oldest | Next Newest »
|