Hello! I’m new to processing, and i’m wondering how can i compare two variables from different classes with each other. Can someone please guide me in the right direction…
if you are wondering here is my code:
float ang, speed, x, y;
int b_count;
int z_count = 10;
boolean up,down,left,right, shooting = false;
bullet[] b = new bullet[90000];
zombie[] z = new zombie[90000];
void setup() {
size(1200, 800);
smooth();
ang = 0;
speed = 3;
x = width/2;
y = height/2;
for(int i = 0; i < b.length;i++){
b[i] = new bullet();
}
for(int i = 0; i < z.length;i++){
z[i] = new zombie();
}
}
void draw() {
rectMode(CORNER);
background(0);
pushMatrix();
translate(x, y);
rotate(ang);
rect(-20, -7.5, 40, 15); // Center the rect
translate(20, 0); // Translate to default Polar Coordinate 0 radians
ellipse(0, 0, 40, 40); // Display direction
popMatrix();
for (int i = 0; i < b_count; i++){
b[i].show(x,y,ang);
b[i].move();
}
for (int i = 0; i < z_count; i++){
z[i].show();
}
//keys functions!
if(down == true){
x += cos(ang)*speed;
y += sin(ang)*speed;
}
if(up == true){
x -= cos(ang)*speed;
y -= sin(ang)*speed;
}
if(left == true){
ang -= 0.05;
}
if(right == true){
ang += 0.05;
}
}
//keys!!
void keyPressed() {
if(key == 's'){
down = true;
}
if(key == 'w'){
up = true;
}
if(key == 'a'){
left = true;
}
if(key == 'd'){
right = true;
}
///
if(key == ' '){
b_count++;
}
}
void keyReleased() {
if(key == 's'){
down = false;
}
if(key == 'w'){
up = false;
}
if(key == 'a'){
left = false;
}
if(key == 'd'){
right = false;
}
}
class bullet{
float bx,by,bw,bh,bang,bx_,by_;
int bc;
float bspeed = 5;
bullet(){
}
void show(float x_,float y_,float ang_){
if(bc == 0){
bx_ = x_;
by_ = y_;
bx = 0;
by = 0;
bang = ang_/2;
}
bc++;
pushMatrix();
translate(bx_,by_);
rotate(bang);
rectMode(CENTER);; rect(bx,by,10,10);
popMatrix();
}
void move(){
bx -= cos(bang)*bspeed;
by -= sin(bang)*bspeed;
}
}
class zombie{
float zx = random(0,width);
float zy = random(0,height);
float r = 10;
float zspeed = 1;
boolean hit;
void show(){
ellipse(zx,zy,r*2,r*2);
}
}