[Block] Now possible to change grass into dirt.

This commit is contained in:
Quentin Bazin 2018-06-20 04:22:42 +02:00
parent b8239c2f22
commit 46fb26ab76
3 changed files with 37 additions and 11 deletions

View File

@ -18,10 +18,14 @@
#include "Types.hpp"
class Chunk;
class Block {
public:
Block(u32 id);
bool onClickEvent(Chunk *chunk);
glm::vec4 getTexCoords(int face) const;
u32 id() const { return m_id; }

View File

@ -99,6 +99,13 @@ void BlockCursor::onEvent(const SDL_Event &event) {
m_world.setBlock(m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z, 0);
}
else if (event.button.button == SDL_BUTTON_RIGHT) {
Block *block = m_world.getBlock(m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z);
Chunk *chunk = m_world.getChunk(m_selectedBlock.x / Chunk::width,
m_selectedBlock.y / Chunk::height,
m_selectedBlock.z / Chunk::depth);
if (block && !block->onClickEvent(chunk)) {
int face = m_selectedBlock.w;
int x = m_selectedBlock.x;
@ -115,6 +122,7 @@ void BlockCursor::onEvent(const SDL_Event &event) {
m_world.setBlock(x, y, z, 9);
}
}
}
}
void BlockCursor::update(bool useDepthBuffer) {

View File

@ -17,6 +17,20 @@ Block::Block(u32 id) {
m_id = id;
}
#include "Chunk.hpp"
bool Block::onClickEvent(Chunk *chunk) {
if (m_id == 3) {
m_id = 1;
chunk->setChanged(true);
return true;
}
return false;
}
glm::vec4 Block::getTexCoords(int face) const {
u32 id = m_id;