📄 nbreaker.h
字号:
} powertimes_t;#include <sys/time.h> /* For struct timeval. *//* The game state structure. This stores (surprise, surprise) the entire * game state. */typedef struct { /* The current game state (TITLESCREEN, RUNNING, etc.): */ int state; /* The name of the game directory: */ char *gamedir; /* The name of the game file: */ char *gamefile; /* The name of the image to use as the title screen background: */ char *titlebackground; /* Whether to tile the title screen background image: */ int titlebackgroundtiled; /* The name of the image to use as the title screen splash box: */ char *titlesplash; /* The name of the image to use as the game won splash box: */ char *gamewonsplash; /* The name of the image to use as the game lost splash box: */ char *gamelostsplash; /* The entire list of sprites: */ sprite *spritelist; /* The sprite containing the current background image: */ sprite *background; /* Whether the current background should be tiled or not: */ int backgroundtiled; /* The number of points gained when a normal brick is destroyed: */ int normalpoints; /* The number of extra points when a small bonus brick is destroyed: */ int smallbonuspoints; /* The number of extra points when a medium bonus brick is destroyed: */ int mediumbonuspoints; /* The number of extra points when a large bonus brick is destroyed: */ int largebonuspoints; /* The number of extra points when a huge bonus brick is destroyed: */ int hugebonuspoints; /* The number of points gained when a power-up is caught: */ int poweruppoints; /* The number of points gained (typically negative) when a power-down * is caught: */ int powerdownpoints; /* The number of balls to start the game with: */ int startballs; /* The number of extra balls given when a new level is started: */ int newlevelballs; /* The width of each brick: */ int brickwidth; /* The height of each brick: */ int brickheight; /* The list of global (ie. not per-level) bricks: */ brick *bricks; /* An alpha channel the same size as a brick, used when drawing a * brick which has reduced transparency because it's a multiple hit * brick which has been hit at least once but not yet destroyed: */ GR_ALPHA_ID brickalpha; /* The width in bricks of the brick area: */ int width; /* The height in bricks of the brick area: */ int height; /* The height of the bat: */ int batheight; /* The widths of each of the different sizes of bat: */ int batwidths[NUMBATS]; /* The current bat type in use: */ int bat; /* The current X coordinate of the centre of the bat: */ int batx; /* The speed the bat moves at when using the cursor keys: */ int batv; /* The speed the power boxes move at: */ int powerv; /* The period between animation frames: */ int animateperiod; /* The sprites containing the images used to draw each of the bats: */ sprite *bats[NUMBATS]; /* The sprites containing the images used to draw each of the powers: */ sprite *powersprites[NUMPOWERS]; /* The sprite containing the current splash image (or NULL): */ sprite *splash; /* The time in seconds that power-ups last for: */ int poweruptime; /* The time in seconds that power-downs last for: */ int powerdowntime; /* The cheat sequences: */ char *cheats[NUMCHEATS]; /* The current state of the cheat recogniser engine (see do_cheat() * for details): */ char cheatstate[MAXCHEATLEN + 1]; /* Various boolean flags (see the flags_t definition): */ flags_t flags; /* The full list of levels: */ level *levels; /* The current level number: */ int level; /* The total number of levels: */ int numlevels; /* The graphics context used for drawing everything: */ GR_GC_ID gc; /* The ID of the output window: */ GR_WINDOW_ID wid; /* The absolute X position of the output window (used to convert root * window coordinates into our window coordinates so we can get mouse * position events from the root window instead of our own which means * that the bat will continue to respond even when the pointer strays * outside our window): */ GR_COORD winx; /* The ID of the canvas (the double buffer pixmap used to draw * everything onto before it is copied to the screen- this speeds up * exposures a lot, and can potentially speed up blending a lot): */ GR_PIXMAP_ID canvas; /* The IDs of the two temporary canvasses used when fading in: */ GR_PIXMAP_ID oldcanvas; GR_PIXMAP_ID newcanvas; /* The ID of the one-second periodic timer used to decrement the power- * up and power-down timers: */ GR_TIMER_ID tid; /* The width in pixels of the canvas (and output window) area: */ int canvaswidth; /* The height in pixels of the canvas (and output window) area: */ int canvasheight; /* The current game grid: */ grid *grid; /* The number of bricks left to be destroyed in the current level: */ int numbricks; /* The list of powers displayed on the screen (or NULL): */ power *powers; /* Various ball information (see the ball_t definition): */ ball_t ball; /* The number of balls currently left: */ int numballs; /* Various scores information (see the scores_t definition): */ scores_t scores; /* The time that animate() was last called (used to determine how * long the GrGetNextEvent timeout should be): */ struct timeval lastanim; /* The power-up and power-down timers: */ powertimes_t powertimes; /* The rate to fade screens in at: */ int faderate; /* The fade level used fading a screen in: */ int fadelevel; /* The next state after the fading has finished: */ int nextstate;} nbstate;/* The flags that can be associated with a brick: *//* Immutable, ie. the brick can't be destroyed unless the PowerBall power-up * is active: */#define BRICK_FLAG_IMMUTABLE (1 << 0)/* 2 hits are required to destroy the brick (except with PowerBall): */#define BRICK_FLAG_2_HITS (1 << 1)/* 3 hits are required to destroy the brick (except with PowerBall): */#define BRICK_FLAG_3_HITS (1 << 2)/* A small points bonus is given when this brick is destroyed: */#define BRICK_FLAG_SMALL_BONUS (1 << 3)/* A medium points bonus is given when this brick is destroyed: */#define BRICK_FLAG_MEDIUM_BONUS (1 << 4)/* A large points bonus is given when this brick is destroyed: */#define BRICK_FLAG_LARGE_BONUS (1 << 5)/* A huge points bonus is given when this brick is destroyed: */#define BRICK_FLAG_HUGE_BONUS (1 << 6)/* Symbolic names for the different bat sizes: */enum { /* The normal sized bat used most of the time: */ NORMALBAT = 0, /* The small bat used when the NarrowBat power-down is active: */ SMALLBAT, /* The large bat used when the WideBat power-up is active: */ LARGEBAT};/* Symbolic names for the different power-ups and power-downs: */enum { /* No power-up or power-down: */ NOPOWER = -1, /* WideBat (makes the bat larger): */ POWERW, /* SlowMotion (makes the ball move more slowly): */ POWERS, /* sTickyBat (makes the ball stick to the bat when it hits it): */ POWERT, /* PowerBall (makes the ball destroy any brick with one hit): */ POWERP, /* NarrowBat (makes the bat narrower): */ POWERN, /* FastMotion (makes the ball move faster): */ POWERF,};/* Symbolic names for the different cheats: */enum { /* SolidFloor (makes the ball bounce off the floor under the bat): */ SFCHEAT = 0, /* TelePort (skips to the next level): */ TPCHEAT, /* NoBounce (makes the ball go straight through the bricks): */ NBCHEAT, /* NoPowerDown (stops power-downs from being activated): */ NPDCHEAT, /* NoPowerUpTimeOut (stops power-ups from timing out): */ NPUTOCHEAT};/* Symbolic names for the different game states: */enum { /* The title screen is being displayed: */ STATE_TITLESCREEN, /* The next screen is being faded in: */ STATE_FADING, /* The game is being played: */ STATE_RUNNING, /* The game is over; the player won (completed all levels): */ STATE_GAMEWON, /* The game is over; the player lost: */ STATE_GAMELOST, /* The program is about to exit: */ STATE_FINISHED};/* The function prototypes: *//* animate.c */void animate(nbstate *state);/* ball.c */void lost_ball(nbstate *state);void park_ball(nbstate *state);void move_ball(nbstate *state);void calc_new_ball_coords(nbstate *state, coords *c);int check_ball_collision(nbstate *state, coords *c);void redraw_ball(nbstate *state);/* bat.c */void change_bat(nbstate *state, int newbat);void move_bat(nbstate *state, int x);/* brick.c */int brick_collision(nbstate *state, grid *g);/* cheat.c */void do_cheat(nbstate *state, GR_KEY key);/* draw.c */void draw_background(nbstate *state, int x, int y, int w, int h);void draw_splash(nbstate *state);void draw_brick(nbstate *state, grid *g, int x, int y, int w, int h);void draw_bricks(nbstate *state, int x, int y, int w, int h);void draw_bat(nbstate *state);void draw_ball(nbstate *state);void draw_balls(nbstate *state);void draw_scores(nbstate *state);void draw_power(nbstate *state, power *p, int x, int y, int w, int h);void draw_canvas(nbstate *state, int x, int y, int w, int h);#ifdef NB_DEBUG/* dump.c */void dump_state(nbstate *state);#endif/* event.c */void handle_exposure_event(nbstate *state, GR_EVENT_EXPOSURE *ev);void handle_button_event(nbstate *state, GR_EVENT_BUTTON *ev);void handle_mouse_event(nbstate *state, GR_EVENT_MOUSE *ev);int handle_keystroke_event(nbstate *state, GR_EVENT_KEYSTROKE *ev);void handle_update_event(nbstate *state, GR_EVENT_UPDATE *ev);void handle_timer_event(nbstate *state, GR_EVENT_TIMER *ev);/* game.c */void reset_game(nbstate *state);/* init.c */nbstate *init(int argc, char *argv[]);/* levels.c */void increment_level(nbstate *state);void set_level_active(nbstate *state);/* loader.c */int load_game_file(nbstate *state);/* misc.c */void myfree(void *p);void oom(void);/* powers.c */void activate_widebat(nbstate *state);void activate_slowmotion(nbstate *state);void activate_stickybat(nbstate *state);void activate_powerball(nbstate *state);void activate_narrowbat(nbstate *state);void activate_fastmotion(nbstate *state);void do_power_timers(nbstate *state);void new_power(nbstate *state, int type, int x, int y);void redraw_powers(nbstate *state, int x, int y, int w, int h);void destroy_power(nbstate *state, power *p);void power_collision(nbstate *state, power *p);void animate_powers(nbstate *state);/* scores.c */void increment_score(nbstate *state, int points);void load_hiscore(nbstate *state);void save_hiscore(nbstate *state);/* sprite.c */sprite *make_empty_sprite(nbstate *state, char *fname, int width, int height);sprite *load_sprite(nbstate *state, char *fname, int width, int height);void destroy_sprite(nbstate *state, sprite *s);void destroy_all_sprites(nbstate *state);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -