📄 tutorial.txt
字号:
Adding the bat
**************
What do we need to do to add a bat? Firstly we need to keep
track of where it is. Then we need to make it move when some
keys are pressed. Finally we need to draw it to the screen.
The bat module
==============
To do this within our modular structure, we'll create a new
module, which will do all of the above -- but it will be helped
by other modules, of course. The input module will be
responsible for checking the keys, and the display module will
tell the new bat module when to draw and erase the bat.
So the bat module will be called during the game loop to tell
it when to move the bat. It will (for now) check some global
variables, set by the input module, to decide which way to move
(if at all). It will also be called by the display module, to
tell it when to draw and erase the bat.
The objects module
==================
It will simplify things at this stage, though, if we create
another new module as well -- the objects module, which will
coordinate all of the objects in the game (just the bat at the
moment, of course). The bat module will only be called by the
objects module, which will be called by the game module (to
move all the objects) and by the display module (to display or
erase the objects).
Since the objects module is being called by two separate
modules, it will of course have a separate header file to
interface to each.
The global module
=================
In the previous version, the screen dimensions were hard-coded
into `display.c', and the arena dimensions were assumed to be
the same as the screen dimensions. This is not a good way to
proceed; note that the bat module needs to know the arena
dimensions so that it can prevent the bat from moving off the
side.
So I've also created yet another module -- the global module.
This one defines general global variables. It contains layout
variables, telling the screen dimensions and arena position and
dimensions. The declarations for these are in `layout.h',
which will of course be included in the bat module and the
display module, ensuring that they agree on the arena size, in
particular.
The global module and `layout.h' also define the length and
colour of the bat. These are slightly out of place, but we
won't move them elsewhere for a while yet.
The `inpvars.h' header file
===========================
This header file declares the global variables (defined in
`input.c') that the bat module uses to see whether or not it
should move the bat.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -