Flash calls Lua Script: 5

Source: Internet
Author: User
Tags radar

Flash calls Lua Script: 1

Flash calls Lua Script: 2 

Flash calls Lua Script: 3

Flash calls Lua Script: 4

With the accumulation of the previous chapters, we can now show you the complete project.

This is a platform game interface

Next let's take a look at how the script is written:

Specific can see the complete demonstration here: http://rc.qzone.qq.com/100641772

This robot AI simulation engine. Use flash as the host and Lua as the script. Different from the general practice: Using Script Programming to design AI intelligence allows robots to act independently. This is an interesting programming platform, using a few simple linesCodeTo create a living robot.
(1) You can learn the Lua language in an intuitive way, without the trouble of installing and configuring the environment. Opening the output window is a Lua editor, I also learned how scripts work in the game.
(2) friends interested in learning about game production. You can use such an application to learn about the secrets of game programming and how robots follow the laws of physics to trigger and handle collision events, and launch missiles...
(3) All friends who are interested in AI, this is an intuitive AI simulation platform. They can observe the autonomous actions of an AI object, or create multiple robots for PK, or collaboration, or even a cool ant colony simulation.

Create a robot: Enter the following statement:

Local robot = robomanager. createrobot ("robotname") robot. Run ()

(Can also be abbreviated as: Local robot = robomanager. createrobot ("robotname "). run () This script creates a robot in a random position. The robot has a written moving strategy: Randomly design the target point to achieve an approximate random variable speed movement; radar scan shooting mode: The radar scans the target and the turret turns to the target if the turret cool-down time is sufficient. Then a missile is launched. By executing statements multiple times, you can create multiple robots for melee.

For I = 1, 5 do robomanager. createrobot (). Run () End

This Lua loop is used to add multiple robots at a time, which is very convenient for the study of group intelligence. However, it is not recommended to create too many robots, which will make rendering difficult and difficult to observe AI behavior. Then click execute script. You can also use the shortcut key (SHIFT + enter) to execute the script. Close the edit window-this action is not necessary, but it will block your robot. At this time, we can see that the robot just named appears on the screen. These robots run according to an established AI logic and attack each other. To clear a robot, you can call

Robomanager. removerobot (ID)

The ID here is the number displayed after the robot name. This statement will delete all robots on the stage.

Robomanager. clearrobot ()

The above demonstrates how to get a robot already on the stage by adding and deleting a robot?

Local robot = robomanager. getrobot (ID)

The robot here is the robot with the corresponding ID. In the preceding example, we can see that the class specified by the system robomanager has been called. In the game, this class assembles, replaces, manages, creates, deletes, and stores robots, and so on. In game development, such managers are often indispensable. In our system, in addition to this robot manager, there are schedulers, map managers, input managers, animation managers, message managers, and so on. These classes often exist in static or Singleton classes, centralized management of functions in one aspect covers all aspects of the game, enabling the coordinated and unified operation of complex game systems. In a game system, there are classes with managers acting as global players, and classes with robots acting in an independent domain. In the above Code, the last sentence "Local robot = robomanager. getrobot (ID)" gets a robot. The following is an example of an output robot Name:

-- Get the robot with the corresponding ID The output window needs to be opened here. Like the console windows of many editors, game is called. the print () method outputs some print information. You can use the game when a line break or space is required. print ("\ t"), game. print ("\ n "). Using such scripts can create rich and interesting behaviors. Through some of the above code, I learned how the system works. However, it should be noted that the behavior of the robot and the operation of the whole system are far more complex than shown above. The robot has a set of equipment systems, and each system coordinates the work, for example, the target information must be obtained through radar scanning, and the turret turns to the corresponding direction before opening fire. This policy is effective for static targets, but it is not enough for moving targets. In addition, it takes a cool-down time for the turret to fire again after it is fired.
The movement of a robot follows the laws of physics. The only thing that can be done is to provide the robot with the power of F. Acceleration is obtained by means of power. A = F/M. The current speed and acceleration are superimposed and motion is performed according to the parallelogram law. V = V + A * t, s = V * T. If you are not familiar with this, I am afraid you need to review the physical and mathematical vectors of middle school, these will not be the obstacle for you to learn about game development. In fact, it is very interesting to create a behavior that suits the laws of physics and will make your robots look more real, it will also give you a greater sense of accomplishment. More importantly, through such a channel, you will have a deep understanding of how to drive people to perform complex but intelligent behaviors in the game, this is crucial for game development and deserves careful research.
I hope this kind of stuff will help you gradually understand the game, and I will gradually disclose the source code in subsequent tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.