Help with code board gui

Started by Racoon, Mon 19/06/2023 16:27:52

Previous topic - Next topic

Racoon

Hey guys, i hope you are doing well.

I am stuck with trying to find an idea to make a code board gui work without too much effort.

It looks kind of like this:



It has 72 Buttons.

Now the idea is, that there is a pattern, that the player has to push. When the right buttons are pushed they turn green, when a wrong button is pushed it turns red and you have to start over. My problem is, that making this option for each button on its own is very time consuming and I thought maybe someone can help me with finding a quicker way to do it, if there is one.

Matti

Using the ID of the buttons should simplify this a lot.

The idea is that you code this somewhere else than in the button's events, and the pattern should just reflect the ID numbers.

I don't have the time right now to go more into it or to provide code..

Khris

Make it a single button, then use the coordinates to figure out which square was clicked.

Code: ags
function btnGrid_OnClick(GUIControl* control, MouseButton button) {
  if (button != eMouseLeft) return;
  int x = mouse.x - control.OwningGUI.X - control.X;
  int y = mouse.y - control.OwningGUI.Y - control.Y;

  int border = 5;
  int size = 10;
  int gap = 3;
  int columns = 9;

  int col = (x - border - gap / 2) / (size + gap);
  int row = (y - border - gap / 2) / (size + gap);
  int n = row * columns + col;
  // check n against next id in sequence, ...
}

SMF spam blocked by CleanTalk