Treasure game: how to pick up items and end the game?

Hi, I’m trying to make a game that can pick up treasures. right now I can touch them so I will get point but I have no idea how I can let them disappear when I touched them. i need to let the game stop when all the treasures are gone. The code is in dutch. so I will explain some things. the “schat” is the treasure and the “duiker” is het block that need to hit the treasure.

int schermen = 1;
final int ZWART = 0;
final int WIT = 255;
final int BLAUW = #FFF300;

void setup() {
  size (1200, 800);
  setupStartscherm();
  setupSpelscherm();
}

void draw() {
  tekenSchermen();
  switch(keyCode) {
  case DOWN:
    beweegDuikerOmlaag();
    break;
  case UP:
    beweegDuikerOmhoog();
    break;
  case RIGHT:
    beweegDuikerRechts();
    break;
  case LEFT:
    beweegDuikerLinks();
    break;
  }
}

void mousePressed() {
  opStartGeklikt();
  opRetryGeklikt();
}

void tekenSchermen() {
  switch (schermen) {
  case 1:
    {
      clear();
      background(#125498);
      tekenStartScherm();
      break;
    }
  case 2:
    {
      clear();
      tekenSpelScherm();
      break;
    }

  case 3:
    {
      clear();
      tekenEindScherm();
      break;
    }
  }
}
>

</
// overzicht maken
boolean hit = false; 
int xZeemijn;
int xSchat;
int xBoot, yBoot, bBoot, hBoot;
int breedte, hoogte;
int schatten;
int zeemijnen;
int punten;
int levens;
int xPunten;
int xLevens;
int yScorebord;
int tekenWater;
int tekenOppervlakte ;
int tekenSchatten ;
int tekenZeemijnen ;
int tekenDuiker;
int xDuiker, yDuiker, diameterDuiker;
int speed;
int [][] schattenCoor;
int [][] zeemijnenCoor;

void setupSpelscherm() { // op juiste volgorde zetten
  breedte = width / 60;
  hoogte = breedte;
  xDuiker = breedte * 5;
  yDuiker = breedte * 6;
  xBoot = 0;
  bBoot = height / 4;
  yBoot = breedte * 7;
  hBoot = 3 * breedte;
  xPunten = yDuiker;
  xLevens = width / 2;
  yScorebord = breedte + breedte/2;
  schatten = 5; // voor schaalbaarheid
  zeemijnen = 5; // voor schaalbaarheid
  schattenCoor = new int[schatten][2];
  zeemijnenCoor = new int [zeemijnen][2];
  punten = 0; // vast
  levens = 3; // vast
  tekenWater = 0; // vast
  tekenOppervlakte = 1; // vast
  tekenSchatten = 3; // vast
  tekenZeemijnen = 2; //vast
  tekenDuiker = 4;
  diameterDuiker = breedte;
  speed = 3; // te verstellen
}

void tekenSpelScherm() {
  tekenRandomSchatten();
  tekenRandomZeemijnen();
  tekenGrid(grid);
  tekenBoot();
  tekenScorebord();
  tekenDuiker();
  opSchatGeklikt();
  opZeemijnGeklikt();
  stopSpel();
  //even();
}

// dubbele code weghalen
void tekenSchatten (int xSchat, int ySchat) {
  fill(#FFF300);
  rect(xSchat, ySchat, breedte, hoogte);
}

void tekenZeemijnen(int xZeemijn, int yZeemijn) {
  fill(0);
  rect (xZeemijn, yZeemijn, breedte, hoogte);
}

void tekenWater(int xWater, int yWater) {
  //noStroke();
  fill(#5FAEFF);
  rect (xWater, yWater, breedte, hoogte);
}

void tekenOppervlakte(int xOppervlakte, int yOppervlakte) {
  //noStroke();
  fill(255);
  rect (xOppervlakte, yOppervlakte, breedte, hoogte);
}


// dubbele code
void tekenRandomSchatten() {
  while (schatten > 0) {
    int i = floor(random(40));
    int j = floor(random(60));
    if (grid[i][j] == 0) {
      grid[i][j] = 3;
      schatten--;
    }
  }
}

void tekenRandomZeemijnen() {
  while (zeemijnen > 0) {
    int i = floor(random(40));
    int j = floor(random(60));
    if (grid[i][j] == 0) {
      grid[i][j] = 2;
      zeemijnen--;
    }
  }
}


void tekenGrid(int grid [][]) {
  xSchat = 0;
  xZeemijn = 0;
  for (int i = 0; i < grid.length; i++)
    for (int j = 0; j< grid[i].length; j++)
    {
      switch (grid[i][j]) {
      case 0:
        {
          tekenWater(j * breedte, i * breedte); // J * 20 & i * 20 een variable maken?
          break;
        }
      case 1:
        {
          tekenOppervlakte(j * breedte, i * breedte);
          break;
        }
      case 2:
        {
          // dubbele code
          zeemijnenCoor[xZeemijn][0] = j * breedte;
          zeemijnenCoor[xZeemijn][1] = i * breedte;
          println(zeemijnenCoor[xZeemijn][0]);
          println(zeemijnenCoor[xZeemijn][1]);
          xZeemijn++;
          tekenZeemijnen(j * breedte, i * breedte);
          break;
        }
      case 3:
        {
          schattenCoor[xSchat][0] = j * breedte;
          schattenCoor[xSchat][1] = i * breedte;
          println(schattenCoor[xSchat][0]);
          println(schattenCoor[xSchat][1]);
          xSchat++;
          tekenSchatten(j * breedte, i * breedte);
          break;
        }
      }
    }
}
//boolean oneven = true;

//void even() {
//  if (xDuiker % 2 == 0 ) {
//    oneven =  false;
//  }
//}

void tekenBoot () {
  fill(#11524F);
  rect(xBoot, yBoot, bBoot, hBoot);
}

void tekenScorebord() {
  tekenScore();
  tekenLevens();
}


void tekenScore() {
  textSize(yScorebord);
  text("Punten: " + punten, xPunten, yScorebord);
}

void tekenLevens() {
  textSize(yScorebord);
  text("levens: " + levens, xLevens, yScorebord);
}

void tekenDuiker() {
  fill(#AAC9C7);
  square(xDuiker, yDuiker, diameterDuiker);
}

void beweegDuikerOmlaag() {
  if (yDuiker < 780.5) {
    yDuiker = yDuiker + speed;
  }
}

void beweegDuikerOmhoog() { // mag alleen zodra bodem geraakt is.
  if (yDuiker > 200) {
    yDuiker = yDuiker - speed;
  }
}


void beweegDuikerRechts() {
  if (xDuiker < 1200 - diameterDuiker) {
    xDuiker = xDuiker +  speed;
  }
}

void beweegDuikerLinks() {
  if (xDuiker > 0) {
    xDuiker = xDuiker -  speed;
  }
}


void verwijderSchatten() {
  fill(0);
  rect(schattenCoor[4][0], schattenCoor[4][1], breedte, hoogte);
}

//  println("x = " + schattenCoor[0][0] + "y =" + schattenCoor[0][1]+ "b = " + bSchat + "h =" + hSchat + "xD= " +xDuiker + "yD =" + yDuiker);
//  println("x = " + schattenCoor[1][0] + "y =" + schattenCoor[1][1]+ "b = " + bSchat + "h =" + hSchat + "xD= " +xDuiker + "yD =" + yDuiker);
//  println("x = " + schattenCoor[2][0] + "y =" + schattenCoor[2][1]+ "b = " + bSchat + "h =" + hSchat + "xD= " +xDuiker + "yD =" + yDuiker);
//  println("x = " + schattenCoor[3][0] + "y =" + schattenCoor[3][1]+ "b = " + bSchat + "h =" + hSchat + "xD= " +xDuiker + "yD =" + yDuiker);
//  println("x = " + schattenCoor[4][0] + "y =" + schattenCoor[4][1]+ "b = " + bSchat + "h =" + hSchat + "xD= " +xDuiker + "yD =" + yDuiker);

void opSchatGeklikt() {
  for (int i = 0; i < schattenCoor.length; i++) {
    if (dist(xDuiker, yDuiker, schattenCoor[i][0], schattenCoor[i][1]) <= breedte ) {
      hit = true;
    }
    if (hit) {
      punten = punten + 50;
      hit = false;
    }
  }
}

void opZeemijnGeklikt() {
  for (int i = 0; i < zeemijnenCoor.length; i++) {
    if (dist(xDuiker, yDuiker, zeemijnenCoor[i][0], zeemijnenCoor[i][1]) <= breedte ) {
      hit = true;
    }
    if (hit) {
      levens--;
      hit = false;
    }
  }
}



boolean gaatDuikerOmhoog;

void duikerRichtingIsOmhoog() {
  gaatDuikerOmhoog = true;
}

void duikerRichtingIsOmlaag() {
  gaatDuikerOmhoog = false;
}

void stopSpel () {
  if (levens == 0) {
    schermen = 3;
  }
}

>

</
int xKnop;
int xTitle;
int yTitle;
int yKnop;
int bKnop;
int hKnop;
int xText;
int yText;


void tekenStartScherm() {
  tekenTitle();
  tekenStartKnop();
}

void setupStartscherm() {
  xTitle = width / 2;
  yTitle = height / 2;
  hKnop = height / 8;
  bKnop = hKnop * 3;
  xKnop = xTitle - (bKnop/2);
  yKnop = bKnop + (hKnop * 2);
  xText = xKnop + (bKnop / 2);
  yText = yKnop + 40;
}

void tekenTitle() {
  fill(255);
  textSize(50);
  textAlign(CENTER, CENTER);
  text("Diving for treasure", xTitle, yTitle);
}

void tekenStartKnop() {
  fill(255);
  rect(xKnop, yKnop, bKnop, hKnop);
  fill(0);
  text("START", xText, yText);
}

void opStartGeklikt() {
  if (opKnopGeklikt(xKnop, yKnop, bKnop, hKnop, mouseX, mouseY)) {
    schermen = 2;
  }
}

boolean opKnopGeklikt (int xKnop, int yKnop, int bKnop, int hKnop, int muisX, int muisY) {
  return muisX > x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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};

Hi @ArcJAVA,

Can you please do the following before we can help you:

  • Format your code by using the </> button when editing your message or surround your code with backticks like so ``` code ``` → code

  • Give a title that is more explicit. “Asking questions” is the thing that everyone does on the forum :wink: It can be “Treasure game: how to pick up items and end the game?”

  • Your code is quite long and it would be better to reproduce the issue you are facing with a simpler sketch example only with the treasures and simple interaction.

3 Likes

it does detect that im on a treasure and i gives me my point but i cant get it to dissapear.

The part where it is going wrong is the following:

void opSchatGeklikt() {
 for (int i = 0; i < schattenCoor.length; i++) {
   for (int j= 0; j< grid.length; j++) {
     for (int k = 0; k < grid.length; k++) {
       if (dist(xDuiker, yDuiker, schattenCoor[i][0], schattenCoor[i][1]) <= breedte && grid[j][k] == 3) {
         hit = true;
         fill(0);
         rect(schattenCoor[i][0], schattenCoor[i][1], breedte,breedte);
         //grid[j][k] = 0;
       }
       if (hit) {
         punten = punten + 50;
         hit = false;
       }
     }
   }
 }
} 
'''

I was unable to run your minimal reproducible example so I’m going to describe one method of getting ‘hit’ objects to disappear. There may be other techniques of which I am not aware. To use the technique that I know you would have to have a Treasure class with a boolean ‘show’ variable. The Treasure class would also need a ‘display’ function. In the display function would be code which only draws the treasure if treasure.show = true. In the function which detects the ‘hit’ you would set treasure.show to be false. Then when treasure display is called it will see that treasure.show = false and it won’t draw the object. It doesn’t disappear from your array but it just isn’t displayed. Good luck with your project and I hope this technique will help you.

1 Like

I know of that method but for this assignment I’m not allowed to use classes because we haven’t learned about them

The following is theoretical and I don’t know if it would work in your project. The idea would be to create a parallel show array of boolean values. The index of show array items would have to be identical to your treasure array items. Then you could check show[index] before you drew treasure[index]. If show[index] == true then display treasure[index], otherwise don’t draw it. In order for this to work the index would have to be the same in both arrays.

1 Like

I’m sorry but I don’t really get what you’re trying to say. Can you give me an example?

I don’t have an example on my system, but will try to write one; may take a while.

Thank you in advance

Perhaps move the treasure item to outside your screen size dimensions.
So that:

if (hit) {
         punten = punten + 50;
         rect(schattenCoor[i][0] + width, schattenCoor[i][1] + height, breedte, breedte);
         hit = false;
       }

Or larger number amounts to make sure the treasure is off screen.

Also, consider try using the shorten() function to delete items from your array(s) of x, y coordinates.
:nerd_face:

This is a rough example of what I was describing and it does work. For future reference this is a lot easier if you use a class. Otherwise, you have to keep track of the coordinates of every one of the objects (rectangles in this demo).

final int _numRows = 5;
final int _numCols = 5;

int[] x1 = new int[_numRows*_numCols];
int[] y1 = new int[_numRows*_numCols];
int[] x2 = new int[_numRows*_numCols];
int[] y2 = new int[_numRows*_numCols];
boolean[] show = new boolean[_numRows*_numCols];

void initShowArray() {
  for (int x = 0; x<_numRows*_numCols; x++) {
    show[x] = true; // Show them all initially
  }
}

void rectGrid(int l, int t, int w, int h, int hg, int vg) {
  int id = 0;
  for (int k = 0; k < _numRows; k++) {
    for (int j = 0; j < _numCols; j++) {
      x1[id] = l + j*(w+vg);
      y1[id] = t + k*(h+hg);
      x2[id] = w;
      y2[id] = h;
      fill(255);
      if (show[id] == true) {
        rect(x1[id], y1[id], x2[id], y2[id]);
        fill(0);
        textAlign(CENTER, CENTER);
        textSize(20);
        text(str(id), x1[id] + x2[id]/2, y1[id] + y2[id]/2);
      }
      id++;
    }
  }
}

void setup() {
  surface.setTitle("Click on rectangles");
  size(580, 400);
  background(209);
  initShowArray();
  rectGrid(40, 20, 90, 60, 10, 10);
}

void draw() {
  background(209);
  rectGrid(40, 20, 90, 60, 10, 10);
}

void mousePressed() {
  for (int x = 0; x < _numCols*_numRows; x++) {
    if(show[x] == true){ // Don't trap click if false
    if ((mouseX >= x1[x])&& (mouseX <= x1[x] + x2[x] )&& (mouseY >= y1[x])&& (mouseY <= y1[x] + y2[x]) ) {
      show[x] = false;
      println("id =", x);
    }
    }
  }
}

1 Like

I got another question. i have this as my code now. at least the part that is important for the question. but you have a one dimensional array but I have a grid with a two dimensional array and with no rows and coloms. if I try to change that I would not achieve one of the must haves of my assignment. The most important part in your code is the boolean show part . (if I’m correct) but I don’t know how to do that with the array and code I have. so I’m wondering your method is possible with my code. if not do i need to make major changes or where do i need to change it?

final int ZWART = 0;
final int WIT = 255;
final int BLAUW = #FFF300;

void setup() {
 size (1200, 800);
 setupStartscherm();
 setupSpelscherm();
}

void draw() {
 println("x = " + schattenCoor[0][0] + "y =" + schattenCoor[0][1]+ "b = " + breedte + "h =" + breedte + "xD= " +xDuiker + "yD =" + yDuiker);
 println("x = " + schattenCoor[1][0] + "y =" + schattenCoor[1][1]+ "b = " + breedte + "h =" + breedte + "xD= " +xDuiker + "yD =" + yDuiker);
 println("x = " + schattenCoor[2][0] + "y =" + schattenCoor[2][1]+ "b = " + breedte + "h =" + breedte + "xD= " +xDuiker + "yD =" + yDuiker);
 println("x = " + schattenCoor[3][0] + "y =" + schattenCoor[3][1]+ "b = " + breedte + "h =" + breedte + "xD= " +xDuiker + "yD =" + yDuiker);
 println("x = " + schattenCoor[4][0] + "y =" + schattenCoor[4][1]+ "b = " + breedte + "h =" + breedte + "xD= " +xDuiker + "yD =" + yDuiker);
 tekenSchermen();
 switch(keyCode) {
 case DOWN:
   beweegDuikerOmlaag();
   break;
 case UP:
   beweegDuikerOmhoog();
   break;
 case RIGHT:
   beweegDuikerRechts();
   break;
 case LEFT:
   beweegDuikerLinks();
   break;
 }
}

void mousePressed() {
 opStartGeklikt();
 opRetryGeklikt();
}

void tekenSchermen() {
 switch (schermen) {
 case 1:
   {
     clear();
     background(#125498);
     tekenStartScherm();
     break;
   }
 case 2:
   {
     clear();
     tekenSpelScherm();
     break;
   }

 case 3:
   {
     clear();
     tekenEindScherm();
     break;
   }
 }
}

// overzicht maken
boolean hit = false;
int xZeemijn;
int xSchat;
int xBoot, yBoot, bBoot, hBoot;
int breedte, hoogte;
int schatten;
int zeemijnen;
int punten;
int levens;
int xPunten;
int xLevens;
int yScorebord;
int tekenWater;
int tekenOppervlakte ;
int tekenSchatten ;
int tekenZeemijnen ;
int tekenDuiker;
int xDuiker, yDuiker, diameterDuiker;
int speed;
int [][] schattenCoor;
int [][] zeemijnenCoor;

void setupSpelscherm() { // op juiste volgorde zetten
 breedte = width / 60;
 hoogte = breedte;
 xDuiker = breedte * 5;
 yDuiker = breedte * 6;
 xBoot = 0;
 bBoot = height / 4;
 yBoot = breedte * 7;
 hBoot = 3 * breedte;
 xPunten = yDuiker;
 xLevens = width / 2;
 yScorebord = breedte + breedte/2;
 schatten = 5; // voor schaalbaarheid
 zeemijnen = 5; // voor schaalbaarheid
 schattenCoor = new int[schatten][2];
 zeemijnenCoor = new int [zeemijnen][2];
 punten = 0; // vast
 levens = 3; // vast
 tekenWater = 0; // vast
 tekenOppervlakte = 1; // vast
 tekenSchatten = 3; // vast
 tekenZeemijnen = 2; //vast
 tekenDuiker = 4;
 diameterDuiker = breedte;
 speed = 3; // te verstellen
}

void tekenSpelScherm() {
 tekenRandomSchatten();
 tekenRandomZeemijnen();
 tekenGrid(grid);
 tekenBoot();
 tekenScorebord();
 tekenDuiker();
 opSchatGeklikt();
 opZeemijnGeklikt();
 stopSpel();
}
boolean show;

// dubbele code weghalen
void tekenSchatten (int xSchat, int ySchat) {
 fill(#FFF300);
 rect(xSchat, ySchat, breedte, hoogte);
}

void tekenZeemijnen(int xZeemijn, int yZeemijn) {
 fill(0);
 rect (xZeemijn, yZeemijn, breedte, hoogte);
}

void tekenWater(int xWater, int yWater) {
 //noStroke();
 fill(#5FAEFF);
 rect (xWater, yWater, breedte, hoogte);
}

void tekenOppervlakte(int xOppervlakte, int yOppervlakte) {
 //noStroke();
 fill(255);
 rect (xOppervlakte, yOppervlakte, breedte, hoogte);
}


// dubbele code
void tekenRandomSchatten() {
 while (schatten > 0) {
   int i = floor(random(40));
   int j = floor(random(60));
   if (grid[i][j] == 0) {
     grid[i][j] = 3;
     schatten--;
   }
 }
}

void tekenRandomZeemijnen() {
 while (zeemijnen > 0) {
   int i = floor(random(40));
   int j = floor(random(60));
   if (grid[i][j] == 0) {
     grid[i][j] = 2;
     zeemijnen--;
   }
 }
}


void tekenGrid(int grid [][]) {
 xSchat = 0;
 xZeemijn = 0;
 for (int i = 0; i < grid.length; i++)
   for (int j = 0; j< grid[i].length; j++)
   {
     switch (grid[i][j]) {
     case 0:
       {
         tekenWater(j * breedte, i * breedte); // J * 20 & i * 20 een variable maken?
         show = true; 
         break;
       }
     case 1:
       {
         tekenOppervlakte(j * breedte, i * breedte);
         show = true; 
         break;
       }
     case 2:
       {
         // dubbele code
         zeemijnenCoor[xZeemijn][0] = j * breedte;
         zeemijnenCoor[xZeemijn][1] = i * breedte;
         println(zeemijnenCoor[xZeemijn][0]);
         println(zeemijnenCoor[xZeemijn][1]);
         xZeemijn++;
         tekenZeemijnen(j * breedte, i * breedte);
         show = true; 
         break;
       }
     case 3:
       {
         schattenCoor[xSchat][0] = j * breedte;
         schattenCoor[xSchat][1] = i * breedte;
         println(schattenCoor[xSchat][0]);
         println(schattenCoor[xSchat][1]);
         xSchat++;
         tekenSchatten(j * breedte, i * breedte);
         show = true; 
         break;
       }
     }
   }
}

void tekenBoot () {
 fill(#11524F);
 rect(xBoot, yBoot, bBoot, hBoot);
}

void tekenScorebord() {
 tekenScore();
 tekenLevens();
}


void tekenScore() {
 textSize(yScorebord);
 text("Punten: " + punten, xPunten, yScorebord);
}

void tekenLevens() {
 textSize(yScorebord);
 text("levens: " + levens, xLevens, yScorebord);
}

void tekenDuiker() {
 fill(#AAC9C7);
 square(xDuiker, yDuiker, diameterDuiker);
}

void beweegDuikerOmlaag() {
 if (yDuiker < 780.5) {
   yDuiker = yDuiker + speed;
 }
}

void beweegDuikerOmhoog() { // mag alleen zodra bodem geraakt is.
 if (yDuiker > 200) {
   yDuiker = yDuiker - speed;
 }
}


void beweegDuikerRechts() {
 if (xDuiker < 1200 - diameterDuiker) {
   xDuiker = xDuiker +  speed;
 }
}

void beweegDuikerLinks() {
 if (xDuiker > 0) {
   xDuiker = xDuiker -  speed;
 }
}

void opSchatGeklikt() {
 for (int i = 0; i < schattenCoor.length; i++) {
   for (int j= 0; j< grid.length; j++) {
     for (int k = 0; k < grid.length; k++) {
       if (dist(xDuiker, yDuiker, schattenCoor[i][0], schattenCoor[i][1]) <= breedte && grid[j][k] == 3) {
         hit = true;
         //fill(0);
         //rect(schattenCoor[i][0] + width, schattenCoor[i][1] + height, breedte,breedte);
         //grid[j][k] = 0;
         show = false; 
       }
       if (hit) {
         punten = punten + 50;
         hit = false;
       }
     }
   }
 }
}

void opZeemijnGeklikt() {
 for (int i = 0; i < zeemijnenCoor.length; i++) {
   if (dist(xDuiker, yDuiker, zeemijnenCoor[i][0], zeemijnenCoor[i][1]) <= breedte ) {
     hit = true;
     fill(0);
   }
   if (hit) {
     levens--;
     hit = false;
   }
 }
}



boolean gaatDuikerOmhoog;

void duikerRichtingIsOmhoog() {
 gaatDuikerOmhoog = true;
}

void duikerRichtingIsOmlaag() {
 gaatDuikerOmhoog = false;
}

void stopSpel () {
 if (levens == 0 || punten == 250) {
   schermen = 3;
 }
}

// my grid
int  [][] grid = {
 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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0, 0, 0},
 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};

I’d love to run your code, but I get this error:

Screen Shot 2022-10-16 at 11.10.30 AM

Don’t change what you have until we have worked out something better or adapt the technique that I showed you. First a question:

1.) What’s in your two dimensional array? That’s two sets of arrays rolled into one. What’s in each of those arrays?

i’ll send my whole code again so you can run it

the two dimensional array is a array wit 0 and 1. the 1 is for the sky “oppervlakte” for me. and the 0 is for water. i have a randomize function to put 5 random treasures and mines in the array.

i also have 2 arrays with the coordinates of the treasures and the mines.

int schermen = 1;
final int ZWART = 0;
final int WIT = 255;
final int BLAUW = #FFF300;

void setup() {
  size (1200, 800);
  setupStartscherm();
  setupSpelscherm();
}

void draw() {
  println("x = " + schattenCoor[0][0] + "y =" + schattenCoor[0][1]+ "b = " + breedte + "h =" + breedte + "xD= " +xDuiker + "yD =" + yDuiker);
  println("x = " + schattenCoor[1][0] + "y =" + schattenCoor[1][1]+ "b = " + breedte + "h =" + breedte + "xD= " +xDuiker + "yD =" + yDuiker);
  println("x = " + schattenCoor[2][0] + "y =" + schattenCoor[2][1]+ "b = " + breedte + "h =" + breedte + "xD= " +xDuiker + "yD =" + yDuiker);
  println("x = " + schattenCoor[3][0] + "y =" + schattenCoor[3][1]+ "b = " + breedte + "h =" + breedte + "xD= " +xDuiker + "yD =" + yDuiker);
  println("x = " + schattenCoor[4][0] + "y =" + schattenCoor[4][1]+ "b = " + breedte + "h =" + breedte + "xD= " +xDuiker + "yD =" + yDuiker);
  tekenSchermen();
  switch(keyCode) {
  case DOWN:
    beweegDuikerOmlaag();
    break;
  case UP:
    beweegDuikerOmhoog();
    break;
  case RIGHT:
    beweegDuikerRechts();
    break;
  case LEFT:
    beweegDuikerLinks();
    break;
  }
}

void mousePressed() {
  opStartGeklikt();
  opRetryGeklikt();
}

void tekenSchermen() {
  switch (schermen) {
  case 1:
    {
      clear();
      background(#125498);
      tekenStartScherm();
      break;
    }
  case 2:
    {
      clear();
      tekenSpelScherm();
      break;
    }

  case 3:
    {
      clear();
      tekenEindScherm();
      break;
    }
  }
}


void tekenEindScherm() {
  tekenTitle();
  tekenRetryKnop();
  tekenBepaaldePunten();
}


void tekenBepaaldePunten() {
  fill(WIT);
  textSize(20);
  text("Behaalde punten : " + punten, 100, 100);
}

void tekenRetryKnop() {
  fill(#4DCEC4);
  rect(500, 650, 200, 100);
  fill(WIT);
  text("RETRY", 600, 690 );
}

void opRetryGeklikt() {
  if (opKnopGeklikt(500, 650, 200, 100, mouseX, mouseY)) {
    schermen = 1;
  }
}int xLevens;
int yScorebord;
int tekenWater;
int tekenOppervlakte ;
int tekenSchatten ;
int tekenZeemijnen ;
int tekenDuiker;
int xDuiker, yDuiker, diameterDuiker;
int speed;
int [][] schattenCoor;
int [][] zeemijnenCoor;

void setupSpelscherm() { // op juiste volgorde zetten
  breedte = width / 60;
  hoogte = breedte;
  xDuiker = breedte * 5;
  yDuiker = breedte * 6;
  xBoot = 0;
  bBoot = height / 4;
  yBoot = breedte * 7;
  hBoot = 3 * breedte;
  xPunten = yDuiker;
  xLevens = width / 2;
  yScorebord = breedte + breedte/2;
  schatten = 5; // voor schaalbaarheid
  zeemijnen = 5; // voor schaalbaarheid
  schattenCoor = new int[schatten][2];
  zeemijnenCoor = new int [zeemijnen][2];
  punten = 0; // vast
  levens = 3; // vast
  tekenWater = 0; // vast
  tekenOppervlakte = 1; // vast
  tekenSchatten = 3; // vast
  tekenZeemijnen = 2; //vast
  tekenDuiker = 4;
  diameterDuiker = breedte;
  speed = 3; // te verstellen
}

void tekenSpelScherm() {
  tekenRandomSchatten();
  tekenRandomZeemijnen();
  tekenGrid(grid);
  tekenBoot();
  tekenScorebord();
  tekenDuiker();
  opSchatGeklikt();
  opZeemijnGeklikt();
  stopSpel();
}
boolean show;

// dubbele code weghalen
void tekenSchatten (int xSchat, int ySchat) {
  fill(#FFF300);
  rect(xSchat, ySchat, breedte, hoogte);
}

void tekenZeemijnen(int xZeemijn, int yZeemijn) {
  fill(0);
  rect (xZeemijn, yZeemijn, breedte, hoogte);
}

void tekenWater(int xWater, int yWater) {
  //noStroke();
  fill(#5FAEFF);
  rect (xWater, yWater, breedte, hoogte);
}

void tekenOppervlakte(int xOppervlakte, int yOppervlakte) {
  //noStroke();
  fill(255);
  rect (xOppervlakte, yOppervlakte, breedte, hoogte);
}


// dubbele code
void tekenRandomSchatten() {
  while (schatten > 0) {
    int i = floor(random(40));
    int j = floor(random(60));
    if (grid[i][j] == 0) {
      grid[i][j] = 3;
      schatten--;
    }
  }
}

void tekenRandomZeemijnen() {
  while (zeemijnen > 0) {
    int i = floor(random(40));
    int j = floor(random(60));
    if (grid[i][j] == 0) {
      grid[i][j] = 2;
      zeemijnen--;
    }
  }
}


void tekenGrid(int grid [][]) {
  xSchat = 0;
  xZeemijn = 0;
  for (int i = 0; i < grid.length; i++)
    for (int j = 0; j< grid[i].length; j++)
    {
      switch (grid[i][j]) {
      case 0:
        {
          tekenWater(j * breedte, i * breedte); // J * 20 & i * 20 een variable maken?
          show = true; 
          break;
        }
      case 1:
        {
          tekenOppervlakte(j * breedte, i * breedte);
          show = true; 
          break;
        }
      case 2:
        {
          // dubbele code
          zeemijnenCoor[xZeemijn][0] = j * breedte;
          zeemijnenCoor[xZeemijn][1] = i * breedte;
          println(zeemijnenCoor[xZeemijn][0]);
          println(zeemijnenCoor[xZeemijn][1]);
          xZeemijn++;
          tekenZeemijnen(j * breedte, i * breedte);
          show = true; 
          break;
        }
      case 3:
        {
          schattenCoor[xSchat][0] = j * breedte;
          schattenCoor[xSchat][1] = i * breedte;
          println(schattenCoor[xSchat][0]);
          println(schattenCoor[xSchat][1]);
          xSchat++;
          tekenSchatten(j * breedte, i * breedte);
          show = true; 
          break;
        }
      }
    }
}

void tekenBoot () {
  fill(#11524F);
  rect(xBoot, yBoot, bBoot, hBoot);
}

void tekenScorebord() {
  tekenScore();
  tekenLevens();
}


void tekenScore() {
  textSize(yScorebord);
  text("Punten: " + punten, xPunten, yScorebord);
}

void tekenLevens() {
  textSize(yScorebord);
  text("levens: " + levens, xLevens, yScorebord);
}

void tekenDuiker() {
  fill(#AAC9C7);
  square(xDuiker, yDuiker, diameterDuiker);
}

void beweegDuikerOmlaag() {
  if (yDuiker < 780.5) {
    yDuiker = yDuiker + speed;
  }
}

void beweegDuikerOmhoog() { // mag alleen zodra bodem geraakt is.
  if (yDuiker > 200) {
    yDuiker = yDuiker - speed;
  }
}


void beweegDuikerRechts() {
  if (xDuiker < 1200 - diameterDuiker) {
    xDuiker = xDuiker +  speed;
  }
}

void beweegDuikerLinks() {
  if (xDuiker > 0) {
    xDuiker = xDuiker -  speed;
  }
}

void opSchatGeklikt() {
  for (int i = 0; i < schattenCoor.length; i++) {
    for (int j= 0; j< grid.length; j++) {
      for (int k = 0; k < grid.length; k++) {
        if (dist(xDuiker, yDuiker, schattenCoor[i][0], schattenCoor[i][1]) <= breedte && grid[j][k] == 3) {
          hit = true;
          //fill(0);
          //rect(schattenCoor[i][0] + width, schattenCoor[i][1] + height, breedte,breedte);
          //grid[j][k] = 0;
          show = false; 
        }
        if (hit) {
          punten = punten + 50;
          hit = false;
        }
      }
    }
  }
}

void opZeemijnGeklikt() {
  for (int i = 0; i < zeemijnenCoor.length; i++) {
    if (dist(xDuiker, yDuiker, zeemijnenCoor[i][0], zeemijnenCoor[i][1]) <= breedte ) {
      hit = true;
      fill(0);
    }
    if (hit) {
      levens--;
      hit = false;
    }
  }
}



boolean gaatDuikerOmhoog;

void duikerRichtingIsOmhoog() {
  gaatDuikerOmhoog = true;
}

void duikerRichtingIsOmlaag() {
  gaatDuikerOmhoog = false;
}

void stopSpel () {
  if (levens == 0 || punten == 250) {
    schermen = 3;
  }
}

int xKnop;
int xTitle;
int yTitle;
int yKnop;
int bKnop;
int hKnop;
int xText;
int yText;


void tekenStartScherm() {
  tekenTitle();
  tekenStartKnop();
}

void setupStartscherm() {
  xTitle = width / 2;
  yTitle = height / 2;
  hKnop = height / 8;
  bKnop = hKnop * 3;
  xKnop = xTitle - (bKnop/2);
  yKnop = bKnop + (hKnop * 2);
  xText = xKnop + (bKnop / 2);
  yText = yKnop + 40;
}

void tekenTitle() {
  fill(255);
  textSize(50);
  textAlign(CENTER, CENTER);
  text("Diving for treasure", xTitle, yTitle);
}

void tekenStartKnop() {
  fill(255);
  rect(xKnop, yKnop, bKnop, hKnop);
  fill(0);
  text("START", xText, yText);
}

void opStartGeklikt() {
  if (opKnopGeklikt(xKnop, yKnop, bKnop, hKnop, mouseX, mouseY)) {
    schermen = 2;
  }
}

boolean opKnopGeklikt (int xKnop, int yKnop, int bKnop, int hKnop, int muisX, int muisY) {
  return muisX > xKnop && muisX < xKnop + b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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};

Unfortunately I now get this error and there are several more too numerous to list:
Screen Shot 2022-10-16 at 11.35.46 AM

Don’t give up. We will get this. If I can’t fix it then we’ll call for backup; they’re a lot of knowledgeable folks in this forum.

Is this part of the two dimensional array? Could it be a separate array (or is it separate already)?

i also have 2 arrays with the coordinates of the treasures and the mines.

On second thought why can’t you run the treasure array of coordinates and see which one the mouse clicked on? Set the show[index] to false when it’s clicked on and then check the show array before you draw the treasure.

i have 3 arrays

  1. SchattenCoor
  2. zeemijnenCoor
    3 grid

i dont reallt click on them. i move over them and then i get the points or i lose one of my lives.

it knows when im on witch but i don’t know how to put the show functions in there

i cant reply anymore because I’m a new user so i will edit this one each time. but yes there all two dimesional. 'schattenCoor is treasureCoordinates with x and y" and the other one is for the mines also with x and y.

2nd edit:
No i just have boolean show
if i want to initialise it it says i cant be an array.
i would get : boolean show = true. but then i get an error for the [id]

i have two functions that are voids.

and the following is in them.
i changed it a little but now i get a “nullpointerexception” when i hit a treasure

i also have no idea how to do this
Somehow you have to have the array index of the treasure object to match the index (id) of the loop where you trap the hit. Once this is done check the show array before you draw the object.
i put the id+= under it. or do you mean under the whole “opSchatGeklikt” function?

3d edit:
the println (id) goes way beyond 5. i goes from 1 all the way up to 200 and then it starts again.

" What does rect(schattenCoor[i][0], schattenCoor[i][1], breedte,breedte); draw?"
right now it makes the treasure I’m moving over black when I go over it. but it only happens when I’m on the treasure.

4d edit:
i indeed only have 5 treasures and mines. but if i do that i get this error
image

5d edit:
it checks my whole array but that are 2400 elements so don’t know why it checks 200. i have nothing that checks 200 thinks. the function that draws the treasures and the mines puts a random treasure in de array of 2400 elements.
edit 6:
" if (dist(xDuiker, yDuiker, schattenCoor[i][0], schattenCoor[i][1]) <= breedte && grid[j][k] == 3)"
it checks it the distance between my person and the treasure. if its in a specific racios and if its a treasure in the array; the last part is unnessecarry because i don’t use i anymore. i had i for a test. i first had something similar. but i checkt is i was between the x and de y of the treasure but then it would only work if the x of the person was on the treasure. this line of code i got from someone i know so I’m sorry if my explanation is not really clear.

edit 7:
i got the unnecessary parts out of the code and now the id is only 1.

edit 8:
it now goes to 5.
edit 9:
“That may not be good; is that what you intended?”
it wasn’t but i fixed that.

edit 10:
i put it under hit = true. but now i does show anything in the console
edit 11:
“To make sure I understand the goal, you want the treasure to turn black when you move over it and then not be drawn again. Is this correct?”

i trying to make the treasure disappear. that i changes to black was just a test i did. it just needs to disappear completely so i cant get any more points from it.

edit 12:
if i put id++ right below rect() then it will always say id = 0. but when in go over 1 of my treasure it goes to one. but it cant detect witch one. its kinda hard to tell sinds he checks / runs 60 frames a second.

edit 13:
the moment I’m on a treasure doesn’t matter which one it says id = 1. I put the println to know which treasue i have but what do i need to do with that? And the println(id) shows 0 when I’m not on a treasure.

edit 14:
i = 0,1,2,3 or 4. the first time I’m on a treasure its 0 second one 1, etc. the same treasure has the same number each time i got over it. the one that’s drawn first is 0. drawn second =1 etc.

edit 15:
Hallelujah!! If you know i = 0 to 4 then you have the index for your treasure. UnREM the line show[i] = false;

if i do this do i also need to unREM the boolean show = new boolean[5]?

edit 16:
i did unREM both of them but now i have this error
image

edit 17:
i did that but that didn’t change anything right?
alright then i have this:

edit 18:
“Where are you drawing the treasure to start with? We need to put a loop in there to check the show array before your app draws every treasure.”
drawing or putting it in de array. if its drawing then its the function "tekenSchatten(…,…){}:

edit 19:
it thought maybe do the () away but now there not yellow anymore.
it says the following:
image

// this part draws it. 
void tekenSchatten (int xSchat, int ySchat) {
  for (int i = 0; i < show.length(); i++) {
    if (show[i] == true) {
      fill(#FFF300);
      rect(xSchat, ySchat, breedte, hoogte);
    }
  }
}




boolean [] show = new boolean[5];

void opSchatGeklikt() {
  int id = 0;
  for (int i = 0; i < schattenCoor.length; i++) {
    //for (int j= 0; j< grid.length; j++) {
    //  for (int k = 0; k < grid.length; k++) {
    if (dist(xDuiker, yDuiker, schattenCoor[i][0], schattenCoor[i][1]) <= breedte) {
      hit = true;
      println("id =" + id);
      show[i] = false;
      fill(0);
      rect(schattenCoor[i][0], schattenCoor[i][1], breedte, breedte);
      println("i =" + i);
      id++;
      //grid[j][k] = 0;
    }
    if (hit) {
      punten = punten + 50;
      hit = false;
    }
    //id++;
    println("id =" + id);
  }
}

I understand ‘grid’. Can you translate the other two. So you’re saying they are all two dimensional?

i move over them

How do you trap which treasure or mine you are over?