How to use Director to write "Puzzle Game"

zhaozj2021-02-16  61

How to use Director to write "Puzzle Game"

Today, many big companies in the world use Director to make their own multimedia teaching discs. This includes Microsoft, Apple, Adobe, etc. (although these companies are not multimedia production companies). Recently, Director and Quiktime VR technology also use Director and Quiktime VR technology in the "X Files Unrestricted Access" of Fox, IPA. More and more people who use Director abroad, more and more people, but also many people in China are engaged in Director's programming. Director has now become a factual standard for multimedia production tools. But compare, we are still at a lower level for Director. I have seen a lot of domestic multimedia companies, most of the interaction control is simple, nothing more than flashing buttons and images, clicking can enter other scenes, such as slideshow. It is estimated that countless GOTO XX statements are used, and a lot of two-dimensional animations that are filled with art. This type of disc is better than using PowerPoint to make (just a joke). There are many reasons, the most important thing is that our programmer is not well mastered in lingo language, which directly affects the idea of ​​creativity. If the programmer cannot achieve ideas with Director, many of the original idea will be revoked, so The application of programmers directly affects the final product advantage. This requires more Director programmers to fully grasp Lingo. I only throw the jade here, share the experience of using the Director making a game with many Director lovers.

Many people have played "puzzle game", I am very early to be a "puzzle game" fan,. First is playing Apple Computer (Macintosh) puzzle game Puzzle. Later, a very chance, I got an Apple version of Adobe Illustrator installation CD. Unexpected discovery has a puzzle game with a Vinaas avatar (this is the start screen of Illustrator), and finding that it is written in Director (Hong Kong aspects "and Liu Xiaohui's" a week "and a week of Liu Xiaihui also designed a puzzle. game). At that time I have started using Director to write multimedia demo (that is 1995), but lacks the master's high-level feature to lingo, often I have written a lot of functions, and the data structure such as list and objects Not used. In some cases, this programming is often multiplied. Three years ago, I used Director to write the first "puzzle game", this version fee for a long time (about a week), the program code is very long, and it is very chaotic. Later, I didn't understand myself. As I have increasingly understanding Lingo, I gradually discovered how stupidity did not use the list in previously written programs. A few days ago, I reused the new version of "Puzzle Game" with Director. Not only the original code is reduced (easier to understand), but only for two hours. Now we gradually analyze how to write "puzzle game" with Director.

The list of uses is the key to writing "Jigsaw Game", and it can be said that the list is more critical to the Lingo program. Because users who use LingO object-oriented functions should be less than users who use their traditional data structural functions (there are many users using Lingo objects abroad). The interface I have written "Puzzle" is shown below:

First, I made a puzzle of 16 BMP formats, each for each 100 * 100 pixel size. Represents 16 small puzzles in the above map, named 1.BMP, 2.BMP, 3.BMP, 4.BMP, 5.BMP, ... ... And import these 16 files into the Director. They are 1 to 16 characters in the role library. As shown below:

At the same time, we will arrange this 16 puzzles on the 1st to 16 channels, as shown below:

Now, we have to discuss the idea of ​​using Director to write "puzzle game". Online replacement role functions in LingO The MemberNum of Sprite is the most important function used to. When we click on the corresponding wizard channel through the mouse, the role of the clicked wizard is replaced with a single blank bitmap role in 16 puzzles. There are several difficulties in this to pay attention. First, this replacement is not arbitrary, only a puzzle that is vertical and horizontal in the blank can move. For example, see the figure below:

The spelling of the above-picture blank block only has a number of puzzles with 6, 9, 7, and 14 to move. Other puzzles will not be replaced with the blank when clicked. This requires a list of moving channels that can be created when blank blocks at different channels. Here is a global variable gempty, which is used to store the channel number of the role; second, each time the "puzzle game" is started, and this puzzle must be randomly arranged, and each pattern is different. This must establish a list of roles per channel; third, a judgment condition must be established, and the final player spells the pattern shown in the first figure, indicating that the player has successfully spelled the graphic. This requires a list of lists, namely the role library list in each channel in the final pattern, that is, list finish = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]. To compare with the final list Finish, when the current frame cycle, each time you exit the current frame to generate a list of roles of each channel; there is a little, the first time you need to enter the role of all channels according to the random list. Alternative, while entering the cycle frame in the next few cycles, it is not necessary, there is no need to determine whether the variable is required to determine if it is the first time entry cycle frame.

It looks very complicated, but actually doing it. It is not so troublesome. Relatively use other high-level languages ​​to write this program. Lingo requires you to use new ideas to consider programming. It makes you don't have to involve many programming details, while more considering how to solve the problem, and it is not a traditional scripting language.

First, we need to write several functions (or personal handles).

The first function is a function generateList that generates 16 random lists.

Its specific code is as follows:

On GenerateList

Global gempty, randomlist

Set randomlist = []

REPEAT WITH X = 1 to 16

Addat (Randomlist, Random (x), x)

End repeat

end

Because LingO does not provide a function of randomly arranged a list, this "LINGO!" A code in the Advanced Guide, which is very secluded with addat (), and the random () function generates a random list through the loop statement. It is randomly generates a list position in the loop and gives it a value in 1-16. When adding a value in the same location in the ADDAT () function, it will be pushed, and this special work mode will not Repeated phenomenon will occur.

The second function is also the most important function Exchange (). It has a parameter. This parameter is the channel number. When you click on a puzzle with blank vertical or horizontal, the role of the two should be changed, that is, the channel where the blank is located to change the role to the role of the clicked channel, and the clicked channel The role is changed to blank. The clicked channel number is given to the variable GemPty identifying the space where the blank is located. The variable x in the function is a temporary variable for replacing the data. ON Exchange N

Global Gempty

Set x to the membernum of sprite gempty

Set the membernum of sprite gempty to the membernum of sprite n

Set the membernum of sprite n to x

Updatestage

Set gempty = n

end

This function is used in channel 1-16 in each cycle, the usage is as follows:

ON Mouseup

IF inlist (1) THEN

EXCHANGE 1

PuppetSound "Click"

END IF

end

Here, another written function inList () is used, which is used to discriminate whether the currently clicked channel is in the removable list m, and if it is in the list m, returns TRUE.

The function inList () code is as follows:

On Inlist CNT

Set countnum = count (m)

Repeat with x = 1 to countnum

IF CNT = Getat (M, X) THEN

Return True

EXIT REPEAT

END IF

End repeat

end

Where m is the current mobile channel number list, first function using the count () function calculates the number of members in the list M, and imparts it to the variable countnum, the variable countnum is the termination variable of the loop detection. In the loop statement, it is determined whether the parameter CNT of InList () is in the list m. If there is, returns true and exits the loop.

Another function is Move (), which will return a list of current movable channels.

ON Move Sth

Return Getat (mlist, sth)

end

It returns a list of current movable puzzle channel numbers based on blank. Here I use a two-dimensional list mList = [M1, M2, M3, M4, M5, M6, M7, M8, M13, M14, M15, M16], wherein M1, M2, M3 , ... is a blank at 1, 2, 3, 4, 5, ..., movable channel number list. For example, as the first picture, when the blank is 16 channels, the channels can be moved 12 and 15, i.e., M16 = [12, 15]. All of these lists will be initialized in the on StartMovie event handle. The specific code is as follows:

On Startmovie

Global Gempty, Randomlist, First, finish, TMP, M1, M2, M3, M4, M5, M6, M7, M8, M9, M14, M11, M12, MLIST, M14, M15, M16, MLIST, M

SET M = []

SET TMP = []

Set finish = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]

Set m1 = [2,5]

Set m2 = [1, 3, 6]

SET M3 = [2, 4, 7]

SET M4 = [3, 8]

SET M5 = [1, 6, 9]

SET M6 = [2, 5, 7, 10]

SET M7 = [3, 6, 8, 11]

SET M8 = [4, 7, 12]

SET M9 = [5, 10, 13]

SET M10 = [6, 9, 11, 14]

SET M11 = [7, 10, 12, 15]

SET M12 = [8, 11, 16]

SET M13 = [9,14]

SET M14 = [10, 13, 15]

Set M15 = [11, 14, 16]

Set m16 = [12,15]

Set mlist = [M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13, M14, M15, M16]

Set first = 0

GenerateList

Set gempty = getone (randomlist, 16)

Repeat with i = 1 to 16

PuppetSprite I, True

End repeat

End Startmovie

There are a few things to do this: First, the list and many global variables are initialized. Where the FIRST variable gives a value of 0. When entering the cyclic frame for the first time, the role of each channel is required to generate the role of each channel according to the geneList function, to generate a random pattern that enters the game; secondly, use the getone () function Get the channel number where the 16th role (ie, blank role) in the global variable Randomlist is obtained;

I have already described all written functions, and the remaining step is the last and the most critical step. That is, these functions are called in the frame script of the cycle frame.

The specific frame scripts are as follows:

Global Gempty, Randomlist, First, finish, TMP, M1, M2, M3, M4, M5, M6, M7, M8, M9, M14, M11, M12, MLIST, M14, M15, M16, MLIST, M

ON Enterframe

If first = 0 THEN

Repeat with i = 1 to 16

PuppetSprite I, True

Set The Membernum of Sprite I to Getat (Randomlist, i)

End repeat

Set first = 1

END IF

IF finish = tmp

Go the frame 1

Else

SET TMP = []

END IF

SET M = Move (Gempty)

end

In entering the frame event handle on EnterFrame, first determine whether or not to enter the current loop frame in the first time, the determination condition is 0. If so, the role of the channel 1 - 16 is updated according to the value in the Randomlist list. After updating, the variable first assigns a value of 1. To avoid this operation next time. Then compare whether the final list Finish is the same between the Temporal TMP, if the same, the puzzle ends. Skip to the end frame. Otherwise continue in the current frame loop and assign the TMP list to avoid superposition of the TMP list due to the operation of the on exitframe. Finally, get a movable list M at the time of the current channel.

ON EXITFRAME

REPEAT WITH X = 1 to 16

Addat (TMP, THE MEMBERNUM OF SPRITE X)

End repeat

Go the frame

end

In Exit Frame Event Handle on EXITFRAME, generate the role temporary list TMP of the current channels by looping, and cycles with Go the frame in the current frame. All program code has been described. If you replace this 16 images into your favorite pictures, you can generate your own style puzzle game. With the above story, you will find that lingo programming is indeed different. Such a game can be written in a short period of time with such a simple code. Although this procedure is not complicated, it contains many Lingo skills.

转载请注明原文地址:https://www.9cbs.com/read-16008.html

New Post(0)