C # development Wpf/silverlight animation and games series Tutorials (Game Course): (12)

Source: Internet
Author: User
Tags silverlight

C # development Wpf/silverlight animation and games series Tutorials (Game Course): (12) Magical copy Map

The previous sections explain the complete structure of the game map in detail, and it is difficult to realize the inner layer of the map such as obstacles. A * algorithm often allows many beginners to Shing, the slope of the alpha map is more need for a certain degree of geometry and abstract thinking. Many friends asked: what age, are talking about object-oriented, improve the efficiency of development, there is no popular can make all levels of ability of friends can easily make map engine method? Do you remember a little suspense left in the last section, the Killer Brook is it: the Magic copy map.

We first look at the picture, the left is the map presentation layer, its size is 800*600. On the right is a copy of the map that I sketched on the basis of Photoshop, as well as the size of 800*600. The special mention here is that the copy is made up of simple pure tones, so it can be compressed to a very small capacity, almost negligible, which is a prerequisite for our powerful tools and a necessary condition for Silverlight to make a web-based game. OK, next we will give a detailed description of this copy: it is easy to compare the original image of the black above it is actually representing the obstacles in the map, that large white area? It's actually the area we can go anywhere. As for yellow, smart friends should not be difficult to guess, it represents the map of the transmission point. Of course, you can also add such as red to represent traps, green to represent special NPC, and so on. Do you think it's like drawing? Hey, this is my idea of object-oriented game programming innovation. To make the copy of this map complete, then how to use it?

The essence appears again, to see the graceful color-picking method:

//图片拾色
private Color pickColor(BitmapSource bitmapsource, int x, int y) {
 CroppedBitmap crop = new CroppedBitmap(bitmapsource as BitmapSource, new Int32Rect(x, y, 1, 1));
 byte[] pixels = new byte[4];
 try {
   crop.CopyPixels(pixels, 4, 0);
   crop = null;
 } catch (Exception ee) {
   MessageBox.Show(ee.ToString());
 }
 //蓝pixels[0] 绿pixels[1]  红pixels[2] 透明度pixels[3]
 return Color.FromArgb(pixels[3], pixels[2], pixels[1], pixels[0]);
}

is too strong, with it is like lui bu take us painting Ji-ease! (This method can only be used in WPF, and Silverlight3.0 will give you a perfect solution as to how to invoke it in Silverlight.) ^_^)

The role of the replica map is very ferocious, on top of it we can freely paint red, yellow, blue, green, orange, violet, etc. n multiple colors to depict different map attributes, and then implement something like the following:

1, if the protagonist to pick the point is black is equivalent to the protagonist encountered obstacles, then the protagonist's action is to stop.

2, if the transmission point, according to the coordinate range (or other conditions, etc.) to determine which map is transmitted;

3, if it is a trap will trigger what events, such as blood or be transmitted, or brush strange and so on;

4, of course, there can be other colors, if the game has flying mounts and other elements exist (to achieve 2D map of the three-dimensional space), the same can be used as a blue to represent the air barrier area, or with purple to represent the land and air are the obstacles, these are quite flexible.

5, White is able to pass, the protagonist in the above can move normally.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.