From 3aaa6740f4a62e9244348d0c83bb91d2049248a9 Mon Sep 17 00:00:00 2001 From: Trianta <56975502+Trimutex@users.noreply.github.com> Date: Mon, 30 Dec 2024 17:14:00 -0600 Subject: [PATCH] pong: let bot idle last longer --- src/pong.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pong.ts b/src/pong.ts index 89ed43a..d46b19a 100644 --- a/src/pong.ts +++ b/src/pong.ts @@ -45,6 +45,7 @@ class Paddle { isLeft: boolean; score: number; dy: number; + idleCounter: number; constructor(_geometry: Box, _isLeft: boolean) { this.geometry = _geometry; @@ -53,6 +54,7 @@ class Paddle { this.isBot = true; this.score = 0; this.dy = 0; + this.idleCounter = 0; } scored() { @@ -254,6 +256,10 @@ class PongCore { // Randomly move the bot paddle when ball not towards it botIdle(player: Paddle) { + if (player.idleCounter < 10) { + player.idleCounter++; + return; + } let direction: number = Math.floor(Math.random() * 3); switch (direction) { case 0: