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

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

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

File size: 4.5 KB
RevLine 
[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 "director.h"
16#include "game.h"
17#include "lisp.h"
18#include "fonts.h"
[2]19
20director scene_director;
21
[124]22void director::scroll_text(char *Text)
23{ text=Text;
[2]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
[39]41int text_draw(int y, int x1, int y1, int x2, int y2, char const *buf, JCFont *font, uint8_t *cmap, char color)
[2]42{
43  short cx1,cy1,cx2,cy2,word_size,word_len;
44  screen->get_clip(cx1,cy1,cx2,cy2);
[124]45  screen->in_clip(x1,y1,x2,y2);
[2]46  int h=font->height()+2,w=font->width(),x=x1,dist;
47  y+=y1;
[39]48  char const *word_start;
[2]49
50  while (buf && *buf)
51  {
[124]52    do
53    {
[2]54      if (*buf=='\\' && buf[1]=='n')
55      {
[124]56    x=x1;
57    y+=h*2;
58    buf+=2;
[2]59      }
[124]60
[2]61      // skip space
62      if (*buf==' ' || *buf=='\r' || *buf=='\n' || *buf=='\t')
[124]63      {
64    x+=w;
65    while (*buf==' ' || *buf=='\r' || *buf=='\n' || *buf=='\t')   // skip space until next word
[2]66          buf++;
67      }
68
69      word_start=buf;
[494]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++);
[124]72
[2]73      if (word_size<x2-x1) // make sure the word can fit on the screen
74      {
[124]75    if (word_size+x>x2)    // does word not fit on line?
76    {
77      y+=h;                // go to next line
78      x=x1;
79    }
[2]80      }
81
82
83      if (y+h<y1)         // word on screen yet?
[124]84    x+=word_size;
[2]85
86    } while (*buf && y+h<y1);     // if not on screen yet, fetch next word
87
88    dist=31;
89    if (y-y1<dist)
[162]90    {
[2]91      if (y-y1<1) dist=0;
92      else dist=y-y1;
[162]93    }
[2]94
95    if (y2-y<dist)
[162]96    {
[2]97      if (y2-y<1) dist=0;
[124]98      else dist=y2-y;
[162]99    }
[2]100
101    int c=cmap[dist];
[124]102    if (y>y2) { buf=NULL; }
[2]103    else
104    {
105      while (word_len--)
106      {
[124]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;
[2]111      }
112    }
113
114  }
115  screen->set_clip(cx1,cy1,cx2,cy2);
[124]116  return (y<=y1);
[2]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;
[492]131  LSymbol *pan_symbol = LSymbol::FindOrCreate("pan"),
132             *text_symbol = LSymbol::FindOrCreate("text");
[124]133
[106]134  JCFont *font=wm->font();
[2]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      {
[124]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    }
[2]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,
[124]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()
[494]166
[124]167            ))
[2]168        text=NULL;
169      if (text_time)
170      {
[124]171    if ((int)(cur_time.diff_time(text_time)*1000)>scroll_speed)
[494]172    {
[124]173      text_y+=text_step;
174      delete text_time;
175      if (text)
[494]176        text_time=new time_marker;
[124]177      else
178        text_time=NULL;
179    }
[494]180      } else text_time=new time_marker;
[2]181    } else if (arg==text_symbol) done=1;
[494]182
183    wm->flush_screen();
[106]184    while (wm->event_waiting())
[494]185    {
186      event ev;
[106]187      wm->get_event(ev);
[2]188      if (ev.type==EV_KEY)
189      {
[124]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    }
[494]211      }
212    }
[2]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.