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