Liquid Digital Lab

A Jungle Jumble Using Lists in Director

Posted 2 years, 11 months ago by Simon

In this tutorial I’d like to discuss the use of lists (as Director calls them) or arrays (as most other software packages call them) in simple puzzle games as a way of checking if a solution has been found. This particular game called ‘Animal Misfits’ had a few possible solutions, and using lists was the most obvious way to go.

Aimed at the younger age bracket (as you can probably tell), this game splits up 3 animal characters into head, body and legs sections and jumbles them up. The player can drag and drop the sections into the spaces on the screen and try to complete the characters. Once all three characters are put back together properly the game plays a tune and then jumbles them up again. There is a complication from a programming point of view in that the characters can be recompiled in different orders left to right, and all possible successful combinations have to be checked for.

How does it work?

Well, after a little intro sequence you can click on the screen to start the game.

Unsurprisingly, each piece is a separate sprite in Director’s score and as such can be identified with a sprite number. In my case, the sprite channels used range from 18 to 26. A frame script handles the bulk of the game, and the game part of the movie runs in a single frame.

The frame script compiles a variable called gGameList, which is actually a list of sprite numbers. Each item in the list represents a square on the grid on screen where a piece can be placed. There are 9 pieces (3 per animal) and there are 12 boxes on the grid, giving us 3 blank squares at anytime so the pieces can be moved out of the way in order to build up the animals - try the game and you’ll see why the 3 blank squares are needed!

So, gGameList is a list with 12 items, 3 of which will always be 0 (representing a blank square) and 9 of which will contain a unique number from 18 to 26, representing the sprite channel of the piece that’s been placed there.

The framescript runs code at the start of the game to populate the first 9 items in gGameList with numbers chosen randomly from 18 to 26, making sure no number is duplicated. First the list is created and populate with zero’s:

gGameList = []
repeat with a = 1 to 12
add gGameList,0
end repeat

and then a sequence is run to mix the animals up a bit, and also take note of the invisible sprites I’ve placed on the stage to indicate where the squares are:

pieceSprites = [] -- sp nos for init only
snapSprites = [] — sp nos for init only
repeat with a = 1 to 9
add pieceSprites,(a + 17) — adding 17 to a will give us a valid sprite number
end repeat
repeat with a = 1 to 12
add snapSprites, (a + 4)-adding 4 to a gives us valid sprite number
end repeat
– populate board
pFlag = FALSE
repeat while pFlag = FALSE
r = random (pieceSprites.count)
r2 = random (snapSprites.count)
if getAt (gameList,r2) <> 0 then
next repeat
else
setAt gameList,r2, (getAt (pieceSprites,r))
deleteAt piecesprites,r
if pieceSprites.count = 0 then
pFlag = TRUE
exit repeat
end if
end if
end repeat
end if

Then, when the sprites initialise they look at the global variable list and place themselves in the correct location on screen.

For non-director programmers, I’d better mention that Lingo uses 1 to refer to the first item in a list, not 0 as used in many other languages!

Using simple code for drag and drop, the pieces snap into position if dragged to an empty square, or snaps back to the starting point if dropped on a full square or not on a square at all. I’ve used code to decide if a drop is close enough to a square to be considered accurate enough or not, which basically checks if the mouse position when the piece is dropped is within the target square on the grid.

As a finishing touch, and partly for my own amusement, I’ve added sound effects of each creature on mouseUp when they’re dropped in a valid place, and a ’snap back’ sound when they zoom back to their starting position.

Now then, the point of this tutorial was how to use lists! So, the secret with this game is quite simply to predict the possible winning combinations, which I store in a global list when the game begins:

gWinningWays = [[21, 18, 24, 19, 22, 25, 20, 26, 23, 0, 0, 0],[18, 21, 24, 22, 19, 25, 26, 20, 23, 0, 0, 0],[18, 24, 21, 22, 25, 19, 26, 23, 20, 0, 0, 0],[21, 24, 18, 19, 25, 22, 20, 23, 26, 0, 0, 0],[24, 21, 18, 25, 19, 22, 23, 20, 26, 0, 0, 0],[24, 18, 21, 25, 22, 19, 23, 26, 20, 0, 0, 0]]

The list above show a list containing the 5 possible winning combinations, and also gives another insight into how the positions of each piece are referenced by the code. Each time a piece is dropped it uses sendsprite to tell the frame script where it is. The frame script then decides if it’s a valid position or not (it has analyzed the valid positions and stored them in, yes you’ve guessed it - another list) and tells the piece sprite whether to snap into position or jump back to the starting point.

After each movement of a piece, the frame script does a check to see if gGameList is equal to any of the possible solutions nested within gWinningWays. If it finds a match then it plays a quick flashing sequence, plays a victory tune and starts the game all over again.

Comments on 'A Jungle Jumble Using Lists in Director'


Hey - I remember my little brother playing this in smiths wen we went to spain a few years ago!

Kris - 8 May 2008

sounds like something a Liverpool supporter would come up with.not a Man u fan.

shaun - 22 July 2008

Yeah - thanks for that Shaun!!

admin - 27 July 2008

Leave a Comment

Three D Clock

Classic clock built in processing

Posted by Lloyd - Comments (0)

This Happened #5

Lloyd gets chance to go along to the 5th gathering of This Happened

Posted by Lloyd - Comments (0)

Tom survives in one piece!

Tom makes it back to the office through 19 peaks over 149 miles, 60 flood warnings, 60mph gusts and 48hours of torrential rain, all in the name of MS Society, Wheels4Life and a weekend to remember!

Posted by Tom - 3 Comments (3)

Liquid goes Coast to Coast

Inspired by his managers previous fundraising wetsuit exploits, our newest designer Tom will be tackling the coast to coast bike ride this September.

Posted by Tom - Comments (1)

Liquid Artwork

Have a look at the artwork we created for the front office

Posted by Lloyd - 3 Comments (3)

Decisions, decisions… A Bit More Game AI

Game AI goes a few steps forwards, and 2000 years into the past…

Posted by Simon - 3 Comments (3)

Ever Won The Lottery?

Winning The Big One!
I recently read somewhere that winning the UK national lottery is easy. All you have to do is …

Posted by Simon - Comments (1)

3DS Max - Basics and Blueprints

The start of a series of tutorials in 3ds max from Liquids latest addition to the creative team.

Posted by Lloyd - 9 Comments (9)

Sound Reactive Sketch

We created this experimental Music Visualiser in processing & minim sound library.

Posted by Lloyd - 2 Comments (2)

Pathfinding in Games - Using A* in Director

Discover the joys of the A* pathfinding algorithm in our retro Director maze

Posted by Simon - Comments (1)

Colour Clock Screensaver

We’ve made an animated clock screensaver. You can have it too.

Posted by Ben - 2 Comments (2)

Using the Flash Tween Class

Trying to create realistic bouncing balls or elastic objects in Flash? Ben Stevens shows us the easy way to code motion using the Flash Tween Class.

Posted by Ben - 6 Comments (6)

A Jungle Jumble Using Lists in Director

What do you get if you cross a monkey, an elephant and a giant chicken-thing? Simon Edwards tries to explain using lists in Director.

Posted by Simon - 3 Comments (3)

Lloyd Survives the 2007 London Triathlon

Liquid’s very own budding triathlete successfully completes the Michelob ULTRA London Triathlon in a time of 2 hours and 42 minutes. Find out how he got on.

Posted by Lloyd - Comments (1)

Simple AI in Director

Simon Edwards discusses some of the techniques that developers call upon when programming games, particularly for defining logic that the computer will use for taking a turn in a 2-player game scenario.

Posted by Simon - Comments (0)

Ruby on Rails Tutorial - An Online DVD Catalogue

John Cove takes us through the process of making an online catalogue using RoR.

Posted by John - Comments (0)

Why write an ActiveX control?

Howard Peters discusses the advantages of using ActiveX, and explains how to create your own simple ActiveX control.

Posted by Howard - Comments (0)

Nichola’s Placement Year

Nichola, our resident student placement, has now been with us for a whole year and will be leaving us soon. So we asked her what it’s been like to work with the Liquid team.

Posted by Nichola - Comments (0)

Kinetica Soundwaves Exhibition

Exhibition visit

Posted by Ben - Comments (0)

PHP Tutorial - Creating a Quiz

John Cove explains how to use HTML and PHP to create an online quiz.

Posted by John - Comments (0)

Director Tutorial - Vector Font Outlines

Simon Edwards demonstrates an undocumented Director feature enabling you to map out a string of text in a vector cast member.

Posted by Simon - Comments (0)

HDR Photography

HDR (High Dynamic Range), is a software based, photographic technique that extracts tonal information from multiple exposures of the same shot. If you exposure bracket the same shot, you can merge all 3 images into one, then, using the data from all 3, create one output file which preserves accurate details from all exposures, bringing out highlights from the shadows.

Posted by Darren - Comments (0)

Happy Birthday To Us!

Liquid Digital Ltd has reached the end of its first financial year. There’s no time for cake and a candle though - there are some big things on the horizon for the first quarter of Year 2. Watch this space for news soon.

Posted by Simon - Comments (0)

Director Tutorial - Counting Down To A Launch Date

Tutorial written by our resident Director Guru, Simon Edwards.

Posted by Simon - Comments (0)

Lloyd in a wetsuit

Our creative leader will be braving the elements by competing in the Michelbob ULTRA London Triathlon on 4th August 2007.

Posted by Ben - Comments (0)