Javascript: Bilding Bricks on Canvas

458 views Asked by At

Okay, I have searched everywhere but haven't found something specifically useful for me. Im trying to code a BreakOut Game with pure JavaScript. I've had my ups and downs, as I'm a beginner, but I managed to display and control the paddle aswell as the Ball. But I seem too stupid to build the brickwall for the ball to destroy. Im working with a few more .js files, so the Code is not stuffed into one file.

The bricks shall be initialised within the BreakOutGame.js (Main File) but the drawing of the bricks needs to be done in the file Brick.js

Here's the code in the BreakOutGame.Js

function privateInitContent(){
var bricks = [];
for (var r = 0; r < BRICK_ROWS; r++){
 for (var c = 0; c < BRICK_COLUMNS; c++){
  var brick[r][c] = new Brick(privateContext, BRICK_XPOS, BRICK_YPOS, BRICK_COLOR, BRICK_WIDTH, BRICK_HEIGHT);
   bricks[r][c].push(brick);
  }
 }
}

This seems not to work. And here's the content of the Brick.js file:

var Brick = function(context, xPos, yPos, color, width, height) {

this.context = context;

this.BrickXPos = xPos;
this.BrickYPos = yPos;
this.BrickWidth = width;
this.BrickHeight = height;

this.BrickColor = color;

}

Brick.prototype.draw = function() {

this.context.fillStyle = this.color;
 this.context.fillRect(this.BrickXPos,this.BrickYPos,this.BrickWidth,this.BrickHeight);


}

Can anyone give me an idea? I really need this :/

0

There are 0 answers