Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft CSharp Programming For The Absolute Beginner (2002) [eng]-1.pdf
Скачиваний:
46
Добавлен:
16.08.2013
Размер:
15.71 Mб
Скачать

Placing the Platform on the Form

In my first attempt, I simply copied the lander form over to make the platform position code, but when I started play−testing, I discovered a problem. Every once in a while, the lander’s position is mainly off the screen, so it is impossible to land on. Players don’t mind being challenged, but they’ll get grumpy if you make it impossible to succeed. I had to modify the code slightly to guarantee that the landing platform would be visible on the screen. You simply subtract the width and height of the platform from the screen width and height, and it becomes impossible for the random number generator to create a position that will cause the platform to be invisible.

Summary

In this chapter you learned how to build an arcade game, but the experience led you through several other important programming concepts as well. You learned how to add multiple images to an ImageList control. You learned how to read information directly from the keyboard in a couple different ways. You learned how to move objects around on the screen and what to do when they reach a screen boundary. You learned how to detect collisions between objects, and you created message boxes that can return values. In the next chapter you’ll learn more about groups of objects and the fun things you can do with them.

Challenges

Modify the difficulty level of the Lunar Lander game. There are several ways you could tweak the code. Perhaps you could change gravity by modifying the change in dy during each tick of the timer. You could also adjust how much dx and dy change during each key press or how fast time progresses by modifying the timer’s interval. Another easy change would be to modify the size of the landing pad or the lander.

Allow the lander to land on the bottom of the platform. This opens several new opportunities for changing the theme of the game. Maybe you are underwater in a buoyant craft and have to expend energy to go down, or maybe you can land from any angle because the platforms are somehow suspended in space.

Have the platform move. The platform could start with no motion but then move slowly after the user has some success. Have the platform speed up as the user is more successful. Then add random erratic motion to the platform.

Add obstacles to the game, perhaps having bits of floating debris the user must avoid. Similarly, you could add floating gas tanks for extra fuel, or other “powerups” that can make any landing safe, or provide some other short−term benefit.

Add support for a second player. Add another lander, and read some other keys for the second player’s controls. Award points only to the first player who lands in each round.

Write a similar game based on the same ideas. You should be able to write a variant of the classic arcade game Joust with the skills you’ve learned in this chapter. In essence, that game places the user on an ostrich with a lance. You have to flap the ostrich to move vertically, and you have to spear opponents from above.

202

Соседние файлы в предмете Программирование на C++