C # development Wpf/silverlight animation and game series Tutorials (Game Course): (21) thematic Map movement mode
Have you looked forward to it for a long time? This section will be a heavyweight opening statement: Thematic map movement mode. What is the thematic map movement mode, that is, the protagonist as the center, its movement drives all objects including maps, objects, other players, monsters and so on relative movement, these objects are moved by the protagonist for reference. The most typical example is the current popular MMORPG, the role you control in the map is always in the center of the window position (except 8 corners), this is the thematic map movement mode (pictured below).
A friend began to fret: my mother, just learned the traction Map Mobile mode, not fully absorbed, and what a ghost Thematic map movement mode, the head is big!
In fact, there is no need to worry, a clear structure of the program only need you a gentle operation that can achieve functional innovation. Do you remember the magic of modesty? The magic moment is coming, let me show you the principle:
The game window size is still tentatively 800 * 600, as shown above, I divide the game map (size 1750 * 1440) into 9 parts; When the protagonist is on the left (spirit.x<=400 && spirit.y<=390), Upper right (spirit.x>=950 && spirit.y<=390), lower left (spirit.x<=400 && spirit.y>=1050), lower right (spirit.x> =950 && spirit.y>=1050) These 4 corner areas, the map is still, the protagonist, as in the Nineth section of the same can be arbitrarily in the window to move, directly speaking is the protagonist in the window display position is its picture in the upper left corner point (X-centerx, Y-centery);
When the protagonist is in the middle (spirit.x>400 && spirit.x<950 && spirit.y <=390), Down (spirit.x>400 && spirit.x<950 && spirit.y >=1050) These 2 edge areas, the protagonist is always centered horizontally, moving it will only move up and down in the window, The horizontal direction through the map relative reverse movement to form the protagonist horizontal direction forward visual effect;
When the protagonist is in the left (spirit.>390 && spirit.y<1050 && spirit.x<=400), right middle (spirit.>390 && spirit.y<1050 && spirit.x>=950) in these 2 edge areas, the protagonist is always centered vertically, and it moves only horizontally around the window, Vertical direction through the map of the reverse movement to form a leading role in the vertical direction of the visual effect;
When the protagonist is in the middle zone, that is, the protagonist in the game most of the time, the protagonist is always at the center of the game window position (positioning to the soles of the feet), when it moves, in the window through the map of the reverse movement thereby in the visual formation of the protagonist in the mobile (in fact the lead is still, only to This is similar to the traction map movement pattern in the 20th section, but the two are just the opposite: the former protagonist does not move, map reverse movement, the latter for the map with the mouse traction and move, the protagonist does not move. Finally, we conclude that we just need to modify the Allmove () method in section 20th to achieve perfect pattern conversion.