My new game - need help working with images

Look what I have achieved is that when I click on a figure suddenly both are changed at the same time. So now I do not know how to ask a question and relate it to the images. I want for example to say “Click on the rectangle” and when you click on the image it adds 1 point, and when you make a mistake, it subtracts. I have this.

PImage[] myImageArray = new PImage[4];

void setup() {

size(400, 600);

background(255);

myImageArray[0] = loadImage(“RECTAANGULO.png”);

myImageArray[1] = loadImage(“TRIAANGULO.png”);

myImageArray[2] = loadImage(“PENTAAGONO.png”);

myImageArray[3] = loadImage(“HEXAAGONO.png”);

noLoop();

}

void draw() {

image(myImageArray[(int)random(2)], 20, 220);

image(myImageArray[(int)random(2,4)], 200, 220);

}

void mousePressed() {

redraw();

}

Sorry, could explain the issue you’re having/ what you’re trying to do?

Yes, I’m trying to make an agility game with geometrical figures, so what I want to do is appear on the screen for example, “Click on the rectangle”, and then you have two options, a rectangle and a square for example (but all this randomly, without following an order), then click on the rectangle and give you 1 point, and if you click on the square that you subtract.

Missatge de Hedgy processingfoundation1@discoursemail.com del dia ds., 1 de set. 2018 a les 0:00:

Right, for the detection of whether you pressed the square or rectangle, Id have an if statement in the mousePressed() function.

public mousePressed() {
  if((mouseX > squareX) && (mouseY > squareY) && (mouseX < squareX+width) && (mouseY < squareY+height)) {
  points++;
  } else {
  points--;
  }
}

Thank you very much for answering me, but I think I have not explained myself well.

Let’s see, until now I have achieved that when you click on an image, change the two randomly for the next question. The problem is that I do not know how to make appear a question related to the two figures that appear in a random way.

An example: The game tells me to click the rectangle, then I have an image of a square and another of a rectangle, click on the rectangle and add 1 point. Suddenly I jump to the next question with different figures (randomly).

That is what I want to achieve, that everything works in a random way and that it is related.

If you could help me, I would greatly appreciate it.

Missatge de Hedgy processingfoundation1@discoursemail.com del dia ds., 1 de set. 2018 a les 0:37:

What I want to do is like a Quiz, just changing the order of everything, so that the person who plays many times does not follow an order and know it by heart.

Missatge de Pedro Garcia pg9394086@gmail.com del dia ds., 1 de set. 2018 a les 0:59:

Ah yes, My bad. I recommend you to read up on this from the processing documentation: https://processing.org/reference/random_.html

Please format your code :blush:

It consist on these two steps:

  1. In your code editor (PDE, VS code, Eclipse, etc) ensure you execute the beautifier function. This function automatically indents your code. Auto-indenting makes your code easier to read and helps catching bugs due to mismatch parenthesis, for instance. In the PDE, you use the key combination: ctrl+t
  2. You copy and paste your code in the forum. Then you select the code and you hit the formatting button aka. the button with this symbol: </>

That’s it! Please notice you do not create a new post in case you need to format something you already posted. You can edit your post, copy the code to the PDE, indent the code properly there and then past it back here, format the code and >> save << the edits.

Extra info:

Formatting your code makes everybody’s life easier, your code looks much better plus it ensures your code integrity is not affected by the forum’s formatting (Do you know the forum processes markup code?) Please visit the sticky posts or the FAQ section/post to learn about this, other advantages and super powers you can get in this brand new forum.

Kf

There are two tutorials that you should check and it will help you getting started:

Objects / Processing.org

Collision Detection - Happy Coding

The second one will help you to manage detecting when the mouse clicked is inside an object, or at least, it will explain the most basic concepts needed for this task.

You also can freely explore available examples as they show core concepts common in many applications.

You are in the right track. With this information you should be able to generate the next layer of code.

Kf