ajout de billot de bois

This commit is contained in:
Jonathan Trottier 2023-11-20 16:02:45 -05:00
parent 79013fe5d1
commit 3118f71b9c
7 changed files with 192 additions and 109 deletions

View File

@ -36,7 +36,7 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y
float height = simplex.eval(xnoiz, ynoiz) * 50.f;// +1.f;
for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) {
if (GetBlock(ix, iy, iz) == BTYPE_AIR)
SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr);
SetBlock(ix, iy, iz, BTYPE_GREENGRASS, nullptr);
}
}
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Lacs"
@ -46,6 +46,37 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y
SetBlock(ix, iy, iz, BTYPE_ICE, nullptr);
}
}
int rnd = rand() % 15;
if (rnd == 4)
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // structure
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
for (int iy = 0; iy < 14; ++iy) {
if (ix == 3)
if (GetBlock(ix, iy, iz) == BTYPE_AIR)
Structure(ix, iy, iz, 2);
}
}
if (rnd == 3)
for (int ix = 0; ix < CHUNK_SIZE_Z; ++ix) // structure
for (int iz = 0; iz < CHUNK_SIZE_X; ++iz) {
for (int iy = 0; iy < 14; ++iy) {
if (iz == 4)
if (GetBlock(ix, iy, iz) == BTYPE_AIR)
Structure(ix, iy, iz, 2);
}
}
if (rnd == 6)
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // structure
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
for (int iy = 0; iy < 14; ++iy) {
if (ix == 3)
if (GetBlock(ix, iy, iz) == BTYPE_AIR)
Structure(ix, iy, iz, 2);
}
}
//for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Arbres"
// for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
// float xnoiz, ynoiz;
@ -61,8 +92,8 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y
// break;
// }
// }
/* }
else {
/* }
else {
input.seekg(0, std::ios_base::end);
int size = input.tellg();
input.seekg(0, std::ios_base::beg);
@ -75,7 +106,7 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz)
for (int iy = 0; iy < CHUNK_SIZE_Y; ++iy)
m_blocks.Set(ix, iy, iz, data[ix + (iz * CHUNK_SIZE_X) + (iy * CHUNK_SIZE_Z * CHUNK_SIZE_X)]);
}*/
}*/
}
Chunk::~Chunk() {
@ -140,3 +171,31 @@ void Chunk::MakeClean() { m_isDirty = false; }
void Chunk::MakeModified() { m_isModified = true; }
void Chunk::Structure(int x, int y, int z,int height)
{
for (int i = 0; i < height; i++)
{
SetBlock(x, i + y, z, BTYPE_GRASS, nullptr);
}
}

View File

@ -28,6 +28,7 @@ class Chunk {
void CheckNeighbors(unsigned int x, unsigned int z, World* world);
void GetPosition(unsigned int& x, unsigned int& y) const;
void Structure(int x, int y, int z, int height);
bool IsDirty() const;
void MakeDirty();
void MakeClean();

View File

@ -9,9 +9,9 @@
#define BUFFER_LENGTH 150
#define CHUNK_SIZE_X 4
#define CHUNK_SIZE_X 6
#define CHUNK_SIZE_Y 64
#define CHUNK_SIZE_Z 4
#define CHUNK_SIZE_Z 6
#define MAX_SELECTION_DISTANCE 5
#define SEED 0
#define COUNTDOWN 300
@ -34,7 +34,7 @@
#define BULLET_TIME .1
typedef uint8_t BlockType;
enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST };
enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_GREENGRASS, BTYPE_LAST };
typedef uint64_t Timestamp;
#ifdef _WIN32

View File

@ -398,6 +398,7 @@ void Engine::LoadResource() {
TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png");
TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png");
TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png");
TextureAtlas::TextureIndex texGreenGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "greengrass.png");
if (!m_textureAtlas.Generate(TEXTURE_SIZE, false)) {
std::cout << " Unable to generate texture atlas ..." << std::endl;
@ -413,7 +414,8 @@ void Engine::LoadResource() {
m_blockinfo[BTYPE_METAL] = new BlockInfo(BTYPE_METAL, "Metal", u, v, s, 1);
m_textureAtlas.TextureIndexToCoord(texIceIndex, u, v, s, s);
m_blockinfo[BTYPE_ICE] = new BlockInfo(BTYPE_ICE, "Ice", u, v, s, 1);
m_textureAtlas.TextureIndexToCoord(texGreenGrassIndex, u, v, s, s);
m_blockinfo[BTYPE_GREENGRASS] = new BlockInfo(BTYPE_GREENGRASS, "GreenGrass", u, v, s, 1);
std::cout << " Loading and compiling shaders ..." << std::endl;
if (!m_shader01.Load(SHADER_PATH "shader01.vert", SHADER_PATH "shader01.frag", true)) {
std::cout << " Failed to load shader " << std::endl;
@ -441,6 +443,7 @@ void Engine::SystemNotification(std::string systemLog) {
DisplayNotification(message);
}
void Engine::KillNotification(Player killer, Player killed) {
std::string message = "";
@ -1023,11 +1026,14 @@ void Engine::Render(float elapsedTime) {
m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation
// (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!).
if (m_key1) bloc++;
else if (m_key2) bloc--;
if (m_mouseWU) bloc++;
else if (m_mouseWD) bloc--;
if (bloc == BTYPE_LAST + 1) bloc = BTYPE_AIR + 1;
else if (bloc == BTYPE_AIR) bloc = BTYPE_LAST; // La selection de BTYPE_LAST <20>quipe l'arme.
m_mouseWU = m_mouseWD = false;
m_mouseWU = m_mouseWD = m_key1 = m_key2 = false;
if (m_mouseL) {
if (bloc != BTYPE_LAST)
@ -1200,6 +1206,10 @@ void Engine::KeyPressEvent(unsigned char key) {
break;
case 24: // Y - Ignorer
break;
case 27: // 1
break;
case 28: // 2
break;
case 255: // Fn - Ignorer
break;
default:
@ -1274,6 +1284,12 @@ void Engine::KeyReleaseEvent(unsigned char key) {
else
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
break;
case 27: // 1
m_key1 = true;
break;
case 28: // 2
m_key2 = true;
break;
case 57: // Espace - Stop sauter
m_keySpace = false;
break;
@ -1394,3 +1410,5 @@ bool Engine::LoadTexture(Texture& texture, const std::string& filename, bool use
return true;
}

View File

@ -58,6 +58,9 @@ private:
void DrawHud(float elapsedTime, BlockType bloc);
void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f);
Connector m_conn;
Shader m_shader01;
BlockInfo* m_blockinfo[BTYPE_LAST];
@ -123,6 +126,8 @@ private:
bool m_soloMultiChoiceMade = false;
bool m_stopcountdown = false;
bool m_key1 = false;
bool m_key2 = false;
bool m_keyK = false;
bool m_keyL = false;
bool m_keyW = false;

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB