Development of games using Windows GDI (2)

Source: Internet
Author: User

 

Article 2

 

Now, we can start making a project. At the beginning, we need to build a framework program for game operation, which is similar to most games. As mentioned above, we do not intend to use the MFC framework, but rather use the Win32 API directly. Let's start to build this framework.

 

I believe you have installed Microsoft Visual C ++, vc6.0, and vc2003. I use vc2008. Here we will not talk nonsense about how to build the programming environment. I suppose you have already set up the environment.

 

First, use the Wizard to generate a Win32 GUI framework program.

 

I cut the picture, just a few mouse clicks, I believe no one will do it, Microsoft's things are so good, a lot of silly operations.

 

Step 1:

Select the created software type. Select the Win32 project.

 

Step 2: click Next. If you click Finish, A Win32 GUI framework is automatically generated.

 

Then, click the green triangle in the toolbar to compile and run it. A typical window program will come out.

 

But this is only the framework of a general program. We need to make some settings to make it a game program framework.

 

First, we need to set the window size to 800x600. In addition, we add a public header file commonhead. h for public data definition.

Public Data is defined as follows:

# Ifndef _ h_commonhead_h <br/> # DEFINE _ h_commonhead_h <br/> const int c_tile_w = 32; <br/> const int c_tile_h = 32; <br/> const int c_map_w = 25; <br/> const int c_map_h = 18; <br/> # endif <br/> 

 

 

Modify stdafx. h and add an include command.

# Include "commonhead. H"

 

 

Modify the window size.

Hwnd = createwindow (szwindowclass, sztitle, ws_overlappedwindow,

Cw_usedefault, 0, cw_usedefault, 0, null, null, hinstance, null );

Is

Hwnd = createwindow (szwindowclass, sztitle, ws_overlappedwindow,

Cw_usedefault, 0, c_tile_w * c_map_w, c_tile_h * c_map_h, null, null, hinstance, null );

 

 

Modify the window title to the Chinese name,

Delete loadstring (hinstance, ids_app_title, sztitle, max_loadstring );

Change to wsprintf (sztitle, _ T ("tank wars 1.0 "));

Then run and check out. Although monotonous, the framework is still a bit like a game. As for the menu, you can remove or retain it as you wish.

To remove the menu, you only need to modify

Wcex. lpszmenuname = makeintresource (idc_tankwar );

Wcex. lpszmenuname = NULL;

 

In the next article, we need to write a real game.

 

However, we need to write a map editor so that we can easily build our map for the game's main program to read. The map editor is written in MFC and provided. The code is not explained.

 

We analyze the terrain, which can be divided into the ground surface and obstacles. We still have a tree layer, but we observe that the tree layer is the same as the ground layer, but the display is different (the tree is painted on the top ).

But for ease of processing, we classify them as terrain.

There are seven kinds of terrain: land, steel walls, mountains, rivers, snow, forests, and e. Four digits are enough. We will assign a byte (8 bits) to the map ).

 

Therefore, the map occupies 25*18 = 450 bytes.

 

 

 

This map is very simple, but it only reflects the terrain, so it is not very difficult to write.

 

 

Download the map editor http://download.csdn.net/source/1775917click to download

 

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.