As this is a function, make sure to call it with updateMobs();
.
I believe mobsBlue
and mobsRed
are arrays (since you call mobsBlue[b]
and you index it), so for your for
loop, you want to loop for (var b = 0; b < mobsBlue.length; b++){
As such:
var arr = [1, 2, 3, 4]
for(var i = 0;i < arr.length;i++){
item = arr[i]
alert(item)
}
Here is your edited code:
var updateMobs = function(){
for (var b = 0; b < mobsBlue.length; b++){
BM = mobsBlue[b]
BM.x = BM.x - 1
doCollision(BM, redBase, BM)
doCollision(BM, debugPlayer, BM)
console.log("draw1")
BM.Draw(ctx, false)
}
for (var r = 0; r < mobsRed.length; r++){
RM = mobsRed[r]
RM.x = RM.x + 1
doCollision(RM, blueBase, RM)
doCollision(RM, debugPlayer, RM)
console.log("draw2")
RM.Draw(ctx, false)
for (var bb = 0; bb < mobsBlue.length; bb++){
BM = mobsBlue[bb]
console.log("draw3")
BM.Draw(ctx, false)
RM.Draw(ctx, false)
}
}
}