C # Basic Video tutorial 7.1 How to write a simple game

Source: Internet
Author: User

To do a flappybird, the most core function is to create a few chunks, if a collision is the end of the game (birds hit the pipe, or birds to the ground), as to randomly generate some tubes, how birds jump, and finally how to count scores, are not difficult to figure out how to do.

?

The first is to know how to draw what you want on the form, C # provides us with GDI + functionality, you can define a graphic object, and then call its Draw method, you can find a lot of things to draw, rectangles, ellipses, polygons, curves and so on (drawing is a polygon, with a pen instance , filled is also polygons, with SolidBrush instances, of course, in addition to pen and SolidBrush there are other tools, you can draw dashed lines, arrows and so on)

?

When drawing attention is the paint method, this method does not take the initiative, but only when needed to execute (such as the size of the form, the form is moved, etc.), so I drag the scroll bar, To artificially trigger the Refresh method of the form to update the drawing (I made a label to detect the number of executions of the true paint method, which is also an important debugging technique to test whether a thing is executing, and the output of the MessageBox is not enough for complex situations)

?

With so two zones (one fixed, one x,y,width,height all determined by four scroll bars), we can test collisions. It seems that C # does not provide us with a two-region collision detection method. It is easy to think of the point of traversing each window, if the point exists in the A area, also exists in the B area, it is considered that the AB region overlap, that is, collision. We have a lot of pixels on our screen (at least 800*600 hundreds of thousands of points), and if you really want to traverse through a single point it will cost a lot of resources. So in order to improve efficiency, we can wait for the sampling on the line. I randomly tested the rough situation, I manually let the yellow square movement to produce a superposition point, it is really possible to detect collisions (of course, the left side of the situation also collided)

?

It is not difficult to think, I will increase the accuracy of one time, you can detect the initialization of the collision when the situation (in fact, those dense black dots do not need to draw out, wasting system resources, now to do the test or to the draft)

?

?

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.1 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.