I’m trying to create a tower defense game, but atm my enemy keeps vanishing & it’s x keeps showing up nan. Can anyone tell me why?
sketch.js
var wall = [35];
var bs = 25;
var enemy;
function preload(){
wallT = loadTable('wall.csv', 'csv');
}
function setup() {
createCanvas(600, 600);
for (var i = 0; i < wallT.getColumnCount(); i++){
var tn = wallT.getNum(0,i);
wall[i] = new Wall(tn);
}
enemy = new Enemy(50);
}
function draw() {
background(0);
for (var i = 0; i < wall.length; i++){
wall[i].show();
}
enemy.show();
enemy.move();
}
Enemy.js
class Enemy extends Block{
constructor(n) {
super(n);
var xspd = 1;
var yspd = 0;
}
show() {
fill(0,255,0);
rect(this.x,this.y,bs,bs);
}
move() {
this.x += this.xspd;
//this.y += this.yspd;
//print(this.x);
}
}
wall.js
class Wall extends Block{
constructor(n) {
super(n);
}
show() {
fill(255);
rect(this.x,this.y,bs,bs);
}
}
block.js
class Block{
constructor(n) {
this.x = n;
this.y = 0;
while (this.x > 23){
this.y += 1;
this.x -= 24;
}
this.y *= bs;
this.x *= bs;
}
}
wall.csv
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,47,48,71,72,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,119,120,143,144,167,168,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,215,216,239,240,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,287,288,311,312,335,336,359,360,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,407,408,431,432,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,479,480,503,504,527,528,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575