Hey, I'm sort of new to processing but I'm trying to get an understanding of how to use constructors and classes. For a fun project, I'm trying to make a little tank that will drive around with "WASD" keys and move its cannon with the mouse. I've gotten pretty far but I'm just stuck! Can anyone help me with my code? I keep getting an error message that says my constructor is undefined. How is my syntax wrong? Thanks!
Code:Tank myTank;
void setup() {
size(400,400);
smooth();
myTank = new Tank();
}
void draw() {
background(0);
myTank.drawMe();
myTank.control();
}
class Tank {
float x, y;
float theta;
Tank(float ix, float iy, float itheta) {
x = ix;
y = iy;
theta = itheta;
}
void drawMe() {
strokeWeight(1);
fill(159,219,169);
ellipse(x,y,30,30);
fill(205,247,207);
ellipse(x,y,12,12);
translate(x,y);
rotate(theta);
strokeWeight(4);
line(0,0,25,0);
}
void control() {
theta = atan2(mouseY - y, mouseX - x);
if (key == 'w' && keyPressed){
y-=2;
}
else if (key == 's' && keyPressed) {
y+=2;
}
else if (key == 'a' && keyPressed) {
x-=2;
}
else if (key == 'd' && keyPressed) {
x+=2;
}
}
}