I need to make my player move in all of 8 directions using W A S D and my code makes some weird stuff when I press more than one key and I don’t know why
class Vini {
float x = width/2;
float y = height/2;
float vel = 10;
boolean [] keys = new boolean[128];
void display() {
ellipse(x, y, 50, 50);
}
void movement() {
if (keyPressed) {
keys[key]= true;
if (keys['w']) {
y -= vel;
}
if (keys['s']) {
y += vel;
}
if (keys['a']) {
x -= vel;
}
if (keys['d']) {
x += vel;
}
} else if (keyPressed == false) {
keys[key] = false;
}
}
}
Vini vini;
void setup() {
size(600, 600);
vini = new Vini();
}
void draw() {
background(50);
vini.display();
vini.movement();
}
if anyone could helpme I would be very grateful