Home  >  Article  >  Web Front-end  >  Han Shunping H5 game development tank battle video source code courseware sharing

Han Shunping H5 game development tank battle video source code courseware sharing

黄舟
黄舟Original
2017-12-04 11:28:162707browse

"Han Shunping H5 Game Development Tank Battle Video Tutorial" is an online open course selected by Han Shunping. It introduces how to use HTML5 to create a tank battle game. It has significantly improved H5 technology. I will take you with me Make a 3D top-down tank battle game. From the most basic controls to the enemy AI and the entire game system, we will guide you step by step to realize a complete game. In this tutorial, we focus on the use of programs and Unity, so we won’t talk too much about art resources. I will use a resource package from Unity’s official Training Day,

Han Shunping H5 game development tank battle video source code courseware sharing

Course playback address: http://www.php.cn/course/ 409.html

The teacher’s teaching style:

The lectures are friendly and natural, unpretentious, not pretentious or deliberately exaggerated, but eloquent Talking loudly and talking carefully, teachers and students have silent emotional exchanges in an atmosphere of equality, collaboration, and harmony, integrating the thirst and exploration of knowledge into a simple and real teaching situation, and students Gain knowledge through quiet thinking and silent approval

The more difficult part in this video is the production idea:

Keyboard event triggering problem:

If the player needs to control the tank to move by pressing keys, the first thing many people think of is to bind the corresponding movement function to the onkeydown of the corresponding key. above the event.

Generally speaking, there is a problem with writing this way, that is, in order to prevent situations such as an old man letting go slowly and causing keyboard events to be triggered multiple times. Only when you press the key for a certain period of time will the events continue. To trigger.

The reflection of this problem in the game is that your tank will always start to move continuously after a period of time after you press the button, which greatly affects the game experience.

The solution to this problem is very simple:

let keyInfo = {};     //按键是否被按下的信息let aKey = [72 , 74 , 87 , 83 , 65 , 68 , 38 , 40 , 37 , 39 , 17];      //这里面的数字是wasdhj等按键的键值
for (let i = 0; i < aKey.length; i++) {
    keyInfo[aKey[i]] = {
        pressed : false
    }
}

Use the key value of the key as the attribute name and store the key status in the keyInfo object , the initial values ​​are all false, indicating that the button is not pressed.

When the corresponding key on the keyboard is pressed, the keyCode, which is the key value, of the pressed key is directly captured through the event delegate.

After the onkeydown event is triggered, set the corresponding attribute in keyInfo to true, indicating that the key is pressed. After the onkeyup event is triggered, set the corresponding attribute in keyInfo to false.

Finally, loop through the game to detect the authenticity of the corresponding key attributes in keyInfo and perform the corresponding operations.

Path problem:

Without mentioning the collision problem between tanks and bullets, the path problem is basically determining where your tank and bullets (the problem of bullets is actually more complicated, which will be discussed in detail later) can and cannot go on the map. , although this issue is not very complicated, in my opinion this issue can be said to be the core of the entire game, because many subsequent issues revolve around Lu Jin.

Wait

Here we also recommend downloading source code resources: http://www.php.cn/xiazai/learn/2048

The resources share video courseware and ppt with you:

  1. Materials

  2. Documents

  3. Source code

The above is the detailed content of Han Shunping H5 game development tank battle video source code courseware sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn