Leaf Object not moving
var winstonX=177;
var winstonY=162;
var Winston=function(inventory, speed) {
//this.x=x;
//this.y=y;
this.inventory=inventory;
this.width=50;
this.height=50;
this.speed=speed;
this.img=getImage("creatures/Winston");
this.health=100;
};
Winston.prototype.draw = function() {
image(this.img, winstonX, winstonY, this.width, this.height);
//if (this.inventory[0]==="green leaf" && keyIsPressed && key.toString()==="z") {
//pushMatrix();
//translate(this.x+70, this.y-9);
//rotate(45);
//image(baseLeaf, 0, 0, 50, 50);
//popMatrix();
//}
};
Winston.prototype.up = function() {
this.img=getImage("creatures/Winston");
if (keyIsPressed && key.toString()==="w") {
winstonY-=this.speed;
}
};
Winston.prototype.down = function() {
this.img=getImage("creatures/Winston");
if (keyIsPressed && key.toString()==="s") {
winstonY+=this.speed;
}
};
Winston.prototype.left = function() {
this.img=getImage("creatures/Winston");
if (keyIsPressed && key.toString()==="a") {
winstonX-=this.speed;
}
};
Winston.prototype.right = function() {
this.img=getImage("creatures/Winston");
if (keyIsPressed && key.toString()==="d") {
winstonX+=this.speed;
}
};
var Leaf = function(type, x, y) {
this.type=type;
this.x=x;
this.y=y;
this.img=getImage("avatars/leaf-green");
this.width=50;
this.height=50;
};
Leaf.prototype.draw = function() {
if (this.type==="green") {
this.img=getImage("avatars/leaf-green");
pushMatrix();
translate(this.x, this.y);
rotate(45);
image(this.img, 0, 0, this.width, this.height);
popMatrix();
}
};
var winstonInventory=["green leaf"];
var Winston=new Winston(winstonInventory, 3);
var leafType="";
if (winstonInventory[0]==="green leaf") {
leafType="green";
}
var Leaf=new Leaf(leafType, winstonX+70, winstonY-9);
draw = function() {
background(255,255,255);
Winston.up();
Winston.down();
Winston.left();
Winston.right();
Winston.draw();
if (keyIsPressed && key.toString()==="z") {
Leaf.draw();
}
};
This is code for a game I am making. I tried to make it so that the Leaf object would move along with the Winston object, but the Leaf object stays in one spot even when the Winston object moves. What am I doing wrong?
Iniciar sesión para dejar un comentario.