ANT maze
- richmond62
- Posts: 2910
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
Use INTERSECT in the CARD SCRIPT to let the computer know when the ANT hits the green target:
- -
Now you can SHOW the smiley face, and then HIDE it again:
-
- -
Now you can SHOW the smiley face, and then HIDE it again:
-
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 2910
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
Now you can use the button "HOME" to help you:
- -
- -
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 2910
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
Life, of course, would be much, much more fun if the ANT could turn round to face the direction it is travelling in the maze:
- -
So: here's a small stack to play with:
- -
You will find that it contains 4 images: "A1", "A2", "A3", and "A4"
and a graphic "ANT"
The CARD SCRIPT of this stack goes like this:
- -
So: here's a small stack to play with:
- -
You will find that it contains 4 images: "A1", "A2", "A3", and "A4"
and a graphic "ANT"
The CARD SCRIPT of this stack goes like this:
Code: Select all
on arrowKey FLECHE
if FLECHE is "Up" then
set the backGroundPattern of graphic "ANT" to the ID of image "A1"
end if
--
if FLECHE is "Down" then
set the backGroundPattern of graphic "ANT" to the ID of image "A3"
end if
--
if FLECHE is "Left" then
set the backGroundPattern of graphic "ANT" to the ID of image "A4"
end if
--
if FLECHE is "Right" then
set the backGroundPattern of graphic "ANT" to the ID of image "A2"
end if
--
end arrowKey
- Attachments
-
- TURNER.oxtstack.zip
- (5.89 KiB) Downloaded 25 times
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 2910
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
This version of the Ant maze stack contains a graphic "ANT".
You will need to modify the CARD SCRIPT to take into account that the image "ANT" has been replaced with a graphic "ANT", and to set the backGroundPattern of the graphic "ANT" so that it shows an image of an ANT facing in the correct position:
- -
I have made the BORDER of the graphic "ANT" visible so you can see where it is: but when you have set its backGroundPattern[/b] that will no longer be necessary.
You will need to modify the CARD SCRIPT to take into account that the image "ANT" has been replaced with a graphic "ANT", and to set the backGroundPattern of the graphic "ANT" so that it shows an image of an ANT facing in the correct position:
- -
I have made the BORDER of the graphic "ANT" visible so you can see where it is: but when you have set its backGroundPattern[/b] that will no longer be necessary.
- Attachments
-
- ANT_2_5.oxtstack.zip
- (225.78 KiB) Downloaded 24 times
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 2910
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
This is the FINISHED Ant maze: if you have followed through the work (rather than "cheating" by downloading the stacks BEFORE doing the work), you should have a basic grounding in aspects of animation in OXT:
-
-
- Attachments
-
- ANT_2_6.oxtstack.zip
- (225.95 KiB) Downloaded 27 times
https://richmondmathewson.owlstown.net/
- tperry2x
- Posts: 1690
- Joined: Tue Dec 21, 2021 9:10 pm
- Location: Britain (Previously known as Great Britain)
- Contact:
Re: ANT maze
Can the maze be randomly generated?
Can a CPU controlled enemy (an ant-eater) be added?
Can a CPU controlled enemy (an ant-eater) be added?
- richmond62
- Posts: 2910
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
This is a 'reception class' thing, and the maze is nothing more than a PNG image (Papua New Guinea).
And, as 'that' it should sit as 'that'.
Should you wish to clone the stack, post it in a different thread (!), concoct a routine to generate a random maze, by all means do that.
And, as 'that' it should sit as 'that'.
Should you wish to clone the stack, post it in a different thread (!), concoct a routine to generate a random maze, by all means do that.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 2910
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
Of course, and my next 'class' will contain that sort of thing; but NOT here.Can a CPU controlled enemy (an ant-eater) be added?
https://richmondmathewson.owlstown.net/
-
- Posts: 285
- Joined: Thu Sep 16, 2021 1:40 pm
- Contact:
Re: ANT maze
That's pretty cool, it still ignores some walls. I don't know if I trust that intersect command,
I figured it out!
I moved the ant much slower per frame, like extremely slow, but ant paced-ish
I SET the location of the ant back from a hit wall 2 pixels before moving to rebound position
I' halved the rebound position so it centered in the tunnel and didn't hit the wall behind it.
I keep track of the hit wall with a global bHitWall boolean
I keep track of the key that was down when we hit the wall with global gLastArrowKey
If still holding a key or repeatedly pressing a key after hit a wall in that direction, then key presses will be ignored!
I also used the "pixels" threshold of the intersect command.
Works great, until I increased the ant speed (pixels per turn), then it started walking over walls again.
I'm pretty sure there's a pile of arrow key commands up in the buffer when I'm done with the maze.
I figured it out!
I moved the ant much slower per frame, like extremely slow, but ant paced-ish
I SET the location of the ant back from a hit wall 2 pixels before moving to rebound position
I' halved the rebound position so it centered in the tunnel and didn't hit the wall behind it.
I keep track of the hit wall with a global bHitWall boolean
I keep track of the key that was down when we hit the wall with global gLastArrowKey
If still holding a key or repeatedly pressing a key after hit a wall in that direction, then key presses will be ignored!
I also used the "pixels" threshold of the intersect command.
Works great, until I increased the ant speed (pixels per turn), then it started walking over walls again.
I'm pretty sure there's a pile of arrow key commands up in the buffer when I'm done with the maze.
- richmond62
- Posts: 2910
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
The arrow keys are far from satisfactory (in fact in the beasties thread you have already got the jump on me), and using 'WASD' is far better.
Unfortunately OXT cannot trap an 'up' and a 'down' signal from an arrow key.
If, for the sake of argument, we use the 'w' key for sending a sprite UP the screen we can write something like this:
The advantage of using 'keyUp' rather than 'keyDown' is that it prevents the sort of activity where, by keeping the 'up' arrowkey depressed we can force a sprite to over ride an INTERSECT check.
Unfortunately OXT cannot trap an 'up' and a 'down' signal from an arrow key.
If, for the sake of argument, we use the 'w' key for sending a sprite UP the screen we can write something like this:
Code: Select all
on keyUp KUP
if KUP = "w" then
-- do something
end if
end keyUp
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 2910
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
Here's an illustration how to move something using keyboard keys:
- -
it ALSO uses a SWITCH statement in the CARD SCRIPT as this is easier to understand than lots of IF . . . THEN loops:
I have used these keys:
- -
because having 8 directional keys near to W,A,S,D is not very easy.
The 'HOME' button will return the Beetle to the middle of the stack.
- -
it ALSO uses a SWITCH statement in the CARD SCRIPT as this is easier to understand than lots of IF . . . THEN loops:
Code: Select all
on keyUp KUP
put item 1 of the location of image "BEETLE" into HORIZONTAL_LOCATION
put item 2 of the location of image "BEETLE" into VERTICAL_LOCATION
switch KUP
case "Y"
put (VERTICAL_LOCATION - 50) into VERTICAL_LOCATION
break
case "B"
put (VERTICAL_LOCATION + 50) into VERTICAL_LOCATION
break
case "G"
put (HORIZONTAL_LOCATION - 50) into HORIZONTAL_LOCATION
break
case "H"
put (HORIZONTAL_LOCATION + 50) into HORIZONTAL_LOCATION
break
case "T"
put (HORIZONTAL_LOCATION - 50) into HORIZONTAL_LOCATION
put (VERTICAL_LOCATION - 50) into VERTICAL_LOCATION
break
case "N"
put (HORIZONTAL_LOCATION + 50) into HORIZONTAL_LOCATION
put (VERTICAL_LOCATION + 50) into VERTICAL_LOCATION
break
case "U"
put (HORIZONTAL_LOCATION + 50) into HORIZONTAL_LOCATION
put (VERTICAL_LOCATION - 50) into VERTICAL_LOCATION
break
case "V"
put (HORIZONTAL_LOCATION - 50) into HORIZONTAL_LOCATION
put (VERTICAL_LOCATION + 50) into VERTICAL_LOCATION
break
end switch
move image "BEETLE" to HORIZONTAL_LOCATION, VERTICAL_LOCATION
end keyUp
- -
because having 8 directional keys near to W,A,S,D is not very easy.
The 'HOME' button will return the Beetle to the middle of the stack.
- Attachments
-
- Key Mover.oxtstack.zip
- (20.64 KiB) Downloaded 28 times
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 2910
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
Here is an improved version that illustrates 2 points:
1. The use of backGroundPattern in a graphic rectangle.
2. The requirement to set the dimensions (width & height) of a graphic to fit the backGroundPattern (to avoid tiling).
- - -
The following image illustrates tiling of a backGroundPattern if the dimensions of a graphic are not set to fit the backGroundPattern images:
-
1. The use of backGroundPattern in a graphic rectangle.
2. The requirement to set the dimensions (width & height) of a graphic to fit the backGroundPattern (to avoid tiling).
- - -
The following image illustrates tiling of a backGroundPattern if the dimensions of a graphic are not set to fit the backGroundPattern images:
-
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 2910
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: ANT maze
And here is that stack.
The 8 beetle images are stored off-screen (you can see them if you set the width of the stack to 1400).
The 8 beetle images are stored off-screen (you can see them if you set the width of the stack to 1400).
- Attachments
-
- Key Mover_2.oxtstack.zip
- (70.05 KiB) Downloaded 24 times
https://richmondmathewson.owlstown.net/
Who is online
Users browsing this forum: No registered users and 4 guests