[2] | 1 | #include "automap.hpp" |
---|
| 2 | #include "game.hpp" |
---|
| 3 | |
---|
| 4 | automap *current_automap=0; |
---|
| 5 | |
---|
| 6 | void automap::draw() |
---|
| 7 | { |
---|
| 8 | if (!automap_window) return ; |
---|
| 9 | image *screen=automap_window->screen; |
---|
| 10 | |
---|
| 11 | long sx,ex,sy,ey,x,y,window_xstart,window_ystart, |
---|
| 12 | window_xend,window_yend,centerx,centery, |
---|
| 13 | draw_xstart,draw_ystart, |
---|
| 14 | i,j; |
---|
| 15 | |
---|
| 16 | x=the_game->first_view->x_center(); |
---|
| 17 | y=the_game->first_view->y_center(); |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | window_xstart=automap_window->x1(); |
---|
| 21 | window_ystart=automap_window->y1(); |
---|
| 22 | window_xend=automap_window->x2(); |
---|
| 23 | window_yend=automap_window->y2(); |
---|
| 24 | centerx=(window_xstart+window_xend)/2; |
---|
| 25 | centery=(window_ystart+window_yend)/2; |
---|
| 26 | |
---|
| 27 | sx=x/f_wid-w/2; // start drawing with this foretile |
---|
| 28 | sy=y/f_hi-h/2; |
---|
| 29 | ex=sx+w; |
---|
| 30 | ey=sy+h; |
---|
| 31 | |
---|
| 32 | if (sx<0) // does the map scroll past the left side ? |
---|
| 33 | { sx=0; // yes, start drawing at 0 |
---|
| 34 | draw_xstart=centerx-(x*AUTOTILE_WIDTH/f_wid); |
---|
| 35 | } |
---|
| 36 | else |
---|
| 37 | draw_xstart=centerx-(x*AUTOTILE_WIDTH/f_wid-sx*AUTOTILE_WIDTH); |
---|
| 38 | |
---|
| 39 | if (sy<0) |
---|
| 40 | { |
---|
| 41 | sy=0; |
---|
| 42 | draw_ystart=centery-(y*AUTOTILE_HEIGHT/f_hi); |
---|
| 43 | } |
---|
| 44 | else |
---|
| 45 | draw_ystart=centery-(y*AUTOTILE_HEIGHT/f_hi-sy*AUTOTILE_HEIGHT); |
---|
| 46 | |
---|
| 47 | // if view position hasn't changed, only update the binking dot and return |
---|
| 48 | if (draw_xstart==old_dx && draw_ystart==old_dy) |
---|
| 49 | { |
---|
| 50 | automap_window->screen->add_dirty(centerx,centery,centerx,centery); |
---|
| 51 | if ((tick++)&4) |
---|
| 52 | automap_window->screen->putpixel(centerx,centery,255); |
---|
| 53 | else |
---|
| 54 | automap_window->screen->putpixel(centerx,centery,27); |
---|
| 55 | return ; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | old_dx=draw_xstart; |
---|
| 59 | old_dy=draw_ystart; |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | if (ex>=cur_lev->foreground_width()) |
---|
| 63 | ex=cur_lev->foreground_width()-1; |
---|
| 64 | if (ey>=cur_lev->foreground_height()) |
---|
| 65 | ey=cur_lev->foreground_height()-1; |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | screen->bar(window_xstart,window_ystart,draw_xstart,window_yend,0); |
---|
| 69 | screen->bar(window_xstart,window_ystart,window_xend,draw_ystart,0); |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | /* if (ex>=cur_lev->foreground_width()) |
---|
| 73 | { |
---|
| 74 | draw_xend=center |
---|
| 75 | ex=foreground_width()-1; */ |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | // we are going to redraw the whole map, so make the dirty rect work easier by marking |
---|
| 81 | // everything dirty |
---|
| 82 | screen->add_dirty(window_xstart,window_ystart,window_xend,window_yend); |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | // draw the tiles that will be around the border of the automap with put_image |
---|
| 88 | // because it handles clipping, but for ths reason is slower, the rest |
---|
| 89 | // we will slam on as fast as possible |
---|
| 90 | |
---|
| 91 | screen->set_clip(window_xstart,window_ystart,window_xend,window_yend); |
---|
| 92 | /* for (i=draw_xstart,j=draw_ystart,x=sx,y=sy;y<=ey;j+=AUTOTILE_HEIGHT,y++) |
---|
| 93 | foretiles[cur_lev->get_fg(x,y)]->micro_image->put_image(screen,i,j,0); |
---|
| 94 | |
---|
| 95 | for (i=draw_xstart+ex*AUTOTILE_WIDTH,j=draw_ystart,y=sy,x=ex;y<=ey;j+=AUTOTILE_HEIGHT,y++) |
---|
| 96 | foretiles[cur_lev->get_fg(x,y)]->micro_image->put_image(screen,i,j,0); |
---|
| 97 | |
---|
| 98 | for (i=draw_xstart,j=draw_ystart,x=sx,y=sy;x<=ex;i+=AUTOTILE_WIDTH,x++) |
---|
| 99 | foretiles[cur_lev->get_fg(x,y)]->micro_image->put_image(screen,i,j,0); |
---|
| 100 | |
---|
| 101 | for (i=draw_xstart,j=draw_ystart+ey*AUTOTILE_HEIGHT,x=sx,y=ex;x<=ex;i+=AUTOTILE_WIDTH,x++) |
---|
| 102 | foretiles[cur_lev->get_fg(x,y)]->micro_image->put_image(screen,i,j,0); */ |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | unsigned short *fgline; |
---|
| 107 | for (j=draw_ystart,y=sy;y<=ey;j+=AUTOTILE_HEIGHT,y++) |
---|
| 108 | { |
---|
| 109 | fgline=cur_lev->get_fgline(y)+sx; |
---|
| 110 | for (i=draw_xstart,x=sx;x<=ex;i+=AUTOTILE_WIDTH,x++,fgline++) |
---|
| 111 | { |
---|
| 112 | if ((*fgline)&0x8000) |
---|
| 113 | { |
---|
| 114 | int id=foretiles[ (*fgline)&0x7fff]; |
---|
| 115 | if (id>=0) |
---|
| 116 | cash.foret(id)->micro_image->put_image(screen,i,j,0); |
---|
| 117 | else |
---|
| 118 | cash.foret(foretiles[0])->micro_image->put_image(screen,i,j,0); |
---|
| 119 | } |
---|
| 120 | else |
---|
| 121 | screen->bar(i,j,i+AUTOTILE_WIDTH-1,j+AUTOTILE_HEIGHT-1,0); |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | // draw the person as a dot, no need to add a dirty because we marked the whole screen already |
---|
| 130 | if ((tick++)&4) |
---|
| 131 | automap_window->screen->putpixel(centerx,centery,255); |
---|
| 132 | else |
---|
| 133 | automap_window->screen->putpixel(centerx,centery,27); |
---|
| 134 | |
---|
| 135 | // set the clip back to full window size because soemthing else could mess with the area |
---|
| 136 | automap_window->screen->set_clip(0,0,screen->width()-1,screen->height()-1); |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | void automap::toggle_window() |
---|
| 141 | { |
---|
| 142 | if (automap_window) |
---|
| 143 | { |
---|
| 144 | eh->close_window(automap_window); |
---|
| 145 | automap_window=NULL; |
---|
| 146 | } |
---|
| 147 | else |
---|
| 148 | { |
---|
| 149 | old_dx=-1000; // make sure the map gets drawn the first time |
---|
| 150 | old_dy=-1000; |
---|
| 151 | |
---|
| 152 | automap_window=eh->new_window(0,0,w*AUTOTILE_WIDTH,h*AUTOTILE_HEIGHT); |
---|
| 153 | automap_window->screen->bar(17,1,17+8*6+3,6,eh->medium_color()); |
---|
| 154 | eh->font()->put_string(automap_window->screen,20,2,"AUTOMAP"); |
---|
| 155 | draw(); |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | automap::automap(level *l, int width, int height) |
---|
| 161 | { |
---|
| 162 | w=width; |
---|
| 163 | h=height; |
---|
| 164 | |
---|
| 165 | tick=0; |
---|
| 166 | cur_lev=l; |
---|
| 167 | automap_window=NULL; |
---|
| 168 | toggle_window(); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | void automap::handle_event(event &ev) |
---|
| 172 | { |
---|
| 173 | |
---|
| 174 | //only respond to stuff in our window or on the main screen |
---|
| 175 | if (ev.window==NULL || ev.window==automap_window) |
---|
| 176 | { |
---|
| 177 | switch (ev.type) |
---|
| 178 | { |
---|
| 179 | case EV_KEY : |
---|
| 180 | switch(ev.key) |
---|
| 181 | { |
---|
| 182 | case 'A' : |
---|
| 183 | case 'a' : |
---|
| 184 | toggle_window(); |
---|
| 185 | break; |
---|
| 186 | } |
---|
| 187 | break; |
---|
| 188 | case EV_CLOSE_WINDOW : |
---|
| 189 | eh->close_window(automap_window); |
---|
| 190 | automap_window=NULL; |
---|
| 191 | break; |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | |
---|