ANT maze
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
ANT maze
This is a way to learn how to move objects round the screen by making a maze game.
We will start with a stack that looks like this, but contains no code:
- -
To follow along please download the attached stack and open it in OpenXTalk.
We will start with a stack that looks like this, but contains no code:
- -
To follow along please download the attached stack and open it in OpenXTalk.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
Once you have downloaded the zipped OXT file, unzipped it, and opened it in OXT, Please have a look at it and you should see these things:
- -
The image "ANT" is the picture we are going to move around the screen.
The graphic "RR" is a sort of fence to make sure the image "ANT" does not go somewhere we don't want it to.
-
RIGHT-CLICK on the image "ANT" and see that it is LOCATED at 400,300:
-
- -
The image "ANT" is the picture we are going to move around the screen.
The graphic "RR" is a sort of fence to make sure the image "ANT" does not go somewhere we don't want it to.
-
RIGHT-CLICK on the image "ANT" and see that it is LOCATED at 400,300:
-
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
The FIRST thing we are going to do is make a BUTTON to be able to make the image "ANT" return to its 'Home' at location 400,300 in case we lose it.
On the Tools palette click to select a button:
- -
And DRAG it onto your stack:
- -
RIGHT-CLICK on your new button and change its name to "HOME":
- -
SAVE the stack!
On the Tools palette click to select a button:
- -
And DRAG it onto your stack:
- -
RIGHT-CLICK on your new button and change its name to "HOME":
- -
SAVE the stack!
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
Make another button in exactly the same way and change its name to "AWAY":
- -
SAVE your stack.
- -
SAVE your stack.
- Attachments
-
- ANT_1_2.oxtstack.zip
- (40.44 KiB) Downloaded 75 times
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
Now: RIGHT-CLICK on the button "AWAY" to open the SCRIPT EDITOR:
- -
Now the SCRIPT EDITOR for your button will open:
- -
and type this SCRIPT into the SCRIPT EDITOR:
-
-
- -
Now the SCRIPT EDITOR for your button will open:
- -
and type this SCRIPT into the SCRIPT EDITOR:
Code: Select all
on mouseUp
move image "ANT" to 40,40
end mouseUp
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
Click on the APPLY button:
- -
CLOSE the SCRIPT EDITOR.
SAVE your stack.
-
Now, when you CLICK on the button "AWAY" the image "ANT" should MOVE like this:
-
- -
CLOSE the SCRIPT EDITOR.
SAVE your stack.
-
Now, when you CLICK on the button "AWAY" the image "ANT" should MOVE like this:
-
- Attachments
-
- ANT_1_3.oxtstack.zip
- (40.57 KiB) Downloaded 77 times
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
Now it is time for you to do something by yourself: You need to write a SCRIPT in the "HOME" button to return the image "ANT" to 400,300:
-
-
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
An important thing you need to know is that points for LOCATION Up and Down the page start with 0 at the top:
- -
And points for LOCATION ACROSS the page start on the left.
- -
And points for LOCATION ACROSS the page start on the left.
- Attachments
-
- ANT_1_4.oxtstack.zip
- (40.62 KiB) Downloaded 72 times
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
NOW we want to be able to move the image "ANT" with the ARROW keys on our keyboard:
-
-
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
NOW we want to be able to move the image "ANT" with the ARROW keys on our keyboard:
- -
The ARROW keys have easy names:
- -
So that we DO NOT have to use BUTTONS we have to put the script for the ARROW keys into the scriptEDITOR of the CARD:
-
- -
The ARROW keys have easy names:
- -
So that we DO NOT have to use BUTTONS we have to put the script for the ARROW keys into the scriptEDITOR of the CARD:
-
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
The FIRST thing we have to do is find out the LOCATION of the image "ANT":
- -
Then we have to find out which of the ARROW keys has been pushed:
- -
You will see, that at the moment, the SCRIPT for each ARROW key is empty.
- -
Then we have to find out which of the ARROW keys has been pushed:
- -
You will see, that at the moment, the SCRIPT for each ARROW key is empty.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
I have decided to make each move of the image "ANT" 20 points (you can, for course, change this amount if you want to):
- -
Now have some fun pressing the ARROW keys and seeing what happens to the ANT.
If you are NOT careful the ANT will disappear OFF the OXT card.
You can always use the "HOME" button to bring it back again.
- -
Code: Select all
on arrowKey ARKEY
put the item 1 of the location of image "ANT" into HORIZONTAL_POSITION
put the item 2 of the location image "ANT" into VERTICAL_POSITION
put VERTICAL_POSITION
------
If ARKEY is "Up" then
put (VERTICAL_POSITION - 20) into VERTICAL_POSITION
move image "ANT" to HORIZONTAL_POSITION, VERTICAL_POSITION
end if
------
If ARKEY is "Down" then
put (VERTICAL_POSITION + 20) into VERTICAL_POSITION
move image "ANT" to HORIZONTAL_POSITION, VERTICAL_POSITION
end if
------
If ARKEY is "Left" then
put (HORIZONTAL_POSITION - 20) into HORIZONTAL_POSITION
move image "ANT" to HORIZONTAL_POSITION, VERTICAL_POSITION
end if
------
If ARKEY is "Right" then
put (HORIZONTAL_POSITION + 20) into HORIZONTAL_POSITION
move image "ANT" to HORIZONTAL_POSITION, VERTICAL_POSITION
end if
end arrowKey
If you are NOT careful the ANT will disappear OFF the OXT card.
You can always use the "HOME" button to bring it back again.
- Attachments
-
- ANT_1_5.oxtstack.zip
- (40.88 KiB) Downloaded 73 times
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
The way we are going to make sure that our ANT does not get lost is by using INTERSECT.
The FIRST thing we have to is make sure our 'fence', the graphic "RR" is transparent:
- -
RIGHT CLICK on the graphic "RR" and select the Property Inspector:
- -
And make sure that 'Opaque' is unselected.
NOW we can edit out CARD SCRIPT so the ANT does NOT go outside the 'fence'.
The FIRST thing we have to is make sure our 'fence', the graphic "RR" is transparent:
- -
RIGHT CLICK on the graphic "RR" and select the Property Inspector:
- -
And make sure that 'Opaque' is unselected.
NOW we can edit out CARD SCRIPT so the ANT does NOT go outside the 'fence'.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
NOW we can edit out CARD SCRIPT so the ANT does NOT go outside the 'fence'.
- -
You can now edit the CARD SCRIPT for the other 3 ARROW keys.
The PROBLEM about this method is that the ANT gets stuck on the 'fence'.
- -
You can now edit the CARD SCRIPT for the other 3 ARROW keys.
The PROBLEM about this method is that the ANT gets stuck on the 'fence'.
- Attachments
-
- ANT_1_6.oxtstack.zip
- (40.99 KiB) Downloaded 82 times
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
One of the ways to make sure the ANT does NOT get stuck on the 'fence' is to make it 'bounce back' when it hits the 'fence':
-
-
- Attachments
-
- ANT_1_7.oxtstack.zip
- (41.21 KiB) Downloaded 79 times
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
Please make sure you are comfortable with the scripts and how they work, as, in PART 2 of this exercise we will be extending our work to make a full game where, using the ARROW Keys we can navigate an ANT through a Maze:
-
-
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
By changing the order of where the INTERSECT scripts go in the CARD SCRIPT it is possible to STOP the ANT from sitting on the 'fence';
- -
- -
- Attachments
-
- ANT_1_8.oxtstack.zip
- (41.16 KiB) Downloaded 71 times
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
The graphic "RR" has been replaced with an imported PNG image called "maze", so the CARD SCRIPT has to be adjusted to take that into account:
- -
You can see how the script has been adjusted for the 'Up' ARROW Key:
- -
You can write the scripts for the other 3 ARROW Keys.
You should also notice that I have set the "bounce" to 20 so that what happens is the ANT is returned to its starting position.
- -
You can see how the script has been adjusted for the 'Up' ARROW Key:
- -
You can write the scripts for the other 3 ARROW Keys.
You should also notice that I have set the "bounce" to 20 so that what happens is the ANT is returned to its starting position.
- Attachments
-
- ANT_2_1.oxtstack
- (52.81 KiB) Downloaded 70 times
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
Here is the stack with the completed CARD SCRIPT.
- Attachments
-
- ANT_2_2.oxtstack.zip
- (43.01 KiB) Downloaded 75 times
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 3896
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
Now we can introduce a target image and a signalling image that we have completed the Ant maze:
- -
When the ANT hits the Target the signalling image is shown.
Use INTERSECT in the CARD SCRIPT to let the computer know when the ANT hits the green target.
- -
When the ANT hits the Target the signalling image is shown.
Use INTERSECT in the CARD SCRIPT to let the computer know when the ANT hits the green target.
- Attachments
-
- ANT_2_3.oxtstack.zip
- (226.84 KiB) Downloaded 77 times
https://richmondmathewson.owlstown.net/
Who is online
Users browsing this forum: No registered users and 1 guest