Skip to content

Commit

Permalink
Merge branch 'master' into suh-dude
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnBinning authored Mar 23, 2017
2 parents 5ffcd92 + d82d325 commit 52ba2b6
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
2 changes: 2 additions & 0 deletions lib/Block.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ class Block {
}

draw (ctx) {

this.image.src = '../images/burritorb.jpg';
ctx.drawImage(this.image, this.x, this.y, this.width, this.height);

return this;
}
}
Expand Down
2 changes: 0 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ requestAnimationFrame(function gameLoop() {
}
});

// gameFrame()


world.movePaddle()

Expand Down
11 changes: 8 additions & 3 deletions lib/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class World {
this.blocksArray.splice(i, 1);
this.blockDestroySound.play()
this.resultsUpdate(ctx)

}
}
}
Expand Down Expand Up @@ -136,8 +135,9 @@ class World {
//paddle collision
paddleCollision () {
let radius = this.ball.radius

if (this.ball.y + radius >= this.paddle.y &&
this.ball.y - radius <= this.paddle.y + this.paddle.height){
this.ball.y - radius <= this.paddle.y + this.paddle.height) {
this.paddleCollisionTop()
this.paddleCollisionTopLeft()
this.paddleCollisionTopRight()
Expand All @@ -159,9 +159,11 @@ class World {
if (this.ball.x + radius >= this.paddle.x &&
this.ball.x + radius < this.paddle.x + paddleLeftZone &&
this.ball.vx > 0) {

this.ball.vx = this.ball.vx * -1
this.paddleSound.play()
}

}

paddleCollisionTopRight () {
Expand All @@ -171,9 +173,11 @@ class World {
if (this.ball.x - radius <= this.paddle.x + this.paddle.width &&
this.ball.x - radius > this.paddle.x + paddleRightZone &&
this.ball.vx < 0) {

this.ball.vx = this.ball.vx * -1
this.paddleSound.play()
}

}

//scores
Expand Down Expand Up @@ -217,13 +221,15 @@ class World {
}

winGame (ctx) {

ctx.font = "40px 'Just Me Again Down Here'";
ctx.fillStyle = '#FEC325';
ctx.fillText("Suh Dude,You Win", 180, 240);
ctx.font = "24px 'Just Me Again Down Here'";
ctx.fillText("Click the button below to restart fam", 150, 290);
ctx.font = "30px 'Just Me Again Down Here'"
ctx.fillText("it's so lit right now", 200, 330)

this.win = true;
this.winSound.play()
}
Expand All @@ -243,7 +249,6 @@ class World {
}
}


function restartGame () {
document.querySelector("canvas").addEventListener("click", function() {
location.reload();
Expand Down
5 changes: 5 additions & 0 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<head>
<meta charset="utf-8">
<title>Test Suite - Game Time</title>
<style type="text/css">
canvas, button {
display: none;
}
</style>
</head>
<body>
<canvas id="game" width="600" height="500" hidden="true"></canvas>
Expand Down
9 changes: 9 additions & 0 deletions test/block-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ describe('Block', () => {
assert.equal(world.ball.vy, 4);
})

it('should take a block out of the array when the ball hits the block', () => {
let world = new World();

assert.equal(world.blocksArray.length, 40)
world.ball.y = 105
world.ball.x = 17
world.blockCollide()
assert.equal(world.blocksArray.length, 39)
})


})
2 changes: 1 addition & 1 deletion test/paddle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const assert = require('chai').assert

describe('Paddle', () => {
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
let world = new World(canvas);

it('should be a function', () =>{
Expand Down Expand Up @@ -63,6 +62,7 @@ describe('Paddle', () => {

it('should not change ball velocity if the ball is under the paddle', () => {
let world = new World(canvas)

world.ball.vy = -4;
assert.equal(world.ball.vy, -4);
world.ball.x = 301;
Expand Down
10 changes: 0 additions & 10 deletions test/world-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ describe('World', () => {
assert.equal(world.ball.vy, 4)
})

it('should take a block out of the array when the ball hits a block', () => {
assert.equal(world.blocksArray.length, 40)
world.ball.y = 105
world.ball.x = 17
world.blockCollide()
assert.equal(world.blocksArray.length, 39)
})

it('should increase score when the ball hits a block', () =>{
let world = new World(canvas);

Expand All @@ -91,7 +83,6 @@ describe('World', () => {
assert.equal(world.score, 1)
})


it('should decrement one life when the ball hits the bottom and lives are > 1', () => {
world.lives = 3
assert.equal(world.lives, 3)
Expand All @@ -101,5 +92,4 @@ describe('World', () => {

})


})

0 comments on commit 52ba2b6

Please sign in to comment.