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 "bgdraw.h"
00031
00032 BGDraw::BGDraw(){
00033 map_offset_x = map_offset_y = 0;
00034 tilesize = 0;
00035
00036 }
00037
00038 BGDraw::~BGDraw(){
00039 }
00040
00041 void BGDraw::set_display(Screen &s){
00042 screen = s;
00043 if(BGDRAW_DEBUG) printf("ok, background screen set\n");
00044 }
00045
00046 void BGDraw::set_background(BGEntity *bge){
00047 bgentity = bge;
00048 }
00049
00050 void BGDraw::set_paul_info(paul_info *p){
00051 pinfo = p;
00052 }
00053
00054 void BGDraw::set_size(int wwidth, int wheight, int mwidth,
00055 int mheight, int tsize, int charx, int chary){
00056 tilesize = tsize;
00057 pinfo->tilesize = tsize;
00058 pinfo->win_width = wwidth;
00059 pinfo->win_height = wheight;
00060 pinfo->center_x = pinfo->win_width/2;
00061 pinfo->center_y = pinfo->win_height/2;
00062 pinfo->map_width_in_tiles = mwidth;
00063 pinfo->map_height_in_tiles = mheight;
00064 pinfo->map_width = pinfo->map_width_in_tiles*tilesize;
00065 pinfo->map_height = pinfo->map_height_in_tiles*tilesize;
00066 pinfo->paul_ax = charx * tilesize;
00067 pinfo->paul_ay = chary * tilesize;
00068 pinfo->paul_center_ax = pinfo->paul_ax + (tilesize/2);
00069 pinfo->paul_center_ay = pinfo->paul_ay + (tilesize/2);
00070 pinfo->win_width_in_tiles = pinfo->win_width/pinfo->tilesize;
00071 if(pinfo->win_width % pinfo->tilesize != 0) pinfo->win_width_in_tiles++;
00072 pinfo->win_height_in_tiles = pinfo->win_height/pinfo->tilesize;
00073 if(pinfo->win_height % pinfo->tilesize != 0) pinfo->win_height_in_tiles++;
00074 if(BGDRAW_DEBUG){
00075 printf("map:(%d, %d) win:(%d, %d)\n", pinfo->map_width, pinfo->map_height, pinfo->win_width, pinfo->win_height);
00076 printf("paul_a(%d, %d) paul_center_a(%d, %d)\n",pinfo->paul_ax, pinfo->paul_ay, pinfo->paul_center_ax, pinfo->paul_center_ay);
00077 }
00078 }
00079
00080 void BGDraw::set_char_position(int charx, int chary){
00081 pinfo->paul_ax = charx*tilesize;
00082 pinfo->paul_ay = chary*tilesize;
00083 }
00084
00085 void BGDraw::initialize(){
00086 int x, y, index;
00087 int current_tilex, current_tiley;
00088 SDL_Rect rect;
00089 int start_x;
00090 int stop_x;
00091 int start_y;
00092 int stop_y;
00093 pinfo->paul_center_ax = pinfo->paul_ax + (tilesize/2);
00094 pinfo->paul_center_ay = pinfo->paul_ay + (tilesize/2);
00095 if((pinfo->paul_center_ax - pinfo->center_x) <= 0){
00096 if(BGDRAW_DEBUG)printf("BGDraw:: initialize left side x ");
00097 pinfo->paul_x = pinfo->paul_ax;
00098 start_x = 0;
00099 stop_x = start_x + pinfo->win_width;
00100 tile_start_x = start_x/tilesize;
00101 tile_stop_x = stop_x/tilesize;
00102 if((stop_x%tilesize) > 0) tile_stop_x++;
00103 map_offset_x = 0;
00104 }else if((pinfo->paul_center_ax + pinfo->center_x) >= pinfo->map_width){
00105 if(BGDRAW_DEBUG)printf("BGDraw:: initialize right side x ");
00106 start_x = pinfo->map_width - pinfo->win_width;
00107 pinfo->paul_x = pinfo->paul_ax - start_x;
00108 stop_x = pinfo->map_width;
00109 tile_start_x = start_x/tilesize;
00110 tile_stop_x = stop_x/tilesize;
00111 map_offset_x = 0 - pinfo->win_width%tilesize;
00112 }else{
00113 if(BGDRAW_DEBUG)printf("BGDraw:: initialize center side x ");
00114 pinfo->paul_x = pinfo->center_x - (tilesize/2);
00115 start_x = pinfo->paul_center_ax - pinfo->center_x;
00116 stop_x = start_x + pinfo->win_width;
00117 tile_start_x = start_x/tilesize;
00118 tile_stop_x = stop_x/tilesize;
00119 if((stop_x%tilesize) > 0) tile_stop_x++;
00120 map_offset_x = 0 - start_x%tilesize;
00121 }
00122 if((pinfo->paul_center_ay - pinfo->center_y) <= 0){
00123 if(BGDRAW_DEBUG)printf("BGDraw:: initialize top side y\n");
00124 pinfo->paul_y = pinfo->paul_ay;
00125 start_y = 0;
00126 stop_y = start_y + pinfo->win_height;
00127 tile_start_y = start_y/tilesize;
00128 tile_stop_y = stop_y/tilesize;
00129 if((stop_y%tilesize) > 0) tile_stop_y++;
00130 map_offset_y = 0;
00131 }else if((pinfo->paul_center_ay + pinfo->center_y) >= pinfo->map_height){
00132 if(BGDRAW_DEBUG)printf("BGDraw:: initialize bottom side y\n");
00133 start_y = pinfo->map_height - pinfo->win_height;
00134 pinfo->paul_y = pinfo->paul_ay - start_y;
00135 stop_y = pinfo->map_height;
00136 tile_start_y = start_y/tilesize;
00137 tile_stop_y = stop_y/tilesize;
00138 map_offset_y = 0 - pinfo->win_height%tilesize;
00139 }else{
00140 if(BGDRAW_DEBUG)printf("BGDraw:: initialize center side y\n");
00141 pinfo->paul_y = pinfo->center_y - (tilesize/2);
00142 start_y = pinfo->paul_center_ay - pinfo->center_y;
00143 stop_y = start_y + pinfo->win_height;
00144 tile_start_y = start_y/tilesize;
00145 tile_stop_y = stop_y/tilesize;
00146 if((stop_y%tilesize) > 0) tile_stop_y++;
00147 map_offset_y = 0 - start_y%tilesize;
00148 }
00149
00150 pinfo->tile_start_x = tile_start_x;
00151 pinfo->tile_stop_x = tile_stop_x;
00152 pinfo->tile_start_y = tile_start_y;
00153 pinfo->tile_stop_y = tile_stop_y;
00154 pinfo->tile_ax_in_win = map_offset_x;
00155 pinfo->tile_ay_in_win = map_offset_y;
00156
00157
00158
00159 if(BGDRAW_DEBUG)printf("X:(%d,%d) Y:(%d,%d)\n", start_x, stop_x, start_y, stop_y);
00160
00161 current_tilex = map_offset_x;
00162 current_tiley = map_offset_y;
00163 if(BGDRAW_DEBUG)printf("mapxy(%d, %d)\n", map_offset_x, map_offset_y);
00164 screen.blank(makerect(0,0,screen.get_width(), screen.get_height()));
00165 for(x=tile_start_x; x<tile_stop_x; x++){
00166 current_tiley = map_offset_y;
00167 for(y=tile_start_y; y<tile_stop_y; y++){
00168
00169 index = (y*pinfo->map_width_in_tiles)+x;
00170 rect = makerect(current_tilex, current_tiley, tilesize, tilesize);
00171 screen.blit(bgentity[index].tiledata->tile[0], rect);
00172 current_tiley += tilesize;
00173 }
00174 current_tilex += tilesize;
00175 }
00176 }
00177
00178 void BGDraw::move(int dir){
00179 int amount = 10;
00180 cerr << "BGDraw::move WHAT THE HEY!!!!\n";
00181 switch(dir){
00182 case 0: if(pinfo->paul_ay - amount > 0) pinfo->paul_ay -= amount;
00183 break;
00184 case 1: if(pinfo->paul_ax + amount + tilesize < pinfo->map_width) pinfo->paul_ax += amount;
00185 if(pinfo->paul_ay - amount > 0) pinfo->paul_ay -= amount;
00186 break;
00187 case 2: if(pinfo->paul_ax + amount + tilesize < pinfo->map_width) pinfo->paul_ax += amount;
00188 break;
00189 case 3: if(pinfo->paul_ax + amount + tilesize < pinfo->map_width) pinfo->paul_ax += amount;
00190 if(pinfo->paul_ay + amount + tilesize < pinfo->map_height) pinfo->paul_ay += amount;
00191 break;
00192 case 4: if(pinfo->paul_ay + amount + tilesize < pinfo->map_height) pinfo->paul_ay += amount;
00193 break;
00194 case 5: if(pinfo->paul_ax - amount > 0) pinfo->paul_ax -= amount;
00195 if(pinfo->paul_ay + amount + tilesize < pinfo->map_height) pinfo->paul_ay += amount;
00196 break;
00197 case 6: if(pinfo->paul_ax - amount > 0) pinfo->paul_ax -= amount;
00198 break;
00199 case 7: if(pinfo->paul_ax - amount > 0) pinfo->paul_ax -= amount;
00200 if(pinfo->paul_ay - amount > 0)pinfo->paul_ay -= amount;
00201 break;
00202 }
00203 initialize();
00204 }
00205
00206 void BGDraw::update_screen(){
00207
00208 }
00209
00210
00211 void BGDraw::refresh_all(){
00212
00213 }