Beispiel #1
0
void Game_Event::MoveTypeAwayFromPlayer() {
	int sx = DistanceXfromPlayer();
	int sy = DistanceYfromPlayer();
	int last_direction = GetDirection();

	if ( std::abs(sx) + std::abs(sy) >= 20 ) {
		MoveRandom();
	} else {
		switch (Utils::GetRandomNumber(0, 5)) {
		case 0:
			MoveRandom();
			break;
		case 1:
			MoveForward();
			break;
		default:
			MoveAwayFromPlayer();
		}
	}

	if (move_failed && !starting) {
		if (stop_count >= max_stop_count + 60) {
			stop_count = 0;
		} else {
			SetDirection(last_direction);
			if (!(IsDirectionFixed() || IsFacingLocked()))
				SetSpriteDirection(last_direction);
		}
	}
}
Beispiel #2
0
void Game_Character::TurnAwayFromHero() {
	int sx = DistanceXfromPlayer();
	int sy = DistanceYfromPlayer();

	if ( std::abs(sx) > std::abs(sy) ) {
		Turn((sx > 0) ? Right : Left);
	} else {
		Turn((sy > 0) ? Down : Up);
	}
}
Beispiel #3
0
void Game_Character::TurnTowardHero() {
	int sx = DistanceXfromPlayer();
	int sy = DistanceYfromPlayer();

	if ( std::abs(sx) > std::abs(sy) ) {
		Turn((sx > 0) ? Left : Right);
	} else {
		Turn((sy > 0) ? Up : Down);
	}
}
Beispiel #4
0
void Game_Character::TurnTowardPlayer() {
	int sx = DistanceXfromPlayer();
	int sy = DistanceYfromPlayer();

	if ( std::abs(sx) > std::abs(sy) ) {
		(sx > 0) ? TurnLeft() : TurnRight();
	}
	else if ( std::abs(sx) < std::abs(sy) ) {
		(sy > 0) ? TurnUp() : TurnDown();
	}
}
Beispiel #5
0
void Game_Character::MoveAwayFromPlayer() {
	int sx = DistanceXfromPlayer();
	int sy = DistanceYfromPlayer();

	if (sx != 0 || sy != 0) {
		if ( std::abs(sx) > std::abs(sy) ) {
			Move((sx > 0) ? Right : Left);
			if (move_failed && sy != 0)
				Move((sy > 0) ? Down : Up);
		} else {
			Move((sy > 0) ? Down : Up);
			if (move_failed && sx != 0)
				Move((sx > 0) ? Right : Left);
		}
	}
}
Beispiel #6
0
void Game_Character::MoveAwayFromPlayer() {
	int sx = DistanceXfromPlayer();
	int sy = DistanceYfromPlayer();

	if (sx != 0 || sy != 0) {
		if ( std::abs(sx) > std::abs(sy) ) {
			(sx > 0) ? MoveRight() : MoveLeft();
			if (move_failed && sy != 0) {
				(sy > 0) ? MoveDown() : MoveUp();
			}
		} else {
			(sy > 0) ? MoveDown() : MoveUp();
			if (move_failed && sx != 0) {
				(sx > 0) ? MoveRight() : MoveLeft();
			}
		}
	}
}
Beispiel #7
0
void Game_Character::MoveTowardsPlayer() {
	int sx = DistanceXfromPlayer();
	int sy = DistanceYfromPlayer();

	// Try in the same direction of the last failed move
	if (last_move_failed) {
		MoveForward();
		if (!move_failed)
			return;
	}

	if (sx != 0 || sy != 0) {
		if ( std::abs(sx) > std::abs(sy) ) {
			Move((sx > 0) ? Left : Right);
			if (move_failed && sy != 0)
				Move((sy > 0) ? Up : Down);
		} else {
			Move((sy > 0) ? Up : Down);
			if (move_failed && sx != 0) {
				Move((sx > 0) ? Left : Right);
			}
		}
	}
}