File size: 4,589 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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
//These are the coordinates of the player.
I64 x=0,y=GR_HEIGHT/2;
/*This is a FIFO (first-in first-out) data structure
which keeps track of bullets. When a new bullet is
fired, the bullets_in val is increased by one.
When a bullet expires, the bullets_out val is increased
by one. The in and out vals loop-around, back to
the start of the arrays. It is known as a ring-buffer.
*/
#define BULLETS_NUM 32
I64 bullets_in=0,bullets_out=0,bx[BULLETS_NUM],by[BULLETS_NUM];
//This is a fifo which keeps track of the bad guys.
#define DEAD_NUM 32
I64 dead_in=0,dead_out=0,gx[DEAD_NUM],gy[DEAD_NUM];
Bool g_dead[DEAD_NUM];
/*This is a sprite created and edited by pressing
<CTRL-r>. When created, they are assigned
a num. Press <CTRL-t>, to see the hidden DolDoc
place holder for the sprite. The text in quotes
can be set to whatever you want or nothing,
but the ending num can't be changed. It
is controled by the editor.
*/
<1>/* Graphics Not Rendered in HTML */
<2>/* Graphics Not Rendered in HTML */
<3>/* Graphics Not Rendered in HTML */
//Called by the Window Mgr system task 30fps.
//The task arg is the task owning the window.
U0 DrawIt(CTask *task,CDC *dc)
{
I64 i,j;
//<CTRL-t> now to see the DolDoc place holder
//where the sprite num is encoded. $IB...$ stands
//for "insert ptr to binary object".
Sprite3(dc,x,y,0,<1>);
i=bullets_out;
while (i!=bullets_in) {
j=i++ &(BULLETS_NUM-1);
GrLine(dc,bx[j],by[j],bx[j]-2,by[j]);
}
i=dead_out;
while (i!=dead_in) {
j=i++ &(BULLETS_NUM-1);
if (!g_dead[j]) {
if (gx[j]%10>4)
Sprite3(dc,gx[j],gy[j],0,<2>);
else
Sprite3(dc,gx[j],gy[j],0,<3>);
}
}
dc->color=BLACK;
GrPrint(dc,0,0,"If you aspire to making games,");
GrPrint(dc,0,FONT_HEIGHT,"you must learn to make-up rules.");
}
U0 SongTask(I64)
{//Randomly generate (by God :-)
Fs->task_end_cb=&SndTaskEndCB;
MusicSettingsRst;
while (TRUE) {
Play("5qDqDsDCDC4etB5C4B5qCqCqCqCqDqDsDCDC4etB5C4B5qCqCqCqCqCq"
"CsCCCCetCCBeBBeBBqBqBqCqCsCCCCetCCBeBBeBBqBqB");
}
}
U0 TheDead()
{
I64 i,j,i1,j1,k=0,sc=0,ch=0,msg_code,arg1,arg2;
Bool gun_on=FALSE;
MenuPush(
"File {"
" Abort(,CH_SHIFT_ESC);"
" Exit(,CH_ESC);"
"}"
"Play {"
" Fire(,CH_SPACE);"
" Up(,,SC_CURSOR_UP);"
" Down(,,SC_CURSOR_DOWN);"
"}"
);
SettingsPush; //See SettingsPush
AutoComplete;
WinBorder;
WinMax;
DocCursor;
DocClear;
Fs->song_task=Spawn(&SongTask,NULL,"Song",,Fs);
Fs->draw_it=&DrawIt;
try {
do {
if (msg_code=ScanMsg(&arg1,&arg2,1<<MSG_KEY_DOWN | 1<<MSG_KEY_UP)) {
//With keyboard msgs, the two msg args
//are the scan code and ascii val for the key.
sc=arg2; ch=arg1;
if (msg_code==MSG_KEY_DOWN) {
//The low byte of the scan code identifies the key.
if (sc.u8[0]==SC_CURSOR_DOWN) {
y+=10;
if (y>GR_HEIGHT-30)
y=GR_HEIGHT-30;
} else if (sc.u8[0]==SC_CURSOR_UP) {
y-=10;
if (y<0)
y=0;
} else if (sc.u8[0]==SC_CURSOR_RIGHT ||
ch==CH_SPACE)
gun_on=TRUE;
} else if (msg_code==MSG_KEY_UP) {
if (sc.u8[0]==SC_CURSOR_RIGHT ||
ch==CH_SPACE)
gun_on=FALSE;
}
}
i=bullets_out;
while (i!=bullets_in) {
j=i++ &(BULLETS_NUM-1);
bx[j]+=5;
if (bx[j]>GR_WIDTH)
bullets_out++;
else {
i1=dead_out;
while (i1!=dead_in) {
j1=i1++ &(DEAD_NUM-1);
if (gy[j1]<=by[j]<=gy[j1]+38 &&
gx[j1]<=bx[j]<=gx[j1]+40)
g_dead[j1]=TRUE;
}
}
}
if (gun_on) {
j=bullets_in&(BULLETS_NUM-1);
bx[j]=x+32;
by[j]=y+14;
bullets_in++;
}
//Runs one out of four passes through this loop.
if (!(k % 4)) {
i=dead_out;
while (i!=dead_in) {
j=i++ &(DEAD_NUM-1);
gx[j]-=1;
if (gx[j]<25)
dead_out++;
}
}
//Runs one out of 150 passes through this loop.
if (!(k%150)) {
j=dead_in&(DEAD_NUM-1);
gx[j]=GR_WIDTH-30;
gy[j]=RandU32%(GR_HEIGHT-50)+25;
g_dead[j]=FALSE;
dead_in++;
}
k++;
Sleep(10); //Swap this task out for 10 miliseconds.
} while (ch!=CH_ESC && ch!=CH_SHIFT_ESC);
} catch
PutExcept;
SettingsPop;
MenuPop;
}
TheDead; //Run program when #included
|