File size: 2,690 Bytes
806d4b5 | 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 |
/*This shows how you can make a
background very easily.
*/
<1>/* Graphics Not Rendered in HTML */
<2>/* Graphics Not Rendered in HTML */
CDC *background;
#define BALL_TIME 0.2
#define FANS_NUM 10
I64 x[FANS_NUM],y[FANS_NUM];
Bool hit[FANS_NUM];
F64 theta[FANS_NUM],ball_t;
I64 target_x,target_y,pitcher_x,pitcher_y;
U0 DrawIt(CTask *,CDC *dc)
{
I64 i,*r;
F64 xx,yy,t0;
background->flags|=DCF_NO_TRANSPARENTS;
GrBlot(dc,0,0,background);
for (i=0;i<FANS_NUM;i++)
Sprite3ZB(dc,x[i],y[i],0,<fan>,theta[i]);
if (ball_t) {
t0=(tS-ball_t)/BALL_TIME;
if (t0>1.0)
ball_t=0;
else {
xx=t0*target_x+(1.0-t0)*pitcher_x;
yy=t0*target_y+(1.0-t0)*pitcher_y;
xx/=1.5-t0;
yy/=1.5-t0;
r=Mat4x4New(dc->r,dc->mem_task);
Mat4x4Scale(r,1.5-t0);
Free(dc->r);
DCMat4x4Set(dc,r);
dc->flags|=DCF_TRANSFORMATION;
Sprite3ZB(dc,xx,yy,0,<ball>,t0);
}
}
dc->color=RED;
GrPrint(dc,FONT_WIDTH,FONT_HEIGHT,"Peg the Fans");
}
U0 AnimateTask(I64)
{
I64 i;
F64 xx,yy,t0;
while (TRUE) {
if (ball_t) {
t0=(tS-ball_t)/BALL_TIME;
xx=t0*target_x+(1.0-t0)*pitcher_x;
yy=t0*target_y+(1.0-t0)*pitcher_y;
}
for (i=0;i<FANS_NUM;i++) {
if (ball_t)
if (Sqr(x[i]-xx)+Sqr(y[i]-yy)<200) {
hit[i]=TRUE;
theta[i]=-pi/2;
}
if (!hit[i]) {
x[i]+=SignI64(RandI16);
y[i]+=SignI64(RandI16);
theta[i]+=Sign(RandI16)/25.0;
if (!(0<=x[i]<GR_WIDTH)) x[i]=GR_WIDTH/2;
if (!(10<=y[i]<100)) y[i]=50;
if (!(-0.75<=theta[i]<0.75)) theta[i]=0;
}
}
Sleep(10);
}
}
U0 Init()
{
I64 i;
for (i=0;i<FANS_NUM;i++) {
x[i]=RandU16%GR_WIDTH;
y[i]=50;
theta[i]=0;
hit[i]=FALSE;
}
}
U0 Stadium()
{
I64 msg_code,arg1,arg2,ch=0;
SettingsPush; //See SettingsPush
Cd(__DIR__);
Fs->win_inhibit|=WIG_DBL_CLICK;
MenuPush(
"File {"
" Abort(,CH_SHIFT_ESC);"
" Exit(,CH_ESC);"
"}"
"Play {"
" Restart(,'\n');"
"}"
);
AutoComplete;
WinBorder;
WinMax;
DocCursor;
DocClear;
Init;
Fs->animate_task=Spawn(&AnimateTask,NULL,"Animate",,Fs);
background=GRRead("StadiumBG");
Fs->draw_it=&DrawIt;
do {
msg_code=GetMsg(&arg1,&arg2,1<<MSG_KEY_DOWN+1<<MSG_MS_L_DOWN);
if (msg_code==MSG_KEY_DOWN) {
ch=arg1;
if (ch=='\n')
Init;
} else {
target_x=arg1; target_y=arg2;
pitcher_x=GR_WIDTH/2; pitcher_y=GR_HEIGHT;
ball_t=tS;
}
} while (ch!=CH_SHIFT_ESC && ch!=CH_ESC);
GetMsg(,,1<<MSG_KEY_UP);
DCDel(background);
SettingsPop;
MenuPop;
}
Stadium;
|