Detailed explanation of horizontal shooting game based on HTML5
Mar 24, 2017 pm 03:33 PMFunction Description:
Based onHTML5's horizontal version of the shooting game, refer to the flash game "Double Agent". The left and right arrow keys control movement, the down arrow key to squat, the up arrow key to jump, please turn off the input method before experiencing it.
## This game is based on the self-developed HTML5 game framework cnGameJSEffect preview:
Implementation analysis:
1. About multi-layer maps
In the previous HTML5 game "Tank Support Team", the map used was only. A simple single-layer map means that there is only one layer of open space except for stones. However, this single-layer map has relatively large limitations. If you need to implement scene-based games (such as Super Mario and the above games). ), a map with only one layer is often not enough, because in addition to the obstacles where the game protagonist is standing, we also have game background and other elements (such as the wall behind, etc.), so we need to layer the map objects to achieve multiple The purpose of layer display. New layer object: Each layer object maintains the sprite of the layer, is responsible for updating and drawing them, and can obtain the specified coordinates on the matrix of the layer. The value of the layer object is as follows:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
1 2 3 4 5 6 7 8 9 10 11 |
|
2. About the mobile scene. # In the last HTML5 "Game Super Mario Game Demo", we achieved the effect of player fixation and scene movement by converting the movement of the game player into the movement of the game scene. However, this implementation method has A bigger problem, because it interferes with the changes in the xy values of the map and the player, so it will cause a lot of inconvenience.
A better implementation is to keep the xy values of the player and the map unchanged, and only change when drawing them. The coordinates of the origin.The new method of the view object: applyInView:
The function of the applyIn
View methodis to not change the actual coordinates of the map and the player. Next, the view is fixed when drawing, and other game elements move relative to the view to achieve the effect of moving the background. For example, we need to make the player fixed relative to the midpoint of the view, and all other game elements on the map move relative to the view. Just need to initialize:
1 2 |
|
1 2 3 |
|
In this way, all elements in the map will move relative to the view.
The implementation principle of applyInView is also very simple. It just keeps making the origin of drawing and the coordinates of the view equal and opposite:
1 2 3 4 5 6 7 8 9 |
|
In this way, no matter how the coordinates of the view change, the view will visually change Always fixed to
canvas, the coordinates of other elements are always visually relative to the view.
The above is the detailed content of Detailed explanation of horizontal shooting game based on HTML5. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
