Skip to content

Commit

Permalink
Player no longer can place a block that overlaps with itself
Browse files Browse the repository at this point in the history
  • Loading branch information
yvt committed Aug 31, 2013
1 parent 55677ea commit 55dd4a2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
33 changes: 31 additions & 2 deletions Sources/Client/Player.cpp
Expand Up @@ -336,7 +336,8 @@ namespace spades {
result = GetWorld()->GetMap()->CastRay2(GetEye(),
GetFront(),
8);
if(result.hit && (result.hitBlock + result.normal).z < 62){
if(result.hit && (result.hitBlock + result.normal).z < 62 &&
!OverlapsWithOneBlock(result.hitBlock + result.normal)){
blockCursorActive = true;
blockCursorPos = result.hitBlock + result.normal;
}else{
Expand Down Expand Up @@ -1136,7 +1137,8 @@ namespace spades {

void Player::KilledBy(KillType type,
Player *killer,
int respawnTime) {
int respawnTime) {
SPADES_MARK_FUNCTION();
health = 0;
weapon->SetShooting(false);

Expand Down Expand Up @@ -1169,6 +1171,7 @@ namespace spades {
}

Player::HitBoxes Player::GetHitBoxes() {
SPADES_MARK_FUNCTION_DEBUG();
Player::HitBoxes hb;

Vector3 front = GetFront();
Expand Down Expand Up @@ -1258,6 +1261,7 @@ namespace spades {
}

void Player::SetWeaponType(WeaponType weap){
SPADES_MARK_FUNCTION_DEBUG();
if(this->weapon->GetWeaponType() == weap)
return;
delete this->weapon;
Expand All @@ -1269,6 +1273,7 @@ namespace spades {
}

bool Player::IsReadyToUseTool() {
SPADES_MARK_FUNCTION_DEBUG();
switch(tool){
case ToolBlock:
return world->GetTime() > nextBlockTime &&
Expand All @@ -1284,6 +1289,7 @@ namespace spades {
}

bool Player::IsToolSelectable(ToolType type) {
SPADES_MARK_FUNCTION_DEBUG();
switch(type){
case ToolSpade:
return true;
Expand All @@ -1299,6 +1305,29 @@ namespace spades {
}
}

bool Player::OverlapsWith(const spades::AABB3 &aabb) {
SPADES_MARK_FUNCTION_DEBUG();
float offset, m;
if(input.crouch){
offset = .45f;
m = .9f;
}else{
offset = .9f;
m = 1.35f;
}
AABB3 playerBox(eye.x - .45f,
eye.y - .45f,
eye.z,
.9f, .9f, offset + m);
return aabb && playerBox;
}

bool Player::OverlapsWithOneBlock(spades::IntVector3 vec) {
SPADES_MARK_FUNCTION_DEBUG();
return OverlapsWith(AABB3(vec.x, vec.y, vec.z,
1, 1, 1));
}

#pragma mark - Block Construction
bool Player::IsBlockCursorActive(){
return tool == ToolBlock && blockCursorActive;
Expand Down
3 changes: 3 additions & 0 deletions Sources/Client/Player.h
Expand Up @@ -236,6 +236,9 @@ namespace spades {
* @param dir normalized direction vector.
* @return true if ray may hit the player. */
bool RayCastApprox(Vector3 start, Vector3 dir);

bool OverlapsWith(const AABB3&);
bool OverlapsWithOneBlock(IntVector3);
};
}
}

0 comments on commit 55dd4a2

Please sign in to comment.