hschumann2's picture
Upload folder using huggingface_hub
806d4b5 verified
Raw History Blame Contribute Delete
3.67 kB
<1>/* Graphics Not Rendered in HTML */
<2>/* Graphics Not Rendered in HTML */ <3>/* Graphics Not Rendered in HTML */ <4>/* Graphics Not Rendered in HTML */ <5>/* Graphics Not Rendered in HTML */ <6>/* Graphics Not Rendered in HTML */ <7>/* Graphics Not Rendered in HTML */ <8>/* Graphics Not Rendered in HTML */ <9>/* Graphics Not Rendered in HTML */ <10>/* Graphics Not Rendered in HTML */
#define BASE_X (GR_WIDTH/2)
#define BASE_Y (3*GR_HEIGHT/4)
#define TEE_HEIGHT 34
#define BATTER_T 0.25
#define BATTER_IMGS_NUM 4
U8 *batter_imgs[BATTER_IMGS_NUM]={<2>,<3>,<4>,<5>};
#define RUNNER1_T 1.5
#define RUNNER1_IMGS_NUM 6
U8 *runner1_imgs[RUNNER1_IMGS_NUM]={<5>,<6>,<7>,<7>,<7>,<8>};
#define RUNNER2_T 0.4
#define RUNNER2_IMGS_NUM 4
U8 *runner2_imgs[RUNNER2_IMGS_NUM]={<8>,<9>,<8>,<10>};
F64 t0,hit_t0;
F64 ball_x,ball_y;
U0 DrawIt(CTask *,CDC *dc)
{
F64 tt=tS-t0;
I64 i=(BATTER_IMGS_NUM-1)*tt/BATTER_T;
U8 *tmps;
dc->color=WHITE;
dc->thick=3;
GrLine3(dc,BASE_X,BASE_Y,0,BASE_X-200,BASE_Y-200,0);
GrLine3(dc,BASE_X,BASE_Y,0,BASE_X+200,BASE_Y-200,0);
Sprite3(dc,BASE_X,BASE_Y,0,<1>);
dc->color=WHITE;
GrCircle(dc,ball_x+BASE_X,ball_y+BASE_Y-TEE_HEIGHT,2);
if (!t0)
Sprite3(dc,BASE_X-23,BASE_Y,0,batter_imgs[0]);
else if (i<BATTER_IMGS_NUM-1) {
tmps=SpriteInterpolate(
((BATTER_IMGS_NUM-1)/BATTER_T)*(tt%(BATTER_T/(BATTER_IMGS_NUM-1))),
batter_imgs[i],batter_imgs[i+1]);
Sprite3(dc,BASE_X-23,BASE_Y,0,tmps);
Free(tmps);
if (!hit_t0 && tt>BATTER_T/2)
hit_t0=tS;
} else {
tt-=BATTER_T;
i=(RUNNER1_IMGS_NUM-1)*tt/RUNNER1_T;
if (i<RUNNER1_IMGS_NUM-1 ) {
tmps=SpriteInterpolate(
((RUNNER1_IMGS_NUM-1)/RUNNER1_T)*
(tt%(RUNNER1_T/(RUNNER1_IMGS_NUM-1))),
runner1_imgs[i],runner1_imgs[i+1]);
Sprite3(dc,BASE_X-23,BASE_Y,0,tmps);
Free(tmps);
} else {
tt-=RUNNER1_T;
i=RUNNER2_IMGS_NUM*tt/RUNNER2_T;
if (i<30) {
tmps=SpriteInterpolate(
(RUNNER2_IMGS_NUM/RUNNER2_T)*(tt%(RUNNER2_T/RUNNER2_IMGS_NUM)),
runner2_imgs[i%RUNNER2_IMGS_NUM],
runner2_imgs[(i+1)%RUNNER2_IMGS_NUM]);
Sprite3(dc,BASE_X-23-50*tt,BASE_Y-50*tt,0,tmps);
Free(tmps);
} else {
t0=0;
ball_x=0;
ball_y=0;
}
}
}
}
#define BALL_PATH_PTS 7
CD3I32 ball_path[BALL_PATH_PTS]={
{0,0,0},{20,-40,0},{40,20,0},
{40,20,0},{50,-30,0},{55,10,0},
{55,10,0}
};
Bool PlotBall(U8 *,I64 _x,I64 _y,I64)
{
ball_x=_x; ball_y=_y;
Sleep(3);
return TRUE;
}
U0 AnimateTask(I64)
{
while (TRUE) {
if (hit_t0) {
Noise(25,86,93);
BSpline2(NULL,&ball_path,BALL_PATH_PTS,&PlotBall);
hit_t0=0;
}
Sleep(1);
}
}
U0 Init()
{
t0=0;
hit_t0=0;
ball_x=0;
ball_y=0;
}
U0 TeeBall()
{
SettingsPush; //See SettingsPush
Fs->text_attr=GREEN<<4+WHITE;
AutoComplete;
WinBorder;
WinMax;
DocCursor;
DocClear;
Fs->animate_task=Spawn(&AnimateTask,NULL,"Animate",,Fs);
MenuPush(
"File {"
" Abort(,CH_SHIFT_ESC);"
" Exit(,CH_ESC);"
"}"
"Play {"
" Swing(,CH_SPACE);"
" Restart(,'\n');"
"}"
);
Init;
Fs->draw_it=&DrawIt;
try {
while (TRUE) {
switch (GetChar(,FALSE)) {
case '\n':
Init;
break;
case CH_SPACE:
t0=tS;
break;
case CH_SHIFT_ESC:
case CH_ESC:
goto tb_done;
}
}
tb_done:
} catch
PutExcept;
SettingsPop;
MenuPop;
}
TeeBall;