Skip to content

Commit

Permalink
Merge pull request #187 from ucsd-cse125-sp24/feat/floor
Browse files Browse the repository at this point in the history
new floor texture with split up floor
  • Loading branch information
Tyler-Lentz authored Jun 3, 2024
2 parents 57f7874 + 68447d9 commit ca0fc9a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 39 deletions.
1 change: 1 addition & 0 deletions include/server/game/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/* GridCell Constants */
#define DEFAULT_GRIDCELL_WIDTH 3
#define DM_Z_DISCOUNT 0.2
#define GRIDS_PER_FLOOR_OBJECT 5

// Player Stat Constants
#define INITIAL_HEALTH 100
Expand Down
73 changes: 34 additions & 39 deletions src/server/game/servergamestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ ServerGameState::ServerGameState(GameConfig config) {
this->spawner = std::make_unique<Spawner>();
this->spawner->spawnDummy(*this);


MazeGenerator generator(config);
int attempts = 1;
auto grid = generator.generate();
Expand Down Expand Up @@ -1454,23 +1455,41 @@ void ServerGameState::loadMaze(const Grid& grid) {
}

// Step 5: Add floor and ceiling SolidSurfaces.
std::vector<std::vector<bool>> freeSpots(grid.getRows(), std::vector<bool>(grid.getColumns(), false));

// Create Ceiling
this->objects.createObject(new SolidSurface(false, Collider::Box, SurfaceType::Ceiling,
glm::vec3(0.0f, MAZE_CEILING_HEIGHT, 0.0f),
glm::vec3(this->grid.getColumns() * Grid::grid_cell_width, 0.1,
this->grid.getRows() * Grid::grid_cell_width)
));

SolidSurface* floor = new SolidSurface(false, Collider::None, SurfaceType::Floor,
glm::vec3(0.0f, -0.1f, 0.0f),
glm::vec3(this->grid.getColumns() * Grid::grid_cell_width, 0.1,
this->grid.getRows() * Grid::grid_cell_width)
);
this->objects.createObject(floor);
// create multiple floor and ceiling objects to populate the size of the entire maze.
// currently doing this to stretch out the floor texture by the desired factor. here
// in the maze generation we can have a lot of control over how frequently the floor texture
// will repeat. I'd like to have this done on the client side instead and repeat the texture
// many times across one huge floor, but unfortuantely I cannot figure out how to get
// OpenGL to repeat the texture that many times.
for (int c = 0; c < this->grid.getColumns(); c+=GRIDS_PER_FLOOR_OBJECT) {
for (int r = 0; r < this->grid.getRows(); r+=GRIDS_PER_FLOOR_OBJECT) {
auto type = this->grid.getCell(c, r)->type;
if(type == CellType::OutsideTheMaze) {
continue;
}

// this is for floor highlighting
std::vector<std::vector<bool>> freeSpots(grid.getRows(), std::vector<bool>(grid.getColumns(), false));
glm::vec3 floor_corner = glm::vec3(c * Grid::grid_cell_width, -0.1f, r * Grid::grid_cell_width);
SolidSurface* floor = new SolidSurface(false, Collider::None, SurfaceType::Floor,
floor_corner,
glm::vec3(Grid::grid_cell_width * GRIDS_PER_FLOOR_OBJECT, 0.1,
Grid::grid_cell_width * GRIDS_PER_FLOOR_OBJECT)
);
this->objects.createObject(floor);

glm::vec3 ceiling_corner = glm::vec3(c * Grid::grid_cell_width, MAZE_CEILING_HEIGHT, r * Grid::grid_cell_width);
SolidSurface* ceiling = new SolidSurface(false, Collider::Box, SurfaceType::Ceiling,
ceiling_corner,
glm::vec3(Grid::grid_cell_width * GRIDS_PER_FLOOR_OBJECT, 0.1,
Grid::grid_cell_width * GRIDS_PER_FLOOR_OBJECT)
);
this->objects.createObject(ceiling);

if(freeSpots[r][c])
solidSurfaceInGridCells.insert({{c, r}, {floor}});
}
}

// Step 6: For each GridCell, add an object (if not empty) at the
// GridCell's position.
Expand Down Expand Up @@ -1761,30 +1780,6 @@ void ServerGameState::loadMaze(const Grid& grid) {
}
}

// Create Floor
//for (int c = 0; c < this->grid.getColumns(); c++) {
// for (int r = 0; r < this->grid.getRows(); r++) {
// auto type = this->grid.getCell(c, r)->type;
// if (isWallLikeCell(type) || type == CellType::OutsideTheMaze) {
// continue;
// }

// glm::vec3 corner = glm::vec3(c * Grid::grid_cell_width, -0.1f, r * Grid::grid_cell_width);

// SolidSurface* floor = new SolidSurface(false, Collider::None, SurfaceType::Floor,
// corner,
// glm::vec3(Grid::grid_cell_width, 0.1,
// Grid::grid_cell_width)
// );

// this->objects.createObject(floor);

// if(freeSpots[r][c]) {
// solidSurfaceInGridCells.insert({{c, r}, {floor}});
// }
// }
//}

}

void ServerGameState::spawnWall(GridCell* cell, int col, int row, bool is_internal) {
Expand Down

0 comments on commit ca0fc9a

Please sign in to comment.