Guard obstacle drawing behind flag
This commit is contained in:
		
							parent
							
								
									cc3a719542
								
							
						
					
					
						commit
						639c56333e
					
				
							
								
								
									
										18
									
								
								boids.mjs
								
								
								
								
							
							
						
						
									
										18
									
								
								boids.mjs
								
								
								
								
							| 
						 | 
				
			
			@ -64,6 +64,7 @@ class Boids
 | 
			
		|||
 | 
			
		||||
            radius: 10,
 | 
			
		||||
            color: 'black',
 | 
			
		||||
            debug: false,
 | 
			
		||||
        }, params);
 | 
			
		||||
 | 
			
		||||
        // Current width and height of the canvas
 | 
			
		||||
| 
						 | 
				
			
			@ -277,15 +278,18 @@ class Boids
 | 
			
		|||
        );
 | 
			
		||||
 | 
			
		||||
        // Draw obstacles
 | 
			
		||||
        this.ctx.fillStyle = '#dddddd';
 | 
			
		||||
        this.ctx.beginPath();
 | 
			
		||||
 | 
			
		||||
        for (let i = 0; i < obstaclesLength; ++i)
 | 
			
		||||
        if (this.params.debug)
 | 
			
		||||
        {
 | 
			
		||||
            this.obstacles[i].draw(this.ctx);
 | 
			
		||||
        }
 | 
			
		||||
            this.ctx.fillStyle = '#dddddd';
 | 
			
		||||
            this.ctx.beginPath();
 | 
			
		||||
 | 
			
		||||
        this.ctx.fill();
 | 
			
		||||
            for (let i = 0; i < obstaclesLength; ++i)
 | 
			
		||||
            {
 | 
			
		||||
                this.obstacles[i].draw(this.ctx);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            this.ctx.fill();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Draw boids
 | 
			
		||||
        this.ctx.fillStyle = this.params.color;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,7 +32,7 @@
 | 
			
		|||
                new Rectangle(-400, -200, 200, 150),
 | 
			
		||||
                new Circle(200, 200, 100),
 | 
			
		||||
                new Circle(300, 200, 100),
 | 
			
		||||
            ]);
 | 
			
		||||
            ], {debug: true});
 | 
			
		||||
 | 
			
		||||
            canvas.onclick = ev =>
 | 
			
		||||
            {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue