Summary
This article provides the design process and flowchart of an Aircraft shooting (submarine) game, and provides the Demo version of the source code. The game passes debugging under sun wtk v2.2.
Disclaimer: most of the resources used by this game do not belong to the author. The code is only for reference for non-commercial purposes.
Which of the following are game images?
740) this. width = 740 "border = undefined>
Game Design
1. Game Operation Process:
The initial screen of the game is an implusive List format. After you select new game, you can start the game. The game is enabled in full screen mode, however, there are still command response function keys for pausing, starting, and exiting. When the game is suspended, the sea water and marine creature will continue to be active, but the enemy's submarine and all the torpedo will remain static, and the player's control will not work, until the game is started again. Exiting from the game status will return to the menu interface, and selecting to exit again will exit the program.
The following is the overall flowchart of the game:
740) this. width = 740 "border = undefined>
2. algorithm processing
The game itself is a single-State structure (singletone), where a Controller processes the current screen and status. The main display categories include the main screen, game canvas, help screen, and some auxiliary Alert, the most important of which is the game screen. The game runs in the MIDP 2 state, so the screen inherits from GameCanvas. The role layers in the game are all loaded on a layer manager much larger than the screen size of the mobile phone. When the player position moves, the layer manager synchronously calculates the relative position of the player and moves the display position of the current layer.
The essence of this game is to use the entire canvas as a thread after the midlet starts, scan the user's key operations every 25 ms, and scan the movement status of the enemy and torpedo and other objects every 50 ms, the keyPressed method is inherited for the demanding real-time response of bullet injection.
When scanning a player's movements, the key code is passed in to the response method of the player's submarine. Scan enemy and torpedo movements in two steps.
The first step is to move the image of each object. The program does not open a new thread for each new torpedo or enemy. Too many threads will cause the program to decline in performance. Instead, it retains a Vector Array for each object type. Every time a new object is generated, it will be first added to the array to which the type is changed, and then drawn on the layer; when the object is eliminated, in addition to the layer, it also needs to be deleted from the response array. In this way, a registration mechanism is formed. The generation and Elimination of All game objects must be registered with the canvas. The canvas has all the "Lists" of different types of objects. Therefore, when executing a mobile command, you only need to traverse various types of arrays and execute the moving method of each element in sequence.
The second step is to reproduce the image in the general sense. Here, flushGraphics () is used to replace the traditional repaint (). Because this game uses image import as the operation object, the changes to the image position have been implemented in the first step, so there is no pixel-level re-painting involved, only the layers corresponding to each object array need to be loaded to the new layer manager during game initialization.