SQC-15_online #1
| @@ -2,132 +2,163 @@ | |||||||
| #include "world.h" | #include "world.h" | ||||||
|  |  | ||||||
| Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y) { | Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y) { | ||||||
|     //std::ostringstream pos; // V<>rifie l'existence d'un fichier .chunk avec sa position. | 	//std::ostringstream pos; // V<>rifie l'existence d'un fichier .chunk avec sa position. | ||||||
|     //pos << CHUNK_PATH << x << '_' << y << ".chunk"; | 	//pos << CHUNK_PATH << x << '_' << y << ".chunk"; | ||||||
|     //std::ifstream input(pos.str(), std::fstream::binary); | 	//std::ifstream input(pos.str(), std::fstream::binary); | ||||||
|  |  | ||||||
|     //if (input.fail()) { | 	//if (input.fail()) { | ||||||
|         OpenSimplexNoise::Noise simplex = OpenSimplexNoise::Noise(seed); | 	OpenSimplexNoise::Noise simplex = OpenSimplexNoise::Noise(seed); | ||||||
|         m_blocks.Reset(BTYPE_AIR); | 	m_blocks.Reset(BTYPE_AIR); | ||||||
|  |  | ||||||
|         for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Montagnes | 	for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Montagnes | ||||||
|             for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { | 		for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { | ||||||
|                 float xnoiz, ynoiz; | 			float xnoiz, ynoiz; | ||||||
|                 xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 4096.; | 			xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 4096.; | ||||||
|                 ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 4096.; | 			ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 4096.; | ||||||
|                 double height = 0; | 			double height = 0; | ||||||
|                 for (int x = 0; x < 39; ++x) { | 			for (int x = 0; x < 39; ++x) { | ||||||
|                     height += simplex.eval(xnoiz, ynoiz); | 				height += simplex.eval(xnoiz, ynoiz); | ||||||
|                     height *= .79; | 				height *= .79; | ||||||
|                     xnoiz *= 1.139; | 				xnoiz *= 1.139; | ||||||
|                     ynoiz *= 1.139; | 				ynoiz *= 1.139; | ||||||
|                 } | 			} | ||||||
|                 height = height * 2000. * simplex.eval((double)(ix + x * CHUNK_SIZE_X) / 512., (double)(iz + y * CHUNK_SIZE_Z) / 512.); | 			height = height * 2000. * simplex.eval((double)(ix + x * CHUNK_SIZE_X) / 512., (double)(iz + y * CHUNK_SIZE_Z) / 512.); | ||||||
|                 height /= (CHUNK_SIZE_Y / 1.9); | 			height /= (CHUNK_SIZE_Y / 1.9); | ||||||
|                 height += 15.; | 			height += 15.; | ||||||
|                 for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) | 			for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) | ||||||
|                     SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); | 				SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); | ||||||
|             } | 		} | ||||||
|         for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Collines | 	for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Collines | ||||||
|             for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { | 		for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { | ||||||
|                 float xnoiz, ynoiz; | 			float xnoiz, ynoiz; | ||||||
|                 xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 512.; | 			xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 512.; | ||||||
|                 ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 512.; | 			ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 512.; | ||||||
|                 float height = simplex.eval(xnoiz, ynoiz) * 50.f;// +1.f; | 			float height = simplex.eval(xnoiz, ynoiz) * 50.f;// +1.f; | ||||||
|                 for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) { | 			for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) { | ||||||
|                     if (GetBlock(ix, iy, iz) == BTYPE_AIR) | 				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" | 	for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Lacs" | ||||||
|             for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { | 		for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { | ||||||
|                 for (int iy = 0; iy < 13; ++iy) { | 			for (int iy = 0; iy < 13; ++iy) { | ||||||
|                     if (GetBlock(ix, iy, iz) == BTYPE_AIR) | 				if (GetBlock(ix, iy, iz) == BTYPE_AIR) | ||||||
|                         SetBlock(ix, iy, iz, BTYPE_ICE, nullptr); | 					SetBlock(ix, iy, iz, BTYPE_ICE, nullptr); | ||||||
|                 } | 			} | ||||||
|             } | 		} | ||||||
|         //for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Arbres" |  | ||||||
|         //    for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { |  | ||||||
|         //        float xnoiz, ynoiz; |  | ||||||
|         //        xnoiz = (double)(iz * CHUNK_SIZE_Y + x * CHUNK_SIZE_X) / 256.; |  | ||||||
|         //        ynoiz = (double)(ix * CHUNK_SIZE_Y + y * CHUNK_SIZE_Z) / 256.; |  | ||||||
|         //        bool tree = (int)(abs(simplex.eval(xnoiz, ynoiz)) * 17933.f) % CHUNK_SIZE_Y > 126 ? true : false; |  | ||||||
|         //        for (int iy = 0; iy < CHUNK_SIZE_Y - 10; ++iy) |  | ||||||
|         //            if (GetBlock(ix, iy, iz) == BTYPE_AIR) |  | ||||||
|         //                if (GetBlock(ix, iy - 1, iz) == BTYPE_GRASS) |  | ||||||
|         //                    if (tree) { |  | ||||||
|         //                        for (int i = 0; i < (int)(abs(simplex.eval(xnoiz, ynoiz) * 4)) % 42 + 1; ++i) |  | ||||||
|         //                            SetBlock(ix, iy + i, iz, BTYPE_DIRT, nullptr); |  | ||||||
|         //                        break; |  | ||||||
|         //                    } |  | ||||||
|         //    } |  | ||||||
|     /* } |  | ||||||
|     else { |  | ||||||
|         input.seekg(0, std::ios_base::end); |  | ||||||
|         int size = input.tellg(); |  | ||||||
|         input.seekg(0, std::ios_base::beg); |  | ||||||
|  |  | ||||||
|         char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z]; | 	int rnd = rand() % 15; | ||||||
|         input.read(data, size); | 	if (rnd == 4) | ||||||
|         input.close(); | 		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) |  | ||||||
|             for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) | 	//for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Arbres" | ||||||
|                 for (int iy = 0; iy < CHUNK_SIZE_Y; ++iy) | 	//    for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { | ||||||
|                     m_blocks.Set(ix, iy, iz, data[ix + (iz * CHUNK_SIZE_X) + (iy * CHUNK_SIZE_Z * CHUNK_SIZE_X)]); | 	//        float xnoiz, ynoiz; | ||||||
|     }*/ | 	//        xnoiz = (double)(iz * CHUNK_SIZE_Y + x * CHUNK_SIZE_X) / 256.; | ||||||
|  | 	//        ynoiz = (double)(ix * CHUNK_SIZE_Y + y * CHUNK_SIZE_Z) / 256.; | ||||||
|  | 	//        bool tree = (int)(abs(simplex.eval(xnoiz, ynoiz)) * 17933.f) % CHUNK_SIZE_Y > 126 ? true : false; | ||||||
|  | 	//        for (int iy = 0; iy < CHUNK_SIZE_Y - 10; ++iy) | ||||||
|  | 	//            if (GetBlock(ix, iy, iz) == BTYPE_AIR) | ||||||
|  | 	//                if (GetBlock(ix, iy - 1, iz) == BTYPE_GRASS) | ||||||
|  | 	//                    if (tree) { | ||||||
|  | 	//                        for (int i = 0; i < (int)(abs(simplex.eval(xnoiz, ynoiz) * 4)) % 42 + 1; ++i) | ||||||
|  | 	//                            SetBlock(ix, iy + i, iz, BTYPE_DIRT, nullptr); | ||||||
|  | 	//                        break; | ||||||
|  | 	//                    } | ||||||
|  | 	//    } | ||||||
|  | /* } | ||||||
|  | else { | ||||||
|  | 	input.seekg(0, std::ios_base::end); | ||||||
|  | 	int size = input.tellg(); | ||||||
|  | 	input.seekg(0, std::ios_base::beg); | ||||||
|  |  | ||||||
|  | 	char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z]; | ||||||
|  | 	input.read(data, size); | ||||||
|  | 	input.close(); | ||||||
|  |  | ||||||
|  | 	for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) | ||||||
|  | 		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() { | Chunk::~Chunk() { | ||||||
|     /*if (m_isModified) { | 	/*if (m_isModified) { | ||||||
|         char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z]; | 		char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z]; | ||||||
|  |  | ||||||
|         for (int x = 0; x < CHUNK_SIZE_X; ++x) | 		for (int x = 0; x < CHUNK_SIZE_X; ++x) | ||||||
|             for (int z = 0; z < CHUNK_SIZE_Z; ++z) | 			for (int z = 0; z < CHUNK_SIZE_Z; ++z) | ||||||
|                 for (int y = 0; y < CHUNK_SIZE_Y; ++y) | 				for (int y = 0; y < CHUNK_SIZE_Y; ++y) | ||||||
|                     data[x + (z * CHUNK_SIZE_X) + (y * CHUNK_SIZE_Z * CHUNK_SIZE_X)] = (char)GetBlock(x, y, z); | 					data[x + (z * CHUNK_SIZE_X) + (y * CHUNK_SIZE_Z * CHUNK_SIZE_X)] = (char)GetBlock(x, y, z); | ||||||
|  |  | ||||||
|         std::ostringstream pos; | 		std::ostringstream pos; | ||||||
|         pos << CHUNK_PATH << m_posX << '_' << m_posY << ".chunk"; | 		pos << CHUNK_PATH << m_posX << '_' << m_posY << ".chunk"; | ||||||
|  |  | ||||||
|         std::ofstream output(pos.str(), std::fstream::binary); | 		std::ofstream output(pos.str(), std::fstream::binary); | ||||||
|         output.write(data, sizeof(data)); | 		output.write(data, sizeof(data)); | ||||||
|         output.close(); | 		output.close(); | ||||||
|     }*/ | 	}*/ | ||||||
| } | } | ||||||
|  |  | ||||||
| void Chunk::RemoveBlock(int x, int y, int z, World* world) { | void Chunk::RemoveBlock(int x, int y, int z, World* world) { | ||||||
|     m_blocks.Set(x, y, z, BTYPE_AIR); | 	m_blocks.Set(x, y, z, BTYPE_AIR); | ||||||
|     CheckNeighbors(x, y, world); | 	CheckNeighbors(x, y, world); | ||||||
|     m_isDirty = true; | 	m_isDirty = true; | ||||||
| } | } | ||||||
|  |  | ||||||
| void Chunk::SetBlock(int x, int y, int z, BlockType type, World* world) { | void Chunk::SetBlock(int x, int y, int z, BlockType type, World* world) { | ||||||
|     m_blocks.Set(x, y, z, type); | 	m_blocks.Set(x, y, z, type); | ||||||
|     if (world) CheckNeighbors(x, z, world); // Si nullptr, ne pas v<>rifier les chunks voisines. | 	if (world) CheckNeighbors(x, z, world); // Si nullptr, ne pas v<>rifier les chunks voisines. | ||||||
|     m_isDirty = true; | 	m_isDirty = true; | ||||||
| } | } | ||||||
|  |  | ||||||
| BlockType Chunk::GetBlock(int x, int y, int z) { return m_blocks.Get(x, y, z); } | BlockType Chunk::GetBlock(int x, int y, int z) { return m_blocks.Get(x, y, z); } | ||||||
|  |  | ||||||
| void Chunk::CheckNeighbors(unsigned int x, unsigned int z, World* world) { | void Chunk::CheckNeighbors(unsigned int x, unsigned int z, World* world) { | ||||||
|     unsigned int cx, cy; | 	unsigned int cx, cy; | ||||||
|  |  | ||||||
|     world->GetScope(cx, cy); | 	world->GetScope(cx, cy); | ||||||
|  |  | ||||||
|     if (x == 0 && m_posX - cx >= 0 && | 	if (x == 0 && m_posX - cx >= 0 && | ||||||
|         world->ChunkAt((m_posX - cx - 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)) | 		world->ChunkAt((m_posX - cx - 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)) | ||||||
|         world->ChunkAt((m_posX - cx - 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)->MakeDirty(); | 		world->ChunkAt((m_posX - cx - 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)->MakeDirty(); | ||||||
|     else if (x == CHUNK_SIZE_X - 1 && m_posX - cx < WORLD_SIZE_X &&  | 	else if (x == CHUNK_SIZE_X - 1 && m_posX - cx < WORLD_SIZE_X && | ||||||
|         world->ChunkAt((m_posX - cx + 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)) | 		world->ChunkAt((m_posX - cx + 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)) | ||||||
|         world->ChunkAt((m_posX - cx + 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)->MakeDirty(); | 		world->ChunkAt((m_posX - cx + 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)->MakeDirty(); | ||||||
|  |  | ||||||
|     if (z == 0 && m_posY - cy >= 0 &&  | 	if (z == 0 && m_posY - cy >= 0 && | ||||||
|         world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy - 1) * CHUNK_SIZE_Z)) | 		world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy - 1) * CHUNK_SIZE_Z)) | ||||||
|         world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy - 1) * CHUNK_SIZE_Z)->MakeDirty(); | 		world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy - 1) * CHUNK_SIZE_Z)->MakeDirty(); | ||||||
|     else if (z == CHUNK_SIZE_X - 1 && m_posY - cy < WORLD_SIZE_Y && | 	else if (z == CHUNK_SIZE_X - 1 && m_posY - cy < WORLD_SIZE_Y && | ||||||
|         world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy + 1) * CHUNK_SIZE_Z)) | 		world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy + 1) * CHUNK_SIZE_Z)) | ||||||
|         world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy + 1) * CHUNK_SIZE_Z)->MakeDirty(); | 		world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy + 1) * CHUNK_SIZE_Z)->MakeDirty(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Chunk::GetPosition(unsigned int& x, unsigned int& y) const { x = m_posX; y = m_posY; } | void Chunk::GetPosition(unsigned int& x, unsigned int& y) const { x = m_posX; y = m_posY; } | ||||||
| @@ -140,3 +171,31 @@ void Chunk::MakeClean() { m_isDirty = false; } | |||||||
|  |  | ||||||
| void Chunk::MakeModified() { m_isModified = true; } | 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); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | } | ||||||
|   | |||||||
| @@ -28,6 +28,7 @@ class Chunk { | |||||||
|         void CheckNeighbors(unsigned int x, unsigned int z, World* world); |         void CheckNeighbors(unsigned int x, unsigned int z, World* world); | ||||||
|         void GetPosition(unsigned int& x, unsigned int& y) const; |         void GetPosition(unsigned int& x, unsigned int& y) const; | ||||||
|  |  | ||||||
|  |         void Structure(int x, int y, int z, int height); | ||||||
|         bool IsDirty() const; |         bool IsDirty() const; | ||||||
|         void MakeDirty(); |         void MakeDirty(); | ||||||
|         void MakeClean(); |         void MakeClean(); | ||||||
|   | |||||||
| @@ -9,9 +9,9 @@ | |||||||
|  |  | ||||||
| #define BUFFER_LENGTH 150 | #define BUFFER_LENGTH 150 | ||||||
|  |  | ||||||
| #define CHUNK_SIZE_X  4 | #define CHUNK_SIZE_X  6 | ||||||
| #define CHUNK_SIZE_Y  64 | #define CHUNK_SIZE_Y  64 | ||||||
| #define CHUNK_SIZE_Z  4 | #define CHUNK_SIZE_Z  6 | ||||||
| #define MAX_SELECTION_DISTANCE 5 | #define MAX_SELECTION_DISTANCE 5 | ||||||
| #define SEED 0 | #define SEED 0 | ||||||
| #define COUNTDOWN 300 | #define COUNTDOWN 300 | ||||||
| @@ -34,7 +34,7 @@ | |||||||
| #define BULLET_TIME .1 | #define BULLET_TIME .1 | ||||||
|  |  | ||||||
| typedef uint8_t BlockType; | 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; | typedef uint64_t Timestamp; | ||||||
|  |  | ||||||
| #ifdef _WIN32 | #ifdef _WIN32 | ||||||
|   | |||||||
| @@ -398,6 +398,7 @@ void Engine::LoadResource() { | |||||||
| 	TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); | 	TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); | ||||||
| 	TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png"); | 	TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png"); | ||||||
| 	TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.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)) { | 	if (!m_textureAtlas.Generate(TEXTURE_SIZE, false)) { | ||||||
| 		std::cout << " Unable to generate texture atlas ..." << std::endl; | 		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_blockinfo[BTYPE_METAL] = new BlockInfo(BTYPE_METAL, "Metal", u, v, s, 1); | ||||||
| 	m_textureAtlas.TextureIndexToCoord(texIceIndex, u, v, s, s); | 	m_textureAtlas.TextureIndexToCoord(texIceIndex, u, v, s, s); | ||||||
| 	m_blockinfo[BTYPE_ICE] = new BlockInfo(BTYPE_ICE, "Ice", u, v, s, 1); | 	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; | 	std::cout << " Loading and compiling shaders ..." << std::endl; | ||||||
| 	if (!m_shader01.Load(SHADER_PATH "shader01.vert", SHADER_PATH "shader01.frag", true)) { | 	if (!m_shader01.Load(SHADER_PATH "shader01.vert", SHADER_PATH "shader01.frag", true)) { | ||||||
| 		std::cout << " Failed to load shader " << std::endl; | 		std::cout << " Failed to load shader " << std::endl; | ||||||
| @@ -441,6 +443,7 @@ void Engine::SystemNotification(std::string systemLog) { | |||||||
|  |  | ||||||
| 	DisplayNotification(message); | 	DisplayNotification(message); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Engine::KillNotification(Player killer, Player killed) { | void Engine::KillNotification(Player killer, Player killed) { | ||||||
| 	std::string message = ""; | 	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  | 		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!). | 		// (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++; | 		if (m_mouseWU) bloc++; | ||||||
| 		else if (m_mouseWD) bloc--; | 		else if (m_mouseWD) bloc--; | ||||||
| 		if (bloc == BTYPE_LAST + 1) bloc = BTYPE_AIR + 1; | 		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. | 		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 (m_mouseL) { | ||||||
| 			if (bloc != BTYPE_LAST) | 			if (bloc != BTYPE_LAST) | ||||||
| @@ -1200,6 +1206,10 @@ void Engine::KeyPressEvent(unsigned char key) { | |||||||
| 		break; | 		break; | ||||||
| 	case 24: // Y - Ignorer | 	case 24: // Y - Ignorer | ||||||
| 		break; | 		break; | ||||||
|  | 	case 27: // 1 | ||||||
|  | 		break; | ||||||
|  | 	case 28: // 2 | ||||||
|  | 		break; | ||||||
| 	case 255: // Fn - Ignorer | 	case 255: // Fn - Ignorer | ||||||
| 		break; | 		break; | ||||||
| 	default: | 	default: | ||||||
| @@ -1274,6 +1284,12 @@ void Engine::KeyReleaseEvent(unsigned char key) { | |||||||
| 		else | 		else | ||||||
| 			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | 			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | ||||||
| 		break; | 		break; | ||||||
|  | 	case 27: // 1 | ||||||
|  | 		m_key1 = true; | ||||||
|  | 		break; | ||||||
|  | 	case 28: // 2 | ||||||
|  | 		m_key2 = true; | ||||||
|  | 		break; | ||||||
| 	case 57: // Espace - Stop sauter | 	case 57: // Espace - Stop sauter | ||||||
| 		m_keySpace = false; | 		m_keySpace = false; | ||||||
| 		break; | 		break; | ||||||
| @@ -1394,3 +1410,5 @@ bool Engine::LoadTexture(Texture& texture, const std::string& filename, bool use | |||||||
|  |  | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -58,6 +58,9 @@ private: | |||||||
|     void DrawHud(float elapsedTime, BlockType bloc); |     void DrawHud(float elapsedTime, BlockType bloc); | ||||||
|     void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f); |     void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     Connector m_conn; |     Connector m_conn; | ||||||
|     Shader m_shader01; |     Shader m_shader01; | ||||||
|     BlockInfo* m_blockinfo[BTYPE_LAST]; |     BlockInfo* m_blockinfo[BTYPE_LAST]; | ||||||
| @@ -123,6 +126,8 @@ private: | |||||||
|     bool m_soloMultiChoiceMade = false; |     bool m_soloMultiChoiceMade = false; | ||||||
|     bool m_stopcountdown = false; |     bool m_stopcountdown = false; | ||||||
|      |      | ||||||
|  |     bool m_key1 = false; | ||||||
|  |     bool m_key2 = false; | ||||||
|     bool m_keyK = false; |     bool m_keyK = false; | ||||||
|     bool m_keyL = false; |     bool m_keyL = false; | ||||||
|     bool m_keyW = false; |     bool m_keyW = false; | ||||||
|   | |||||||
							
								
								
									
										
											BIN
										
									
								
								SQCSim2021/media/textures/greengrass.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SQCSim2021/media/textures/greengrass.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 1.3 MiB | 
		Reference in New Issue
	
	Block a user