aboutsummaryrefslogtreecommitdiff
path: root/engines/avalanche/tripoop.cpp
blob: 15035c864dc2ea8f2f28a960350e883d49aec1b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#include "ptoc.h"

                 /* Trip Oop (Trippancy 4 Andexor */
#include "graph.h"
/*#include "Crt.h"*/


const integer up = 0;
const integer right = 1;
const integer down = 2;
const integer left = 3;

const integer numtr = 1; /* current max no. of sprites */

struct adxtype {
           varying_string<12> name; /* name of character */
           byte num; /* number of pictures */
           byte xl,yl; /* x & y lengths of pictures */
           byte seq; /* how many in one stride */
           word size; /* the size of one picture */
           byte fgc,bgc; /* foreground & background bubble colours */
};

class triptype {
public:
            adxtype a; /* vital statistics */
            byte face,step;
            integer x,y; /* current xy coords */
            integer ox,oy; /* last xy coords */
            integer tax,tay; /* "behind" taken at... */
            shortint ix,iy; /* amount to move sprite by, each step */
            matrix<1,24,0,1,pointer> pic;     /* the pictures themselves */
            boolean quick,visible,homing;
            pointer behind; /* what's behind you */
            integer hx,hy; /* homing x & y coords */

            triptype* init(byte spritenum);   /* loads & sets up the sprite */
            void original();    /* just sets Quick to false */
            void andexor();    /* drops sprite onto screen 1 */
            void turn(byte whichway);      /* turns him round */
            void appear(integer wx,integer wy, byte wf); /* switches him on */
            void walk();    /* prepares for do_it, andexor, etc. */
            void do_it();    /* Actually copies the picture over */
            void getback();    /* gets background before sprite is drawn */
            void putback();    /* ...and wipes sprite from screen 1 */
            void walkto(integer xx,integer yy); /* home in on a point */
            void stophoming();    /* self-explanatory */
            void homestep();    /* calculates ix & iy for one homing step */
            void speed(shortint xx,shortint yy); /* sets ix & iy, non-homing, etc */
            void halt();    /* Stops the sprite from moving */
};

integer gd,gm;
array<1,1,triptype> tr;

void copier(integer x1,integer y1,integer x2,integer y2,integer x3,integer y3,integer x4,integer y4);


static boolean dropin(integer xc,integer yc,integer x1,integer y1,integer x2,integer y2)
/* Dropin returns True if the point xc,yc falls within the 1-2 rectangle. */
{boolean dropin_result;
;
 dropin_result=((xc>=x1) && (xc<=x2) && (yc>=y1) && (yc<=y2));
return dropin_result;
}



static void transfer(integer x1,integer y1,integer x2,integer y2)
{
    pointer p,q; word s;
;
 s=imagesize(x1,y1,x2,y2); setfillstyle(1,0);
 mark(q); getmem(p,s);
 setactivepage(1); getimage(x1,y1,x2,y2,p);
 setactivepage(0); putimage(x1,y1,p,copyput);
 setactivepage(1); release(q);
}



static integer lesser(integer a,integer b)
{integer lesser_result;
;
 if (a<b)  lesser_result=a; else lesser_result=b;
return lesser_result;
}



static integer greater(integer a,integer b)
{integer greater_result;
;
 if (a>b)  greater_result=a; else greater_result=b;
return greater_result;
}

void copier(integer x1,integer y1,integer x2,integer y2,integer x3,integer y3,integer x4,integer y4)

{;
 if (dropin(x3,y3,x1,y1,x2,y2)
 || dropin(x3,y4,x1,y1,x2,y2)
 || dropin(x4,y3,x1,y1,x2,y2)
 || dropin(x4,y4,x1,y1,x2,y2)) 
 {;     /* Overlaps */
  transfer(lesser(x1,x3),lesser(y1,y3),greater(x2,x4),greater(y2,y4));
 } else
 {;     /* Doesn't overlap- copy both of them seperately */
  transfer(x3,y3,x4,y4); /* backwards- why not...? */
  transfer(x1,y1,x2,y2);
 }
}

void setup()
{
    integer gd,gm;
;
 gd=3; gm=0; initgraph(gd,gm,"");
 for( gd=0; gd <= 1; gd ++)
 {;
  setactivepage(gd);
  setfillstyle(9,1); bar(0,0,640,200);
 }
 for( gm=1; gm <= numtr; gm ++) tr[gm].original();
}

triptype* triptype::init(byte spritenum)
{
 integer gd,gm; word s; untyped_file f; varying_string<2> xx; pointer p,q; word bigsize;
 byte sort,n;
;
 str(spritenum,xx); assign(f,string("v:sprite")+xx+".avd");
 reset(f,1); seek(f,59);
 blockread(f,a,sizeof(a)); blockread(f,bigsize,2);
 setvisualpage(3); setactivepage(3);
 for( sort=0; sort <= 1; sort ++)
 {;
  mark(q); getmem(p,bigsize);
  blockread(f,p,bigsize);
  putimage(0,0,p,0); release(q); n=1;
  { adxtype& with = a; 
   for( gm=0; gm <= (with.num / with.seq)-1; gm ++) /* directions */
    for( gd=0; gd <= with.seq-1; gd ++) /* steps */
    {;
     getmem(pic[n][sort],a.size); /* grab the memory */
     getimage((gm / 2)*(with.xl*6)+gd*with.xl,(gm % 2)*with.yl,
       (gm / 2)*(with.xl*6)+gd*with.xl+with.xl-1,(gm % 2)*with.yl+with.yl-1,
       pic[n][sort]); /* grab the pic */
     putimage((gm / 2)*(with.xl*6)+gd*with.xl,(gm % 2)*with.yl,
       pic[n][sort],notput); /* test the pic */
     n += 1;
   }}
 }
 close(f); setactivepage(0); setvisualpage(0);
 x=0; y=0; quick=true; visible=false; getmem(behind,a.size);
 homing=false; ix=0; iy=0;
return this;
}

void triptype::original()
{;
 quick=false;
}

void triptype::getback()
{;
 tax=x; tay=y;
 getimage(x,y,x+a.xl,y+a.yl,behind);
}

void triptype::andexor()
{
    byte picnum; /* Picnum, Picnic, what ye heck */
;
 picnum=face*a.seq+step+1;
 putimage(x,y,pic[picnum][0],andput);
 putimage(x,y,pic[picnum][1],xorput);
}

void triptype::turn(byte whichway)
{;
 face=whichway; step=0;
}

void triptype::appear(integer wx,integer wy, byte wf)
{;
 x=wx; y=wy; ox=wx; oy=wy; turn(wf); visible=true;
}

void triptype::walk()
{;
 ox=x; oy=y;
 if (homing)  homestep();
 x=x+ix; y=y+iy;
 step += 1; if (step==a.seq)  step=0; getback();
}

void triptype::do_it()
{;
 copier(ox,oy,ox+a.xl,oy+a.yl,x,y,x+a.xl,y+a.yl);
}

void triptype::putback()
{;
 putimage(tax,tay,behind,0);
}

void triptype::walkto(integer xx,integer yy)
{;
 speed(xx-x,yy-y); hx=xx; hy=yy; homing=true;
}

void triptype::stophoming()
{;
 homing=false;
}

void triptype::homestep()
{
    integer temp;
;
 if ((hx==x) && (hy==y)) 
 {;     /* touching the target */
  homing=false; return;
 }
 ix=0; iy=0;
 if (hy!=y) 
 {;
  temp=hy-y; if (temp>4)  iy=4; else if (temp<-4)  iy=-4; else iy=temp;
 }
 if (hx!=x) 
 {;
  temp=hx-x; if (temp>4)  ix=4; else if (temp<-4)  ix=-4; else ix=temp;
 }
}

void triptype::speed(shortint xx,shortint yy)
{;
 ix=xx; iy=yy;
 if ((ix==0) && (iy==0))  return; /* no movement */
 if (ix==0) 
 {;     /* No horz movement */
  if (iy<0)  turn(up); else turn(down);
 } else
 {;
  if (ix<0)  turn(left); else turn(right);
 }
}

void triptype::halt()
{;
 ix=0; iy=0; homing=false;
}

void trip()
{
    byte fv;
;
 for( fv=1; fv <= numtr; fv ++)
  {
  triptype& with = tr[fv]; 
  ;
   walk();
   if (with.quick && with.visible)  andexor();
   do_it();
   putback();
  }
}

int main(int argc, const char* argv[])
{pio_initialize(argc, argv);
;
 setup();
 {
 triptype& with = tr[1]; 
 ;
  init(1);
  appear(600,100,left);
  do {
   /*
   speed(-5,0); repeat trip until keypressed or (x=  0);
   speed( 5,0); repeat trip until keypressed or (x=600);
   */
   walkto( 10, 10); do { trip(); } while (!(keypressed() || ! with.homing));
   walkto( 70,150); do { trip(); } while (!(keypressed() || ! with.homing));
   walkto(600, 77); do { trip(); } while (!(keypressed() || ! with.homing));
  } while (!keypressed());
 }
return EXIT_SUCCESS;
}