Hello! I just started using classes in my processing games(as in, this is my first attempt). I am incredibly lost as to how to do it correctly. I looked at the processing 3 language reference and it doesn’t have much on classes.
In my head, the following code should work to create an enemy that moves around the screen as a red rectangle. However, when I press run, all the variable declarations for enemy(E1.x = 57; and so on) get an error and say I should consider adding variabledeclaratorId. I could find nothing on this on the internet and so I assume it is simply a poorly worded error message. Could someone please fix this, and help me find references for classes in processing? The syntax and where to put the statements(setup, draw, or in-between?) has me lost.
void setup()
{
size(200, 200);
}
Enemy E1 = new Enemy;
E1.x = 57;//x position
E1.y = 98;//y position
E1.w = 20;//width
E1.h = 30;//height
E1.speedX = 7;
E1.speedY = -12;
void draw()
{
background(0);
//update enemy position
E1.x += E1.speedX;
E1.y += E1.speedY;
fill(255, 0, 0);
rect(E1.x, E1.y, E1.w, E1.h);//draw enemy
}
class Enemy
{
int x, y, speedX, speedY, w, h;
}