From c76fed5ccd0885fb21e5e6b43bd94793297269fb Mon Sep 17 00:00:00 2001 From: aldrin312 Date: Tue, 3 Dec 2024 17:37:16 -0500 Subject: [PATCH] more code clean up --- components/GameScreen.vue | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/components/GameScreen.vue b/components/GameScreen.vue index 4509454..626ce3d 100644 --- a/components/GameScreen.vue +++ b/components/GameScreen.vue @@ -115,16 +115,14 @@ function animateZoom(currentTime: number) { isZooming = false; } } -function followPlayerBot(botx: number, boty: number, username: string) { + +function followPlayerBot(botx: number, boty: number) { if (!appRef.value || !gameState.value) { return; } const playerBot = Object.values(gameState.value.bots)?.[0]; - if (!playerBot) { - return; - } - if (username == playerBot.username) { + if (playerBot) { const currentPos = appRef.value.stage.position; const targetPos = { x: -botx * appRef.value.stage.scale.x + appRef.value.screen.width / 2, @@ -267,6 +265,7 @@ watch(gameState, async (newState, prevState) => { autoDensity: true, }); + // Follow player bot function follow() { isFollowing = !isFollowing; if (!gameState.value) { @@ -284,10 +283,9 @@ watch(gameState, async (newState, prevState) => { } } - const button = document.getElementById("button"); - - if (button) { - button.addEventListener("click", function () { + const followButton = document.getElementById("followButton"); + if (followButton) { + followButton.addEventListener("click", function () { follow(); }); } @@ -461,9 +459,9 @@ watch(gameState, async (newState, prevState) => { const x = prevBot.x + (bot.x - prevBot.x) * progress; const y = prevBot.y + (bot.y - prevBot.y) * progress; const botDirection = getDirection(prevBot, bot); - // follow players bot + // Follow players bot if (isFollowing) { - followPlayerBot(x, y, bot.username); + followPlayerBot(x, y); } drawBot({ bot: { ...bot, x, y }, graphics: existingBot, botDirection }); @@ -486,7 +484,7 @@ watch(gameState, async (newState, prevState) => { >
follow my bot