Compare commits
	
		
			No commits in common. "main" and "bfec223da15905ff1b8bcebe31175a70164a3669" have entirely different histories.
		
	
	
		
			main
			...
			bfec223da1
		
	
		
					 3 changed files with 33 additions and 42 deletions
				
			
		|  | @ -1,7 +0,0 @@ | ||||||
| # p5-breakout |  | ||||||
| The game Breakout made in JavaScript using p5.js. |  | ||||||
| 
 |  | ||||||
| You can play it at this link below: |  | ||||||
| 
 |  | ||||||
| https://preview.p5js.org/lunalcampbell/present/wm3vA1Ss4 |  | ||||||
| 
 |  | ||||||
							
								
								
									
										61
									
								
								sketch.js
									
									
									
									
									
								
							
							
						
						
									
										61
									
								
								sketch.js
									
									
									
									
									
								
							|  | @ -14,7 +14,7 @@ let hit = false; | ||||||
| let hitTile = false; | let hitTile = false; | ||||||
| let tileX; | let tileX; | ||||||
| let tileY; | let tileY; | ||||||
| let ballSpeed = 15; | let ballSpeed = 12; | ||||||
| let turn = 0; | let turn = 0; | ||||||
| let button; | let button; | ||||||
| let score = 0; | let score = 0; | ||||||
|  | @ -77,45 +77,41 @@ function draw() { | ||||||
|       tileY = grid[i][j].y |       tileY = grid[i][j].y | ||||||
|       hitTile = collideRectCircle(tileX, tileY, width / 13, width / 64, ballX, ballY, width / 64); |       hitTile = collideRectCircle(tileX, tileY, width / 13, width / 64, ballX, ballY, width / 64); | ||||||
|       if (hitTile === true) { |       if (hitTile === true) { | ||||||
|         vec = createVector(random(-1, 1), random(0, 4)); |         // vec = createVector(random(-1, 1), random(0, 4));
 | ||||||
|         vec.normalize(); |         // vec.normalize();
 | ||||||
|         ballSpeedX = vec.x * ballSpeed; |         grid[i][j].hit = true; | ||||||
|         ballSpeedY = vec.y * ballSpeed; |         ballSpeedX *= -1; | ||||||
|         // ballSpeedX *= -1;
 |         ballSpeedY *= -1; | ||||||
|         // ballSpeedY *= -1;
 |  | ||||||
|         grid[i].splice(j, 1) |  | ||||||
| 
 | 
 | ||||||
|         //ADDING SCORE WHEN BALL HITS TILES
 |         //ADDING SCORE WHEN BALL HITS TILES
 | ||||||
| 
 | 
 | ||||||
|         if (j >= 0 && j <= 6) { |         if (j === 5) { | ||||||
|           score += 6 - j |           score += 1 | ||||||
|  |         } else if (j === 4) { | ||||||
|  |           score += 2 | ||||||
|  |         } else if (j === 3) { | ||||||
|  |           score += 3 | ||||||
|  |         } else if (j === 2) { | ||||||
|  |           score += 4 | ||||||
|  |         } else if (j === 1) { | ||||||
|  |           score += 5 | ||||||
|  |         } else if (j === 0) { | ||||||
|  |           score += 6 | ||||||
|         } |         } | ||||||
|         break; | 
 | ||||||
|       } |       } | ||||||
|  |       grid[i][j].deleteOnHit() // DELETES THE TILE ON HIT
 | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   // BALL COLLISION FOR PADDLE
 | ||||||
| 
 | 
 | ||||||
|   // BALL COLLISION FOR LEFT AND RIGHT PADDLE
 |   hit = collideRectCircle(mouseX, paddleY, width / 12, height / 64, ballX, ballY, width / 64); | ||||||
| 
 |   if (hit === true) { | ||||||
|   hitLeft = collideRectCircle(mouseX, paddleY, width / 24, height / 64, ballX, ballY, width / 64); |  | ||||||
|   if (hitLeft === true) { |  | ||||||
|     vec = createVector(random(-1, 1), random(0, 4)); |     vec = createVector(random(-1, 1), random(0, 4)); | ||||||
|     vec.normalize(); |     vec.normalize(); | ||||||
|     vec.setHeading(45) |  | ||||||
|     ballSpeedX = vec.x * -ballSpeed; |     ballSpeedX = vec.x * -ballSpeed; | ||||||
|     ballSpeedY = vec.y * -ballSpeed; |     ballSpeedY = vec.y * -ballSpeed; | ||||||
| 
 |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   hitRight = collideRectCircle(mouseX + width / 24, paddleY, width / 16, height / 64, ballX, ballY, width / 64); |  | ||||||
|   if (hitRight === true) { |  | ||||||
|     vec = createVector(random(-1, 1), random(0, 4)); |  | ||||||
|     vec.normalize(); |  | ||||||
|     vec.setHeading(90) |  | ||||||
|     ballSpeedX = vec.x * -ballSpeed; |  | ||||||
|     ballSpeedY = vec.y * -ballSpeed; |  | ||||||
|      |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -129,14 +125,9 @@ function draw() { | ||||||
|   //   paddleX += 10
 |   //   paddleX += 10
 | ||||||
|   // };
 |   // };
 | ||||||
|   // rectMode(CENTER)
 |   // rectMode(CENTER)
 | ||||||
|   push() |  | ||||||
|   noStroke() |  | ||||||
|   fill(255); |   fill(255); | ||||||
|   rect(mouseX, paddleY, width / 24, height / 64); //Left Paddle
 |   rect(mouseX, paddleY, width / 12, height / 64); | ||||||
|   rect(mouseX + width / 24, paddleY, width / 24, height / 64); //Right Paddle
 |  | ||||||
|   rectMode(CORNER) |   rectMode(CORNER) | ||||||
|   pop() |  | ||||||
|    |  | ||||||
| 
 | 
 | ||||||
|   // SCORE KEEPING
 |   // SCORE KEEPING
 | ||||||
| 
 | 
 | ||||||
|  | @ -145,9 +136,9 @@ function draw() { | ||||||
| 
 | 
 | ||||||
|   // WIN CONDITION
 |   // WIN CONDITION
 | ||||||
| 
 | 
 | ||||||
|   if (level === 1 && grid.every(row => row.length == 0)) { |   if (level === 1 && grid.length === 0) { | ||||||
|     winGame() |     winGame() | ||||||
|   } else if  (grid.every(row => row.length == 0)) { |   } else if  (grid.length === 0) { | ||||||
|     lostGame() |     lostGame() | ||||||
|     level++ |     level++ | ||||||
|   } |   } | ||||||
|  |  | ||||||
							
								
								
									
										7
									
								
								tile.js
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								tile.js
									
									
									
									
									
								
							|  | @ -8,6 +8,7 @@ class Tile { | ||||||
|         this.colors = colors |         this.colors = colors | ||||||
|         this.x = i * width / 13; |         this.x = i * width / 13; | ||||||
|         this.y = j * width / 64; |         this.y = j * width / 64; | ||||||
|  |         this.hit = false; | ||||||
|         this.score = score |         this.score = score | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -21,4 +22,10 @@ class Tile { | ||||||
|         this.colors = colors |         this.colors = colors | ||||||
|         return colors; |         return colors; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     deleteOnHit() { | ||||||
|  |         if (this.hit) { | ||||||
|  |             grid[this.i].splice(this.j, 1) | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
		Loading…
	
		Reference in a new issue