diff options
Diffstat (limited to 'src/world.c')
| -rw-r--r-- | src/world.c | 66 | 
1 files changed, 44 insertions, 22 deletions
| diff --git a/src/world.c b/src/world.c index 17e35b9..65a2095 100644 --- a/src/world.c +++ b/src/world.c @@ -51,40 +51,62 @@ void drawWorld(World *world)  	}  } +int intersects(Vector3 h1, Vector3 h2, Vector3 pos1, Vector3 pos2) +{ +	return ( +			pos1.x <= h2.x+pos2.x && +			h1.x+pos1.x >= h2.x && +			pos1.y <= h2.y+pos2.y && +			h1.y+pos1.y >= h2.y && +			pos1.z <= h2.z+pos2.z && +			h1.z+pos1.z >= h2.z +		   ); +} +  void handleCollision(World *world, Player *player)  {  	int posX, posY, posZ;  	posX = (int)player->pos.x;  	posY = (int)player->pos.y;  	posZ = (int)player->pos.z; -	//Floor check: -	if (world->map[posY][posX][posZ]!=0) { -		player->is_on_floor=1; -		if (player->velocity.y < 0.0f) { -			player->velocity.y = 0.0f; +	player->is_on_floor=0; +	for(int x=-1;x<2;x++)  +	for(int y=-1;y<2;y++) +	for(int z=-1;z<2;z++) { +		int cPosX, cPosY, cPosZ; +		cPosX = posX+x; +		cPosY = posY+y; +		cPosZ = posZ+z; +		if (world->map[cPosY][cPosX][cPosZ]!=0) { +			int inter = intersects( +						player->hitbox, +						(Vector3){1.0f, 1.0f, 1.0f}, +						player->pos, +						(Vector3){ +							(float)cPosX, +							(float)cPosY-1, +							(float)cPosZ, +						} +						); +			if (inter) { +				player->velocity.y=0.0f; +				player->pos.y=cPosY+1.0f; +				player->is_on_floor=1; +			}  		} -	} else { -		player->is_on_floor=0; -	} -	if (world->map[posY][posX][posZ]!=0 -	&& (float)posY!=player->pos.y) { -		player->camera.position.y=(float)posY+2; -		//player->velocity.y = 0.0f;  	}  }  void handleGravity(World *world, Player *player)  { -	if (player->velocity.y > 0.0f) { -		player->velocity.y *= 0.9f; -	} -	if (player->velocity.y <= 0.1f && player->velocity.y > 0.0f) { -		player->velocity.y = 0.0f; -	} +	//if (player->velocity.y > 0.0f) { +	//	player->velocity.y *= 0.9f; +	//}  	int posX, posY, posZ;  	posX = (int)player->pos.x;  	posY = (int)player->pos.y;  	posZ = (int)player->pos.z; +	player->velocity.y -= 0.01f;  	printf(  			"Player.pos.y:\t%d\n"  			"Player.pos.x:\t%d\n" @@ -94,8 +116,8 @@ void handleGravity(World *world, Player *player)  			posZ  			);  	printf("%d\n", (int)world->map[posY][posX][posZ]); -	if (player->velocity.y <= 0.0f -	&& world->map[posY][posX][posZ]==0) { -		player->velocity.y -= 0.1f; -	} +	//if (player->velocity.y <= 0.0f +	//&& world->map[posY][posX][posZ]==0) { +	//	player->velocity.y -= 0.01f; +	//}  } | 
