Little noise.
This commit is contained in:
parent
315832e87f
commit
b3e1f03df1
7
TODO
7
TODO
@ -1 +1,8 @@
|
||||
- Big map && map generation
|
||||
- Improve vect3D
|
||||
- Improve cursor
|
||||
- Move cube tests in another file
|
||||
- Multi-biome
|
||||
- Fix multi-biome problem in manageEvents
|
||||
- Save and load map
|
||||
- Autofire
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
class Biome {
|
||||
public:
|
||||
Biome(int x, int y, int z, GLuint texture);
|
||||
Biome(int x, int y, int z, Textures textures);
|
||||
~Biome();
|
||||
|
||||
void draw();
|
||||
|
@ -20,6 +20,8 @@
|
||||
#ifndef CUBE_H
|
||||
#define CUBE_H
|
||||
|
||||
typedef std::map<std::string, GLuint> Textures;
|
||||
|
||||
class Cube {
|
||||
public:
|
||||
Cube(int x, int y, int z, GLuint texture, Map *map);
|
||||
|
@ -53,8 +53,6 @@ class Scene {
|
||||
static Cube *selectedCube;
|
||||
|
||||
private:
|
||||
typedef std::map<std::string, GLuint> Textures;
|
||||
|
||||
bool m_cont;
|
||||
Textures m_textures;
|
||||
};
|
||||
|
@ -72,34 +72,51 @@ u16 map[5 * 5 * 5] = {
|
||||
0, 0, 0, 0, 0,
|
||||
};*/
|
||||
|
||||
u16 _width = 3;
|
||||
u16 _depth = 3;
|
||||
u16 _height = 2;
|
||||
u16 _width = 16;
|
||||
u16 _depth = 16;
|
||||
u16 _height = 8;
|
||||
|
||||
u16 _map[3 * 3 * 2] = {
|
||||
1, 1, 1,
|
||||
1, 1, 1,
|
||||
1, 1, 1,
|
||||
|
||||
0, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 0
|
||||
};
|
||||
u16 *_map = (u16*)malloc(_width * _depth * _height * sizeof(u16));
|
||||
|
||||
Map *m_map = new Map{_width, _depth, _height, _map};
|
||||
|
||||
Biome::Biome(int x, int y, int z, GLuint texture) {
|
||||
Biome::Biome(int x, int y, int z, Textures textures) {
|
||||
srand(time(NULL));
|
||||
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
m_z = z;
|
||||
|
||||
m_texture = texture;
|
||||
m_texture = textures["stone"];
|
||||
|
||||
for(s32 z = 0 ; z < m_map->height ; z++) {
|
||||
for(s32 y = 0 ; y < m_map->depth ; y++) {
|
||||
for(s32 x = 0 ; x < m_map->width ; x++) {
|
||||
if(m_map->map[MAP_POS(x, y, z)] == 1) {
|
||||
m_cubes.push_back(new Cube(x, y, z, m_texture, m_map));
|
||||
if(z == 0) {
|
||||
m_map->map[MAP_POS(x, y, z)] = 3;
|
||||
}
|
||||
else if(z < m_map->height - 2) {
|
||||
if(rand()%3 >= 2) m_map->map[MAP_POS(x, y, z)] = 2;
|
||||
} else {
|
||||
if(rand()%3 >= 2) m_map->map[MAP_POS(x, y, z)] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(s32 z = 0 ; z < m_map->height ; z++) {
|
||||
for(s32 y = 0 ; y < m_map->depth ; y++) {
|
||||
for(s32 x = 0 ; x < m_map->width ; x++) {
|
||||
switch(m_map->map[MAP_POS(x, y, z)]) {
|
||||
case 1:
|
||||
m_cubes.push_back(new Cube(x, y, z, textures["grass"], m_map));
|
||||
break;
|
||||
case 2:
|
||||
m_cubes.push_back(new Cube(x, y, z, textures["stone"], m_map));
|
||||
break;
|
||||
case 3:
|
||||
m_cubes.push_back(new Cube(x, y, z, textures["bedrock"], m_map));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -145,22 +162,34 @@ void Biome::deleteCube(Cube *cube) {
|
||||
|
||||
void Biome::addCube(Cube *selectedCube) {
|
||||
if(selectedCube->selectedFace() == 0) {
|
||||
if((MAP_POS(selectedCube->x(), selectedCube->y() + 1, selectedCube->z()) >= 0) && (MAP_POS(selectedCube->x(), selectedCube->y() + 1, selectedCube->z()) < m_map->width * m_map->depth * m_map->height))
|
||||
m_map->map[MAP_POS(selectedCube->x(), selectedCube->y() + 1, selectedCube->z())] = 1;
|
||||
m_cubes.push_back(new Cube(selectedCube->x(), selectedCube->y() + 1, selectedCube->z(), m_texture, m_map));
|
||||
}
|
||||
else if(selectedCube->selectedFace() == 1) {
|
||||
if((MAP_POS(selectedCube->x() + 1, selectedCube->y(), selectedCube->z()) >= 0) && (MAP_POS(selectedCube->x() + 1, selectedCube->y(), selectedCube->z()) < m_map->width * m_map->depth * m_map->height))
|
||||
m_map->map[MAP_POS(selectedCube->x() + 1, selectedCube->y(), selectedCube->z())] = 1;
|
||||
m_cubes.push_back(new Cube(selectedCube->x() + 1, selectedCube->y(), selectedCube->z(), m_texture, m_map));
|
||||
}
|
||||
else if(selectedCube->selectedFace() == 2) {
|
||||
if((MAP_POS(selectedCube->x() - 1, selectedCube->y(), selectedCube->z()) >= 0) && (MAP_POS(selectedCube->x() - 1, selectedCube->y(), selectedCube->z()) < m_map->width * m_map->depth * m_map->height))
|
||||
m_map->map[MAP_POS(selectedCube->x() - 1, selectedCube->y(), selectedCube->z())] = 1;
|
||||
m_cubes.push_back(new Cube(selectedCube->x() - 1, selectedCube->y(), selectedCube->z(), m_texture, m_map));
|
||||
}
|
||||
else if(selectedCube->selectedFace() == 3) {
|
||||
if((MAP_POS(selectedCube->x(), selectedCube->y() - 1, selectedCube->z()) >= 0) && (MAP_POS(selectedCube->x(), selectedCube->y() - 1, selectedCube->z()) < m_map->width * m_map->depth * m_map->height))
|
||||
m_map->map[MAP_POS(selectedCube->x(), selectedCube->y() - 1, selectedCube->z())] = 1;
|
||||
m_cubes.push_back(new Cube(selectedCube->x(), selectedCube->y() - 1, selectedCube->z(), m_texture, m_map));
|
||||
}
|
||||
else if(selectedCube->selectedFace() == 4) {
|
||||
if((MAP_POS(selectedCube->x(), selectedCube->y(), selectedCube->z() + 1) >= 0) && (MAP_POS(selectedCube->x(), selectedCube->y(), selectedCube->z() + 1) < m_map->width * m_map->depth * m_map->height))
|
||||
m_map->map[MAP_POS(selectedCube->x(), selectedCube->y(), selectedCube->z() + 1)] = 1;
|
||||
m_cubes.push_back(new Cube(selectedCube->x(), selectedCube->y(), selectedCube->z() + 1, m_texture, m_map));
|
||||
}
|
||||
else if(selectedCube->selectedFace() == 5) {
|
||||
m_cubes.push_back(new Cube(selectedCube->x(), selectedCube->y(), selectedCube->z() - 1, m_texture, m_map));
|
||||
if((MAP_POS(selectedCube->x(), selectedCube->y(), selectedCube->z() - 1) >= 0) && (MAP_POS(selectedCube->x(), selectedCube->y(), selectedCube->z() - 1) < m_map->width * m_map->depth * m_map->height))
|
||||
m_map->map[MAP_POS(selectedCube->x(), selectedCube->y(), selectedCube->z() - 1)] = 1;
|
||||
if(selectedCube->z() - 1 >= 0) m_cubes.push_back(new Cube(selectedCube->x(), selectedCube->y(), selectedCube->z() - 1, m_texture, m_map));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
---------------------------------------------------------------------------------*/
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <GL/gl.h>
|
||||
|
@ -55,6 +55,8 @@ bool Scene::intersectionLinePlane(vect3D normal, vect3D planePoint, vect3D lineO
|
||||
|
||||
float k = p2 / p1;
|
||||
|
||||
if(k < 0) return false;
|
||||
|
||||
vect3D i; // Intersection point
|
||||
|
||||
i.x = lineOrigPoint.x + k * directionVector.x;
|
||||
@ -238,7 +240,7 @@ Scene::Scene() {
|
||||
|
||||
loadTextures();
|
||||
|
||||
biome = new Biome(4, 4, 0, m_textures["stone"]);
|
||||
biome = new Biome(4, 4, 0, m_textures);
|
||||
|
||||
selectedCube = new Cube(-1, -1, -1, m_textures["dirt"], NULL);
|
||||
}
|
||||
@ -392,6 +394,7 @@ void Scene::loadTextures() {
|
||||
m_textures["grass"] = loadTexture("textures/grass.bmp");
|
||||
m_textures["cobble"] = loadTexture("textures/cobble.bmp");
|
||||
m_textures["stone"] = loadTexture("textures/stone.bmp");
|
||||
m_textures["bedrock"] = loadTexture("textures/bedrock.bmp");
|
||||
}
|
||||
|
||||
void Scene::drawField() {
|
||||
|
BIN
textures/bedrock.bmp
Normal file
BIN
textures/bedrock.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 822 B |
BIN
textures/photo-1559119.jpg
Normal file
BIN
textures/photo-1559119.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1012 B |
Loading…
x
Reference in New Issue
Block a user