Skip to content

Commit

Permalink
Merge pull request #31 from Gumichocopengin8/feature/refactor
Browse files Browse the repository at this point in the history
Code Refactor
  • Loading branch information
Gumichocopengin8 authored Mar 29, 2022
2 parents 4add39d + 16c2023 commit 4b5e62f
Show file tree
Hide file tree
Showing 39 changed files with 1,116 additions and 1,190 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
cmake-build-debug/
cmake-build-release/
.vscode/
.DS_Store
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.20)
project(project)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -framework GLUT -framework OpenGL")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -framework GLUT -framework OpenGL")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")

Expand All @@ -18,6 +18,8 @@ add_executable(
block/types_of_block.h
camera/Camera.cpp
camera/Camera.h
utils/Utils.cpp
utils/Utils.h
window/Window.cpp
window/Window.h
player/Player.cpp
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ Check out [this video!](https://youtu.be/Iv7E1rnGXKs)
- `d`: move right
- `a`: move left
- `space`: jump

You can use mouse to see around
14 changes: 3 additions & 11 deletions biome/Biome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@
//

#include <cmath>
#include <utility>
#include "Biome.h"

using namespace std;

Biome::Biome(string id, int x, int z, BiomeType *type) {
this->id = id;
this->x = x;
this->z = z;
this->type = type;
}

float Biome::distance_to(float x, float z) {
return pow(x - this->x, 2) + pow(z - this->z, 2);
float Biome::distance_to(float x, float z) const {
return pow(x - this->x, 2) + pow(z - this->z, 2);
}
15 changes: 8 additions & 7 deletions biome/Biome.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@

#include <iostream>
#include <string>
#include <utility>

#include "BiomeType.h"

class Biome {

public:
std::string id;
int x;
int z;
BiomeType *type;
[[maybe_unused]] std::string id;
int x;
int z;
std::shared_ptr<BiomeType> type;

Biome(std::string id, int x, int z, BiomeType *type);
explicit Biome(std::string id, int x, int z, std::shared_ptr<BiomeType> type) : id{std::move(id)}, x{x}, z{z},
type{std::move(type)} {};

float distance_to(float x, float z);
[[nodiscard]] float distance_to(float x, float z) const;
};


Expand Down
21 changes: 15 additions & 6 deletions biome/BiomeType.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@
#include "../block/types_of_block.h"

struct BiomeType {

std::string id;
int ground = GRASS;
float tree_frequency = 0;
float cactus_frequency = 0;
float rock_frequency = 0;
BiomeType() {
this->id = "";
this->ground = GRASS;
}

explicit BiomeType(const BiomeType *pType) {
this->id = pType->id;
this->ground = pType->ground;
}

std::string id;
int ground = GRASS;
float tree_frequency = 0;
float cactus_frequency = 0;
float rock_frequency = 0;
};


Expand Down
83 changes: 48 additions & 35 deletions block/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,56 @@

#include "Block.h"
#include "../texture/Texture.h"
#include <iostream>
#include <cstdlib>
#import <GLUT/glut.h>

#include "../main.h"

using namespace std;

Block::Block(int type, int x, int y, int z) {
this->type = type;
this->x = x;
this->y = y;
this->z = z;
}

void Block::render() {

// Transforms
glPushMatrix();
glTranslated(x, y, z);

// Texture
Texture texture;

if (this->type == GROUND) { texture.ground(); }
else if (this->type == GRASS) { texture.grass(); }
else if (this->type == TREETRUNK) { texture.treeTrunk(); }
else if (this->type == TREELEAVES) { texture.treeLeaves(); }
else if (this->type == SNOW) { texture.snow(); }
else if (this->type == WATER) { texture.water(); }
else if (this->type == CLOUD) { texture.cloud(); }
else if (this->type == ORANGE) { texture.orange(); }
else if (this->type == LAWNGREEN) { texture.lawngreen(); }
else if (this->type == SAND) { texture.sand(); }
else if (this->type == ROCK) { texture.rock(); }
else { texture.ground(); }

glutSolidCube(1);
glPopMatrix();
void Block::render() const {
// Transforms
glPushMatrix();
glTranslated(x, y, z);

// Texture
Texture texture;

switch (this->type) {
case GROUND:
texture.ground();
break;
case GRASS:
texture.grass();
break;
case TREETRUNK:
texture.treeTrunk();
break;
case TREELEAVES:
texture.treeLeaves();
break;
case SNOW:
texture.snow();
break;
case WATER:
texture.water();
break;
case CLOUD:
texture.cloud();
break;
case ORANGE:
texture.orange();
break;
case LAWNGREEN:
texture.lawngreen();
break;
case SAND:
texture.sand();
break;
case ROCK:
texture.rock();
break;
default:
texture.ground();
}

glutSolidCube(1);
glPopMatrix();
}
12 changes: 6 additions & 6 deletions block/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
class Block {

private:
int type;
int x;
int y;
int z;
int type;
int x;
int y;
int z;

public:
Block(int type, int x, int y, int z);
explicit Block(int type, int x, int y, int z) : type{type}, x{x}, y{y}, z{z} {};

void render();
void render() const;
};


Expand Down
24 changes: 12 additions & 12 deletions block/types_of_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
#ifndef PROJECT_TYPES_OF_BLOCK_H
#define PROJECT_TYPES_OF_BLOCK_H

#define AIR 0
#define GROUND 1
#define GRASS 2
#define TREETRUNK 3
#define TREELEAVES 4
#define SNOW 5
#define WATER 6
#define CLOUD 7
#define ORANGE 8
#define LAWNGREEN 9
#define SAND 10
#define ROCK 11
constexpr int AIR = 0;
constexpr int GROUND = 1;
constexpr int GRASS = 2;
constexpr int TREETRUNK = 3;
constexpr int TREELEAVES = 4;
constexpr int SNOW = 5;
constexpr int WATER = 6;
constexpr int CLOUD = 7;
constexpr int ORANGE = 8;
constexpr int LAWNGREEN = 9;
constexpr int SAND = 10;
constexpr int ROCK = 11;

#endif //PROJECT_TYPES_OF_BLOCK_H
Loading

0 comments on commit 4b5e62f

Please sign in to comment.