pong: let bot idle last longer
This commit is contained in:
		
							parent
							
								
									51ec729979
								
							
						
					
					
						commit
						3aaa6740f4
					
				@ -45,6 +45,7 @@ class Paddle {
 | 
				
			|||||||
    isLeft: boolean;
 | 
					    isLeft: boolean;
 | 
				
			||||||
    score: number;
 | 
					    score: number;
 | 
				
			||||||
    dy: number;
 | 
					    dy: number;
 | 
				
			||||||
 | 
					    idleCounter: number;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(_geometry: Box, _isLeft: boolean) {
 | 
					    constructor(_geometry: Box, _isLeft: boolean) {
 | 
				
			||||||
        this.geometry = _geometry;
 | 
					        this.geometry = _geometry;
 | 
				
			||||||
@ -53,6 +54,7 @@ class Paddle {
 | 
				
			|||||||
        this.isBot = true;
 | 
					        this.isBot = true;
 | 
				
			||||||
        this.score = 0;
 | 
					        this.score = 0;
 | 
				
			||||||
        this.dy = 0;
 | 
					        this.dy = 0;
 | 
				
			||||||
 | 
					        this.idleCounter = 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    scored() {
 | 
					    scored() {
 | 
				
			||||||
@ -254,6 +256,10 @@ class PongCore {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Randomly move the bot paddle when ball not towards it
 | 
					    // Randomly move the bot paddle when ball not towards it
 | 
				
			||||||
    botIdle(player: Paddle) {
 | 
					    botIdle(player: Paddle) {
 | 
				
			||||||
 | 
					        if (player.idleCounter < 10) {
 | 
				
			||||||
 | 
					            player.idleCounter++;
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        let direction: number = Math.floor(Math.random() * 3);
 | 
					        let direction: number = Math.floor(Math.random() * 3);
 | 
				
			||||||
        switch (direction) {
 | 
					        switch (direction) {
 | 
				
			||||||
            case 0:
 | 
					            case 0:
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user