ANT maze

A forum to share your demonstrations stacks, fun stacks, games, etc.
User avatar
richmond62
Posts: 2848
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ANT maze

Post by richmond62 »

Use INTERSECT in the CARD SCRIPT to let the computer know when the ANT hits the green target:
-
target_1.png
target_1.png (33.4 KiB) Viewed 176 times
-
Now you can SHOW the smiley face, and then HIDE it again:
-
Screenshot 2024-02-13 at 16.40.21.png
Screenshot 2024-02-13 at 16.40.21.png (45.19 KiB) Viewed 174 times
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 2848
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ANT maze

Post by richmond62 »

Now you can use the button "HOME" to help you:
-
Screenshot 2024-02-13 at 16.42.32.png
Screenshot 2024-02-13 at 16.42.32.png (27.45 KiB) Viewed 173 times
-
Screenshot 2024-02-13 at 16.43.18.png
Screenshot 2024-02-13 at 16.43.18.png (43.92 KiB) Viewed 172 times
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 2848
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ANT maze

Post by richmond62 »

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:
-
Screenshot 2024-02-13 at 16.49.45.png
Screenshot 2024-02-13 at 16.49.45.png (32.54 KiB) Viewed 171 times
-
So: here's a small stack to play with:
-
Screenshot 2024-02-13 at 16.53.17.png
Screenshot 2024-02-13 at 16.53.17.png (36.54 KiB) Viewed 169 times
-
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 21 times
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 2848
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ANT maze

Post by richmond62 »

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:
-
Screenshot 2024-02-13 at 17.06.15.png
Screenshot 2024-02-13 at 17.06.15.png (245.25 KiB) Viewed 165 times
-
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 19 times
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 2848
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ANT maze

Post by richmond62 »

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:
-
Screenshot 2024-02-13 at 17.15.49.png
Screenshot 2024-02-13 at 17.15.49.png (246.64 KiB) Viewed 163 times
Attachments
ANT_2_6.oxtstack.zip
(225.95 KiB) Downloaded 23 times
https://richmondmathewson.owlstown.net/
User avatar
tperry2x
Posts: 1607
Joined: Tue Dec 21, 2021 9:10 pm
Location: Britain (Previously known as Great Britain)
Contact:

Re: ANT maze

Post by tperry2x »

Can the maze be randomly generated?
Can a CPU controlled enemy (an ant-eater) be added?
User avatar
richmond62
Posts: 2848
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ANT maze

Post by richmond62 »

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. 8-)
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 2848
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ANT maze

Post by richmond62 »

Can a CPU controlled enemy (an ant-eater) be added?
Of course, and my next 'class' will contain that sort of thing; but NOT here.
https://richmondmathewson.owlstown.net/
xAction
Posts: 285
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Re: ANT maze

Post by xAction »

That's pretty cool, it still ignores some walls. I don't know if I trust that intersect command,
I figured it out!
ANT_02_15_2024_xActionUpdates.livecode
(238.34 KiB) Downloaded 22 times
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.
User avatar
richmond62
Posts: 2848
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ANT maze

Post by richmond62 »

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:

Code: Select all

on keyUp KUP
if KUP = "w" then
  -- do something
  end if
  end keyUp
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.
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 2848
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ANT maze

Post by richmond62 »

Here's an illustration how to move something using keyboard keys:
-
SShot 2024-02-16 at 14.55.09.png
SShot 2024-02-16 at 14.55.09.png (66.42 KiB) Viewed 133 times
-
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
I have used these keys:
-
keyMOVES.png
keyMOVES.png (13.09 KiB) Viewed 131 times
-
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 21 times
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 2848
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ANT maze

Post by richmond62 »

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).
-
Screenshot 2024-02-18 at 18.06.23.png
Screenshot 2024-02-18 at 18.06.23.png (312.39 KiB) Viewed 90 times
-
Screenshot 2024-02-18 at 18.12.20.png
Screenshot 2024-02-18 at 18.12.20.png (56.94 KiB) Viewed 88 times
-
The following image illustrates tiling of a backGroundPattern if the dimensions of a graphic are not set to fit the backGroundPattern images:
-
Screenshot 2024-02-18 at 18.13.19.png
Screenshot 2024-02-18 at 18.13.19.png (144.56 KiB) Viewed 87 times
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 2848
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ANT maze

Post by richmond62 »

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).
Attachments
Key Mover_2.oxtstack.zip
(70.05 KiB) Downloaded 20 times
https://richmondmathewson.owlstown.net/
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests