Hi there,
trying to follow this tutorial by TheCodingTrain on YouTube with some modification:
I keep getting the error “bullet.push is not a function”.
Any help is much appreciated.
Please see my sketch.js code below:
var character;
var scl = 20;
var projectile = [];
var bullet = [];
function setup() {
createCanvas(1000, 1000);
character = new Character();
bullet = new Bullet(width/2, height/2);
for (var i = 0; i < 5; i++) {
projectile [i] = new Projectile(i*80+80, 60);
}
}
function draw() {
background(0,0,0);
character.update();
character.show();
for (var i = 0; i < bullet.length; i++) {
bullet[i].show();
bullet[i].move();
}
for (var i = 0; i < 5; i++) {
projectile [i].show();
}
}
function keyPressed() {
if (keyCode === LEFT_ARROW) {
character.dir(-3, -3);
} else if (keyCode === UP_ARROW) {
character.dir(3, -3);
} else if (keyCode === RIGHT_ARROW) {
character.dir(3, 3);
} else if (keyCode === DOWN_ARROW) {
character.dir(-3, 3);
}
if (keyCode === 32) {
var bullet = new Bullet(character.x, height);
bullet.push (bullet);
}
}
function keyReleased() {
if (keyCode === LEFT_ARROW) {
character.dir(0, 0);
} else if (keyCode === UP_ARROW) {
character.dir(0, 0);
} else if (keyCode === RIGHT_ARROW) {
character.dir(0, 0);
} else if (keyCode === DOWN_ARROW) {
character.dir(0, 0);
}
}