/* Graphics Not Rendered in HTML */
/* Graphics Not Rendered in HTML */
/* Graphics Not Rendered in HTML */
/* Graphics Not Rendered in HTML */
/* Graphics Not Rendered in HTML */
/* Graphics Not Rendered in HTML */
/* Graphics Not Rendered in HTML */
/* Graphics Not Rendered in HTML */
/* Graphics Not Rendered in HTML */
/* Graphics Not Rendered in HTML */
/* Graphics Not Rendered in HTML */
/* Graphics Not Rendered in HTML */
/* Graphics Not Rendered in HTML */
/* Graphics Not Rendered in HTML */
#define CMD_NULL 0
#define CMD_SPIN_LEFT 1
#define CMD_SPIN_RIGHT 2
#define CMD_THRUST 3
#define CMD_FIRE 4
#define CMD_GAME_OVER 5
I64 cmd_code=CMD_NULL;
#define STARS_NUM 100
I64 stars_x[STARS_NUM],stars_y[STARS_NUM];
Bool bounce;
#define OT_SHIELD_SHIP 0
#define OT_NO_SHIELD_SHIP 1
#define OT_CARGO 2
#define OT_SHOT 3
#define OT_TINY_ROCK 4
#define OT_SMALL_ROCK 5
#define OT_MEDIUM_ROCK 6
#define OT_LARGE_ROCK 7
#define OT_TYPES_NUM 8
F64 radii[OT_TYPES_NUM]={15,15,30,7,5,11,20,26};
U8 *imgs[OT_TYPES_NUM*2]=
{, ,
, ,
, ,
, ,
, ,
, ,
, ,
,
};
#define A_TRANSITION -1
#define A_INACTIVE 0
#define A_ACTIVE 1
class Order2D2theta
{
F64 x,y,theta;
F64 DxDt,DyDt,DthetaDt;
};
class Obj
{
I32 active;
I32 type;
U8 *img;
F64 mass,radius;
F64 timeout;
};
#define O_SHIP 0
#define O_CARGO 1
#define O_OBJS_NUM 256
CMathODE *ode;
Order2D2theta *o_state;
Obj *objs;
U0 ObjInit(I64 i, I64 type)
{
objs[i].active=A_ACTIVE;
objs[i].timeout=0;
objs[i].type=type;
objs[i].radius=radii[type];
objs[i].img=imgs[type*2+i&1];
objs[i].mass=objs[i].radius*objs[i].radius*objs[i].radius;
}
I64 last_obj_alloced=0;
I64 ObjAlloc(I64 type)
{
while (objs[last_obj_alloced].active!=A_INACTIVE)
last_obj_alloced=(last_obj_alloced+1)%O_OBJS_NUM;
ObjInit(last_obj_alloced,type);
return last_obj_alloced;
}
U0 DrawIt(CTask *task,CDC *dc)
{
I64 i,x,y;
task->text_attr=BLACK<<4+WHITE;
dc->color=WHITE;
for (i=0;iGR_WIDTH) {
x%=GR_WIDTH;
o_state[i].x=x;
}
if (y<0) {
y=GR_HEIGHT-AbsI64(y)%GR_HEIGHT;
o_state[i].y=y;
} else if (y>GR_HEIGHT) {
y%=GR_HEIGHT;
o_state[i].y=y;
}
switch (objs[i].type) {
case OT_SHIELD_SHIP:
if (cmd_code==CMD_THRUST && RandU16&0x8000)
Sprite3ZB(dc,x,y,0,imgs[OT_SHIELD_SHIP*2+1],o_state[i].theta);
else
Sprite3ZB(dc,x,y,0,imgs[OT_SHIELD_SHIP*2],o_state[i].theta);
break;
case OT_NO_SHIELD_SHIP:
if (cmd_code==CMD_THRUST && RandU16&0x8000)
Sprite3ZB(dc,x,y,0,imgs[OT_NO_SHIELD_SHIP*2+1],o_state[i].theta);
else
Sprite3ZB(dc,x,y,0,imgs[OT_NO_SHIELD_SHIP*2],o_state[i].theta);
break;
case OT_SHOT:
case OT_TINY_ROCK:
case OT_SMALL_ROCK:
case OT_MEDIUM_ROCK:
case OT_LARGE_ROCK:
case OT_CARGO:
Sprite3ZB(dc,x,y,0,objs[i].img,o_state[i].theta);
break;
}
}
}
}
dc->color=WHITE;
GrPrint(dc,0,0,"Escort the cargo ship.");
}
U0 Init()
{
I64 i,j;
cmd_code=CMD_NULL;
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_code) {
case CMD_SPIN_LEFT:
DstateDt[O_SHIP].DthetaDt-=10.0;
break;
case CMD_SPIN_RIGHT:
DstateDt[O_SHIP].DthetaDt+=10.0;
break;
case CMD_THRUST:
DstateDt[O_SHIP].DxDt+=100.0*Cos(state[O_SHIP].theta-pi/2.0);
DstateDt[O_SHIP].DyDt+=100.0*Sin(state[O_SHIP].theta-pi/2.0);
break;
}
DstateDt[O_CARGO].DxDt+=2.0*Cos(state[O_CARGO].theta-pi/2.0);
DstateDt[O_CARGO].DyDt+=2.0*Sin(state[O_CARGO].theta-pi/2.0);
}
U0 Collision(I64 i,I64 j)
{
I64 i2;
switch (objs[i].type) {
case OT_SHIELD_SHIP:
case OT_NO_SHIELD_SHIP:
if (!bounce) {
cmd_code=CMD_GAME_OVER;
objs[i].active=A_INACTIVE;
}
break;
case OT_CARGO:
cmd_code=CMD_GAME_OVER;
objs[i].active=A_INACTIVE;
break;
case OT_TINY_ROCK:
if (objs[j].type==OT_SHOT && !bounce)
objs[i].active=A_INACTIVE;
break;
case OT_SHOT:
if (!bounce)
objs[i].active=A_INACTIVE;
break;
case OT_SMALL_ROCK:
case OT_MEDIUM_ROCK:
i2=ObjAlloc(objs[i].type-1);
objs[i2].active=A_TRANSITION;
o_state[i2].x=o_state[i].x+objs[i2].radius+2.0;
o_state[i2].y=o_state[i].y;
o_state[i2].theta=o_state[i].theta;
o_state[i2].DxDt=o_state[i].DxDt;
o_state[i2].DyDt=o_state[i].DyDt;
o_state[i2].DthetaDt=o_state[i].DthetaDt;
i2=ObjAlloc(objs[i].type-1);
objs[i2].active=A_TRANSITION;
o_state[i2].x=o_state[i].x-objs[i2].radius-2.0;
o_state[i2].y=o_state[i].y;
o_state[i2].theta=o_state[i].theta;
o_state[i2].DxDt=o_state[i].DxDt;
o_state[i2].DyDt=o_state[i].DyDt;
o_state[i2].DthetaDt=o_state[i].DthetaDt;
objs[i].active=A_INACTIVE;
break;
case OT_LARGE_ROCK:
i2=ObjAlloc(objs[i].type-1);
objs[i2].active=A_TRANSITION;
o_state[i2].x=o_state[i].x+objs[i2].radius+4.0;
o_state[i2].y=o_state[i].y+objs[i2].radius+4.0;
o_state[i2].theta=o_state[i].theta;
o_state[i2].DxDt=o_state[i].DxDt;
o_state[i2].DyDt=o_state[i].DyDt;
o_state[i2].DthetaDt=o_state[i].DthetaDt;
i2=ObjAlloc(objs[i].type-1);
objs[i2].active=A_TRANSITION;
o_state[i2].x=o_state[i].x-objs[i2].radius-4.0;
o_state[i2].y=o_state[i].y-objs[i2].radius-4.0;
o_state[i2].theta=o_state[i].theta;
o_state[i2].DxDt=o_state[i].DxDt;
o_state[i2].DyDt=o_state[i].DyDt;
o_state[i2].DthetaDt=o_state[i].DthetaDt;
i2=ObjAlloc(objs[i].type-1);
objs[i2].active=A_TRANSITION;
o_state[i2].x=o_state[i].x-objs[i2].radius-4.0;
o_state[i2].y=o_state[i].y+objs[i2].radius+4.0;
o_state[i2].theta=o_state[i].theta;
o_state[i2].DxDt=o_state[i].DxDt;
o_state[i2].DyDt=o_state[i].DyDt;
o_state[i2].DthetaDt=o_state[i].DthetaDt;
i2=ObjAlloc(objs[i].type-1);
objs[i2].active=A_TRANSITION;
o_state[i2].x=o_state[i].x+objs[i2].radius+4.0;
o_state[i2].y=o_state[i].y-objs[i2].radius-4.0;
o_state[i2].theta=o_state[i].theta;
o_state[i2].DxDt=o_state[i].DxDt;
o_state[i2].DyDt=o_state[i].DyDt;
o_state[i2].DthetaDt=o_state[i].DthetaDt;
objs[i].active=A_INACTIVE;
break;
}
switch (objs[j].type) {
case OT_SHIELD_SHIP:
case OT_NO_SHIELD_SHIP:
if (!bounce) {
cmd_code=CMD_GAME_OVER;
objs[j].active=A_INACTIVE;
}
break;
case OT_CARGO:
cmd_code=CMD_GAME_OVER;
objs[j].active=A_INACTIVE;
break;
case OT_TINY_ROCK:
if (objs[i].type==OT_SHOT && !bounce)
objs[j].active=A_INACTIVE;
break;
case OT_SHOT:
if (!bounce)
objs[j].active=A_INACTIVE;
break;
case OT_SMALL_ROCK:
case OT_MEDIUM_ROCK:
i2=ObjAlloc(objs[j].type-1);
objs[i2].active=A_TRANSITION;
o_state[i2].x=o_state[j].x+objs[i2].radius+2.0;
o_state[i2].y=o_state[j].y;
o_state[i2].theta=o_state[j].theta;
o_state[i2].DxDt=o_state[j].DxDt;
o_state[i2].DyDt=o_state[j].DyDt;
o_state[i2].DthetaDt=o_state[j].DthetaDt;
i2=ObjAlloc(objs[j].type-1);
objs[i2].active=A_TRANSITION;
o_state[i2].x=o_state[j].x-objs[i2].radius-2.0;
o_state[i2].y=o_state[j].y;
o_state[i2].theta=o_state[j].theta;
o_state[i2].DxDt=o_state[j].DxDt;
o_state[i2].DyDt=o_state[j].DyDt;
o_state[i2].DthetaDt=o_state[j].DthetaDt;
objs[j].active=A_INACTIVE;
break;
case OT_LARGE_ROCK:
i2=ObjAlloc(objs[j].type-1);
objs[i2].active=A_TRANSITION;
o_state[i2].x=o_state[j].x+objs[i2].radius+4.0;
o_state[i2].y=o_state[j].y+objs[i2].radius+4.0;
o_state[i2].theta=o_state[j].theta;
o_state[i2].DxDt=o_state[j].DxDt;
o_state[i2].DyDt=o_state[j].DyDt;
o_state[i2].DthetaDt=o_state[j].DthetaDt;
i2=ObjAlloc(objs[j].type-1);
objs[i2].active=A_TRANSITION;
o_state[i2].x=o_state[j].x-objs[i2].radius-4.0;
o_state[i2].y=o_state[j].y-objs[i2].radius-4.0;
o_state[i2].theta=o_state[j].theta;
o_state[i2].DxDt=o_state[j].DxDt;
o_state[i2].DyDt=o_state[j].DyDt;
o_state[i2].DthetaDt=o_state[j].DthetaDt;
i2=ObjAlloc(objs[j].type-1);
objs[i2].active=A_TRANSITION;
o_state[i2].x=o_state[j].x-objs[i2].radius-4.0;
o_state[i2].y=o_state[j].y+objs[i2].radius+4.0;
o_state[i2].theta=o_state[j].theta;
o_state[i2].DxDt=o_state[j].DxDt;
o_state[i2].DyDt=o_state[j].DyDt;
o_state[i2].DthetaDt=o_state[j].DthetaDt;
i2=ObjAlloc(objs[j].type-1);
objs[i2].active=A_TRANSITION;
o_state[i2].x=o_state[j].x+objs[i2].radius+4.0;
o_state[i2].y=o_state[j].y-objs[i2].radius-4.0;
o_state[i2].theta=o_state[j].theta;
o_state[i2].DxDt=o_state[j].DxDt;
o_state[i2].DyDt=o_state[j].DyDt;
o_state[i2].DthetaDt=o_state[j].DthetaDt;
objs[j].active=A_INACTIVE;
break;
}
}
U0 CheckCollisions()
{
I64 i,j;
F64 d,d1,dd,dx,dy;
CDC *dc;
for (i=0;icolor=ROP_COLLISION;
dc->bkcolor=BLACK;
Sprite3ZB(dc,o_state[j].x-o_state[i].x+32,
o_state[j].y-o_state[i].y+32,0,
objs[j].img,o_state[j].theta);
if (dc->collision_cnt>0)
Collision(i,j);
DCDel(dc);
}
}
}
}
}
for (i=0;iMUZZLE_VELOCITY*5.0)
In(" ");
}
}
U0 SongTask(I64)
{ //Song by Terry A. Davis
Fs->task_end_cb=&SndTaskEndCB;
MusicSettingsRst;
while (TRUE) {
Play("5eGGsGGeGGGe.GeCDsEDeC4BAe.A5eG");
Play("5GsGGeGGGe.GeFEsDEeDC4Be.A5eFD");
Play("5EDFDEDECDCECDCsGGeG");
Play("5GG4hG5sGGeGGG4hG");
}
}
U0 Rocks()
{
I64 ch,sc,msg_code;
CMenuEntry *tmpse;
PopUpOk(
"I refuse to rip-off the original\n"
"so this is intentionally unplayable\n"
"and included for demonstration\n"
"purposes.\n\n"
"Write games, don't play them.\n");
SettingsPush; //See SettingsPush
Fs->song_task=Spawn(&SongTask,NULL,"Song",,Fs);
MenuPush(
"File {"
" Abort(,CH_SHIFT_ESC);"
" Exit(,CH_ESC);"
"}"
"Play {"
" Restart(,'\n');"
" Fire(,CH_SPACE);"
" Fwd(,,SC_CURSOR_UP);"
" Left(,,SC_CURSOR_LEFT);"
" Right(,,SC_CURSOR_RIGHT);"
" ToggleBounce(,'b');"
"}"
);
tmpse=MenuEntryFind(Fs->cur_menu,"Play/ToggleBounce");
tmpse->checked=bounce=TRUE;
ode=ODENew(O_OBJS_NUM*6,0.01);
ode->derive=&MyDerivative;
ode->min_tolerance=0.001*ode->max_tolerance;
o_state=ode->state;
objs=MAlloc(O_OBJS_NUM*sizeof(Obj));
AutoComplete;
WinBorder;
WinMax;
DocCursor;
DocClear;
Init;
QueIns(ode,Fs->last_ode);
Fs->draw_it=&DrawIt;
try {
while (TRUE) {
while (msg_code=ScanMsg(&ch,&sc,1<cur_menu,"Play/ToggleBounce");
tmpse->checked=bounce=!bounce;
if (bounce)
objs[O_SHIP].type=OT_SHIELD_SHIP;
else
objs[O_SHIP].type=OT_NO_SHIELD_SHIP;
break;
}
else //MSG_KEY_UP
cmd_code=CMD_NULL;
}
CheckCollisions;
CheckCrazy;
if (cmd_code==CMD_GAME_OVER) {
Sleep(1000);
Init;
}
Refresh; //msgs are only qued by winmgr
}
rk_done:
GetMsg(,,1<popup_task);
TaskWait(task->popup_task);
PostMsgWait(task->popup_task,MSG_KEY_DOWN_UP,CH_SPACE,0);
DeathWait(&task->popup_task);
PostMsgWait(task,MSG_KEY_DOWN,0,SC_CURSOR_RIGHT);
Sleep(300);
for (i=0;i<15;i++) {
PostMsgWait(task,MSG_KEY_DOWN_UP,CH_SPACE,0);
Sleep(100);
}
PostMsgWait(task,MSG_KEY_UP,0,SC_CURSOR_RIGHT);
PostMsgWait(task,MSG_KEY_DOWN_UP,CH_SHIFT_ESC,0);
DeathWait(&task,TRUE);
}
Rocks/* Graphics Not Rendered in HTML */