Using JS to reconstruct the basic knowledge of StarCraft

Source: Internet
Author: User

Demo Address

Http://www.script8.com/works/sc/index.htm

Background information
For many people, JavaScript is a rather cryptic language, which is parsed by browsers and can be implemented in very complex functions, but is rarely used in practice. In the relative positioning as the basis of the Web site system, JS is not essential, the first browser does not support JS, just use pure static HTML, but also to establish a full-featured Web site. For page developers, the use of JS is estimated to be used for data legality check. In recent years, with the rise of Ajax concept, JS use has increased, but in addition to Web mailboxes, such as a few tool-type Web site, its role is still auxiliary.
In fact, JS as the most popular scripting language, the function is very powerful, the author has used JS to simulate StarCraft. As we all know, StarCraft is a milestone in the history of real-time strategic game, in the player's mind, the position is self-evident, bubble in a variety of internet cafes playing StarCraft was a part of my life. Only with cavity blood, I began to use JS to develop Interstellar, this is a difficult course, full of setbacks, but also enjoy the fun, and finally able to complete, but at the beginning I did not expect to.
JS Star source code was first released in the forum of worry-free script, got a lot of netizens praise, let me moved, but also more efforts. Through this development, my JS development technology has a lot of improvement, but also know a lot of people like JS development friends, fortunately! JS Interstellar Current storage address is http://www.script8.com/works/sc/index.htm, interested friends Welcome to participate in the discussion.

The


solution
Seek algorithm is the basis of the game and the most computational component. I do not use a * algorithm, because the script is too expensive, but the independent development of a new algorithm, called the intersection method, characterized by linear search, the number of small operations, the disadvantage is that the result is not guaranteed to the shortest path. The basic ideas of intersection method are summarized as follows:
1. Draw a straight line from the beginning to the end, and when intersecting with the obstacles, there will always be a corresponding entry point and a point to wear out.
2. From the point of entry in the two direction at the same time to bypass obstacles, choose first to get through the point of the route as the forward route, so that a relatively primitive route.
3. Optimize the route to determine whether two points form a path, delete redundant points, get the final path.
Search for a large number of uses to determine whether the point of the operation, the general practice is to traverse the array, compared to get the results. I put the obstacle point sequence into a long string, through the string contains the relationship can determine whether the current point is the point of obstacle, so that a lot of calculation.
JS Interstellar is equivalent to the opening part of StarCraft, the mining, building and production of soldiers, and the fighting part is slightly involved. Before coding, need to have a lot of preparation work, just the production of pictures is very annoying lock, need extremely patience to do. In addition, I developed a map editor using HTA technology to generate map data.
The Control panel in the game is more streamlined, and the thumbnail and selection information is integrated into a small panel in the upper-right corner, and the rest is part of the game scene. Each mobile unit has 8 directions, take the gun as an example, need to use 24 pictures to show standing and walking around all kinds of posture. These pictures are integrated in a large picture, according to walk or stand, showing the corresponding parts, such as walking around, to determine the direction of walking, while moving the gun position, three pictures on one side of the display, showing the situation of walking.
Game initialization, load the map data, according to the different building properties, on the one hand to generate the scene, on the other hand to create a list of obstacles for the use of road search. By default, there are several miners on the map, after circle, click on the target can walk autonomously, according to the game requirements, if the click of the ore, will be in the mining and headquarters to move back and forth, each round-trip will increase the amount of mineral resources.
As to what kind of building can produce soldiers, how many resources each soldier needs, what is the production order of buildings, these are relatively easy to do more picture processing and more logical judgments, limited to the length of the detailed introduction.


experience sharing
Do not worry about the implementation of features, because JS has been very perfect, you can do all kinds of operations, using the absolute positioning mechanism, you can easily create an interface, and then use the clock to simulate multithreading, real-time moving pictures, Can show animation, the problem is mainly reflected in speed and performance. Because JS as a scripting language, its computational performance is undoubtedly congenitally deficient, while the browser does not support DirectX and OpenGL and other hard acceleration, animation ability can not be satisfied. Only by reducing the amount of computation and allocating the animation resources reasonably can the smooth operation of the game be ensured. The development of JS Interstellar, it is everywhere to follow this principle, can contributors Jane, can save province, very economical use of various resources, and finally to achieve.
Do not use filter technology in the game, especially the dynamic filter, filter rendering will occupy a large amount of CPU, in the CPU occupancy of more than 80%, the game will feel the comparison card. This is very different from the same kind of program that Flash does, even if the CPU occupancy rate is close to the 100%,flash program can still maintain quite smooth.
by heart, the client's game development, should still be mainly flash. In contrast, the advantage of JS is that it can be seamlessly connected to the site, and do not need to install plug-ins. Of course, as long as it is fun and practical game, even with JS developed, also may not.

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.