My C language learning history: Games

Source: Internet
Author: User

Try to write your own game

Knowing how to display a graphic gives rise to the idea of a 2D graphic game.

I used graphic materials in the flash game "Death vsfire movie" and provided them online.

There are not many available memory for the learning machine, so I can only save on memory usage. For graphic display, I use the following methods:

Call the related action function to obtain the Image array of the specified frame. After the image is painted to the background image, it is directly released. At this time, the memory occupied is only the memory occupied by a frame image.

I tested it and used a black-yundun standing animation. The background was completely white:

After adding an animation for a moving action, it takes a lot of time to make a graph to the left, considering that only the person is directed to the right and not to the left, so I want a graphics horizontal flip algorithm, I used his mind to think about it, it is not difficult, just need to replace the pixels of each line of the picture left and right, horizontal flip graphics code here: http://blog.csdn.net/liuchao35758600/article/details/6685536

During the test of this program, a problem occurs when the character moves to the edge of the screen and the display is abnormal. After a lot of time and careful research, the problem is finally solved as follows:

Even if it is displayed in the upper left corner of the screen, there will be no display problem, that is, there is a problem with the data processing method. If the image is out of the display range, you can crop it.

Graphics Processing of 2D games involves mostly knowledge about graphics processing algorithms, such as image mixing and image cropping.

After that, if you are free and interested, you will continue to write the game, until the preparation of the game has been suspended in recent months, because I want to write my own GUI library;

This is the current effect of the game:

The background image is edited by PS. It takes a little time. As for text, it is also edited by PS in advance.

The red cursor behind the text "press the OK key to continue", with a flickering animation effect, is achieved by adjusting the transparency of the red cursor, And the Alpha value increases from 0 to 255, for the fade-in effect, on the contrary, from 255 to 0. For the fade-out effect, the two effects are used repeatedly and then changed to the flashing animation effect.

After pressing the OK key, the entire screen will fade out, and then use the fade in effect to enter the main menu. select the option cursor or the red cursor with the flashing animation effect, when moving the cursor, I used a translation animation, with the cursor blinking and moving.

After the game starts, it is the effect. At first, there was no character status bar, which was added later. After the status bar was added, the refreshing speed of the game screen became slower, I don't know how to improve the image refresh efficiency.

The original motion animation is released at one time. I think this is too dead. I will separate the movements and skills of the characters, separately handle the display, and hold down the U key, once every other time, the Moon and teeth are released. After being released, the characters can be moved to contact them.

The game has not yet added artificial intelligence, attack and attack processing. Now, looking at the game's source code, we still feel that some code is not well written. We plan to make most of the changes to the game's source code in the future.

If you need the source code, please leave a message. It seems that there is still the source code. However, if you test it on the computer end, you can only go to the main menu. When you enter the game, a segment error will occur, because the screen resolution of the computer is larger than that of the learning machine, code writing is based on the screen size of the learning machine. A large screen size may cause data processing errors. The environment required for source code compilation is a Linux-based system environment, which cannot be compiled in Windows because the header file is different from the function.

Not complete, To be continued ......


The previous Games (mostly online games) have some ideas in their minds. I think there are still many improvements to this game, sometimes it is very hard for game developers to improve their games based on my suggestions. Of course, this is impossible. Instead of asking them to change their games, it is better to write their own games, isn't it good to design a game based on your own ideas?

Now, with C language, you can write 2D games by yourself, write core code, and call graphics for display. Writing programs and your own ideas are very important, you can use the correct code to describe your thoughts to get the desired results. errors or warnings occur during compilation, which are syntactic errors and can be easily solved, the errors that occur during the running process of the program are the logic issue of the code. You need to debug the code yourself and find the location where the error occurs. This is difficult and hard-working, I once spent a whole day testing to solve a small problem.

Related Article

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.