Help with a Maze
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Help with a Maze
Hello, I'm currently trying to create a maze where you drag a ball to the finish line to go to the next card. I have a series of rectangles on top of one another for the path, and an image called "theBlue.png" in the background where I want an intersection of the ball being dragged and "theBlue.png" to reset the coordinates of the ball. Attached is an image of what it looks like.
Basically, what I'm trying to do is have an intersection of the red ball with the blue background image trigger a reset of the ball. I tried to do this with the mouseStillDown handler, but to no avail. Any ideas for what code could allow this to work?
Thanks! #firstpost!
Basically, what I'm trying to do is have an intersection of the red ball with the blue background image trigger a reset of the ball. I tried to do this with the mouseStillDown handler, but to no avail. Any ideas for what code could allow this to work?
Thanks! #firstpost!
Last edited by phebreze on Sun Jun 26, 2016 10:22 pm, edited 1 time in total.
Re: Help with a Maze
Hi.
Maybe think of this the other way. If the ball is not within the rect of any of your rectangle graphics, you detect that and destroy the computer. Trap the "mouseMove" message and loop through the several graphics, testing for "within".
Craig Newman
Maybe think of this the other way. If the ball is not within the rect of any of your rectangle graphics, you detect that and destroy the computer. Trap the "mouseMove" message and loop through the several graphics, testing for "within".
Craig Newman
Re: Help with a Maze
What would some example code for this look like? I'm not too familiar with LiveCode, sorry!dunbarx wrote:Hi.
Maybe think of this the other way. If the ball is not within the rect of any of your rectangle graphics, you detect that and destroy the computer. Trap the "mouseMove" message and loop through the several graphics, testing for "within".
Craig Newman
Re: Help with a Maze
Additionally, what do you mean by "trapping" the "mouseMove" command and "looping through the several graphics?"dunbarx wrote:Hi.
Maybe think of this the other way. If the ball is not within the rect of any of your rectangle graphics, you detect that and destroy the computer. Trap the "mouseMove" message and loop through the several graphics, testing for "within".
Craig Newman
Re: Help with a Maze
Hmmm. you need to learn the basics of LC.
That said, do this. Make a button and a field on a new card. Now make a freehand graphic that mimics a maze. Please practice and learn how to draw such a thing. You can make it simpler than your current maze, just as long as it contains just a few twists and turns. Put this into the card script:
Hold down the optionKey (why is that there at all?) and see what that button is up to.
Now look up all of these messages and functions. Try to see what each line does (there are only three, you know) and write me back with what you learn, discover and are thrilled about.
Craig
That said, do this. Make a button and a field on a new card. Now make a freehand graphic that mimics a maze. Please practice and learn how to draw such a thing. You can make it simpler than your current maze, just as long as it contains just a few twists and turns. Put this into the card script:
Code: Select all
on mouseMove
put "" into fld 1
if the optionKey is down then set the loc of btn 1 to the mouseLoc
if intersect(grc 1,btn 1,255) then put "Crash" into fld 1
end mouseMove
Now look up all of these messages and functions. Try to see what each line does (there are only three, you know) and write me back with what you learn, discover and are thrilled about.
Craig
Re: Help with a Maze
Well, funny thing is, this is part of a large final project for the summer course I'm taking on LiveCode. I just wasn't quite sure what to do in this situation and was a little bit confused by the wording.dunbarx wrote:Hmmm. you need to learn the basics of LC.
That said, do this. Make a button and a field on a new card. Now make a freehand graphic that mimics a maze. Please practice and learn how to draw such a thing. You can make it simpler than your current maze, just as long as it contains just a few twists and turns. Put this into the card script:Hold down the optionKey (why is that there at all?) and see what that button is up to.Code: Select all
on mouseMove put "" into fld 1 if the optionKey is down then set the loc of btn 1 to the mouseLoc if intersect(grc 1,btn 1,255) then put "Crash" into fld 1 end mouseMove
Now look up all of these messages and functions. Try to see what each line does (there are only three, you know) and write me back with what you learn, discover and are thrilled about.
Craig
When I executed the code, holding down the alt key brought the button to the location of my cursor, and an intersection of the button and the cursor filled the field with "Crash."
Line one dealt with clearing the field on mouseMove.
Line two dealt with bringing the button to the cursor while the alt key is held down.
Line three dealt with detecting the collision.
I got that. I'm just confused as to how I could implement this into the maze. Also, what's 255?
EDIT: I put some code into the card script that seemed to work as long as each rectangle had the same name. However, I couldn't find a way to do this without releasing the mouse. Here was the code:
Code: Select all
on mouseMove
if intersect(grc "theBall",grc "Rectangle") then
else
set the loc of grc "theBall" to 21,255
end if
end mouseMove
Re: Help with a Maze
You are among the only people who have ever taken be at my word and actually examined the code as I asked.
So can you see your way to making your maze with a single, though admittedly complex polyline? It will take just a little patience. But the advantage is enormous, in that only a single control is present, instead of that suite of rectangles you had. This means that only a single pair of controls need be tested for intersection.
If you had done it with all those rectangles, you would have had to (pseudo):
The "255" is what you were supposed to learn about when you read ALL of the dictionary entry for the native function "intersect". Get going. If you are industrious, lose that parameter entirely in my handler, and see what happens.
The pseudo "resetBall" is just whatever you want to do when you get a collision. Might it be something like "set the loc of grc "ball" to startingLoc"?
Craig
So can you see your way to making your maze with a single, though admittedly complex polyline? It will take just a little patience. But the advantage is enormous, in that only a single control is present, instead of that suite of rectangles you had. This means that only a single pair of controls need be tested for intersection.
If you had done it with all those rectangles, you would have had to (pseudo):
Code: Select all
rrepeat with y = 1 to the number of graphics
if intersect("ball",grc y,"255") then resetBall
end repeat
The pseudo "resetBall" is just whatever you want to do when you get a collision. Might it be something like "set the loc of grc "ball" to startingLoc"?
Craig
Re: Help with a Maze
Hmm. Whenever I execute that code, my program stops responding.dunbarx wrote:You are among the only people who have ever taken be at my word and actually examined the code as I asked.
So can you see your way to making your maze with a single, though admittedly complex polyline? It will take just a little patience. But the advantage is enormous, in that only a single control is present, instead of that suite of rectangles you had. This means that only a single pair of controls need be tested for intersection.
If you had done it with all those rectangles, you would have had to (pseudo):The "255" is what you were supposed to learn about when you read ALL of the dictionary entry for the native function "intersect". Get going. If you are industrious, lose that parameter entirely in my handler, and see what happens.Code: Select all
rrepeat with y = 1 to the number of graphics if intersect("ball",grc y,"255") then resetBall end repeat
The pseudo "resetBall" is just whatever you want to do when you get a collision. Might it be something like "set the loc of grc "ball" to startingLoc"?
Craig
EDIT: The line that I made has a box around it, and even if the ball goes off of the line, it's still in this "box," so the new code won't execute. What can I do to get around this?
Re: Help with a Maze
Execute the "rrepeat" loop? With that extra "R"? (typo).
That was only to show you what you might have to go through if you did not make the maze from a single graphic polyLine. It was "pseudo" after all, though a little sloppy, I admit. I think the compiler would have been justified in throwing an error.
I want you to do this with one polyline, Do you have any issues with that? You may, and please enumerate them. My point is one of simplified coding, not structural issues with your project. Let me know...
Craig
That was only to show you what you might have to go through if you did not make the maze from a single graphic polyLine. It was "pseudo" after all, though a little sloppy, I admit. I think the compiler would have been justified in throwing an error.
I want you to do this with one polyline, Do you have any issues with that? You may, and please enumerate them. My point is one of simplified coding, not structural issues with your project. Let me know...
Craig
Re: Help with a Maze
dunbarx wrote:Execute the "rrepeat" loop? With that extra "R"? (typo).
That was only to show you what you might have to go through if you did not make the maze from a single graphic polyLine. It was "pseudo" after all, though a little sloppy, I admit. I think the compiler would have been justified in throwing an error.
I want you to do this with one polyline, Do you have any issues with that? You may, and please enumerate them. My point is one of simplified coding, not structural issues with your project. Let me know...
Craig
I'm saying that the line I made has a box around it, and even when the ball isn't on the line, if it is still in that box, then it registers as still being on the line. Am I constructing the line wrong?
Also, I put the code in without the typo and adjusted everything to the names of my objects.
-
- Livecode Opensource Backer
- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Re: Help with a Maze
Have fun!
- Attachments
-
- maze.livecode.zip
- Here's the stack
- (48.75 KiB) Downloaded 154 times
Re: Help with a Maze
Hey, thanks for this! I hope you don't mind, but I rewrote the code from the ground up how I would write it because this is my final project, but this helped me understand this much better! I think the arrowKey handler was the way to go on this. Thank you!richmond62 wrote:Have fun!
-
- Livecode Opensource Backer
- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Re: Help with a Maze
You're more than welcome 
It would be both fun and informative of you could post your rejigged version here.
Here's my take:
https://www.dropbox.com/s/nbf70thqcamr2 ... e.zip?dl=0
You will see that this uses a graphic object in such a way that the 'crab' always faces in the right direction.

It would be both fun and informative of you could post your rejigged version here.
Here's my take:
https://www.dropbox.com/s/nbf70thqcamr2 ... e.zip?dl=0
You will see that this uses a graphic object in such a way that the 'crab' always faces in the right direction.