[Jsvm2]-(Open Source) JS Starcraft (for jsvm2)

Source: Internet
Author: User

It's really awesome !!! StarCraft, written in jsvm2, has to be shared.

 

Source:Http://jsvm.org/forums/1902/ShowPost.aspx

:[Ie Only] JS Starcraft v1.01.061219 (for jsvm2).rar



Port the JS Starcraft of magic cloud to the jsvm platform, and take a look at it.CodeThe style sheet is separated, and the page Code standardizes the points. (JS written by magic Yu does not add comments, and each sentence is followed by no extra points. Khan ~), The core file for path search is written as JSC and packaged as a JS-lib package ~

Note: Currently, this game can only be played in IE kernel browsers (or ie7.0), because this is an early work of magic cloud (only supports IE ), if you are interested, you can try to build a version compatible with multiple browsers ~

Haha, you can play games when you are bored. If you are interested in JS games, you can study them ~


Enjoy it ~

 


Background

For many people, JavaScript is quite
For the mysterious language, this language is parsed by a browser and can implement very complex functions, but it is rarely used in reality. In a website system based on relative positioning, JS is not essential and the earliest browsing
JS is not supported. You only need to use static HTML to build a fully functional website. For page developers, it is estimated that JavaScript is used for checking data validity. In recent years,
With the rise of the Ajax concept, the use of JS has increased, but in addition to a few tool-type websites such as web mail, its role is still auxiliary.

In fact, JS acts
The most popular scripting language has powerful functions. I used JavaScript to simulate Starcraft. As we all know, Starcraft is a milestone in the history of real-time strategic games.
Yu, playing in various Internet cafes is a part of my life. With just a bit of blood, I am using js to develop Starcraft. This is a tough process, full of setbacks and fun,
I did not expect it at the beginning.

The JS interstellar source code was first published in the carefree script forum and won praise from many netizens.
Make more efforts. Through this development, my Js development technology has improved a lot and I have known many friends who like JS development. Fortunately! The current storage address of JS interstellar isHttp://www.script8.com/works/ SC /index.htmIf you are interested, welcome to the discussion.

Solution

Path searchAlgorithmIt is the foundation of the game and the biggest part of the computing workload. I didn't use the * algorithm, because the script overhead is too large, but I developed a new
An algorithm, called the intersection method, is characterized by linear path finding and computation. The disadvantage is that the result cannot be the shortest path. The intersection method is described as follows:
1. draw a straight line from the start point to the end point,
When encountering an obstacle, there will always be a corresponding penetration point and exit point.
2. From the two directions of the penetrating point to bypass the obstacle at the same time, select the route that first reaches the penetrating point as the forward route.
A relatively primitive route.
3. Optimize the route, determine whether the two points form a path, delete the redundant points, and obtain the final path.
A large number of uses are used to determine whether or not to find the path
The general method of obstacle point calculation is to traverse the array and compare them to obtain the result. I turn the obstacle point sequence into a long string. Through the string inclusion relationship, I can determine whether the current point is an obstacle point. In this way
Reduces a lot of computing workload.

The implementation of JS Starcraft is equivalent to the StarCraft opening part, namely mining, building manufacturing, and producing soldiers. The combat part is slightly involved. In Encoding
Before, there is a lot of preparation work, It is very annoying to make pictures, it takes a lot of patience. In addition, I developed a map editor using HTA technology to generate map data.


The control panel in the game is relatively simple, and the thumbnail map and selection information are integrated into a small panel in the upper right corner. Other parts belong to the game scenario. Each Mobile Unit has eight directions. For example, you need to use 24
Images to show standing and moving posture. These images are integrated into a large image. The corresponding parts are displayed based on walking or standing conditions. For example, when walking around, you can determine the moving direction and move the gun positions.
Display Three images on one side, showing moving.

During Game initialization, map data is loaded based on different building attributes. On the one hand, scenes are generated and obstacles are generated.
A list of things used for path searching. By default, there are several miners on the map. After selecting the target, you can click the target to walk independently. According to the game requirements, if you click the ore, you will move back and forth between the mining area and the headquarters,
Each round trip will increase the amount of deposits.

As to which building can produce troops, how much resources each soldier needs, and the production sequence of the building, it is relatively easy,
It is nothing more than doing more image processing and making more logical judgments. It will not be detailed in length.

Experience Sharing

Don't worry too much about features
Because JS is already very well-developed, you can perform various operations as you like. Using the absolute positioning mechanism, you can easily create an interface, and use the clock to simulate multithreading and move images in real time.
Animation, the problem mainly lies in speed and performance. As Javascript is a scripting language, its computing performance is undoubtedly inherently inadequate. Meanwhile, the browser does not support hard addition such as DirectX and OpenGL.
Speed, animation capabilities cannot be satisfied. The smooth operation of the game can be ensured only by reducing the computing workload and rationally allocating animation resources. JS star development follows this principle everywhere, which can be simplified and simplified, while saving
Save, and use various resources very economically.

Do not use the filter technology in the game, especially the dynamic filter. Filter rendering consumes a large amount of CPU.
When the CPU usage exceeds 80%, the game will feel stuck. This is similar to flash.ProgramThere is a significant difference, even if the CPU usage is close to 100%, flash programs can still maintain
It is quite smooth.

In all fairness, the client-side game development should be dominated by flash. In contrast, the advantage of JS is that it can be seamlessly connected to the website without the need to install or plug
. Of course, as long as it is a fun and practical game, even developed with JS, it is not a problem.

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.