Super Mary 2, super Mary perfect Version 2
Zookeeper
Stage 2:
Objective: To enable Mario to accept the control of left and right movement and jump, execute the left and right walking animation and maintain the air status, and design the Mario state machine. There is no collision detection in this process.
1: This is a horizontal scroll control category game. Although the touch mechanism on the simulated mobile device is clicked with the mouse, it is still inconvenient to test. For example, when you press two buttons at the same time, you can't do it with a single mouse touch. Therefore, in order to facilitate testing at the early stage of development, we need to slightly modify the engine so that the game can receive messages from the keyboard and respond. This is not difficult to do. The link here is very clear, and it will be OK. [Http://blog.csdn.net/a7833756/article/details/7772115]
CCGameLayer: voidprocessWin32KeyPress (UINTmessage, WPARAM wParam, LPARAM lParam); this method can capture messages from the keyboard and process different buttons in the function, this is consistent with win32 programming.
2: The simulation physical environment is not used in the game. The left and right movements and jumps in the game are implemented by changing the parameter values. In the CCGameLayer class, there are two variables about left and right movement, floatccMoveOffset; it is a fixed value initialized in the constructor, floatmoveOffset; it is convenient for unified external updates, if you press the left button during the game, the moveOffset will be attached with-ccMoveOffset. If you press the right button, the moveOffset will be attached with ccMoveOffset.
This is also for the convenience of subsequent modifications. If there are numbers everywhere, it will be troublesome to modify them. In this way, you only need to modify the ccMoveOffset value.
3: Next we will introduce the core idea of Maio's walking and jumping between the left and right sides in the game. In the update (floatdt); of the CCGameLayer class, this is a function that controls the update of Mario. The core code of this function is:
This function is executed once every frame. Two bool values are maintained in the CCGameLayer class, indicating whether the Left or Right bool values are pressed.
These four buttons are controlled by the four buttons on the UI control handle. When the left button is pressed, isLeftKeyDown is true and moveOffset is set to-ccMoveOffset. The same applies when the right-click is pressed.
4: let Mario execute a walking animation while moving left and right. In this case, we need to talk about cocos2dx about animation. Frame Animation is used here, which means a picture of the same size is used to make an animation, and stored in the engine's own animation cache. The animation production, storage, and calling are all in the AnimationManager class:
This is a singleton. Singleton is a common design mode. In principle, when a game is running, classes of only one object can be designed as Singleton. There are also many classes in the engine designed as Singleton, such as the director class CCDirector, and various cache classes CCTextureCache and CCAnimationCache. In the Mario class, animation is called through enumeration. In the GameEnum. h file:
This file contains all enumeration types used in the game, such as animations in the game, types of monsters, and various collision detection elements on the map. On the basis of the previous paragraph, when you press the left button, Mario plays the animation that is going to the left, and finally adjusts the playback interval and moving speed of the animation, which looks more natural, the values involved here are not directly written in the code, but in the form of parameters for debugging and modification.
5: Skip implementation. This is different from the previous concept of left-side walking. The Skip does not need to maintain a bool value. When the jump button is pressed, It is vacated, in addition, the texture of Mario is changed to a vacant image. This involves a bool logo for whether Mario is in the air, because when Mario is vacated, the jump button cannot be invalid, only when Mario is on the ground or on the bricks of the map, to respond to the jump button. When Mario falls onto the ground, Mario's texture will be selected based on the current orientation of Mario. Because Mario accepts the response from the left and right buttons in the air, when Mario jumps to the right, he suddenly presses the left button, mario's turn will change. Here, how can we determine whether or not Mario is vacant involves collision detection in the vertical direction, that is, collision detection with some of the standing bricks on the ground and the map. The following is the logic behind the press of the hop button.
The last line in the CCGameLayer: collistionV () function:
In this way, we can achieve a gradual deceleration effect during the upward jump process of Mario until jumpOffset is reduced to 0. At this time, Mario also reached the maximum jump, and continued to execute the subtraction above, mario will be on the ground again, and the execution logic is as follows:
6: maintenance of the Mario state machine. The performance of Mario in the game is the arbitrary switching of a state machine. How can we refine the status of Mario in the game? One aspect is from the shape of Mario, which refers to the shape of before and after eating mushrooms, and to the bullets. The other aspect is from the motion of Mario, such as standing left and right, walking left and right, and left and right. All the logic in the state machine of Mario is handled in this way. One point to mention after the group is that the state of Mario is also set for every frame, which brings about a problem, if the current state is the same as that of the previous frame, there is no need to update the state of Mario. At this time, a current state and the previous state are introduced. The state machine function initially has a judgment:
If the current status is the same as the status passed in by the parameter, it will be returned directly. If the status is different, it means that the status of Mario has changed and then all the actions of Mario are stopped, match and update based on the new status.
7: the implementation of the control handle is neither technically difficult nor hard to understand. It is to respond to the win32 Keyboard Message and set the control variable of Mario according to the message.
8: Implementation of map tracking and implementation that Mario cannot go back. This may be difficult to understand. There are also many questions on the network. Before solving this problem, we must first have a deep understanding of the concept of the anchor and the relationship between the local coordinate systems, these two do not understand that this requirement is very difficult to achieve.
Conclusion: The results of this phase: Mario can accept and process messages from the keyboard. Mario can walk freely on the map, and there is a real walking animation that can jump and land, you can jump to some bricks on the map,
Northlink handle, super Mary
This depends on the simulator of the game you are using. In this case, you must first set the control settings of the two controllers before using the Overlord simulator. set
How many levels does a classic Mini-game "Super Mario" have?
Each of the eight major Customs levels has four minor customs levels.
The details are from 1-1 to 8-4, but players can select the marker by searching for the climblient. For example, after 1-2, you can directly jump to 4--2. You can directly jump to 8-1 with dark-lattice gold coins and vine climbing.
There is also the Cat version, which was initially the four major Customs version, with no minor customs. Now the full version is already on the top of the 8 mark.