source: abuse/trunk/src/director.cpp @ 494

Last change on this file since 494 was 494, checked in by Sam Hocevar, 11 years ago

style: remove trailing spaces, fix copyright statements.

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