[56] | 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 | |
---|
[2] | 12 | #include "director.hpp" |
---|
| 13 | #include "game.hpp" |
---|
| 14 | #include "lisp.hpp" |
---|
| 15 | #include "fonts.hpp" |
---|
| 16 | |
---|
| 17 | director scene_director; |
---|
| 18 | |
---|
[124] | 19 | void director::scroll_text(char *Text) |
---|
| 20 | { text=Text; |
---|
[2] | 21 | text_y=the_game->first_view->cy2-the_game->first_view->cy1+1; |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | director::director() |
---|
| 25 | { |
---|
| 26 | tleft=ttop=tright=tbottom=pan_xv=pan_yv=0; |
---|
| 27 | text_step=-2; |
---|
| 28 | frame_speed=100; |
---|
| 29 | scroll_speed=60; |
---|
| 30 | pan_speed=60; |
---|
| 31 | scene_abort=0; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | extern unsigned char *white_light; |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | |
---|
[39] | 38 | int text_draw(int y, int x1, int y1, int x2, int y2, char const *buf, JCFont *font, uint8_t *cmap, char color) |
---|
[2] | 39 | { |
---|
| 40 | short cx1,cy1,cx2,cy2,word_size,word_len; |
---|
| 41 | screen->get_clip(cx1,cy1,cx2,cy2); |
---|
[124] | 42 | screen->in_clip(x1,y1,x2,y2); |
---|
[2] | 43 | int h=font->height()+2,w=font->width(),x=x1,dist; |
---|
| 44 | y+=y1; |
---|
[39] | 45 | char const *word_start; |
---|
[2] | 46 | |
---|
| 47 | while (buf && *buf) |
---|
| 48 | { |
---|
[124] | 49 | do |
---|
| 50 | { |
---|
[2] | 51 | if (*buf=='\\' && buf[1]=='n') |
---|
| 52 | { |
---|
[124] | 53 | x=x1; |
---|
| 54 | y+=h*2; |
---|
| 55 | buf+=2; |
---|
[2] | 56 | } |
---|
[124] | 57 | |
---|
[2] | 58 | // skip space |
---|
| 59 | if (*buf==' ' || *buf=='\r' || *buf=='\n' || *buf=='\t') |
---|
[124] | 60 | { |
---|
| 61 | x+=w; |
---|
| 62 | while (*buf==' ' || *buf=='\r' || *buf=='\n' || *buf=='\t') // skip space until next word |
---|
[2] | 63 | buf++; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | word_start=buf; |
---|
[124] | 67 | for (word_len=0,word_start=buf,word_size=0;*buf && *buf!=' ' && *buf!='\r' && *buf!='\n' && |
---|
| 68 | *buf!='\t' && (*buf!='\\' || buf[1]!='n');buf++,word_size+=w,word_len++); |
---|
| 69 | |
---|
[2] | 70 | if (word_size<x2-x1) // make sure the word can fit on the screen |
---|
| 71 | { |
---|
[124] | 72 | if (word_size+x>x2) // does word not fit on line? |
---|
| 73 | { |
---|
| 74 | y+=h; // go to next line |
---|
| 75 | x=x1; |
---|
| 76 | } |
---|
[2] | 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | if (y+h<y1) // word on screen yet? |
---|
[124] | 81 | x+=word_size; |
---|
[2] | 82 | |
---|
| 83 | } while (*buf && y+h<y1); // if not on screen yet, fetch next word |
---|
| 84 | |
---|
| 85 | dist=31; |
---|
| 86 | if (y-y1<dist) |
---|
[162] | 87 | { |
---|
[2] | 88 | if (y-y1<1) dist=0; |
---|
| 89 | else dist=y-y1; |
---|
[162] | 90 | } |
---|
[2] | 91 | |
---|
| 92 | if (y2-y<dist) |
---|
[162] | 93 | { |
---|
[2] | 94 | if (y2-y<1) dist=0; |
---|
[124] | 95 | else dist=y2-y; |
---|
[162] | 96 | } |
---|
[2] | 97 | |
---|
| 98 | int c=cmap[dist]; |
---|
[124] | 99 | if (y>y2) { buf=NULL; } |
---|
[2] | 100 | else |
---|
| 101 | { |
---|
| 102 | while (word_len--) |
---|
| 103 | { |
---|
[124] | 104 | font->put_char(screen,x+1,y+1,*word_start,0); |
---|
| 105 | font->put_char(screen,x,y,*word_start,c); |
---|
| 106 | word_start++; |
---|
| 107 | x+=w; |
---|
[2] | 108 | } |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | } |
---|
| 112 | screen->set_clip(cx1,cy1,cx2,cy2); |
---|
[124] | 113 | return (y<=y1); |
---|
[2] | 114 | } |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | void director::wait(void *arg) |
---|
| 124 | { |
---|
| 125 | if (scene_abort) return ; |
---|
| 126 | pan_time=frame_time=text_time=NULL; |
---|
| 127 | int done=0; |
---|
| 128 | void *pan_symbol=make_find_symbol("pan"), |
---|
| 129 | *text_symbol=make_find_symbol("text"); |
---|
[124] | 130 | |
---|
[106] | 131 | JCFont *font=wm->font(); |
---|
[2] | 132 | |
---|
| 133 | do |
---|
| 134 | { |
---|
| 135 | the_game->draw_map(the_game->first_view); |
---|
| 136 | time_marker cur_time; |
---|
| 137 | |
---|
| 138 | if (pan_steps) |
---|
| 139 | { |
---|
| 140 | if (pan_time) |
---|
| 141 | { |
---|
[124] | 142 | if ((int)(cur_time.diff_time(pan_time)*1000)>pan_speed) |
---|
| 143 | { |
---|
| 144 | the_game->pan(pan_xv,pan_yv); |
---|
| 145 | pan_steps--; |
---|
| 146 | delete pan_time; |
---|
| 147 | if (pan_steps) |
---|
| 148 | pan_time=new time_marker; |
---|
| 149 | else pan_time=NULL; |
---|
| 150 | } |
---|
[2] | 151 | } else pan_time=new time_marker; |
---|
| 152 | } else if (arg==pan_symbol) done=1; |
---|
| 153 | |
---|
| 154 | if (text) |
---|
| 155 | { |
---|
| 156 | if (text_draw(text_y, |
---|
[124] | 157 | the_game->first_view->cx1+tleft, |
---|
| 158 | the_game->first_view->cy1+ttop, |
---|
| 159 | the_game->first_view->cx2-tright, |
---|
| 160 | the_game->first_view->cy2-tbottom,text,font, |
---|
| 161 | white_light+32*256, |
---|
| 162 | wm->bright_color() |
---|
| 163 | |
---|
| 164 | )) |
---|
[2] | 165 | text=NULL; |
---|
| 166 | if (text_time) |
---|
| 167 | { |
---|
[124] | 168 | if ((int)(cur_time.diff_time(text_time)*1000)>scroll_speed) |
---|
| 169 | { |
---|
| 170 | text_y+=text_step; |
---|
| 171 | delete text_time; |
---|
| 172 | if (text) |
---|
| 173 | text_time=new time_marker; |
---|
| 174 | else |
---|
| 175 | text_time=NULL; |
---|
| 176 | } |
---|
| 177 | } else text_time=new time_marker; |
---|
[2] | 178 | } else if (arg==text_symbol) done=1; |
---|
[124] | 179 | |
---|
| 180 | wm->flush_screen(); |
---|
[106] | 181 | while (wm->event_waiting()) |
---|
[124] | 182 | { |
---|
| 183 | event ev; |
---|
[106] | 184 | wm->get_event(ev); |
---|
[2] | 185 | if (ev.type==EV_KEY) |
---|
| 186 | { |
---|
[124] | 187 | switch (ev.key) |
---|
| 188 | { |
---|
| 189 | case JK_UP : |
---|
| 190 | case JK_LEFT : |
---|
| 191 | { |
---|
| 192 | if (scroll_speed>=20) |
---|
| 193 | scroll_speed-=20; |
---|
| 194 | else text_step--; |
---|
| 195 | } |
---|
| 196 | break; |
---|
| 197 | case JK_RIGHT : |
---|
| 198 | case JK_DOWN : |
---|
| 199 | { |
---|
| 200 | if (text_step<-2) |
---|
| 201 | text_step++; |
---|
| 202 | else if (scroll_speed<200) scroll_speed+=20; |
---|
| 203 | break; |
---|
| 204 | case JK_ESC : set_abort(1); done=1; break; |
---|
| 205 | case JK_ENTER : done=1; break; |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | } |
---|
| 209 | } |
---|
[2] | 210 | } while (!done); |
---|
| 211 | if (pan_time) delete pan_time; |
---|
| 212 | if (frame_time) delete frame_time; |
---|
| 213 | if (text_time) delete text_time; |
---|
| 214 | } |
---|
| 215 | |
---|