afegides zones

This commit is contained in:
2025-11-29 09:04:18 +01:00
parent 832f77de80
commit 89302a2ee3
6 changed files with 55 additions and 21 deletions

View File

@@ -79,9 +79,8 @@ void Bala::mou(float delta_time) {
centre_.y += dy;
centre_.x += dx;
// Desactivar si surt dels marges (no rebota com els ORNIs)
if (centre_.x < Constants::MARGE_ESQ || centre_.x > Constants::MARGE_DRET ||
centre_.y < Constants::MARGE_DALT || centre_.y > Constants::MARGE_BAIX) {
// Desactivar si surt de la zona de joc (no rebota com els ORNIs)
if (!Constants::dins_zona_joc(centre_.x, centre_.y)) {
esta_ = false;
}
}

View File

@@ -85,10 +85,14 @@ void Enemic::mou(float delta_time) {
float new_y = centre_.y + dy;
float new_x = centre_.x + dx;
// Obtenir límits de la zona de joc
float min_x, max_x, min_y, max_y;
Constants::obtenir_limits_zona(min_x, max_x, min_y, max_y);
// Lògica Pascal: Actualitza Y si dins, sinó ajusta angle aleatòriament
// if (dy>marge_dalt) and (dy<marge_baix) then orni.centre.y:=round(Dy)
// else orni.angle:=orni.angle+(random(256)/512)*(random(3)-1);
if (new_y > Constants::MARGE_DALT && new_y < Constants::MARGE_BAIX) {
if (new_y > min_y && new_y < max_y) {
centre_.y = new_y;
} else {
// Pequeño ajuste aleatorio: (random(256)/512)*(random(3)-1)
@@ -103,7 +107,7 @@ void Enemic::mou(float delta_time) {
// Lògica Pascal: Actualitza X si dins, sinó ajusta angle aleatòriament
// if (dx>marge_esq) and (dx<marge_dret) then orni.centre.x:=round(Dx)
// else orni.angle:=orni.angle+(random(256)/512)*(random(3)-1);
if (new_x > Constants::MARGE_ESQ && new_x < Constants::MARGE_DRET) {
if (new_x > min_x && new_x < max_x) {
centre_.x = new_x;
} else {
float rand1 = (static_cast<float>(std::rand() % 256) / 512.0f);

View File

@@ -116,13 +116,16 @@ void Nau::aplicar_fisica(float delta_time) {
(velocitat_ * delta_time) * std::cos(angle_ - Constants::PI / 2.0f) +
centre_.x;
// Boundary checking - només actualitzar si dins dels marges
// Boundary checking - només actualitzar si dins de la zona de joc
// Acumulació directa amb precisió subpíxel
if (dy > Constants::MARGE_DALT && dy < Constants::MARGE_BAIX) {
float min_x, max_x, min_y, max_y;
Constants::obtenir_limits_zona(min_x, max_x, min_y, max_y);
if (dy > min_y && dy < max_y) {
centre_.y = dy;
}
if (dx > Constants::MARGE_ESQ && dx < Constants::MARGE_DRET) {
if (dx > min_x && dx < max_x) {
centre_.x = dx;
}