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

Last change on this file since 124 was 124, checked in by Sam Hocevar, 15 years ago
  • Get rid of ugly tabs and trailing spaces everywhere.
File size: 4.4 KB
RevLine 
[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
17director scene_director;
18
[124]19void 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
24director::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
34extern unsigned char *white_light;
35
36
37
[39]38int 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)
87      if (y-y1<1) dist=0;
88      else dist=y-y1;
89
90    if (y2-y<dist)
91      if (y2-y<1) dist=0;
[124]92      else dist=y2-y;
[2]93
94    int c=cmap[dist];
[124]95    if (y>y2) { buf=NULL; }
[2]96    else
97    {
98      while (word_len--)
99      {
[124]100    font->put_char(screen,x+1,y+1,*word_start,0);
101    font->put_char(screen,x,y,*word_start,c);
102    word_start++;
103    x+=w;
[2]104      }
105    }
106
107  }
108  screen->set_clip(cx1,cy1,cx2,cy2);
[124]109  return (y<=y1);
[2]110}
111
112
113
114
115
116
117
118
119void director::wait(void *arg)
120{
121  if (scene_abort) return ;
122  pan_time=frame_time=text_time=NULL;
123  int done=0;
124  void *pan_symbol=make_find_symbol("pan"),
125       *text_symbol=make_find_symbol("text");
[124]126
[106]127  JCFont *font=wm->font();
[2]128
129  do
130  {
131    the_game->draw_map(the_game->first_view);
132    time_marker cur_time;
133
134    if (pan_steps)
135    {
136      if (pan_time)
137      {
[124]138    if ((int)(cur_time.diff_time(pan_time)*1000)>pan_speed)
139    {
140      the_game->pan(pan_xv,pan_yv);
141      pan_steps--;
142      delete pan_time;
143      if (pan_steps)
144          pan_time=new time_marker;
145      else pan_time=NULL;
146    }
[2]147      } else pan_time=new time_marker;
148    } else if (arg==pan_symbol) done=1;
149
150    if (text)
151    {
152      if (text_draw(text_y,
[124]153            the_game->first_view->cx1+tleft,
154            the_game->first_view->cy1+ttop,
155            the_game->first_view->cx2-tright,
156            the_game->first_view->cy2-tbottom,text,font,
157            white_light+32*256,
158            wm->bright_color()
159       
160            ))
[2]161        text=NULL;
162      if (text_time)
163      {
[124]164    if ((int)(cur_time.diff_time(text_time)*1000)>scroll_speed)
165    {   
166      text_y+=text_step;
167      delete text_time;
168      if (text)
169        text_time=new time_marker;   
170      else
171        text_time=NULL;
172    }
173      } else text_time=new time_marker;   
[2]174    } else if (arg==text_symbol) done=1;
[124]175   
176    wm->flush_screen();   
[106]177    while (wm->event_waiting())
[124]178    {   
179      event ev;   
[106]180      wm->get_event(ev);
[2]181      if (ev.type==EV_KEY)
182      {
[124]183    switch (ev.key)
184    {
185      case JK_UP :
186      case JK_LEFT :
187      {
188        if (scroll_speed>=20)
189        scroll_speed-=20;
190          else text_step--;
191      }
192      break;
193      case JK_RIGHT :
194      case JK_DOWN :
195      {
196        if (text_step<-2)
197        text_step++;
198        else if (scroll_speed<200) scroll_speed+=20;
199        break;
200        case JK_ESC : set_abort(1); done=1; break;
201        case JK_ENTER : done=1; break;
202      }   
203    }   
204      }
205    }
[2]206  } while (!done);
207  if (pan_time) delete pan_time;
208  if (frame_time) delete frame_time;
209  if (text_time) delete text_time;
210}
211
Note: See TracBrowser for help on using the repository browser.