Page 1 of 1

Bored Games

Posted: Wed Apr 08, 2020 7:25 am
by richmond62
Yes, I did mean to spell "bored" in that way. 8)
-
dt.png
-
Script in "pawn":

Code: Select all

on mouseDown
   grab me
end mouseDown

on mouseUp
   put 1 into TARGE
   repeat until TARGE > 16
      put ("t" & TARGE) into DEST
      if  not within (img DEST, the mouseLoc) then
         -- do nix
         else
         set the loc of img "pawn" to the loc of img DEST
      end if
      add 1 to TARGE
   end repeat
end mouseUp

Re: Bored Games

Posted: Wed Apr 08, 2020 8:33 am
by richmond62
dt2.png

Re: Bored Games

Posted: Wed Apr 08, 2020 9:29 am
by richmond62
dt3.png
-

Code: Select all

on mouseDown
   grab me
end mouseDown

on mouseUp
   put 1 into TARGE
   repeat until TARGE > 16
      put ("t" & TARGE) into DEST
      if  not within (img DEST, the mouseLoc) then
         -- do nix
      else
         set the loc of img "pawn" to the loc of img DEST
         put the loc of img DEST into LOQ --XXX--
      end if
      add 1 to TARGE
   end repeat
   if the loc of img "pawn2" is LOQ then --XXX--
      put random(16) into RNX
      put ("t" & RNX) into TRGT
      set the loc of img "pawn2" to the loc of img TRGT
      end if --XXX--
end mouseUp
Changes in code are marked with "--XXX--"

Re: Bored Games

Posted: Wed Apr 08, 2020 3:21 pm
by RogGuay
Thank you, Richmond. That's pretty much what I've done as well except I used intersect instead of within. Is there good reason to choose one over the other in this instance?

Roger

Re: Bored Games

Posted: Wed Apr 08, 2020 3:25 pm
by bogs
If you mean where you want the graphic to sit inside one of the squares of the board, then yes, within the rect would be the best choice.

Intersect just tells you if any part of one is crossing a line of the other.

Re: Bored Games

Posted: Wed Apr 08, 2020 4:16 pm
by mrcoollion
Great tutorial :D

Re: Bored Games

Posted: Wed Apr 08, 2020 6:16 pm
by RogGuay
Well, intersect seems to work quite well in my chess game, so what gives?? here's my script:

on determineSquare
repeat with j = 1 to 64
if the intersect(the target, grc j of grp ChessboardArray) then
set the loc of the target to the loc of grc j of grp chessboardArray
put the short name of grc j of grp chessboardArray
end if
end repeat
end determineSquare

Roger

Re: Bored Games

Posted: Wed Apr 08, 2020 6:30 pm
by richmond62
If you drop [i.e. mouseUp] your chess piece in a position where it intersects with 4 squares, how are you going to work out
on which of those 4 squares it is going to end up?
-
board.png
board.png (16.09 KiB) Viewed 9686 times

Re: Bored Games

Posted: Wed Apr 08, 2020 7:58 pm
by RogGuay
I'm not going to drop it on a corner. I'm going to drop it mostly in one square or another....it's working flawlessly!!

Re: Bored Games

Posted: Wed Apr 08, 2020 8:02 pm
by bogs
It doesn't even have to get as complicated as 4 squares, 2 would have been sufficient heh. If your halfway between 1 and the other, your intersecting both, which loc does your piece go to?

The main difference is, as I said before, 'within rect' makes sure you don't have to worry about it. You personally aren't going to drop it halfway, but I guarantee if you have enough testers, or worse, end users, one of them will just to mess with you.

Re: Bored Games

Posted: Wed Apr 08, 2020 8:18 pm
by richmond62
Roger . . .

. . . remember the useful 'fact' that at least 50% of people are stupid (i.e. the other side of the IQ bell curve to Thee and Me) . . .

Now, knowing this, and the fact that I [if you really want to believe what is fairly tendentious crap] have an IQ of 142, I always plan
for the chap (or chappess) who has an IQ of 58 . . .

Re: Bored Games

Posted: Wed Apr 08, 2020 8:30 pm
by RogGuay
I understand what you and Bogs are saying and I'm not against using "within" instead of "intersect", but my script is really working quite well...at least the chess game is working the way I think it should work. Nevertheless, I'll give "within" a try and see if I like it better.

Thanks,
Roger

Re: Bored Games

Posted: Wed Apr 08, 2020 8:36 pm
by RogGuay
I concede!! What I failed to notice was that you all were using the mouseLoc "within" a square which is clearly better, and I like it better!

Thanks for your help!

Roger

Re: Bored Games

Posted: Wed Apr 08, 2020 8:44 pm
by bogs
RogGuay wrote:
Wed Apr 08, 2020 8:36 pm
I concede!!
Wow, Richmond, I've seen some pretty quick conversions in my time, but I think you took the cake with Roger there :twisted:

Re: Bored Games

Posted: Thu Apr 09, 2020 12:36 am
by RogGuay
Bogs, you deserve equal credit.