00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "misc.h"
00031
00032 SDL_Rect makerect(int x, int y, int w, int h){
00033 SDL_Rect rect;
00034 rect.x = x;
00035 rect.y = y;
00036 rect.w = w;
00037 rect.h = h;
00038 return(rect);
00039 }
00040
00041 void wait_frame(){
00042 static Uint32 next_tick = 0;
00043 Uint32 this_tick;
00044 this_tick = SDL_GetTicks();
00045 if(this_tick < next_tick){
00046 SDL_Delay(next_tick - this_tick);
00047 }
00048 next_tick = this_tick + (1000/FRAMES_PER_SECOND);
00049 }
00050
00051 char* get_level_filename(int level_number){
00052 static char prefix[11] = "maps/level";
00053 static char suffix[5] = ".ppm";
00054 int len, i, current_index = 0;
00055 char *str_temp = new char[30];
00056 char *filename = new char[30];
00057 sprintf(str_temp, "%d", level_number);
00058 len = (int)strlen(str_temp);
00059 for(i=0; i<10; i++) filename[current_index++] = prefix[i];
00060 for(i=0; i<len; i++) filename[current_index++] = str_temp[i];
00061 for(i=0; i<4; i++) filename[current_index++] = suffix[i];
00062 return(filename);
00063 }
00064
00065
00066 tile_info* process_tile(int index, int first_flag, char* tilename){
00067 tile_info* info = new tile_info;
00068 if(MISC_DEBUG)printf("In process_tile: %d %d %d: ", index, first_flag, tilename);
00069 if(strcmp(tilename,"data/TEMP") == 0) index = 250;
00070 if((index >= BACKGROUND_BEGIN) && (index <= BACKGROUND_END)){
00071 info->first_prop = 1;
00072 info->second_prop = 1; info->third_prop = 0;
00073 info->first_min = 0; info->first_max = 1;
00074 info->second_min = BG_MIN_DAMAGE; info->second_max = BG_MAX_DAMAGE;
00075 info->third_min = 0; info->third_max = 0;
00076 info->first_string = "walkable";
00077 info->second_string = "damage";
00078 info->third_string = " ";
00079 info->num_images = 1;
00080 info->suffix = new char*[1];
00081 info->suffix[0] = ".gif";
00082 if(MISC_DEBUG) printf("background\n");
00083 }
00084 if(index >= ENEMY_BEGIN && index <= ENEMY_END){
00085 info->first_prop = 0;
00086 if(first_flag == 1) info->first_prop = 1;
00087 info->second_prop = 1; info->third_prop = 1;
00088 info->first_min = 0; info->first_max = 1;
00089 info->second_min = ENEMY_MIN_HTPTS; info->second_max = ENEMY_MAX_HTPTS;
00090 info->third_min = ENEMY_MIN_DAMAGE; info->third_max = ENEMY_MAX_DAMAGE;
00091 info->first_string = "ranged";
00092 info->second_string = "hitpoints";
00093 info->third_string = "damage";
00094 info->suffix = new char*[27];
00095 info->suffix[0] = "_n_1.gif";
00096 info->suffix[1] = "_n_2.gif";
00097 info->suffix[2] = "_n_3.gif";
00098 info->suffix[3] = "_ne_1.gif";
00099 info->suffix[4] = "_ne_2.gif";
00100 info->suffix[5] = "_ne_3.gif";
00101 info->suffix[6] = "_e_1.gif";
00102 info->suffix[7] = "_e_2.gif";
00103 info->suffix[8] = "_e_3.gif";
00104 info->suffix[9] = "_se_1.gif";
00105 info->suffix[10] = "_se_2.gif";
00106 info->suffix[11] = "_se_3.gif";
00107 info->suffix[12] = "_s_1.gif";
00108 info->suffix[13] = "_s_2.gif";
00109 info->suffix[14] = "_s_3.gif";
00110 info->suffix[15] = "_sw_1.gif";
00111 info->suffix[16] = "_sw_2.gif";
00112 info->suffix[17] = "_sw_3.gif";
00113 info->suffix[18] = "_w_1.gif";
00114 info->suffix[19] = "_w_2.gif";
00115 info->suffix[20] = "_w_3.gif";
00116 info->suffix[21] = "_nw_1.gif";
00117 info->suffix[22] = "_nw_2.gif";
00118 info->suffix[23] = "_nw_3.gif";
00119 if(first_flag == 1){
00120 info->num_images = 27;
00121 info->suffix[24] = "_range_1.gif";
00122 info->suffix[25] = "_range_2.gif";
00123 info->suffix[26] = "_range_3.gif";
00124 } else {
00125 info->num_images = 24;
00126 }
00127 if(MISC_DEBUG) printf("enemy\n");
00128 }
00129 if(index >= KEY_BEGIN && index <= KEY_END){
00130 info->first_prop = 0; info->second_prop = 0; info->third_prop = 0;
00131 info->first_min = 0; info->first_max = 0;
00132 info->second_min = 0; info->second_max = 0;
00133 info->third_min = 0; info->third_max = 0;
00134 info->first_string = " ";
00135 info->second_string = " ";
00136 info->third_string = " ";
00137 info->num_images = 1;
00138 info->suffix = new char*[1];
00139 info->suffix[0] = ".gif";
00140 if(MISC_DEBUG) printf("key\n");
00141 }
00142 if(index >= TELEPORTER_BEGIN && index <= TELEPORTER_END){
00143 info->first_prop = 0; info->second_prop = 1; info->third_prop = 1;
00144 info->first_min = 0; info->first_max = 0;
00145 info->second_min = 0; info->second_max = 1000;
00146 info->third_min = 0; info->third_max = 1000;
00147 info->first_string = " ";
00148 info->second_string = "x coor";
00149 info->third_string = "y coor";
00150 info->num_images = 3;
00151 info->suffix = new char*[3];
00152 info->suffix[0] = "_1.gif";
00153 info->suffix[1] = "_2.gif";
00154 info->suffix[2] = "_3.gif";
00155 if(MISC_DEBUG) printf("teleporter\n");
00156
00157 }
00158 if(index >= EXIT_BEGIN && index <= EXIT_END){
00159 info->first_prop = 0; info->second_prop = 1; info->third_prop = 0;
00160 info->first_min = 0; info->first_max = 0;
00161 info->second_min = 0; info->second_max = EXIT_MAX;
00162 info->third_min = 0; info->third_max = 0;
00163 info->first_string = " ";
00164 info->second_string = "next level";
00165 info->third_string = " ";
00166 info->num_images = 1;
00167 info->suffix = new char*[1];
00168 info->suffix[0] = ".gif";
00169 if(MISC_DEBUG) printf("exit\n");
00170 }
00171 if(index >= SCROLL_BEGIN && index <= SCROLL_END){
00172 info->first_prop = 0; info->second_prop = 0; info->third_prop = 0;
00173 info->first_min = 0; info->first_max = 0;
00174 info->second_min = 0; info->second_max = 0;
00175 info->third_min = 0; info->third_max = 0;
00176 info->first_string = " ";
00177 info->second_string = " ";
00178 info->third_string = " ";
00179 info->num_images = 1;
00180 info->suffix = new char*[1];
00181 info->suffix[0] = ".gif";
00182 if(MISC_DEBUG) printf("scroll\n");
00183 }
00184 if(index >= DOOR_BEGIN && index <= DOOR_END){
00185 info->first_prop = 1; info->second_prop = 0; info->third_prop = 0;
00186 info->first_min = 0; info->first_max = 1;
00187 info->second_min = 0; info->second_max = 0;
00188 info->third_min = 0; info->third_max = 0;
00189 info->first_string = "need key";
00190 info->second_string = " ";
00191 info->third_string = " ";
00192 info->num_images = 3;
00193 info->suffix = new char*[3];
00194 info->suffix[0] = "_1.gif";
00195 info->suffix[1] = "_2.gif";
00196 info->suffix[2] = "_3.gif";
00197 if(MISC_DEBUG) printf("door\n");
00198 }
00199 if(index >= POWERUP_BEGIN && index <= POWERUP_END){
00200 info->first_prop = 0; info->second_prop = 1; info->third_prop = 0;
00201 info->first_min = 0; info->first_max = 0;
00202 info->second_min = POWERUP_MIN; info->second_max = POWERUP_MAX;
00203 info->third_min = 0; info->third_max = 0;
00204 info->first_string = " ";
00205 info->second_string = "point change";
00206 info->third_string = " ";
00207 info->num_images = 1;
00208 info->suffix = new char*[1];
00209 info->suffix[0] = ".gif";
00210 if(MISC_DEBUG) printf("powerup\n");
00211 }
00212 if(index >= GOLD_BEGIN && index <= GOLD_END){
00213 info->first_prop = 0; info->second_prop = 1; info->third_prop = 0;
00214 info->first_min = 0; info->first_max = 0;
00215 info->second_min = GOLD_MIN; info->second_max = GOLD_MAX;
00216 info->third_min = 0; info->third_max = 0;
00217 info->first_string = " ";
00218 info->second_string = "value";
00219 info->third_string = " ";
00220 info->num_images = 1;
00221 info->suffix = new char*[1];
00222 info->suffix[0] = ".gif";
00223 if(MISC_DEBUG) printf("gold\n");
00224 }
00225 if(index >= GENERATOR_BEGIN && index <= GENERATOR_END){
00226 info->first_prop = 0; info->second_prop = 1; info->third_prop = 1;
00227 info->first_min = 0; info->first_max = 0;
00228 info->second_min = GEN_MIDX_MIN; info->second_max = GEN_MIDX_MAX;
00229 info->third_min = GEN_MIN_HTPTS; info->third_max = GEN_MAX_HTPTS;
00230 info->first_string = " ";
00231 info->second_string = "monster index";
00232 info->third_string = "hitpoints";
00233 info->num_images = 1;
00234 info->suffix = new char*[1];
00235 info->suffix[0] = ".gif";
00236 if(MISC_DEBUG) printf("generator\n");
00237 }
00238 if(index >= TRAPS_BEGIN && index <= TRAPS_END){
00239 info->first_prop = 0; info->second_prop = 1; info->third_prop = 0;
00240 info->first_min = 0; info->first_max = 0;
00241 info->second_min = TRAP_MIN_DAMAGE; info->second_max = TRAP_MAX_DAMAGE;
00242 info->third_min = 0; info->third_max = 0;
00243 info->first_string = " ";
00244 info->second_string = "damage";
00245 info->third_string = " ";
00246 info->num_images = 1;
00247 info->suffix = new char*[1];
00248 info->suffix[0] = ".gif";
00249 if(MISC_DEBUG) printf("trap\n");
00250 }
00251 if(index == PIEDMONT){
00252 info->first_prop = 1;
00253 info->second_prop = 1; info->third_prop = 1;
00254 info->first_min = 0; info->first_max = 1;
00255 info->second_min = PIEDMONT_MIN_HTPTS; info->second_max = PIEDMONT_MAX_HTPTS;
00256 info->third_min = PIEDMONT_MIN_DAMAGE; info->third_max = PIEDMONT_MAX_DAMAGE;
00257 info->first_string = "ranged";
00258 info->second_string = "hitpoints";
00259 info->third_string = "damage";
00260 info->suffix = new char*[51];
00261 info->suffix[0] = "_walk_n_1.gif";
00262 info->suffix[1] = "_walk_n_2.gif";
00263 info->suffix[2] = "_walk_n_3.gif";
00264 info->suffix[3] = "_walk_ne_1.gif";
00265 info->suffix[4] = "_walk_ne_2.gif";
00266 info->suffix[5] = "_walk_ne_3.gif";
00267 info->suffix[6] = "_walk_e_1.gif";
00268 info->suffix[7] = "_walk_e_2.gif";
00269 info->suffix[8] = "_walk_e_3.gif";
00270 info->suffix[9] = "_walk_se_1.gif";
00271 info->suffix[10] = "_walk_se_2.gif";
00272 info->suffix[11] = "_walk_se_3.gif";
00273 info->suffix[12] = "_walk_s_1.gif";
00274 info->suffix[13] = "_walk_s_2.gif";
00275 info->suffix[14] = "_walk_s_3.gif";
00276 info->suffix[15] = "_walk_sw_1.gif";
00277 info->suffix[16] = "_walk_sw_2.gif";
00278 info->suffix[17] = "_walk_sw_3.gif";
00279 info->suffix[18] = "_walk_w_1.gif";
00280 info->suffix[19] = "_walk_w_2.gif";
00281 info->suffix[20] = "_walk_w_3.gif";
00282 info->suffix[21] = "_walk_nw_1.gif";
00283 info->suffix[22] = "_walk_nw_2.gif";
00284 info->suffix[23] = "_walk_nw_3.gif";
00285 info->suffix[24] = "_attack_n_1.gif";
00286 info->suffix[25] = "_attack_n_2.gif";
00287 info->suffix[26] = "_attack_n_3.gif";
00288 info->suffix[27] = "_attack_ne_1.gif";
00289 info->suffix[28] = "_attack_ne_2.gif";
00290 info->suffix[29] = "_attack_ne_3.gif";
00291 info->suffix[30] = "_attack_e_1.gif";
00292 info->suffix[31] = "_attack_e_2.gif";
00293 info->suffix[32] = "_attack_e_3.gif";
00294 info->suffix[33] = "_attack_se_1.gif";
00295 info->suffix[34] = "_attack_se_2.gif";
00296 info->suffix[35] = "_attack_se_3.gif";
00297 info->suffix[36] = "_attack_s_1.gif";
00298 info->suffix[37] = "_attack_s_2.gif";
00299 info->suffix[38] = "_attack_s_3.gif";
00300 info->suffix[39] = "_attack_sw_1.gif";
00301 info->suffix[40] = "_attack_sw_2.gif";
00302 info->suffix[41] = "_attack_sw_3.gif";
00303 info->suffix[42] = "_attack_w_1.gif";
00304 info->suffix[43] = "_attack_w_2.gif";
00305 info->suffix[44] = "_attack_w_3.gif";
00306 info->suffix[45] = "_attack_nw_1.gif";
00307 info->suffix[46] = "_attack_nw_2.gif";
00308 info->suffix[47] = "_attack_nw_3.gif";
00309 if(first_flag == 1){
00310 info->num_images = 51;
00311 info->suffix[48] = "_range_1.gif";
00312 info->suffix[49] = "_range_2.gif";
00313 info->suffix[50] = "_range_3.gif";
00314 } else {
00315 info->num_images = 48;
00316 }
00317
00318 }
00319 if((index > TRAPS_END) && (index != PIEDMONT)){
00320 info->first_prop = 0; info->second_prop = 0; info->third_prop = 0;
00321 info->first_min = 0; info->first_max = 0;
00322 info->second_min = 0; info->second_max = 0;
00323 info->third_min = 0; info->third_max = 0;
00324 info->first_string = " ";
00325 info->second_string = " ";
00326 info->third_string = " ";
00327 info->suffix = new char*[1];
00328 info->num_images = 1;
00329 info->suffix[0] = ".gif";
00330 if(MISC_DEBUG) printf("other\n");
00331 }
00332 if(MISC_DEBUG){
00333 printf("Properties(%d %d %d) 1st(%d %d) 2nd(%d %d) 3rd(%d %d)\n", info->first_prop,
00334 info->second_prop, info->third_prop, info->first_min, info->first_max,
00335 info->second_min, info->second_max, info->third_min, info->third_max);
00336 printf("Num_Images: %d Strings:%s-%s-%s Suffix: %s\n", info->num_images,
00337 info->first_string, info->second_string, info->third_string, info->suffix[0]);
00338 }
00339 return(info);
00340 }
00341
00342 void print_paul_info(paul_info *p){
00343 printf("hitpoints: %d\n", p->hitpoints);
00344 printf("base_health: %d\n", p->base_health);
00345 printf("damage: %d\n", p->damage);
00346 printf("ranged: %d\n", p->ranged);
00347 printf("keys: %d\n", p->keys);
00348 printf("level: %d\n", p->level);
00349 printf("score: %d\n", p->score);
00350 printf("map_width: %d\n", p->map_width);
00351 printf("map_height: %d\n", p->map_height);
00352 printf("map_width_in_tiles: %d\n", p->map_width_in_tiles);
00353 printf("map_height_in_tiles: %d\n", p->map_height_in_tiles);
00354 printf("win_width: %d\n", p->win_width);
00355 printf("win_height: %d\n", p->win_height);
00356 printf("tilesize: %d\n", p->tilesize);
00357 printf("paul_x: %d\n", p->paul_x);
00358 printf("paul_y: %d\n", p->paul_y);
00359 printf("paul_ax: %d\n", p->paul_ax);
00360 printf("paul_ay: %d\n", p->paul_ay);
00361 printf("center_x: %d\n", p->center_x);
00362 printf("center_y: %d\n", p->center_y);
00363 printf("paul_center_ax: %d\n", p->paul_center_ax);
00364 printf("paul_center_ay: %d\n", p->paul_center_ay);
00365 printf("map_ax: %d\n", p->map_ax);
00366 printf("map_ay: %d\n", p->map_ay);
00367 }
00368
00369 void print_tile_info(tile_info *t){
00370 printf("name: %s\n", t->name);
00371 printf("num_images: %d\n", t->num_images);
00372 printf("first_prop: %d\n", t->first_prop);
00373 printf("second_prop: %d\n", t->second_prop);
00374 printf("third_prop: %d\n", t->third_prop);
00375 printf("first_min: %d\n", t->first_min);
00376 printf("first_max: %d\n", t->first_max);
00377 printf("second_min: %d\n", t->second_min);
00378 printf("second_max: %d\n", t->second_max);
00379 printf("third_min: %d\n", t->third_min);
00380 printf("third_max: %d\n", t->third_max);
00381 printf("first_string: %s\n", t->first_string);
00382 printf("second_string: %s\n", t->second_string);
00383 printf("third_string: %s\n", t->third_string);
00384 }