mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
generating map cells
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.9)
|
||||
project(battleship)
|
||||
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
set(BUILD_TESTS OFF)
|
||||
set(BUILD_TESTS ON)
|
||||
cmake_policy(SET CMP0015 NEW)
|
||||
|
||||
set(states activeGameState.cpp inGameAppState.cpp guiAppState.cpp)
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void Map::loadWaterbodies(LuaManager *luaManager){
|
||||
//TODO : replace the magic value when it's possible to extract fields from nested tables
|
||||
//TODO : replace the magic value
|
||||
int numWaterBodies = 1;
|
||||
string table = "waterBodies";
|
||||
Root *root = Root::getSingleton();
|
||||
@@ -108,10 +108,37 @@ namespace battleship{
|
||||
loadTerrain(luaManager);
|
||||
loadWaterbodies(luaManager);
|
||||
|
||||
generateCells();
|
||||
|
||||
Camera *cam = Root::getSingleton()->getCamera();
|
||||
cam->setPosition(Vector3(1, 1, 1) * 10);
|
||||
cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm());
|
||||
}
|
||||
|
||||
void Map::generateCells(){
|
||||
//TODO replace magic values by retrieving terrain dimensions
|
||||
Vector3 terrainSize = Vector3(20, 6, 20);
|
||||
Vector3 initPos = terrainSize * (-0.5);
|
||||
int numCellsByDim[]{terrainSize.x / cellSize, terrainSize.y / cellSize, terrainSize.z / cellSize};
|
||||
cells = new GraphNode**[numCellsByDim[0]];
|
||||
|
||||
for(int i = 0; i < numCellsByDim[0]; i++){
|
||||
cells[i] = new GraphNode*[numCellsByDim[1]];
|
||||
|
||||
for(int j = 0; j < numCellsByDim[1]; j++){
|
||||
cells[i][j] = new GraphNode[numCellsByDim[2]];
|
||||
|
||||
for(int k = 0; k < numCellsByDim[2]; k++){
|
||||
GraphNode::Type type = GraphNode::SEA;
|
||||
|
||||
GraphNode node;
|
||||
node.type = type;
|
||||
node.pos = initPos + Vector3(cellSize * i, cellSize * j, cellSize * k);
|
||||
cells[i][j][k] = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Map::unload() {}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,13 @@ namespace gameBase{
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
struct GraphNode{
|
||||
enum Type{LAND, SEA, AIR};
|
||||
|
||||
Type type;
|
||||
vb01::Vector3 pos;
|
||||
};
|
||||
|
||||
class Map {
|
||||
public:
|
||||
Map(std::string);
|
||||
@@ -21,11 +28,14 @@ namespace battleship{
|
||||
inline vb01::Node* getWaterNode(){return waterNode;}
|
||||
private:
|
||||
vb01::Node *waterNode = nullptr;
|
||||
std::string mapName;
|
||||
std::string mapName;
|
||||
float cellSize = 1;
|
||||
GraphNode*** cells = nullptr;
|
||||
|
||||
void loadSkybox(gameBase::LuaManager*);
|
||||
void loadTerrain(gameBase::LuaManager*);
|
||||
void loadWaterbodies(gameBase::LuaManager*);
|
||||
void generateCells();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user