So I have been trying to make a game like a shooter similar to diep.io but its like a zombie thing. I could not figure out vectors because I’m too small brain. Anyone wanna help me. Here is the code I have so far.
<class Gunner {
int x = 250;
int y = 250;
void gun(float rotation) {
pushMatrix();
translate(x, y);
rotate(rotation);
fill(0, 0, 0);
rect(0, 0, 15, 10);
fill(0, 255, 0);
ellipse(0, 0, 20, 20);
popMatrix();
}
int getX() {
return x;
}
int getY() {
return y;
}
void setX(int xPos){
x = xPos;
}
void setY(int yPos) {
y = yPos;
}
}
boolean[] keys;
void setup() {
size(500,500);
keys = new boolean[4];
keys[0] = false;
keys[1] = false;
keys[2] = false;
keys[3] = false;
}
int x;
int y;
float xDistance;
float yDistance;
float rotationAngle;
Gunner gunner = new Gunner();
void draw() {
background(255, 255, 255);
gunner.gun(rotationAngle);
if(keys[0]) {
y = gunner.getY();
if(y > 0) {
y–;
gunner.setY(y);
gunner.gun(rotationAngle);
}
}
if(keys[1]) {
x = gunner.getX();
if(x < 500) {
x++;
gunner.setX(x);
gunner.gun(rotationAngle);
}
}
if(keys[2]) {
y = gunner.getY();
if(y < 500) {
y++;
gunner.setY(y);
gunner.gun(rotationAngle);
}
}
if(keys[3]) {
x = gunner.getX();
if(x > 0) {
x–;
gunner.setX(x);
gunner.gun(rotationAngle);
}
}
}
void mouseMoved() {
xDistance = mouseX - gunner.getX();
yDistance = mouseY - gunner.getY();
rotationAngle = atan2(yDistance, xDistance);
gunner.gun(rotationAngle);
}
void keyPressed() {
if (key == ‘w’ || key == ‘W’) {
keys[0] = true;
}
if (key == ‘d’ || key == ‘D’) {
keys[1] = true;
}
if (key == ‘s’ || key == ‘S’) {
keys[2] = true;
}
if (key == ‘a’ || key == ‘A’) {
keys[3] = true;
}
}
void keyReleased() {
if (key == ‘w’ || key == ‘W’) {
keys[0] = false;
}
if (key == ‘d’ || key == ‘D’) {
keys[1] = false;
}
if (key == ‘s’ || key == ‘S’) {
keys[2] = false;
}
if (key == ‘a’ || key == ‘A’) {
keys[3] = false;
}
}
void mouseClicked() {
}>