File size: 3,671 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 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 |
<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;
|