Compare commits
4 Commits
bfec223da1
...
main
Author | SHA1 | Date |
---|---|---|
Luna | 3ab87517da | |
Luna | 94da8b0870 | |
Luna | 10962c4da0 | |
luna | 304d6cafd2 |
|
@ -0,0 +1,7 @@
|
|||
# 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 tileX;
|
||||
let tileY;
|
||||
let ballSpeed = 12;
|
||||
let ballSpeed = 15;
|
||||
let turn = 0;
|
||||
let button;
|
||||
let score = 0;
|
||||
|
@ -77,41 +77,45 @@ function draw() {
|
|||
tileY = grid[i][j].y
|
||||
hitTile = collideRectCircle(tileX, tileY, width / 13, width / 64, ballX, ballY, width / 64);
|
||||
if (hitTile === true) {
|
||||
// vec = createVector(random(-1, 1), random(0, 4));
|
||||
// vec.normalize();
|
||||
grid[i][j].hit = true;
|
||||
ballSpeedX *= -1;
|
||||
ballSpeedY *= -1;
|
||||
vec = createVector(random(-1, 1), random(0, 4));
|
||||
vec.normalize();
|
||||
ballSpeedX = vec.x * ballSpeed;
|
||||
ballSpeedY = vec.y * ballSpeed;
|
||||
// ballSpeedX *= -1;
|
||||
// ballSpeedY *= -1;
|
||||
grid[i].splice(j, 1)
|
||||
|
||||
//ADDING SCORE WHEN BALL HITS TILES
|
||||
|
||||
if (j === 5) {
|
||||
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
|
||||
if (j >= 0 && j <= 6) {
|
||||
score += 6 - j
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
grid[i][j].deleteOnHit() // DELETES THE TILE ON HIT
|
||||
}
|
||||
}
|
||||
|
||||
// BALL COLLISION FOR PADDLE
|
||||
|
||||
hit = collideRectCircle(mouseX, paddleY, width / 12, height / 64, ballX, ballY, width / 64);
|
||||
if (hit === true) {
|
||||
// BALL COLLISION FOR LEFT AND RIGHT PADDLE
|
||||
|
||||
hitLeft = collideRectCircle(mouseX, paddleY, width / 24, height / 64, ballX, ballY, width / 64);
|
||||
if (hitLeft === true) {
|
||||
vec = createVector(random(-1, 1), random(0, 4));
|
||||
vec.normalize();
|
||||
vec.setHeading(45)
|
||||
ballSpeedX = vec.x * -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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -125,9 +129,14 @@ function draw() {
|
|||
// paddleX += 10
|
||||
// };
|
||||
// rectMode(CENTER)
|
||||
push()
|
||||
noStroke()
|
||||
fill(255);
|
||||
rect(mouseX, paddleY, width / 12, height / 64);
|
||||
rect(mouseX, paddleY, width / 24, height / 64); //Left Paddle
|
||||
rect(mouseX + width / 24, paddleY, width / 24, height / 64); //Right Paddle
|
||||
rectMode(CORNER)
|
||||
pop()
|
||||
|
||||
|
||||
// SCORE KEEPING
|
||||
|
||||
|
@ -136,9 +145,9 @@ function draw() {
|
|||
|
||||
// WIN CONDITION
|
||||
|
||||
if (level === 1 && grid.length === 0) {
|
||||
if (level === 1 && grid.every(row => row.length == 0)) {
|
||||
winGame()
|
||||
} else if (grid.length === 0) {
|
||||
} else if (grid.every(row => row.length == 0)) {
|
||||
lostGame()
|
||||
level++
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue