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

Last change on this file since 512 was 512, checked in by Sam Hocevar, 7 years ago

imlib: use vec2i for image::size and unroll all necessary changes
everywhere else in the code.

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