📄 tutorial.txt
字号:
Rules of the game
*****************
Now we have a bat and a ball that bounces around as required,
it's time to add some rules to the game. We'll make the game
end when the ball goes off the bottom of the screen (of course,
we'll stop it bouncing first!) and give the player a score which
increases each time the ball hits the bat.
Making it possible to lose
==========================
So the first thing we do is take out the test in `ball.c' that
makes the ball bounce off the bottom of the arena. Then we put
a similar test in `objects.c', which will then set the
`game_end_flag' variable to end the game when this happens.
Keeping score
=============
The player's score will be a global variable, defined in
`game.c' and declared in `gamevars.h', like `game_end_flag'.
It will start at 0, of course. Increasing it when the ball
hits the bat is simple; it just needs an extra line in
`objects.c', where the ball is made to bounce.
Displaying the score on the screen
==================================
This requires some modifications to `display.c'. I've reduced
the height of the arena slightly and moved it down the screen to
make way for a status bar, on which we can write the score.
Notice the use of subbitmaps. I don't think I mentioned this
earlier; the arena bitmap is a subbitmap of the screen. We can
pass this directly to the objects module and it can draw onto
it without needing to know where it is on the screen. In fact
the real power of this method is that we can easily make the
arena bitmap be independent of the screen, and implement a
different system, such as double buffering or dirty rectangling.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -