📄 objects.c
字号:
/*----------------------------------------------------------------
* objects.c -- object manipulation routines
*----------------------------------------------------------------
* These routines coordinate the movement of game objects.
* Just about anything that need coordinating counts as a
* game object. The actual processing of the objects is
* done by separate modules, one for each object. This
* module just keeps track of the objects.
*/
#include "objects.h"
#include "objdisp.h"
#include "gamevars.h"
#include "layout.h"
#include "bat.h"
#include "ball.h"
/* bat: (local)
* struct bat_t is defined in bat.h -- it holds information
* about the bat. This variable is local (static), not global,
* because not many modules need to know about it. When we ask
* the `bat' module to deal with the bat we'll pass the variable
* to the routine -- this will have more advantages later on.
*/
static struct bat_t bat;
/* ball: (local)
* See the description above, for `bat'.
*/
static struct ball_t ball;
/* objects_init:
* This function initialises all the objects in the game, with the
* help of some subsidiary modules.
*/
void objects_init() {
bat_setup (&bat, arena_width/2, arena_height - bat_height, bat_length, bat_colour);
ball_setup (&ball, arena_width/2, arena_height/2, 1, -1, ball_colour);
}
/* objects_shutdown:
* Yep, you guessed it -- this undoes what objects_init does.
*/
void objects_shutdown() {
ball_unsetup (&ball);
bat_unsetup (&bat);
}
/* objects_update:
* Called once every game cycle to update all the objects.
*/
void objects_update() {
bat_update (&bat);
ball_update (&ball);
/* Check whether the ball should bounce off the bat */
if ((((ball.y >= bat.y) && (ball.oy < bat.y))
|| ((ball.y <= bat.y) && (ball.oy > bat.y)))
&& (ball.x >= bat.x) && (ball.x <= bat.x + bat.l))
{
ball_bounce_y (&ball);
game_score++;
}
/* Check whether the player has missed the ball */
if (ball.y > arena_height) {
game_end_flag = 1;
}
}
/* objects_draw:
* Called by the display module to draw all the objects.
*/
void objects_draw (BITMAP *bmp) {
bat_draw (bmp, &bat);
ball_draw (bmp, &ball);
}
/* objects_erase:
* Called by the display module to erase all the objects.
*/
void objects_erase (BITMAP *bmp, BITMAP *bkgnd) {
bat_erase (bmp, bkgnd, &bat);
ball_erase (bmp, bkgnd, &ball);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -