Game production foundation: use DX to do rpg

zhaozj2021-02-11  158

A simple RPG game first, to make an RPG game. Aspects needed, have the following: 1. Use the keyboard to control the wizard. 2. Since the elves have four walking directions, each direction should have several frame animations (here are two frames). Considering that the configuration of each machine is different (the CPU and the graphics card are different). Therefore, there must be delay between frames and frames. 3. When the Elf walks in our labyrinth, when it encounters "obstacles", it should not be moved. 4. In the game, there should be "bad spirits". In my game, its performance is "chasing controlled elves." (Currently, only a simple chase algorithm is used, so "bad spirits" sometimes card. In the future version, the A * algorithm will be considered.) 5. The movement of the elves should not only limit the high and wide screen, this The reel is required. The following is a specific solution: (corresponding to 4 problems above) 1. Just use Windows messages WM_KEYDOWN. Use DirectInput in a DX environment to operate the keyboard. 2. Assign a memory to save its image information for each of the wizard bitmaps. This corresponds to each bitmap corresponding to a pointer. (Here I use a group of implementations, when the size is determined by the specific image), I specified a pointer to this array. When the elf moves, just operate the pointer = offset, so When drawing, just draw the value of this pointer. Here, I set the motion offset of the controlled elf to 2 (pixels). Then define an int number, which is initially 0, which is valid for each elf (here only means UP, Down, Left, Right Operation, and only one valid each time. Otherwise, it will be used at the same time When any of the four directions in the above four directions, this elves appear as an oblique motion, because it is incremented by simultaneous changes at the same time. The constant value is specified, and it is cleared when the upper INT integer is equal to this constant. This whole operation is, when this int number is equal to a constant value, the wizard state is the first movie in the current direction; when equal is equal to the constant value * 2, it is the second. This creates an animation effect. Talk again, just define a Timer when the WM_CREATE message is required. Then when the pointer offset is set each time, it is first determined whether the Timer is valid. Example: First define Timer, then define a variable state = 0 (whose change is: When Timer occurs, state = 1-state) first animation IF (time delay) IF (time plus variable == constant value) Pointer to the elf array = Elf array offset; second animation if (! Time delay) IF (increasing variable == constant value * 2) pointing to the pointer of the elixi array = Elf array offset; 3. Use a monochrome bitmap to record the map information. White is available, black is not active. This bitmap is then plotted to generate a user-visual map. And record this map with a global two-dimensional array. Then each elf moves, actually moves in this two-dimensional array, and determines whether the next step is feasible before it is moved. The specific judgment method is converted from the coordinates of the elf, and the location in our map array is then taken, and then this location value determines whether or not it can be passed. 4. As for the tracking algorithm for "bad spirits". At present, it is only simple to add and decrease, and there is no need to further explain again. In the future, use a * algorithm to write specific ideas.

转载请注明原文地址:https://www.9cbs.com/read-5078.html

New Post(0)