⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tutorial.txt

📁 乒乓球游戏程序
💻 TXT
字号:
Aesthetic updates
*****************

At first when developping a game it's best to get the game
mechanics working, and not worry about the graphics.  Now that
we have a working Pong game, the next few chapters will add
aesthetic improvements -- title screens, sprites, a menu
system, etc.

Making a title screen
=====================

Technically this is very easy.  We create a new module,
imaginatively called the title module, which will be
initialised, called and shutdown on startup, before the game is
played.  All it does is to load a bitmap on initialisation,
display it when it's told to, and unload it when it is shut
down.  In the `title_screen' function we'll also wait for a key
to be pressed before continuing.

In practice, though, we need to actually make a bitmap to
display.  I'm no artist!  Just get out your favourite paint
program, and draw something.  IMHO it doesn't matter what,
because you can always improve it later on -- it doesn't really
have anything to do with the code.  I won't tell you what sort
of things I think should go on a title screen; it's up to you.

Error handling
==============

Whenever you call a function that can fail, you should always
always always test for the failure, unless you're absolutely
sure that it doesn't matter.  Such functions include:

   * malloc -- returns NULL on failure

   * set_gfx_mode -- returns negative on failure

   * load_* (all Allegro loading functions) -- generally return
     NULL on failure

   * create_bitmap -- returns NULL on failure

Of course this list isn't complete, but you get the idea.  So
far in this Pong game I've done the tests and called `abort' on
critical failures (such as not being able to select the
graphics mode).  This isn't very helpful to the user; all they
see is the message "Abort!", and with the current
implementation of `abort' in djgpp v2.01, Allegro does not get
a chance to shut down.

A better system would be to handle the errors gracefully,
giving the user a meaningful error message.  The new error
module does just that.  When `error_x' is called, it returns to
text mode, prints a filename, a number, and one or two strings
on the screen, then exits smoothly.  If the second string is
NULL it is not printed; it's there because on some errors you
might want to print the contents of `allegro_error'.

The `error_x' function isn't meant to be called directly,
though; it's meant to be called via the `error' macro.  This
macro accepts two arguments (both strings, the second of which
may be NULL as above), and expands into a call to `error_x',
filling in the source filename and line number automatically
using the predefined macros `__FILE__' and `__LINE__'.

Fading in and out
=================

After the title screen fades in then out, the game screen is
displayed rather abruptly.  To soften this, I made it fade in
at the start of the game, quite quickly.  It also now fades out
when the game ends.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -