00001 /************************************************************************* 00002 tiledata.cpp 00003 Project Piedmont game 00004 ------------------------- 00005 00006 Date Created: 9/15/00 Last Modified: 03/20/08 00007 Programmer: David Foster 00008 Copyright: (C) 2000 David Foster (see file COPYING) 00009 E-mail: dfoster@computer.org 00010 00011 Description: to come.... 00012 00013 This program is free software; you can redistribute it and/or modify 00014 it under the terms of the GNU General Public License as published by 00015 the Free Software Foundation; either version 2 of the License, or 00016 (at your option) any later version. 00017 00018 This program is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 GNU General Public License for more details. 00022 00023 You should have received a copy of the GNU General Public License 00024 along with this program; if not, write to the Free Software 00025 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00026 00027 ************************************************************************/ 00028 00029 #include "tiledata.h" 00030 00031 Tiledata::Tiledata(){ 00032 static int i = 0; 00033 tile = new SDL_Surface*[3]; 00034 //name = NULL; 00035 frames = 0; 00036 info = new tile_info; 00037 info->name = " "; 00038 info->first_string = " "; 00039 info->second_string = " "; 00040 info->third_string = " "; 00041 info->num_images = 0; 00042 info->first_prop = info->second_prop = info->third_prop = 0; 00043 info->first_min = info->second_min = info->third_min = 0; 00044 info->first_max = info->second_max = info->third_max = 0; 00045 if(TILEDATA_DEBUG){ 00046 if(i == 255){ cerr << "done initializing tiledata: " << i++ << endl; 00047 }else{ cerr << i++ << " "; 00048 } 00049 } 00050 } 00051 00052 Tiledata::~Tiledata(){ 00053 delete[] tile; 00054 delete info; 00055 } 00056 00057 string Tiledata::get_name(){ 00058 return(name); 00059 } 00060 00061 void Tiledata::set_name(char *tilename){ 00062 name = string(tilename); 00063 if(TILEDATA_DEBUG) cerr << "TILEDATA::set_name: " << tilename << endl; 00064 } 00065 00066 int Tiledata::get_frames(){ 00067 return(frames); 00068 } 00069 00070 void Tiledata::set_frames(int num_frames){ 00071 frames = num_frames; 00072 if(TILEDATA_DEBUG) cerr << "TILEDATA::set_frames: " << num_frames << endl; 00073 } 00074 00075 int Tiledata::load_image(int img_index, char *filename, int transparent){ 00076 if( (tile[img_index] = IMG_Load(filename)) == NULL){ 00077 cerr << "Couldn't load tile " << filename << ": " << SDL_GetError() << endl; 00078 return(0); 00079 } 00080 if(TILEDATA_DEBUG) { 00081 cerr << "TILEDATA::load_image: " << img_index << " " << filename; 00082 cerr << " " << transparent << " success!\n\n"; 00083 } 00084 if(transparent){ //make color 0 transparent for level 1 tiles 00085 SDL_SetColorKey(tile[img_index], (SDL_SRCCOLORKEY|SDL_RLEACCEL), 00086 *((Uint8 *)tile[img_index]->pixels)); 00087 } 00088 00089 return(1); 00090 } 00091 00092 SDL_Surface* Tiledata::get_image(int index){ 00093 if(TILEDATA_DEBUG){ 00094 cerr << "TILEDATA::get_image: " << index << endl; 00095 cerr << "height: " << tile[index]->h << endl; 00096 } 00097 return(tile[index]); 00098 } 00099 00100 void Tiledata::set_num_images(int number){ 00101 delete[] tile; 00102 tile = new SDL_Surface*[number]; 00103 if(TILEDATA_DEBUG) cerr << "TILEDATA::set_num_image: " << number << endl; 00104 } 00105 00106 void Tiledata::set_tile_info(tile_info *ti){ 00107 info->name = (char *)name.c_str(); 00108 info->num_images = frames; 00109 info->first_prop = ti->first_prop; 00110 info->second_prop = ti->second_prop; 00111 info->third_prop = ti->third_prop; 00112 info->first_min = ti->first_min; 00113 info->first_max = ti->first_max; 00114 info->second_min = ti->second_min; 00115 info->second_max = ti->second_max; 00116 info->third_min = ti->third_min; 00117 info->third_max = ti->third_max; 00118 info->first_string = ti->first_string; 00119 info->second_string = ti->second_string; 00120 info->third_string = ti->third_string; 00121 } 00122 00123 tile_info* Tiledata::get_tile_info(){ 00124 return(info); 00125 } 00126 00127 int Tiledata::get_width(){ 00128 return(tile[0]->w); 00129 } 00130 00131 int Tiledata::get_height(){ 00132 return(tile[0]->h); 00133 }