$BD,0$$FD,15$ GrBitMap *RK_base=GrAlias(grbase2,Fs); $PI,"",2$ $PI,"",3$ $PI,"",19$ $PI,"",20$ $PI,"",24$ $PI,"",23$ $PI,"",21$ $PI,"",22$ $PI,"",4$ $PI,"",13$ $PI,"",5$ $PI,"",14$ $PI,"",6$ $PI,"",15$ $PI,"",7$ $PI,"",18$ #define CMD_NULL 0 #define CMD_SPIN_LEFT 1 #define CMD_SPIN_RIGHT 2 #define CMD_THRUST 3 #define CMD_FIRE 4 #define CMD_EXIT 5 I8 cmd=CMD_NULL; #define NUM_STARS 100 I8 stars_x[NUM_STARS],stars_y[NUM_STARS]; BoolU4 bounce=TRUE; #define OT_SHIP 1 #define OT_CARGO 2 #define OT_BULLET 3 #define OT_SPECK 4 #define OT_PEBBLE 5 #define OT_TINY_ROCK 6 #define OT_SMALL_ROCK 7 #define OT_MEDIUM_ROCK 8 #define OT_LARGE_ROCK 9 #define A_TRANSITION -1 #define A_INACTIVE 0 #define A_ACTIVE 1 class Order2D2Theta { double x,y,theta; double DxDt,DyDt,DthetaDt; }; class Object { I4 active; I4 type; U1 *img; double mass,radius; U8 timeout; }; #define NUM_OBJECTS 256 Ode *ode; Order2D2Theta *o; Object *objs; void InitObject(I8 i, I8 type) { objs[i].active=A_ACTIVE; objs[i].timeout=0; objs[i].type=type; switch (type) { case OT_SHIP: objs[i].img=$IB,"",2$; objs[i].radius=15; break; case OT_CARGO: objs[i].img=$IB,"",18$; objs[i].radius=30; break; case OT_BULLET: objs[i].img=$IB,"",9$; objs[i].radius=7; break; case OT_SPECK: objs[i].img=$IB,"",24$; objs[i].radius=3; break; case OT_PEBBLE: objs[i].img=$IB,"",23$; objs[i].radius=5; break; case OT_TINY_ROCK: if (i&1) objs[i].img=$IB,"",21$; else objs[i].img=$IB,"",22$; objs[i].radius=5; break; case OT_SMALL_ROCK: if (i&1) objs[i].img=$IB,"",10$; else objs[i].img=$IB,"",13$; objs[i].radius=11; break; case OT_MEDIUM_ROCK: if (i&1) objs[i].img=$IB,"",11$; else objs[i].img=$IB,"",14$; objs[i].radius=20; break; case OT_LARGE_ROCK: if (i&1) objs[i].img=$IB,"",12$; else objs[i].img=$IB,"",15$; objs[i].radius=26; break; } objs[i].mass=objs[i].radius*objs[i].radius*objs[i].radius; } I8 AllocObject(I8 type) { I8 i; for (i=0;icolor=WHITE; for (i=0;iGR_WIDTH) { x=x%GR_WIDTH; o[i].x=x; } if (y<0) { y=GR_HEIGHT-AbsI8(y)%GR_HEIGHT; o[i].y=y; } else if (y>GR_HEIGHT) { y=y%GR_HEIGHT; o[i].y=y; } switch (objs[i].type) { case OT_SHIP: RK_base->flags|=BMF_TRANSFORMATION; r1=RK_base->r; RK_base->r=GrTheta(o[i].theta); RK_base->x=x; RK_base->y=y; RK_base->z=0; if (cmd==CMD_THRUST && GetTimeStamp&8192) GrElemsPlot(RK_base,0,0,0,$IB,"",3$); else GrElemsPlot(RK_base,0,0,0,$IB,"",2$); Free(RK_base->r); RK_base->r=r1; RK_base->flags&=~BMF_TRANSFORMATION; break; case OT_BULLET: case OT_SPECK: case OT_PEBBLE: case OT_TINY_ROCK: case OT_SMALL_ROCK: case OT_MEDIUM_ROCK: case OT_LARGE_ROCK: case OT_CARGO: RK_base->flags|=BMF_TRANSFORMATION; r1=RK_base->r; RK_base->r=GrTheta(o[i].theta); RK_base->x=x; RK_base->y=y; RK_base->z=0; GrElemsPlot(RK_base,0,0,0,objs[i].img); Free(RK_base->r); RK_base->r=r1; RK_base->flags&=~BMF_TRANSFORMATION; break; } } } } } void SongEndTsk() { Sound(0); Exit; } void SongTsk() { Fs->end_task_cb=&SongEndTsk; ResetMusicSettings; while (TRUE) { Play("qDCDeEGBDetBBFqDeDB"); Play("FAetAFDeDFqAetDFBeDFetFDEqD"); Play("eFAetAFDeDFqAetDFBeDFetFDEqD"); } } void InitObjs() { I8 i,j; for (i=0;i1000000.0) f=1000000.0; } } else f=-2.5*objs[i].mass*objs[j].mass/(dd+1.0); DstateDt[i].DxDt+=f*dx/objs[i].mass; DstateDt[i].DyDt+=f*dy/objs[i].mass; } } } } switch (cmd) { case CMD_SPIN_LEFT: DstateDt[0].DthetaDt-=10.0; break; case CMD_SPIN_RIGHT: DstateDt[0].DthetaDt+=10.0; break; case CMD_THRUST: DstateDt[0].DxDt+=100.0*Cos(state[0].theta-pi/2.0); DstateDt[0].DyDt+=100.0*Sin(state[0].theta-pi/2.0); break; } DstateDt[1].DxDt+=2.0*Cos(state[1].theta-pi/2.0); DstateDt[1].DyDt+=2.0*Sin(state[1].theta-pi/2.0); } void Collision(I8 i,I8 j) { I8 i2; switch (objs[i].type) { case OT_SHIP: if (!bounce) { cmd=CMD_EXIT; objs[i].active=A_INACTIVE; } break; case OT_CARGO: cmd=CMD_EXIT; objs[i].active=A_INACTIVE; break; case OT_SPECK: if (objs[j].type==OT_BULLET && !bounce) objs[i].active=A_INACTIVE; break; case OT_BULLET: if (!bounce) objs[i].active=A_INACTIVE; break; case OT_PEBBLE: case OT_TINY_ROCK: case OT_SMALL_ROCK: case OT_MEDIUM_ROCK: i2=AllocObject(objs[i].type-1); objs[i2].active=A_TRANSITION; o[i2].x=o[i].x+objs[i2].radius+2.0; o[i2].y=o[i].y; o[i2].theta=o[i].theta; o[i2].DxDt=o[i].DxDt; o[i2].DyDt=o[i].DyDt; o[i2].DthetaDt=o[i].DthetaDt; i2=AllocObject(objs[i].type-1); objs[i2].active=A_TRANSITION; o[i2].x=o[i].x-objs[i2].radius-2.0; o[i2].y=o[i].y; o[i2].theta=o[i].theta; o[i2].DxDt=o[i].DxDt; o[i2].DyDt=o[i].DyDt; o[i2].DthetaDt=o[i].DthetaDt; objs[i].active=A_INACTIVE; break; case OT_LARGE_ROCK: i2=AllocObject(objs[i].type-1); objs[i2].active=A_TRANSITION; o[i2].x=o[i].x+objs[i2].radius+4.0; o[i2].y=o[i].y+objs[i2].radius+4.0; o[i2].theta=o[i].theta; o[i2].DxDt=o[i].DxDt; o[i2].DyDt=o[i].DyDt; o[i2].DthetaDt=o[i].DthetaDt; i2=AllocObject(objs[i].type-1); objs[i2].active=A_TRANSITION; o[i2].x=o[i].x-objs[i2].radius-4.0; o[i2].y=o[i].y-objs[i2].radius-4.0; o[i2].theta=o[i].theta; o[i2].DxDt=o[i].DxDt; o[i2].DyDt=o[i].DyDt; o[i2].DthetaDt=o[i].DthetaDt; i2=AllocObject(objs[i].type-1); objs[i2].active=A_TRANSITION; o[i2].x=o[i].x-objs[i2].radius-4.0; o[i2].y=o[i].y+objs[i2].radius+4.0; o[i2].theta=o[i].theta; o[i2].DxDt=o[i].DxDt; o[i2].DyDt=o[i].DyDt; o[i2].DthetaDt=o[i].DthetaDt; i2=AllocObject(objs[i].type-1); objs[i2].active=A_TRANSITION; o[i2].x=o[i].x+objs[i2].radius+4.0; o[i2].y=o[i].y-objs[i2].radius-4.0; o[i2].theta=o[i].theta; o[i2].DxDt=o[i].DxDt; o[i2].DyDt=o[i].DyDt; o[i2].DthetaDt=o[i].DthetaDt; objs[i].active=A_INACTIVE; break; } switch (objs[j].type) { case OT_SHIP: if (!bounce) { cmd=CMD_EXIT; objs[j].active=A_INACTIVE; } break; case OT_CARGO: cmd=CMD_EXIT; objs[j].active=A_INACTIVE; break; case OT_SPECK: if (objs[i].type==OT_BULLET && !bounce) objs[j].active=A_INACTIVE; break; case OT_BULLET: if (!bounce) objs[j].active=A_INACTIVE; break; case OT_PEBBLE: case OT_TINY_ROCK: case OT_SMALL_ROCK: case OT_MEDIUM_ROCK: i2=AllocObject(objs[j].type-1); objs[i2].active=A_TRANSITION; o[i2].x=o[j].x+objs[i2].radius+2.0; o[i2].y=o[j].y; o[i2].theta=o[j].theta; o[i2].DxDt=o[j].DxDt; o[i2].DyDt=o[j].DyDt; o[i2].DthetaDt=o[j].DthetaDt; i2=AllocObject(objs[j].type-1); objs[i2].active=A_TRANSITION; o[i2].x=o[j].x-objs[i2].radius-2.0; o[i2].y=o[j].y; o[i2].theta=o[j].theta; o[i2].DxDt=o[j].DxDt; o[i2].DyDt=o[j].DyDt; o[i2].DthetaDt=o[j].DthetaDt; objs[j].active=A_INACTIVE; break; case OT_LARGE_ROCK: i2=AllocObject(objs[j].type-1); objs[i2].active=A_TRANSITION; o[i2].x=o[j].x+objs[i2].radius+4.0; o[i2].y=o[j].y+objs[i2].radius+4.0; o[i2].theta=o[j].theta; o[i2].DxDt=o[j].DxDt; o[i2].DyDt=o[j].DyDt; o[i2].DthetaDt=o[j].DthetaDt; i2=AllocObject(objs[j].type-1); objs[i2].active=A_TRANSITION; o[i2].x=o[j].x-objs[i2].radius-4.0; o[i2].y=o[j].y-objs[i2].radius-4.0; o[i2].theta=o[j].theta; o[i2].DxDt=o[j].DxDt; o[i2].DyDt=o[j].DyDt; o[i2].DthetaDt=o[j].DthetaDt; i2=AllocObject(objs[j].type-1); objs[i2].active=A_TRANSITION; o[i2].x=o[j].x-objs[i2].radius-4.0; o[i2].y=o[j].y+objs[i2].radius+4.0; o[i2].theta=o[j].theta; o[i2].DxDt=o[j].DxDt; o[i2].DyDt=o[j].DyDt; o[i2].DthetaDt=o[j].DthetaDt; i2=AllocObject(objs[j].type-1); objs[i2].active=A_TRANSITION; o[i2].x=o[j].x+objs[i2].radius+4.0; o[i2].y=o[j].y-objs[i2].radius-4.0; o[i2].theta=o[j].theta; o[i2].DxDt=o[j].DxDt; o[i2].DyDt=o[j].DyDt; o[i2].DthetaDt=o[j].DthetaDt; objs[j].active=A_INACTIVE; break; } } void CheckCollisions() { I8 i,j,*r1; double d,d1,dd,dx,dy; GrBitMap *b; for (i=0;iflags|=BMF_TRANSFORMATION; r1=b->r; b->r=GrTheta(o[i].theta); b->x=32; b->y=32; b->z=0; GrElemsPlot(b,0,0,0,objs[i].img); Free(b->r); b->r=r1; b->bkcolor=ROP_COLLISION+BLACK; r1=b->r; b->r=GrTheta(o[j].theta); b->x=o[j].x-o[i].x+32; b->y=o[j].y-o[i].y+32; b->z=0; GrElemsPlot(b,0,0,0,objs[j].img); Free(b->r); b->r=r1; if (b->collision_cnt>0) Collision(i,j); GrDel(b); } } } } } for (i=0;iMUZZLE_VELOCITY*5.0) Auto(" "); } } void Rocks() { I8 ch=0,i=0,c,p1,p2,sc=0; void *old_update=Fs->update_win; Ltf *l,*old_cur_ltf=Fs->cur_ltf,*old_aux_ltf=Fs->aux_ltf; BoolU4 old_preempt=Preempt(OFF), old_border=WinBorder(OFF); TssStruct *song_tss=Spawn(&SongTsk,"Rocks Song",Fs); I8 old_attr=Fs->text_attribute; SetTypeMatic(0); ode=OdeNew(NUM_OBJECTS*6); ode->derivative=&MyDerivative; ode->tolerance_start=.1; o=ode->state; objs=MAlloc(NUM_OBJECTS*sizeof(Object)); Fs->text_attribute=0x0F; WinMax; Fs->cur_ltf=NULL; Fs->aux_ltf=l=InitSysAuxLtf(TRUE); LtfPutSExt(l,"$$MA+A+TML+IV,\"Restart | \",\" \"$$"); LtfPutSExt(l,"$$MA+A+TML+IV,\"Bounce | \",\"b\"$$"); LtfPutSExt(l,"$$MA+A+TML+IV,\"Exit\",\"\\033\"$$"); LtfPutSExt(l,"$$CM+LX+TY,2,2$$$$TX+BK,\"Escort the cargo ship\"$$"); InitObjs; InsQue(ode,Fs->last_ode); Fs->update_win=&DrawIt; while (ch!=CH_ESC && ch!=CH_CTRLQ) { InitObjs; ch=0; cmd=CMD_NULL; while (ch!=CH_ESC && ch!=CH_CR && ch!=CH_SPACE && ch!=CH_CTRLQ) { while (c=ScanMsg(&p1,&p2,1<best_d && l->cur_entry!=l) { LtfRunEntry(l,l->cur_entry,TRUE,old_preempt); ch=0; l->best_d=MAX_I8; } } else if (ch=='b') bounce=!bounce; else if (sc.u1[0]==SC_CURSOR_RIGHT) cmd=CMD_SPIN_RIGHT; else if (sc.u1[0]==SC_CURSOR_LEFT) cmd=CMD_SPIN_LEFT; else if (sc.u1[0]==SC_CURSOR_UP) cmd=CMD_THRUST; else if (sc.u1[0]==SC_CURSOR_DOWN) Fire; } else cmd=CMD_NULL; } CheckCollisions; CheckCrazy; if (cmd==CMD_EXIT) { Sleep(1000); ch=CH_SPACE; } WinSync; //messages are only queued by winmngr } } Kill(song_tss); Sound(0); LtfDel(l); Fs->aux_ltf=old_aux_ltf; if (Fs->cur_ltf=old_cur_ltf) LtfBottom(Fs->cur_ltf); RemQue(ode); OdeDel(ode); Free(objs); Fs->text_attribute=old_attr; Fs->update_win=old_update; WinBorder(old_border); Preempt(old_preempt); }  љџџџќџџџќџџџњџџџџџџџўџџџўџџџџџџџ§џџџ§џџџїџџџїџџџћџџџћџџџџџџџјџџџјџџџ     єџџџєџџџєџџџєџџџљџџџљџџџљџџџљџџџўџџџ ўџџџ  љџџџќџџџќџџџњџџџџџџџўџџџўџџџџџџџ§џџџ§џџџїџџџїџџџћџџџћџџџџџџџјџџџјџџџџџџџўџџџ ўџџџ      §џџџ    ѓџџџѓџџџјџџџјџџџћџџџ ћџџџ E ўџџџ§џџџѓlп$† n[НўџџџdЈ­hўџџџћџџџn[ЯЖm’$C’$Щ$QЖeлМ„ar–ЭГэйžW’"CšЖНmлВњџџџЖm’6Mл+€ќџџџЄm ўџџџўџџџЄiлT IВrsќџџџєџџџѓцy^нкГm“$элЖmлГg’ЁF CQŒЂd["‰Љ( ГlСАlžзn.$I’TЄ$У їџџџž=л$ЮњџџџЋ]ЛЖm“ІIFI’$I’„IrY–msзzѕжmЖkл&MлЖm“Є%‘’lЖe[’$‰HвЗm›