vendredi 24 juillet 2020

I am trying to make this "fps" game, and for some reason the mouseClicked function is not working

When i try to do this code for some reason this part of it: (RX1 = random x 1, RY1 = random y 1)(the "+50 part is there because the width of the rectangle is 50)

if(mouseClicked && mouseX > RX1 && mouseX < RX1 + 50 && mouseY > RY1 && mouseY < RY1 + 50){
    fill(0, 0, 0);
    rect(RX1, RY1, 50, 50);
}

does not work, the program just ignnores it, ive put it everywhere i could think of, and would appreciate someone's help, thanks!

Here is the direct link to it

Here is the rest of the code in case you need it(everything in it works besides the if mouseclicked section

//random x and y variables for targets
var RX1 = random(25, 375);
var RX2 = random(25, 375);
var RX3 = random(25, 375);
var RX4 = random(25, 375);
var RY1 = random(25, 375);
var RY2 = random(25, 375);
var RY3 = random(25, 375);
var RY4 = random(25, 375);

    //the juicy stuff
    
    draw = function() {
         //coloring
     
      background(255, 255, 255);
        fill(255, 0, 0);
     
     //targets:

        rect(RX1, RY1, 50, 50);
        rect(RX2, RY2, 50, 50);
        rect(RX3, RY3, 50, 50);
        rect(RX4, RY4, 50, 50);
 
 //gun
 fill(0, 0, 0);
 
//front sight
    rect(mouseX - 5, mouseY, 10, 20);
    fill(255, 255, 255);
    ellipse(mouseX + 0.5, mouseY + 5, 5, 5);
    fill(0, 0, 0);
 //back sights
 rect(mouseX + 10, mouseY, 20, 20);
 rect(mouseX - 30, mouseY, 20, 20);
 
 //slide
 rect(mouseX - 35, mouseY + 20, 70, 50);
 
 //grip ledge
 fill(77, 77, 77);
 rect(mouseX - 35, mouseY + 71, 70, 20);
 fill(0, 0, 0);
 
 //grip
 rect(mouseX - 30, mouseY + 90, 60, 100);
 

};
//on mouse click/during shooting
    if(mouseClicked && mouseX > RX1 && mouseX <       RX1 + 50 && mouseY > RY1 && mouseY < RY1 + 50     ){
    fill(0, 0, 0);
    rect(RX1, RY1, 50, 50);
}

P.S. I am aware i made the last snippet only for one rectangle, not a single one works either way

Aucun commentaire:

Enregistrer un commentaire