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

Source: Internet
Author: User

Next we implement the entire game process, and when you click to start the game, you need three things to start running

1 The bird initializes and goes down (of course, you can use the button to fly it)

2 A tube is generated from the left side at a certain time (the width and height are random, producing a period of about 2000ms)

3 Check whether the bird has hit the tube at a certain time (this time period is about 50ms or larger or smaller)

?

The difference with the previous verse is that the bird is the only one, and the pipe is not unique. We were just judging whether a bird and a tube had a collision, and as the tube was constantly generating, it was necessary to detect whether the bird and each tube had a collision. So we put the generated pipe in a list of gamesense, the list stores the instance of the Gamerectange class, and on the other thread of judgment, we need to iterate through every element of the list, and as long as there is any impact, it is considered to have hit

?

We used a lot of classes are static, here the pipe class can not be static, because each pipe size is not the same, every time will be new one out. It can be imagined that if we want to make two birds double game, the bird cannot be made static (so the reader is considering whether it is necessary to make a static class, method, just want to know whether this class will need more than one instance, if necessary can not be static), in this case only the scene is unique, the referee is unique, So you can use static.

?

In order to improve the experience of the game, each produced a pipe, did not bump up, you can give the user a little bit (we use the method of drawing text on the screen, which is more reasonable than the control, at least there is no control of the background color interference). In each sub-thread we put the delayed sleep operation at the end, the reader can test if put in front of what the problem (multiple pop-up window, or the end of the game also produces an extra pipe)

?

Start the game, the game is over, the game empty scene is also a separate method, note that the game empty scene is not the same as the end of the game. At the end of the window to tell the user he hung up, but at this time can not immediately empty the scene (the screen to show where he crashed), click the OK button before going to empty the scene (the original list saves the pipe is thrown away, the bird also back to the initial position, etc., a lot of Boolean value to reset)

?

has been able to test the full run, click on the birds flying, bypassing obstacles, then score, hit the game to tip the end, the next section we continue to improve

?

?

?

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