1 /*************************************************************************** 2 bowl.h - description 3 ------------------- 4 begin : Tue Dec 25 2001 5 copyright : (C) 2001 by Michael Speck 6 email : kulkanie@gmx.net 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef __BOWL_H 19 #define __BOWL_H 20 21 #include "ltris.h" 22 23 enum { 24 KEY_NONE = -1, 25 KEY_LEFT, 26 KEY_RIGHT, 27 KEY_ROT_LEFT, 28 KEY_ROT_RIGHT, 29 KEY_DOWN, 30 KEY_DROP 31 }; 32 33 typedef struct { 34 int sx, sy; /* screen position */ 35 int sw, sh; /* tile size in pixels */ 36 int x, y; /* map position */ 37 float cur_y; /* float pixel y position IN bowl */ 38 int id; /* picture&structure id */ 39 int rot_id; /* 0 - 3 rotation positions */ 40 } Block; 41 42 typedef struct { 43 int transition; /* lines until first transition */ 44 int pieces; /* pieces placed */ 45 int i_pieces; /* how many i pieces */ 46 int cleared[4]; /* singles, doubles, triples, tetris */ 47 int tetris_rate; /* how many lines in tetrises */ 48 int droughts; /* number of droughts */ 49 int max_drought; /* max length of droughts */ 50 int sum_droughts; /* sum of all droughts for average */ 51 } BowlStats; 52 53 typedef struct { 54 int mute; /* if mute no sounds are played */ 55 int blind; /* if this is true all graphical stuff called in a function not 56 ending with hide/show is disabled. */ 57 Font *font; 58 int sx, sy; /* screen position of very first block tile */ 59 int sw, sh; /* screen size */ 60 int w, h; /* measurements in blocks */ 61 int block_size; /* blocksize in pixels */ 62 Controls *controls; /* reacts to these controls */ 63 int das_charge; /* current charge in ms */ 64 int das_maxcharge; /* maximum charge in ms */ 65 int das_drop; /* das charge drop if shifting piece */ 66 int are; /* in ms, if > 0 next piece is blocked until delay times out */ 67 int lock_delay; /* time on collision until piece is inserted */ 68 int stored_key; /* key that was stored this programme cycle */ 69 SDL_Surface *blocks; /* pointer to the block graphics */ 70 SDL_Surface *unknown_preview; /* if preview's unknown this is displayed */ 71 char name[32]; /* player's name for this bowl */ 72 Counter score; /* score gained by this player */ 73 int level; /* level to which player has played (starts at 0) */ 74 int firstlevelup_lines; /* number of lines needed for first level up */ 75 int lines; /* number of cleared lines in total */ 76 int cleared_line_y[4]; /* line indices of cleared lines for last insertion */ 77 int cleared_line_count; /* how many lines where cleared */ 78 int use_figures; /* draw a figure each new level? */ 79 int add_lines, add_tiles; /* add lines or tiles after time out? */ 80 int add_line_holes; /* number of holes in added line */ 81 int dismantle_saves; /* if a line was removed the delay is reset */ 82 Delay add_delay; /* delay until next add action */ 83 int contents[BOWL_WIDTH][BOWL_HEIGHT]; /* indices of blocks or -1 */ 84 Block block;/* current block */ 85 Delay block_hori_delay; /* horizontal movement delay */ 86 int next_block_id; /* id of next block */ 87 int use_same_blocks; /* use global block list? */ 88 int next_blocks_pos; /* position in tetris next_blocks for 89 mulitplayer games */ 90 float block_vert_vel, block_hori_vel; /* velocity per ms */ 91 float block_drop_vel; 92 int score_sx, score_sy, score_sw, score_sh; /* region with score and lines/level */ 93 int game_over; /* set if bowl is filled */ 94 int hide_block; /* block ain't updated */ 95 int paused; 96 int draw_contents; /* set if bowl needs a full redraw next bowl_show() */ 97 int help_sx, help_sy, help_sw, help_sh; /* position of helping shadow */ 98 int preview_center_sx, preview_center_sy; /* preview is centered here if preview_center_x != -1 */ 99 int preview_sx, preview_sy; /* actuall preview is drawn here */ 100 int cpu_dest_x; /* move block to this position (computed in bowl_select_next_block() */ 101 int cpu_dest_rot; /* destination rotation */ 102 int cpu_dest_score; /* AI score */ 103 Delay cpu_delay; /* CPU delay before moving down fast */ 104 Delay cpu_rot_delay; /* rotation delay of CPU */ 105 int cpu_down; /* move down fast? flag is set when delay expires */ 106 #ifdef SOUND 107 Sound_Chunk *wav_leftright; 108 Sound_Chunk *wav_explosion; 109 Sound_Chunk *wav_stop; 110 Sound_Chunk *wav_nextlevel; 111 Sound_Chunk *wav_excellent; 112 #endif 113 114 /* statistics */ 115 int stats_x, stats_y, stats_w, stats_h; 116 BowlStats stats; 117 int drought; /* current drought: pieces since last i piece */ 118 119 /* training */ 120 int zero_gravity; 121 } Bowl; 122 123 /* 124 ==================================================================== 125 Load level figures from file. 126 ==================================================================== 127 */ 128 void bowl_load_figures(); 129 /* 130 ==================================================================== 131 Initate block masks. 132 ==================================================================== 133 */ 134 void bowl_init_block_masks() ; 135 136 /* 137 ==================================================================== 138 Create a bowl at screen position x,y. Measurements are the same for 139 all bowls. Controls are the player's controls defined in config.c. 140 ==================================================================== 141 */ 142 Bowl *bowl_create( int x, int y, int preview_x, int preview_y, SDL_Surface *blocks, SDL_Surface *unknown_preview, char *name, Controls *controls ); 143 void bowl_delete( Bowl *bowl ); 144 145 /* 146 ==================================================================== 147 Check if key belongs to this bowl and store the value for use in 148 bowl_update(). 149 ==================================================================== 150 */ 151 void bowl_store_key( Bowl *bowl, int keysym ); 152 153 /* 154 ==================================================================== 155 Finish game and set game over. 156 ==================================================================== 157 */ 158 void bowl_finish_game( Bowl *bowl ); 159 160 /* 161 ==================================================================== 162 Hide/show/update all animations handled by a bowl. 163 If game_over only score is updated in bowl_update(). 164 ==================================================================== 165 */ 166 void bowl_hide( Bowl *bowl ); 167 void bowl_show( Bowl *bowl ); 168 void bowl_update( Bowl *bowl, int ms, int game_over ); 169 170 /* 171 ==================================================================== 172 Draw a single bowl tile. 173 ==================================================================== 174 */ 175 void bowl_draw_tile( Bowl *bowl, int i, int j ); 176 177 /* 178 ==================================================================== 179 Draw bowl contents to offscreen and screen. 180 ==================================================================== 181 */ 182 void bowl_draw_contents( Bowl *bowl ); 183 184 /* 185 ==================================================================== 186 Draw frames and fix text to bkgnd. 187 ==================================================================== 188 */ 189 void bowl_draw_frames( Bowl *bowl ); 190 191 /* 192 ==================================================================== 193 Toggle pause of bowl. 194 ==================================================================== 195 */ 196 void bowl_toggle_pause( Bowl *bowl ); 197 198 /* 199 ==================================================================== 200 Play an optimized mute game. (used for stats) 201 ==================================================================== 202 */ 203 void bowl_quick_game( Bowl *bowl, int aggr ); 204 205 /* 206 ==================================================================== 207 Actually insert block and remove a line if needed, 208 create shrapnells, give score etc 209 If game is over only insert block. 210 ==================================================================== 211 */ 212 void bowl_insert_block( Bowl *bowl ); 213 214 void bowl_draw_stats(Bowl *bowl); 215 216 void bowl_toggle_gravity(Bowl *bowl); 217 218 #endif 219