Going on.

This commit is contained in:
Quentin BAZIN 2013-05-02 14:54:32 +02:00
parent 48dc21a071
commit 06f1017314
6 changed files with 33 additions and 28 deletions

3
Notes
View File

@ -1,6 +1,3 @@
Bugs:
It's possible to put a cube under yourself without jumping.
Cubes: Cubes:
0: Nothing 0: Nothing
1: Stone 1: Stone

4
TODO
View File

@ -1,4 +1,6 @@
- Physics - Physics:
- Improve jump and collisions.
- Improve game speed.
- Caves - Caves
- Pause menu - Pause menu
- Main menu - Main menu

View File

@ -39,9 +39,9 @@
#define CUBE_POS(x, y, z) (((x) - m_x) + (((y) - m_y) * CHUNK_WIDTH) + (((z) - m_z) * CHUNK_WIDTH * CHUNK_HEIGHT)) #define CUBE_POS(x, y, z) (((x) - m_x) + (((y) - m_y) * CHUNK_WIDTH) + (((z) - m_z) * CHUNK_WIDTH * CHUNK_HEIGHT))
#define PLAYER_HEIGHT 1.8 #define PLAYER_HEIGHT 1.8
#define MOVEMENT_SPEED 3.0 #define MOVEMENT_SPEED 3.5
#define FLY_SPEED 0.05 #define FLY_SPEED 0.05
#define JUMP_SPEED 0.5 #define JUMP_SPEED 0.15
#define GRAVITY 0.025 #define GRAVITY 0.00981
#endif // CONFIG_H #endif // CONFIG_H

View File

@ -70,10 +70,10 @@ Map::Map(u16 width, u16 depth, u16 height) {
for (int xC = 0; xC < CHUNK_WIDTH; xC++) { for (int xC = 0; xC < CHUNK_WIDTH; xC++) {
int x = xx * CHUNK_WIDTH + xC; int x = xx * CHUNK_WIDTH + xC;
int y = yy * CHUNK_DEPTH + yC; int y = yy * CHUNK_DEPTH + yC;
float perlin = get2DPerlinNoiseValue(x, y, 64) * 0 // 3 float perlin = get2DPerlinNoiseValue(x, y, 64) * 3 // 3 - 0
+ get2DPerlinNoiseValue(x, y, 32) * 4 // 0 + get2DPerlinNoiseValue(x, y, 32) * 2 // 0 - 4
+ get2DPerlinNoiseValue(x, y, 16) * 3 // 0.5 + get2DPerlinNoiseValue(x, y, 16) * 2 // 0.5 - 3
+ get2DPerlinNoiseValue(x, y, 8) * 2; // 0.1 + get2DPerlinNoiseValue(x, y, 8) * 1; // 0.1 - 2
int heightValue = int((perlin * float(CHUNK_HEIGHT)) + float(m_height / 2)); int heightValue = int((perlin * float(CHUNK_HEIGHT)) + float(m_height / 2));
if (heightValue < 0) heightValue = 0; if (heightValue < 0) heightValue = 0;

View File

@ -50,7 +50,14 @@ bool inTable(u16 t[], u16 n) {
} }
bool passable(s16 caseX, s16 caseY, s16 caseZ) { bool passable(s16 caseX, s16 caseY, s16 caseZ) {
if(inTable(nonPassableTiles, Game::map->map()[MAP_POS(caseX, caseY, caseZ)])) { // TOO SLOW
/*if(inTable(nonPassableTiles, Game::map->map()[MAP_POS(caseX, caseY, caseZ)])) {
return false;
} else {
return true;
}*/
int cubeid = Game::map->map()[MAP_POS(caseX, caseY, caseZ)];
if(cubeid == 1 || cubeid == 2) {
return false; return false;
} else { } else {
return true; return true;

View File

@ -37,7 +37,7 @@ Player::Player(float x, float y, float z, float angle) {
m_x = x; m_x = x;
m_y = y; m_y = y;
m_eyeheight = z + 0.1; m_eyeheight = z + 0.8;
m_angleH = angle; m_angleH = angle;
m_angleV = 0.0; m_angleV = 0.0;
@ -63,31 +63,30 @@ void Player::move(float distance, float direction) {
} }
void Player::jump() { void Player::jump() {
if(m_isJumping) { if((m_isJumping) &&
m_eyeheight += m_jumpSpeed / 4; (passable(m_x, m_y, m_eyeheight + m_jumpSpeed + 0.5))) {
m_eyeheight += m_jumpSpeed;
m_jumpSpeed -= GRAVITY; m_jumpSpeed -= GRAVITY;
if((m_jumpSpeed < 0) && if((m_jumpSpeed < 0) &&
((!passable(m_x, m_y, m_eyeheight - PLAYER_HEIGHT - m_jumpSpeed / 4 - 0.1)) /* || ((!passable(m_x, m_y, m_eyeheight - PLAYER_HEIGHT - m_jumpSpeed - 0.3)) /* ||
(!passable(m_x + 0.25, m_y, m_eyeheight - PLAYER_HEIGHT - m_jumpSpeed / 4 - 0.3)) || (!passable(m_x + 0.25, m_y, m_eyeheight - PLAYER_HEIGHT - m_jumpSpeed - 0.1)) ||
(!passable(m_x, m_y + 0.25, m_eyeheight - PLAYER_HEIGHT - m_jumpSpeed / 4 - 0.3)) || (!passable(m_x, m_y + 0.25, m_eyeheight - PLAYER_HEIGHT - m_jumpSpeed - 0.1)) ||
(!passable(m_x + 0.25, m_y + 0.25, m_eyeheight - PLAYER_HEIGHT - m_jumpSpeed / 4 - 0.3)) */ )) { (!passable(m_x + 0.25, m_y + 0.25, m_eyeheight - PLAYER_HEIGHT - m_jumpSpeed - 0.1)) */ )) {
m_jumpSpeed = 0.0; m_jumpSpeed = 0.0;
m_isJumping = false; m_isJumping = false;
return;
} }
else if((m_jumpSpeed >= 0) &&
if((m_jumpSpeed >= 0) && ((!passable(m_x, m_y, m_eyeheight + m_jumpSpeed + 0.5)) /* ||
((!passable(m_x, m_y, m_eyeheight + m_jumpSpeed / 4 + 0.5)) /* || (!passable(m_x + 0.25, m_y, m_eyeheight + m_jumpSpeed + 0.5)) ||
(!passable(m_x + 0.25, m_y, m_eyeheight + m_jumpSpeed / 4 + 0.3)) || (!passable(m_x, m_y + 0.25, m_eyeheight + m_jumpSpeed + 0.5)) ||
(!passable(m_x, m_y + 0.25, m_eyeheight + m_jumpSpeed / 4 + 0.3)) || (!passable(m_x + 0.25, m_y + 0.25, m_eyeheight + m_jumpSpeed + 0.5)) */ )) {
(!passable(m_x + 0.25, m_y + 0.25, m_eyeheight + m_jumpSpeed / 4 + 0.3)) */ )) {
m_jumpSpeed = 0.0; m_jumpSpeed = 0.0;
} }
} }
else if((passable(m_x, m_y, m_eyeheight - PLAYER_HEIGHT - m_jumpSpeed / 4 - 0.1)) && else if((passable(m_x, m_y, m_eyeheight - PLAYER_HEIGHT - m_jumpSpeed - 0.3)) /*&&
(passable(m_x, m_y, m_eyeheight - PLAYER_HEIGHT - m_jumpSpeed / 4 - 0.1))) { (passable(m_x, m_y, m_eyeheight - PLAYER_HEIGHT - m_jumpSpeed - 0.1))*/) {
m_jumpSpeed = 0.0; m_jumpSpeed = 0.0;
m_isJumping = true; m_isJumping = true;
} }