Skip to content

Commit

Permalink
Merge pull request #87 from ratulSharker/web-staging
Browse files Browse the repository at this point in the history
Web staging
  • Loading branch information
ratulSharker authored Jan 23, 2023
2 parents 9ac358a + 7b42f61 commit 5e9592f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/js/game-essentials/bat.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Bat.prototype.repositionBatInsideWindow = function() {
}

Bat.prototype.draw = function() {
this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height)
this.clearCanvas()

this.ctx.fillStyle = "#b89ae4"

Expand All @@ -96,6 +96,10 @@ Bat.prototype.draw = function() {
)
}

Bat.prototype.clearCanvas = function() {
this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height)
}

Bat.prototype.centerTop = function() {
return {
x : this.rect.x + (this.rect.width / 2.0),
Expand Down
2 changes: 1 addition & 1 deletion src/js/game-essentials/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ Game.prototype.operateBall = function () {
}
}


Game.prototype.operatePower = function () {
if (this.curState == this.state.running && this.currentPower) {

Expand Down Expand Up @@ -340,6 +339,7 @@ Game.prototype.draw = function () {
this.drawGameOver()
this.drawScore()
this.drawStageName()
this.bat.clearCanvas()
} else {
this.drawLife()
this.drawScore()
Expand Down
13 changes: 6 additions & 7 deletions src/js/gameplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ $(document).ready(function () {

// setup gameplay
var game = new Game(window.innerWidth, window.innerHeight, $("#canvas")[0], $("#bat_canvas")[0], $("#stage_canvas")[0])
const fps = 60
var intervalId = setInterval(gameloop, 1000 / fps)
window.requestAnimationFrame(gameloop);

// Events
function gameloop() {
game.draw()
window.requestAnimationFrame(gameloop);
}

$(window).resize(function () {
Expand All @@ -27,11 +27,10 @@ $(document).ready(function () {
game.on("no_more_life", gameCompletedEitherAllStageCompletedOrNoMoreLife)

function gameCompletedEitherAllStageCompletedOrNoMoreLife(score) {
// TODO: Why need this inside of a `setTimeout` ?
setTimeout(function () {
clearInterval(intervalId)
updateScore(score)
}, 500)
$("body").off("mousemove");
$("body").off("mouseup");
$(window).off("resize");
updateScore(score);
}

function updateScore(score) {
Expand Down

0 comments on commit 5e9592f

Please sign in to comment.