C # Basic Video Tutorial 7.2 How to write a simple game

Source: Internet
Author: User

In the previous section we implemented a simple collision detection, but actually the object of the game is not a standard rectangle (the bird is an irregular object, in fact the collision of the pipeline is also irregular objects), so if really to do the more perfect, we have to write a method, can import an image, And then the image to depict an irregular outline, and then to extract the outline of the point, after the judgment of the time just to determine whether all the points of a graph is in the B area. So the front rectangle and ellipse are not enough, we want to use a custom point array point[] to build the irregular polygon polygon, when the need to judge the point of the time to traverse this array of points.

?

To improve the user experience, we assume that the left mouse button double-click: Start Drawing (Redraw) Right-click: End Drawing (drawing complete) middle mouse click: Pause drawing/Continue drawing. These methods Baidu is not difficult to find, note in order to quickly verify the function, we directly put a PictureBox and in the initialization of the time to register a few events (mouse stand-alone, double-click, move three, you can also register to FORM1)

?

Of course you can also set the trigger mode (I later feel that the mouse press and release to indicate the pause drawing and continue to draw more reasonable, the mouse pressed to continue to draw, the mouse release just move, then no matter)

?

When we use the mouse to depict the contour, is the use of the method of recording the mouse track to get a number of points (there may be hundreds of thousands of), as previously said, in fact, it does not need to be so dense (collision is a collision, do not distinguish between the bird's mouth hit or the bird's chin hit), So the front side to do a way to define the degree of density, originally the original data has 1000, I can set 5 points to collect one, or 10 points to collect one, the overall number of points is much less.

?

The pile of points we get is actually just the track record of the mouse, and what we really need is some relative points (for example, I'm going to write a method to draw a bird, just specify a starting point, a scale or a two scale of XY, you can generate all the points in the back), So you actually have to do the processing at the point of recording. The first point x_1,y_1, the following points only retain the XY difference of the front point, the entire array can be saved, as mentioned above, the data format is we can define their own, the simplest txt on the line, you can see the first line is really more special, If it is not written this is not very good to understand the meaning of the numbers separated by each vertical bar.

?

From the results, as we expected the basic agreement, we put the starting point and the end of the small circle special draw out, because there may be some misoperation (such as the beginning of the drawing is not the real mouse at the first point to be drawn, we can be added when the point processing is exported to judge, If the start and end points are too poor, you can force the starting point to be equal to the end coordinate.

?

In particular, note that these three panning, zooming and rotating functions are very valuable. For example, if we want to do the pipe, the random width and height, then only the standard rectangle according to the X and Y scale. And in many airplane games, bullets need to go round and round, tank games and Tetris can be rotated 90 degrees to adjust posture and so on. Even in this example, the birds we draw may not match the last image to be filled, so we need some scaling and rotation to match the polygon with the imported picture.

?

If your GDI + parameters are illegal, such as scaling is 0, then the whole window will be a fork (the reader needs to be careful to prevent illegal when they do the GDI + function), I have shown here that the scale of Y is 0 when the effect, more errors in the case of the reader can verify their own.

?

?

For more instructional videos and downloads, please pay attention to the following information:

My Youku Space:

Http://i.youku.com/acetaohai123

?

My online forum:

http://csrobot.gz01.bdysite.com/

?

Problem Exchange:

qq:910358960

Email:[email protected]

?

?

C # Basic Video Tutorial 7.2 How to write a simple game

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.