* Finish rocket launcher block

This commit is contained in:
iProgramInCpp 2023-12-31 15:06:05 +02:00
parent de020470f4
commit 90bd2935d4
5 changed files with 41 additions and 16 deletions

View file

@ -65,14 +65,14 @@ void Rocket::tick()
field_B90--;
if (field_B90 == 0)
{
for (int i = 0; i < 50; i++)
for (int i = 0; i < 100; i++)
{
float yaw = sharedRandom.nextFloat() * float(M_PI) * 2;
float pitch = sharedRandom.nextFloat() * float(M_PI) * 2;
float xo = sharedRandom.nextFloat() * cosf(yaw);
float zo = sharedRandom.nextFloat() * sinf(yaw);
float yo = sharedRandom.nextFloat() * sinf(pitch);
float xo = cosf(yaw);
float zo = sinf(yaw);
float yo = sinf(pitch);
m_pLevel->addParticle("explodeColor", m_pos.x, m_pos.y, m_pos.z, xo, yo, zo);
}

View file

@ -31,7 +31,7 @@ bool RocketItem::useOn(ItemInstance* inst, Player* player, Level* level, int x,
case DIR_XPOS: x++; break;
}
level->addEntity(new Rocket(level, float(x), float(y), float(z)));
level->addEntity(new Rocket(level, float(x) + 0.5f, float(y) + 0.5f, float(z) + 0.5f));
inst->m_amount--;
return true;

View file

@ -6,10 +6,17 @@
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#include "RocketLauncherTile.hpp"
#include "world/item/RocketItem.hpp"
#include "world/level/Level.hpp"
#include "world/entity/Rocket.hpp"
RocketLauncherTile::RocketLauncherTile(int id, int texture) : Tile(id, texture, Material::wood)
RocketLauncherTile::RocketLauncherTile(int id) : Tile(id, 16*14+2, Material::wood)
{
setTicking(true);
}
int RocketLauncherTile::getTexture(int dir, int data)
{
return data == 1 ? 16*14+3 : 16*14+2;
}
AABB* RocketLauncherTile::getAABB(Level*, int x, int y, int z)
@ -32,10 +39,26 @@ bool RocketLauncherTile::isSolidRender()
return false;
}
int RocketLauncherTile::use(Level* pLevel, int x, int y, int z, Player* player)
int RocketLauncherTile::use(Level* level, int x, int y, int z, Player* player)
{
// spawn a rocket
if (level->getData(x, y, z) == 1)
return 1;
level->setData(x, y, z, 1);
// spawn a rocket
level->addEntity(new Rocket(level, float(x) + 0.5f, float(y) + 0.5f, float(z) + 0.5f));
// add a tick so that the rocket launcher will reset
level->addToTickNextTick(x, y, z, m_ID, 10);
return 1;
}
void RocketLauncherTile::tick(Level* level, int x, int y, int z, Random* random)
{
if (level->getData(x, y, z) != 1)
return;
level->setData(x, y, z, 0);
}

View file

@ -13,11 +13,13 @@
class RocketLauncherTile : public Tile
{
public:
RocketLauncherTile(int id, int texture);
RocketLauncherTile(int id);
virtual AABB* getAABB(Level*, int x, int y, int z) override;
virtual int getRenderShape() override;
virtual bool isCubeShaped() override;
virtual bool isSolidRender() override;
virtual int use(Level* pLevel, int x, int y, int z, Player* player);
int getTexture(int dir, int data) override;
AABB* getAABB(Level*, int x, int y, int z) override;
int getRenderShape() override;
bool isCubeShaped() override;
bool isSolidRender() override;
int use(Level* pLevel, int x, int y, int z, Player* player) override;
void tick(Level*, int, int, int, Random*) override;
};

View file

@ -699,7 +699,7 @@ void Tile::initTiles()
->setDescriptionId("cryingObsidian");
// Jolly
Tile::rocketLauncher = (new RocketLauncherTile(TILE_ROCKET_LAUNCHER, 16*14+2))
Tile::rocketLauncher = (new RocketLauncherTile(TILE_ROCKET_LAUNCHER))
->init()
->setSoundType(Tile::SOUND_STONE)
->setDescriptionId("rocketLauncher");