So i'm making a game, if i catch the ball i should go to the next level and the plank under the cat should go lower.
this is my plank object.
var Plank = function (c, top, fill) {
this.left = 20;
this.top = top;
this.width = c.width - 52;
this.height = 6;
this.fill = fill;
this.draw = function () {
var rectangle = new fabric.Rect({
left: this.left,
top: this.top,
fill: this.fill,
width: this.width,
height: this.height
});
rectangle.selectable = false;
c.add(rectangle);
};
};
I make a new object instance.
var plank = new Plank(canvas, canvas.height / 4 + 20, '#FFFF00');
plank.draw();
And here's how i define what's gonna happen if the ball gets caught.
function checkBalls() {
for (var i = 0; i < balls.length; i++) {
console.log(balls);
var ball = balls[i];
var x = ball.pokeBall.left;
var y = ball.pokeBall.top;
if (ball.hasFallen) {
//remove from array
ball.pokeBall.ball = null;
balls.splice(i, 1);
}
if (y > 400 && ball.hasFallen == false) {
var pikaPosition = somePika.pika.left;
var pikaPadding = 50;
var plankpos = plank.top;
if ((pikaPosition - pikaPadding) < x && x < (pikaPosition + pikaPadding)) {
ball.hasFallen = true;
score++;
plankpos =+ 30;
elScore.textContent = score;
if (score == 2) {
alert("UP TO LEVEL 2! CATCH 10 MORE POKEBALLS.");
planktop += 10;
}
else if (score == 4) {
alert("LEVEL 3! NICE!");
planktop += 10;
}
else if (score == 6) {
alert("YOU WIN, CONGRATULATIONS!");
document.location.reload();
}
}
}
}
}
But for some reason i can't get the plank to move when i call its property.
Aucun commentaire:
Enregistrer un commentaire