Button collide with Button

Started by Slasher, Sat 07/06/2014 15:32:56

Previous topic - Next topic

Slasher

Hi,

I am trying to implement an old game, well, quite old, into my latest game. It's where you have to move the hoop along a stretch of wire with out it touching, it will buzz if you do touch it. I don't recall the name of this game.

Anyhow, I am using a gui with buttons. Now, I can't use PPC or Overlapping as they do not support buttons.

It's a kind of 'if buttons collide' issue.

I have a button as the Hoop with 2 buttons: 1 at the top of the hoop and 1 at the bottom using Rep exec always x y to button Hoop. These 2 buttons should not touch the button line.

If you catch my drift, are you able to assist me with bringing this idea to life?

Failing a possibly solution would objects be the best course of action instead?

I'm a little limp brained at the moment ;)

slasher



Khris

This should do the trick:
Code: ags
bool ButtonsOverlap(Button *a, Button *b) {
  int ax1 = a.OwningGUI.X + a.X;
  int ax2 = ax1 + a.Width - 1;
  int ay1 = a.OwningGUI.Y + a.Y;
  int ay2 = ay1 + a.Height - 1;
  int bx1 = b.OwningGUI.X + b.X;
  int bx2 = bx1 + b.Width - 1;
  int by1 = b.OwningGUI.Y + b.Y;
  int by2 = by1 + b.Height - 1;
  if (ax2 < bx1) return false;
  if (ax1 > bx2) return false;
  if (ay2 < by1) return false;
  if (ay1 > by2) return false;
  return true;
}

This performs a rectangular overlap check of two buttons, regardless of what GUI they are part of.

SMF spam blocked by CleanTalk