-1
I have a problem that when trying to assign a new position to a player it says is not a Function. How can I fix it so the player looks like a new home.
class Player{
constructor(id, img){
this.id = id;
this.tileID = 0;
}
getID(){
return this.id;
}
setTileCount(diceResult) {
this.tileID = this.tileID + diceResult;
}
getTileID() {
return this.tileID;
}
/////////////////////////////////////////////////////////////
class Tile {
constructor(x, y, lar, alt, id, img) {
this.x = x;
this.y = y;
this.lar = lar;
this.alt = alt;
this.id = id;
this.img = img;
this.centerPos = createVector(x, y);
this.players = [];
this.posPlayer1 = createVector(this.centerPos.x + 20, this.centerPos.y + 40);
this.posPlayer2 = createVector(this.centerPos.x + 50, this.centerPos.y + 40);
this.posPlayer3 = createVector(this.centerPos.x + 50, this.centerPos.y + 60);
this.posPlayer4 = createVector(this.centerPos.x + 20, this.centerPos.y + 60);
}
showTiles() {
//noStroke();
let q = color(223, 216, 216);
fill(q);
rect(this.centerPos.x, this.centerPos.y, this.lar, this.alt, this.id);
image(this.img, this.centerPos.x, this.centerPos.y, this.lar, this.alt);
}
showPlayer(){
if(this.players.length != 0){
for (var i = 0; i<this.players.length; i++){
if(this.players[i].getID() == 1 && this.id == this.players[i].getTileID()){
circle(this.posPlayer1.x, this.posPlayer1.y, 10);
} else if(this.players[i].getID() == 2 && this.id == this.players[i].getTileID()){
circle(this.posPlayer2.x, this.posPlayer2.y, 10);
} else if(this.players[i].getID() == 3 && this.id == this.players[i].getTileID()){
circle(this.posPlayer3.x, this.posPlayer3.y, 10);
} else if(this.players[i].getID() == 4 && this.id == this.players[i].getTileID()){
circle(this.posPlayer4.x, this.posPlayer4.y, 10);
}
}
}
}
startGame() {
this.players.push(pl1);
this.players.push(pl2);
this.players.push(pl3);
this.players.push(pl4);
}
}
////////////////////////////////////////////////////
The problem lies in this draw function.
function draw() {
for (var i=0; i<tileRowDown.length;i++){
tileRowDown[i].showPlayer();
}
pl1.setTileCount(2); //is not a function
pl1.showPlayer();
}