Page 1 of 1

Two quick questions

Posted: Sun Jan 20, 2008 11:22 am
by Josh
The first is painfully easy. What characters do I insert to continue code onto the next line when a line gets too long? I think it's something with the backslash or forward slash, but I can't figure it out or find the answer in Dan's book (though I know it's in there somewhere).

Second, I have a large array of squares that I randomly reassign to new location with every ENTER keypress. I have the squares move with the move command. It works very well, but I need the squares to not overlap. How do I repeat the move code until there is no overlap? Is that possible?

Posted: Sun Jan 20, 2008 1:10 pm
by BvG
1. It's the backslash: \

2. You need to code that behaviour yourself. As you are using rectangles, you can use the intersect function to determine overlaps.

Yes, intersect

Posted: Mon Jan 21, 2008 4:33 am
by Josh
I've tried used that along inside of a repeat loop (e.g., repeat move until no collision) but the code makes it choke each time. I've gone back to the drawing board, but the code did look something like this:

repeat until (collision = false)
put random () into newlocX
put random() into newlocY
move rectangle of cd to newlocx,newlocy
if intersect (rectangle,rectangle) then (collision = true).

One problem I foresee even if I got Revolution to accept the code is that, with 15 rectangles on screen, collisions are inevitable en route. I don't care if rectangles pass through one another as long as their terminal location is a nonoverlapping one. Any additional thoughts? Do I need a background of 0's that turn to 1's with a rectangle overlap. Then, only permit a move if the terminal spot is all 0's? Would anyone know how to code that if that's my only option?

P.S., Thanks for the /, sheesh what a turkey I am!

Solved

Posted: Mon Jan 21, 2008 11:45 pm
by Josh
Hi,

Thanks for the help. I've figured it out. For public record, intersect is only concerned with the terminal location to begin with (good for me, additional difficulty for those hoping for "contact" in motion). I used a collision and grandcollision boolean to set it up.

collision and grandcollision became true if contact was made
collision set to false if contact not made
if grandcollision was false after all object moved, then repeat loop ends.