Created
December 16, 2014 19:51
-
-
Save David-Mimnagh/f85309e770d308bc1394 to your computer and use it in GitHub Desktop.
guard logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Guard::player_search(Player player) | |
{ | |
if (player.Shape().getPosition().x - Shape().getPosition().x <= hunting_distance_) | |
gotoXpos = player.Shape().getPosition().x; | |
movement_distance_ = gotoXpos - Shape().getPosition().x; | |
if (Shape().getPosition().x < gotoXpos) | |
movement_speed_ *= 1.f; | |
if (Shape().getPosition().x > gotoXpos) | |
movement_speed_ *= -1.f; | |
if (Shape().getPosition().x == gotoXpos) | |
patrol_status_ = PatrolStatus::AREAPATROL; | |
} | |
void Guard::area_patrol(Player player) | |
{ | |
std::cout << "Patroling Area" << std::endl; | |
short int patrol_count_ = 5; | |
float patrol_left_ = 100; | |
float patrol_right_ = 100; | |
float start_position_; | |
bool notmoved = true; | |
bool first_touch_ = false; | |
start_position_ = gotoXpos; | |
if (notmoved) | |
{ | |
movement_speed_ *= -1.f; | |
!notmoved; | |
} | |
else | |
do{ | |
if (Shape().getPosition().x > start_position_ - patrol_left_) | |
{ | |
movement_speed_ *= -1.f; | |
if (Shape().getPosition().x == start_position_ - patrol_left_) | |
{ | |
patrol_count_ -= 1; | |
movement_speed_ *= -1.f; | |
first_touch_; | |
} | |
} | |
else if (Shape().getPosition().x < start_position_ + patrol_left_ && !first_touch_) | |
{ | |
movement_speed_ *= 1.f; | |
if (Shape().getPosition().x == start_position_ + patrol_right_) | |
{ | |
patrol_count_ -= 1; | |
movement_speed_ *= 1.f; | |
} | |
} | |
if (player.Shape().getPosition().x - Shape().getPosition().x <= 100) | |
patrol_status_ = PatrolStatus::FOUND; | |
} while (patrol_count_ != 0); | |
if (patrol_count_ == 0) | |
patrol_status_ == PatrolStatus::IDLE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment