Create your first game Pong-game concept

Source: Internet
Author: User
Game Concept

It seems a bit silly to discuss the content of a game like Pong, but I try to keep things as regular as possible. Before you start coding, consider how the game looks and feels important. The larger the game project, the more important the design stage is. I am not saying that you cannot write games or applications without any concept. In fact, most beginners start by writing something and then improving it over and over again until it looks very good. The problem is that it is almost impossible to find the best solution in the first attempt.

Pong's game logic is very simple and does not require too much text or images (as shown in 2-1 ). This makes coding and game ideas easy. Consider all the components required by the game (such as balls, rackets, and screen borders) and your initial ideas.


Figure 2-1

Write down your ideas

Writing down creative concepts does not mean that you have to write down all ideas and draw UML diagrams frantically until everything is planned. I am totally opposed to this approach, because you cannot think of everything. In addition, beginners may not know how to pre-design the entire game in the best way. Instead, you may have a very clear picture of your game in your mind, and when you spend enough time designing your mind, you can get started.

If there are other people working together in your game project, it will be difficult to explain the game concept and keep everyone's thoughts synchronized. For this reason alone, you should develop a habit of writing your game ideas on just one page.

You can not only show this to others, but also write more content, but you have to consider other things-when you write a part of a game idea, you will see that things on paper are more complex than you think in your mind, and you have to consider additional subordination.

For example, in Pong games, you know that you need two rackets and one ball, which are moving between the rackets. However, you may think of more game details only when you write down your initial idea and consider the texture of the genie.

How many lives does a player have? How can I check if the ball hits the edge of the racket and how to deal with it? Does the speed of a racket affect the speed and direction of the ball? When gamers on both sides are bored, is it necessary to increase the speed of the game at regular intervals? Of course, after you finish the first game version, you can improve it in many ways. However, it is much easier to consider all this before you start writing complex code, and you will find that you do not even need to do so.

As an example, I will write down the design concept of the Pong game that you will develop in this chapter. You may want to spend 5 to 10 pages of space to write more complex games, but do not write the idea text of 100 pages without a line of code. It takes too much time and it is difficult to manage these ideas. Using "Agile Methodology", you will often update your ideas and modify some details. I usually start to draw a UML diagram after the code completes at least 50%, the overview diagram and documents are not updated until the end of the project.

Game concept: Pong

This game is a simple Pong game clone version that supports one or two players. In single player mode, the computer controls another racket. In multiplayer mode, two players can either use the gamepad or use different buttons on the same keyboard on the PC, or play on the Xbox 360 console.

The game uses 2D images and sound files for the ball and racket to support special effects that hit the ball or lost a life. There is also a very simple menu that allows you to choose from:

  • Single-user mode

  • Multiplayer Mode

  • Exit

The menu uses a simple texture image. The background is a dark space, and most of the images are bright. Try to make the game as interesting as possible.

Game features and gameplay

The Game has two screen modes: Menu and Game. The menu is previously mentioned. It contains several menu entries. The game consists of a ball, two rackets, and a simple scoring system. Take a look at this simple sketch and you will try to complete the task (Figure 2-2 ):


Figure 2-2

Technology

Obviously, you will use XNA Game Studio Express; no additional class libraries are required, because you only render some simple sprite genie, and 3D models or Shaders are not involved here. Gaming should be available on both Windows and the Xbox 360 console.

As you can see, I have managed to put everything in one page. This is a rule when I write about the concept of a game: first, I put everything in one page, then write some code. If your team or external partners (for example, if you want to show the concept to a game publisher) need it, you can write a 5-10 page White Paper, contains some initial ideas and sketches.

I will never talk about coding at the game conception stage. I just need to determine what technology will be used. Now it is time to consider the issue of execution. Do not consider your actual capabilities when writing game ideas, because this will limit you to too many. Leave them behind.

A more complete example of a game concept is the concept of a Rocket Commander (see Figure 2-3 ). You can view the PDF files in the folders in this chapter. It consists of four pages and a cover, which depicts all concepts of the Rocket Commander. As you can see from the cover, the game looks very different from its conception, but the general idea of the game is embodied.


Figure 2-3

Agile Methodology

Agile Methodology is a conceptual framework for software development. The basic idea is to avoid a large planning stage, because it often brings dangerous and unrealistic project schedules, making it difficult to follow. For a small project, you may only need to repeat it for a short time. However, as the project grows, you may find that you always put yourself in front of the problem, these problems may take months or even years to solve, and they are difficult to plan.

Instead of planning everything to the most detailed level, you only need some rough ideas. During the entire agile development process, each part of the concept is gradually refined and repeated multiple times. With the help of unit testing, the Code is designed, and then the actual code is compiled for implementation, finally, test and write this part of the document. Such repetition should not be more than a few weeks, and all parts of a large project will repeat the process.

Agile Methods also include other ideas about how to make developers and customers, testers, project managers, and designers better work together. Several rules can be used in the agile framework to avoid overall confusion. Because the design phase has been shortened, it seems that there is no detailed plan for the project, similar to the chaotic strong code. But in fact, the design process runs through more projects and is better than designing at the beginning, and has to endure all the errors produced for the entire project planning phase, it is much more useful.

I will not talk too much about agile methodologies in this book, but I will first use unit tests and simple concepts, unit test design, and then code repeatedly throughout all the projects in this book. For more information about unit testing, I recommend that you visit the site http://martinfowler.com of Martin Fowler.

Martin has written several books and I recommend Refactoring: Improving the Design of Existing Code. You can also find it on the website. You can also find more links and information about the agile software development process on his site.

Solve initial difficulties

Now you have the idea of a game, but you have not yet spent time on getting images and sound files, and how to implement them. What should we do if the ball hits the edge of the racket? Do you need to design a simple physical engine for the ball?

After the design phase, all these problems will emerge, and for more complex projects, it may take weeks or even months to solve some basic problems. For example, I made the first. Net 2.0 game Rocket Commander. I had a good idea of displaying thousands of aliens on the screen, and there are millions of them in total. I have a cool idea that they will collide and rebound, but it is not clear how to optimize it. After my initial test, I found that I could not even render more than 100 minor planets without significantly degrading performance. At this time, I did not rewrite my game idea, nor did I create a number of minor planets, annoying games (if there are not many minor planets, it is not a real game-this is the Rocket Commander's game principle ), instead, we tried to classify the minor by Shaders and Material Settings and then render them to solve the problem. If they are invisible, empty them as early as possible and apply only the processing of the physical process to adjacent planets.

Although after a week of work and optimization, the processing of the physical process is still too slow until the minor is rendered with good execution efficiency. Even if the best optimization processing is applied, the collision between each frame may still appear too much if we update between 5,000 and 10,000 of the planets within the visible range of each frame. I still want to hit each other and run normally after the collision. If I only check a certain number of minor planets at each frame, the algorithm will often miss the collision and only capture the collision when both of them have penetrated into each other. It brings more trouble than even the physical removal process. I almost gave up, because I have spent 50% of the time in the project to solve this problem. But then I came up with another idea to split the whole space into several regions. Each region has a specific number of minor planets. Each time an minor leaves a region, it is removed from this region and added to a new region. In this way, the minor only needs to detect the collision of their own and all adjacent areas. It sounds like there are many collision detection operations, but the regional logic is used) it is true that the performance of the physical process is increased by 100 times, and there will be more after optimization.

In most of the game projects I am currently participating in, I will spend more than half of my time solving the initial problems and split them into smaller ones, which will be solved again.

Later, by correctly placing these small fragments together, the game itself will be combined. In about a few days, it will be like magic, and the whole game is complete.

Although it may be possible to complete a game as quickly as possible, there may be a sense of frustration if you cannot see the running results of the game for a long time. In the past, I always modified the game repeatedly until I was satisfied with the results. This does take a long time. Thanks to the agile development process, now I can solve these problems and there is no need to repeat the endless improvement cycle.

What does this mean for your Pong game? Well, the game is very simple, and you don't need to spend a lot of time improving it for 100 times, but you only need to implement a basic version of Pong, hard-coded for the computer) a racket moves up and down along the ball on the left and controls the racket on the right.

After you have improved and tested the single player mode, you may want to add support for the dual player mode, but this is very difficult because you are hardcoded. You may comment out this part of the code, or even delete it, and reconstruct the gameplay code. After testing the dual-game mode, you may want to add a menu, and you can adjust the code position again to re-implement the game code.

Although all these are good practices and force you to constantly refactor your code (refactoring means modifying the code layer without changing the functionality to make it easy to maintain; refer to Martin Fowler's book, Refactoring). It is much easier to focus on only one part of the game at a time and use several versions of parallel testing. In the next part of this chapter, you will do this and hope that you can understand what I mean. Thanks to unit testing, code refactoring is more natural and makes your code easier to use. It also allows you to see the running results faster.

In the following section, one of the problems you want to solve is how to handle the physical motion of the ball and how to detect the part that hits the racket.

Create texture

Before you start coding, you need some textures to display on the screen. Even if you use dummy bitmap or images from other places, it is important to consider the final image, such as the size of the ball and racket, and so on.

Once again, your Pong game is quite simple, but a more complex game may require an art idea, a lot of sketches, and one that can manage these art works and complete them in time, this allows game programmers to implement them. Looking back at the early days of computer games, almost all games were completed by one person. Although this is the easiest way, today no formal game can be developed by only one person. Most outstanding art designers are not programmers, and most programmers are not good art designers. It doesn't matter if you only make a simple game, but the larger your project, you need more time to find partners, skilled art designers and model makers, and organize it all.

Take a look at the game image (see Figure 2-4 ),


Figure 2-4

You will use three texture files: (1) SpaceBackground. dds seek for rackets and balls. Additionally, you can import two audio files (pongballhit.wavand pongballlost.wav) to the project and add a simple XACT project to play the audio. To learn more about sounds and XACT, read chapter 9.

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.