test
This commit is contained in:
@@ -44,14 +44,31 @@ namespace Game::AGame {
|
||||
const float dyv = py - ey;
|
||||
mIsVisible = (dxv * dxv + dyv * dyv) <= (revealRadius * revealRadius);
|
||||
|
||||
// Semi-random movement with periodic direction changes
|
||||
mDirectionChangeTimer += deltaTime;
|
||||
if (mDirectionChangeTimer > 2.0f) {
|
||||
const float angle = static_cast<float>(Utils::getUtils().rirng32(0, 360)) * 3.14159f / 180.f;
|
||||
const float speed = 20.f + static_cast<float>(Utils::getUtils().rirng32(0, 30));
|
||||
mMoveSpeedX = std::cos(angle) * speed;
|
||||
mMoveSpeedY = std::sin(angle) * speed;
|
||||
mDirectionChangeTimer = 0.f;
|
||||
// Check if player is on land (not in ship mode) and within follow distance
|
||||
const float distanceToPlayer = std::sqrt(dxv * dxv + dyv * dyv);
|
||||
const bool playerOnLand = !player->isShipMode();
|
||||
const bool withinFollowRange = distanceToPlayer <= FOLLOW_DISTANCE;
|
||||
|
||||
if (playerOnLand && withinFollowRange) {
|
||||
// Follow player: calculate direction and move at constant speed
|
||||
mFollowingPlayer = true;
|
||||
if (distanceToPlayer > 1.f) { // Avoid division by zero
|
||||
mMoveSpeedX = (dxv / distanceToPlayer) * FOLLOW_SPEED;
|
||||
mMoveSpeedY = (dyv / distanceToPlayer) * FOLLOW_SPEED;
|
||||
}
|
||||
} else {
|
||||
// Revert to random movement when player is on sea or out of range
|
||||
mFollowingPlayer = false;
|
||||
|
||||
// Semi-random movement with periodic direction changes
|
||||
mDirectionChangeTimer += deltaTime;
|
||||
if (mDirectionChangeTimer > 2.0f) {
|
||||
const float angle = static_cast<float>(Utils::getUtils().rirng32(0, 360)) * 3.14159f / 180.f;
|
||||
const float speed = 20.f + static_cast<float>(Utils::getUtils().rirng32(0, 30));
|
||||
mMoveSpeedX = std::cos(angle) * speed;
|
||||
mMoveSpeedY = std::sin(angle) * speed;
|
||||
mDirectionChangeTimer = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
// Move enemy
|
||||
@@ -68,9 +85,9 @@ namespace Game::AGame {
|
||||
const float halfWidth = entityWidth / 2.f;
|
||||
const float halfHeight = entityHeight / 2.f;
|
||||
|
||||
// Get window dimensions for boundary calculations
|
||||
int w = 0, h = 0;
|
||||
SDL_GetWindowSizeInPixels(Window::Window::getSDLWindowBackend(), &w, &h);
|
||||
// Use logical world dimensions (1280×720) not actual screen size
|
||||
constexpr int w = 1280;
|
||||
constexpr int h = 720;
|
||||
const float leftEdge = -w / 2.f + 25.f;
|
||||
|
||||
if (mTransform.x - halfWidth < leftEdge) {
|
||||
|
||||
Reference in New Issue
Block a user