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