Skip to content

Commit

Permalink
2 file edited
Browse files Browse the repository at this point in the history
  • Loading branch information
Croc-Prog-github committed Jul 11, 2024
1 parent ac93079 commit 7b208a8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
53 changes: 49 additions & 4 deletions game/GameMood/BattleRoyal/bots/bot1/bot1B.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,51 @@
document.addEventListener('DOMContentLoaded', () => {
const bot1 = document.getElementById('bot1');
const mover = new MoverTS(bot1);
const bot1 = document.getElementById('bot1');
const mover = new MoverTS(bot1);

//Calcola la distanza tra i 2 elementi in argomento
function getDistance(rect1, rect2) {
const dx = rect1.x - rect2.x;
const dy = rect1.y - rect2.y;
return Math.sqrt(dx * dx + dy * dy);
}

function RadarMode() { //Cerca in un raggio di 100px gli id: player || PwUP
const radius = 100; // Raggio di ricerca in pixel
const botRect = bot1.getBoundingClientRect();

const player = document.getElementById('player');
const PwUP = document.getElementById('PwUP');

let foundElement = null;

mover.glideAtIdElement('', 5)
// Verifica se l'elemento player è entro il raggio
if (player) {
const playerRect = player.getBoundingClientRect();
const distanceToPlayer = getDistance(botRect, playerRect);
if (distanceToPlayer <= radius) {
foundElement = player;
}
}

// Verifica se l'elemento PwUP è entro il raggio
if (PwUP && !foundElement) { // Se non ha già trovato il player
const pwupRect = PwUP.getBoundingClientRect();
const distanceToPwUP = getDistance(botRect, pwupRect);
if (distanceToPwUP <= radius) {
foundElement = PwUP;
}
}

if (foundElement) {
console.info("Elemento più vicino trovato nel raggio: "+radius+"): ", foundElement.id);
} else {
console.warn("RadarMode(): Nessun elemento nel raggio di: "+radius+"px");
mover.glideAt(mover.getRandomX, mover.getRandomY, 3); // Va in una posizione a caso
RadarMode();
}
}

document.addEventListener('DOMContentLoaded', () => {

// Si sposta verso la cassa più vicina
mover.glideAtIdElement('PwUP', 3)
})
4 changes: 3 additions & 1 deletion game/GameMood/BattleRoyal/sopr.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
<script src="/SchedDes.js"></script>

<!-- Bots src script -->
<script src="/game/GameMood/BattleRoyal/bots/bot1/bot1A.js"></script>
<!--<script src="/game/GameMood/BattleRoyal/bots/bot1/bot1A.js"></script>-->
<script src="/game/GameMood/BattleRoyal/bots/Movement-library.ts"></script>
<script src="/game/GameMood/BattleRoyal/bots/bot1/bot1B.js"></script>
</head>
<body style="font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; background-color: #195e79ad; overflow: hidden; margin: 3px; cursor: default;" onload="Timing()">

Expand Down

0 comments on commit 7b208a8

Please sign in to comment.