Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.32 KB | None | 0 0
  1. // call z88dkenv.bat
  2. // zcc +vz -create-app -lm %1.c -o %1.vz
  3.  
  4.  
  5. #include <vz.h>
  6. #include <games.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <conio.h>
  10. #include <graphics.h>
  11. #include <math.h>
  12.  
  13. #define ENEMY_MAX 8
  14. #define BOTTLE_MAX 16
  15. #define SHOT_MAX 8
  16. #define EXPLOSION_MAX 6
  17. #define EXPLOSION_PIECES 12
  18.  
  19. #define FLAGSHIP_APPEAR 100
  20. #define BONUSSHIP_AWARD 500
  21.  
  22. #define BOTTLE_Y 45
  23.  
  24. #define EN_FLAGSHIP 0
  25. #define EN_SLICER 6
  26.  
  27. #define SCRSIZE 0x600
  28. #define _std_seed 10
  29.  
  30. char scr[32*64];
  31.  
  32. char *mem;
  33. char cntr;
  34. int sound1, sound2;
  35. int score, score0, score1, hiscore;
  36. int speed;
  37.  
  38. /* enemies current x,y (represented in 8.8 fractional integers) */
  39. int enemy_x[ENEMY_MAX];
  40. int enemy_y[ENEMY_MAX];
  41. /* enemies step x,y */
  42. int enemy_sx[ENEMY_MAX];
  43. int enemy_sy[ENEMY_MAX];
  44. char enemy_flag[ENEMY_MAX];
  45. char enemy_type[ENEMY_MAX];
  46. char enemy_bottle[ENEMY_MAX];
  47.  
  48. /* flag ship may occur? */
  49. char enemy_fship;
  50.  
  51. /* bottles current x,y (represented in 8.8 fractional integers) */
  52. char bottle_x[BOTTLE_MAX];
  53. char bottle_y[BOTTLE_MAX];
  54. char bottle_dy[BOTTLE_MAX];
  55. char bottle_flag[BOTTLE_MAX];
  56. #define BOTTLE_AVAIL 0x01
  57. #define BOTTLE_STOLEN 0x20
  58. #define BOTTLE_FALLING 0x40
  59. #define BOTTLE_STEAL 0x80
  60. char bottle_cnt;
  61. char bottle_live;
  62.  
  63. /* shots current x,y and color (colour = type) */
  64. char shot_x[SHOT_MAX];
  65. char shot_y[SHOT_MAX];
  66. char shot_c[SHOT_MAX];
  67. char enemy_shot_cnt;
  68. char ship_shot_cnt;
  69.  
  70. /* explosions current x,y and count (>0 is size) */
  71. char expl_x[EXPLOSION_MAX];
  72. char expl_y[EXPLOSION_MAX];
  73. char expl_cnt[EXPLOSION_MAX];
  74. char expl_max[EXPLOSION_MAX];
  75. char expl_pieces[EXPLOSION_MAX];
  76. int expl_dx[EXPLOSION_MAX*EXPLOSION_PIECES];
  77. int expl_dy[EXPLOSION_MAX*EXPLOSION_PIECES];
  78. int expl_sx[EXPLOSION_MAX*EXPLOSION_PIECES];
  79. int expl_sy[EXPLOSION_MAX*EXPLOSION_PIECES];
  80.  
  81. /* ship x,y coordinates */
  82. int ship_x, ship_y;
  83. char ship_explode, ships;
  84.  
  85. /* display scoring */
  86. char add_cnt;
  87.  
  88. /**************************************************************************
  89. * Initialize variables
  90. **************************************************************************/
  91. init_enemy()
  92. {
  93. memset(enemy_flag, 0, sizeof(enemy_flag));
  94. enemy_fship = 0;
  95. }
  96.  
  97. reinit_enemy()
  98. {
  99. int i, b;
  100. for (i = 0; i < ENEMY_MAX; i++)
  101. {
  102. b = enemy_bottle[i];
  103. if (b >= 0)
  104. {
  105. /* put back the bottle to the floor */
  106. bottle_y[b] = BOTTLE_Y;
  107. bottle_flag[b] = BOTTLE_AVAIL;
  108. bottle_cnt++;
  109. }
  110. /* enemy is dead */
  111. enemy_flag[i] = 0;
  112. }
  113. }
  114.  
  115. init_bottle()
  116. {
  117. int i;
  118. for (i = 0; i < BOTTLE_MAX; i++)
  119. {
  120. bottle_x[i] = i * 6 + 16;
  121. bottle_y[i] = BOTTLE_Y;
  122. bottle_flag[i] = BOTTLE_AVAIL;
  123. }
  124. bottle_cnt = BOTTLE_MAX;
  125. bottle_live = BOTTLE_MAX;
  126. }
  127.  
  128. init_ship()
  129. {
  130. ship_x = 64;
  131. ship_y = BOTTLE_Y - 4;
  132. ship_explode = 0;
  133. }
  134.  
  135. init_shot()
  136. {
  137. memset(shot_c, 0, sizeof(shot_c));
  138. ship_shot_cnt = 0;
  139. }
  140.  
  141. init_explosion()
  142. {
  143. memset(expl_cnt, 0, sizeof(expl_cnt));
  144. }
  145.  
  146. /**************************************************************************
  147. * Find specific slots
  148. **************************************************************************/
  149. find_bottle()
  150. {
  151. int i;
  152. i = rand()%BOTTLE_MAX;
  153. if (bottle_flag[i] == BOTTLE_AVAIL)
  154. return i;
  155. for (i = BOTTLE_MAX; i > 0; --i)
  156. {
  157. if (bottle_flag[i] == BOTTLE_AVAIL)
  158. return i;
  159. }
  160. return -1;
  161. }
  162.  
  163. find_shot()
  164. {
  165. int i;
  166. for (i = 0; i < SHOT_MAX; i++)
  167. {
  168. if (!shot_c[i])
  169. return i;
  170. }
  171. return 0;
  172. }
  173.  
  174. find_explosion(x,y,p,n,m,sy)
  175. int x,y,p,n,m,sy;
  176. {
  177. int i, j, k;
  178. for (i = 0; i < EXPLOSION_MAX; i++)
  179. {
  180. if (expl_cnt[i] == 0)
  181. {
  182. expl_x[i] = x;
  183. expl_y[i] = y;
  184. expl_cnt[i] = 1;
  185. expl_max[i] = n;
  186. expl_pieces[i] = p;
  187. for (j = 0; j < p; j++)
  188. {
  189. k = i * EXPLOSION_PIECES + j;
  190. expl_dx[k] = 0;
  191. expl_dy[k] = 0;
  192. expl_sx[k] = (rand()%256 - 128) * m;
  193. expl_sy[k] = (rand()%256 - 128) * m + sy * 128;
  194. }
  195. return;
  196. }
  197. }
  198. }
  199.  
  200. hit_enemy(x,y)
  201. int x,y;
  202. {
  203. int i, j, b, t;
  204. x *= 256;
  205. y *= 256;
  206. for (i = 0; i < ENEMY_MAX; i++)
  207. {
  208. if (enemy_flag[i] == 0)
  209. continue;
  210. if (x > enemy_x[i] - 0x300 && x < enemy_x[i] + 0x300 &&
  211. y > enemy_y[i] - 0x200 && y < enemy_y[i] + 0x200)
  212. {
  213. vz_shape(enemy_x[i]/256-3,enemy_y[i]/256-1,7,3,0,"\xfe\xfe\xfe");
  214. if (enemy_type[i] == EN_FLAGSHIP)
  215. {
  216. t = (rand()%4); /* sometimes let the slicers appear ;-) */
  217. for (j = 0; j < ENEMY_MAX; j++)
  218. {
  219. if (i == j || enemy_flag[j] || (rand()%1) != 0 )
  220. continue;
  221. enemy_x[j] = enemy_x[i] + (rand()%2048) - 1024;
  222. enemy_y[j] = y = enemy_y[i] + (rand()%1024);
  223. enemy_bottle[j] = -1;
  224. if (t == 0)
  225. {
  226. enemy_sx[j] = 0;
  227. enemy_sy[j] = 128;
  228. enemy_flag[j] = 3;
  229. enemy_type[j] = EN_SLICER;
  230. }
  231. else
  232. {
  233. x = ((rand()%112) + 8) * 256;
  234. enemy_sx[j] = (x - enemy_x[i]) / (48 - y/256);
  235. enemy_sy[j] = 128 + rand()%128;
  236. enemy_flag[j] = 2;
  237. enemy_type[j] = (rand()%EN_SLICER-1) + 1;
  238. }
  239. }
  240. t = 12;
  241. }
  242. else
  243. if (enemy_type[i] == EN_SLICER)
  244. {
  245. t = 8;
  246. }
  247. else
  248. {
  249. t = 5;
  250. b = enemy_bottle[i];
  251. if (b >= 0)
  252. {
  253. /* he looses the claim on the bottle now */
  254. bottle_flag[b] &= ~BOTTLE_STEAL;
  255. bottle_cnt++;
  256. /* did the enemy already go up? */
  257. if (bottle_flag[b] & BOTTLE_STOLEN)
  258. {
  259. bottle_flag[b] &= ~BOTTLE_STOLEN;
  260. /* the bottle starts falling now */
  261. bottle_flag[b] |= BOTTLE_FALLING;
  262. /* depth 0 */
  263. bottle_dy[b] = 0;
  264. }
  265. }
  266. }
  267. /* don't move the enemy anymore */
  268. enemy_sx[i] = 0;
  269. enemy_sy[i] = 0;
  270. enemy_flag[i] = 0;
  271. if (enemy_type[i] != EN_FLAGSHIP)
  272. find_explosion(enemy_x[i]/256,enemy_y[i]/256,EXPLOSION_PIECES/2,t,4,-1);
  273. return t;
  274. }
  275. }
  276. return 0;
  277. }
  278.  
  279. hit_ship(x,y)
  280. int x,y;
  281. {
  282. if (ship_explode)
  283. return 0;
  284. if (x > ship_x - 4 && x < ship_x + 4 && y > ship_y - 1 && y < ship_y + 4)
  285. return 1;
  286. return 0;
  287. }
  288.  
  289. hit_bottle(x)
  290. int x;
  291. {
  292. int i;
  293. for (i = 0; i < BOTTLE_MAX; i++)
  294. {
  295. if ((bottle_flag[i] & BOTTLE_AVAIL) == 0)
  296. continue;
  297. if ((bottle_flag[i] & BOTTLE_FALLING) != 0)
  298. continue;
  299. if (x == bottle_x[i] && BOTTLE_Y == bottle_y[i])
  300. {
  301. /* the bottle is now broken... */
  302. find_explosion(bottle_x[i],BOTTLE_Y,EXPLOSION_PIECES/2,10,3,-2);
  303. bottle_flag[i] = 0;
  304. bottle_live--;
  305. bottle_cnt--;
  306. sound2 = 200;
  307. return 1;
  308. }
  309. }
  310. return 0;
  311. }
  312.  
  313. /**************************************************************************
  314. * Draw to screen (or screen buffer)
  315. **************************************************************************/
  316. draw_string(x,y,color,src)
  317. int x,y,color;
  318. char *src;
  319. {
  320. while (*src)
  321. {
  322. vz_char_draw(x,y,color,*src);
  323. x += 6;
  324. src++;
  325. }
  326. }
  327.  
  328. draw_enemy_type(x,y,color,type)
  329. int x,y,color,type;
  330. {
  331. int c, s;
  332. char *enmy;
  333.  
  334. c = cntr & 3;
  335. s = cntr & 7;
  336. x -= 3;
  337. y -= 1;
  338. switch (type)
  339. {
  340. case 0:
  341. /*
  342. * .xxxx.. .xxxx.. .xxxx.. .xxxx..
  343. * x...xx. xx...x. x.x..x. x..x.x.
  344. * .xxxx.. .xxxx.. .xxxx.. .xxxx..
  345. */
  346. switch (c)
  347. {
  348. case 0: vz_shape(x,y,7,3,color,"\x78\x8c\x78"); break;
  349. case 1: vz_shape(x,y,7,3,color,"\x78\xc4\x78"); break;
  350. case 2: vz_shape(x,y,7,3,color,"\x78\xa4\x78"); break;
  351. case 3: vz_shape(x,y,7,3,color,"\x78\x94\x78"); break;
  352. }
  353. switch (s)
  354. {
  355. case 0: sound2 = 60; break;
  356. case 1: sound1 = 62; break;
  357. case 2: sound2 = 40; break;
  358. case 3: sound1 =100; break;
  359. case 4: sound2 = 20; break;
  360. case 5: sound1 = 19; break;
  361. case 6: sound2 = 40; break;
  362. case 7: sound1 = 80; break;
  363. }
  364. break;
  365. case 1:
  366. /*
  367. * ..xxx.. ..xxx.. ..xxx.. ..xxx..
  368. * xx.x.xx xx.x.xx xx.x.xx xx.x.xx
  369. * x.xxx.x ..xxx.. x.xxx.x ..xxx..
  370. */
  371. switch (c)
  372. {
  373. case 0: vz_shape(x,y,7,3,color,"\x38\xd6\xba"); break;
  374. case 1: vz_shape(x,y,7,3,color,"\x38\xd6\x38"); break;
  375. case 2: vz_shape(x,y,7,3,color,"\x38\xd6\xba"); break;
  376. case 3: vz_shape(x,y,7,3,color,"\x38\xd6\x38"); break;
  377. }
  378. break;
  379. case 2:
  380. /*
  381. * x.xxx.. ..xxx.. ..xxx.x ..xxx..
  382. * xxx.xxx xxx.xxx xxx.xxx xxx.xxx
  383. * ..xxx.x ..xxx.. x.xxx.. ..xxx..
  384. */
  385. switch (c)
  386. {
  387. case 0: vz_shape(x,y,7,3,color,"\xb8\xee\x3a"); break;
  388. case 1: vz_shape(x,y,7,3,color,"\x38\xee\x38"); break;
  389. case 2: vz_shape(x,y,7,3,color,"\x3a\xee\xb8"); break;
  390. case 3: vz_shape(x,y,7,3,color,"\x38\xee\x38"); break;
  391. }
  392. break;
  393. case 3:
  394. /*
  395. * .xx.xx. ..x.x.. .xx.xx. ..x.x..
  396. * x..x..x .x.x.x. x..x..x .x.x.x.
  397. * .xx.xx. ..x.x.. .xx.xx. ..x.x..
  398. */
  399. switch (c)
  400. {
  401. case 0: vz_shape(x,y,7,3,color,"\x6c\x92\x6c"); break;
  402. case 1: vz_shape(x,y,7,3,color,"\x28\x54\x28"); break;
  403. case 2: vz_shape(x,y,7,3,color,"\x6c\x92\x6c"); break;
  404. case 3: vz_shape(x,y,7,3,color,"\x28\x54\x28"); break;
  405. }
  406. break;
  407. case 4:
  408. /*
  409. * ..x.x.. .xx.xx. ..x.x.. .xx.xx.
  410. * .x.x.x. xx.x.xx .x.x.x. xx.x.xx
  411. * x..x..x x..x..x x..x..x x..x..x
  412. */
  413. switch (c)
  414. {
  415. case 0: vz_shape(x,y,7,3,color,"\x28\x54\x92"); break;
  416. case 1: vz_shape(x,y,7,3,color,"\x6c\xd6\x92"); break;
  417. case 2: vz_shape(x,y,7,3,color,"\x28\x54\x92"); break;
  418. case 3: vz_shape(x,y,7,3,color,"\x6c\xd6\x92"); break;
  419. }
  420. break;
  421. case 5:
  422. /*
  423. * ..xxx.. x.xxx.x ..xxx.. x.xxx.x
  424. * .xx.xx. .xx.xx. .xx.xx. .xx.xx.
  425. * x.xxx.x ..xxx.. x.xxx.x ..xxx..
  426. */
  427. switch (c)
  428. {
  429. case 0: vz_shape(x,y,7,3,color,"\x38\x6c\xba"); break;
  430. case 1: vz_shape(x,y,7,3,color,"\xba\x6c\x38"); break;
  431. case 2: vz_shape(x,y,7,3,color,"\x38\x6c\xba"); break;
  432. case 3: vz_shape(x,y,7,3,color,"\xba\x6c\x38"); break;
  433. }
  434. break;
  435. case EN_SLICER:
  436. /*
  437. * ...x... ....x.. ....... ..x....
  438. * ...x... ...x... .xxxxx. ...x...
  439. * ...x... ..x.... ....... ....x..
  440. */
  441. switch (c)
  442. {
  443. case 0: vz_shape(x,y,7,3,color,"\x10\x10\x10"); break;
  444. case 1: vz_shape(x,y,7,3,color,"\x08\x10\x20"); break;
  445. case 2: vz_shape(x,y,7,3,color,"\x00\x7c\x00"); break;
  446. case 3: vz_shape(x,y,7,3,color,"\x20\x10\x08"); break;
  447. }
  448. switch (s)
  449. {
  450. case 0: sound1 = 20; break;
  451. case 1: sound1 = 40; break;
  452. case 2: sound2 = 21; break;
  453. case 3: sound1 = 22; break;
  454. case 5: sound1 = 23; break;
  455. case 6: sound2 = 30; break;
  456. }
  457. break;
  458. }
  459. }
  460.  
  461. clear_enemy()
  462. {
  463. int i, x, y;
  464.  
  465. for (i = 0; i < ENEMY_MAX; i++)
  466. {
  467. if (enemy_flag[i] == 0)
  468. continue;
  469. x = enemy_x[i] / 256;
  470. y = enemy_y[i] / 256;
  471. vz_shape(x-3,y-1,7,3,0,"\xfe\xfe\xfe");
  472. if (enemy_type[i] == EN_SLICER && y == (BOTTLE_Y + 1))
  473. {
  474. /* did the slicer hit a bottle? */
  475. if (hit_bottle(x))
  476. enemy_flag[i] = 0;
  477. }
  478. }
  479. }
  480.  
  481. init_ship_explosion()
  482. {
  483. find_explosion(ship_x,ship_y+3,EXPLOSION_PIECES,30,3,-4);
  484. ship_explode = 1;
  485. }
  486.  
  487. draw_enemy()
  488. {
  489. int i, b, j, x, y;
  490.  
  491. for (i = 0; i < ENEMY_MAX; i++)
  492. {
  493. if (enemy_flag[i] == 0)
  494. {
  495. /* eventually create a new enemy */
  496. if ((rand()%0x7fff) > 0x7fc0 - sqrt(score))
  497. {
  498. /* start at a random x offset between 32...95 */
  499. enemy_x[i] = 256 * ((rand()%64) + 32);
  500. enemy_y[i] = 0;
  501. enemy_type[i] = (rand()%EN_SLICER-1) + 1;
  502. enemy_bottle[i] = -1; /* no bottle */
  503. /* the fewer bottles left, the more likely slicers appear */
  504. if ((rand()%bottle_cnt*2) == 0)
  505. enemy_type[i] = EN_SLICER;
  506.  
  507. /* time for a flagship occurance? */
  508. if (enemy_fship)
  509. {
  510. enemy_x[i] = 0x0200;
  511. enemy_y[i] = 0x0c00;
  512. enemy_type[i] = EN_FLAGSHIP;
  513. enemy_sx[i] = 128; /* move right */
  514. enemy_sy[i] = 0; /* horizontally only */
  515. enemy_flag[i] = 2; /* blue */
  516. enemy_fship = 0;
  517. }
  518. else
  519. if (enemy_type[i] == EN_SLICER)
  520. {
  521. enemy_sx[i] = 0; /* don't move horizontally */
  522. enemy_sy[i] = 128; /* half speed down */
  523. enemy_flag[i] = 3; /* red */
  524. }
  525. else
  526. {
  527. int dy;
  528. dy = BOTTLE_Y - enemy_y[i] / 256;
  529. x = ((rand()%64) + 32) * 256;
  530. if (bottle_cnt > 0)
  531. {
  532. b = find_bottle(); /* find a target bottle */
  533. enemy_bottle[i] = b; /* set target */
  534. if (b >= 0)
  535. {
  536. bottle_flag[b] |= BOTTLE_STEAL;
  537. bottle_cnt--;
  538. x = bottle_x[b] * 256;
  539. if (x > enemy_x[i])
  540. x = enemy_x[i] + (rand()%x - enemy_x[i]);
  541. else
  542. x = x + (rand()%enemy_x[i] - x);
  543. dy = bottle_y[b] - enemy_y[i] / 256;
  544. }
  545. }
  546. enemy_sx[i] = (x - enemy_x[i]) / dy;
  547. enemy_sy[i] = speed;
  548. enemy_flag[i] = 2; /* blue */
  549. }
  550. }
  551. else
  552. continue;
  553. }
  554. enemy_x[i] += enemy_sx[i];
  555. enemy_y[i] += enemy_sy[i];
  556. x = enemy_x[i] / 256;
  557. y = enemy_y[i] / 256;
  558. b = enemy_bottle[i];
  559.  
  560. if (hit_ship(x,y) || hit_ship(x-2,y) || hit_ship(x+2,y))
  561. {
  562.  
  563. enemy_flag[i] = 0;
  564. init_ship_explosion();
  565. continue;
  566. }
  567.  
  568. if (y < -4 || y >= 48) /* off the screen? */
  569. {
  570. enemy_flag[i] = 0; /* ship is gone now */
  571. /* is the bottle gone too? */
  572. if (b >= 0 && (bottle_flag[b] & BOTTLE_STOLEN) != 0)
  573. bottle_flag[b] = 0;
  574. continue;
  575. }
  576.  
  577. if (enemy_type[i] == EN_FLAGSHIP && x > 123)
  578. {
  579. enemy_flag[i] = 0; /* ship is gone now */
  580. continue;
  581. }
  582.  
  583. draw_enemy_type(x,y,enemy_flag[i],enemy_type[i]);
  584.  
  585. if (y == BOTTLE_Y/3) /* upper third of the screen? */
  586. {
  587. if (enemy_shot_cnt < 5 && (rand()%256-speed) == 0)
  588. {
  589. int s;
  590.  
  591. s = find_shot();
  592. shot_c[s] = 2;
  593. shot_x[s] = x;
  594. shot_y[s] = y+1;
  595. enemy_shot_cnt++;
  596. for (s = 10; s < 250; s += 40)
  597. vz_sound(s,4);
  598. }
  599. }
  600. else
  601. if (y == BOTTLE_Y/2) /* middle of the screen? */
  602. {
  603. /* got a bottle? */
  604. if (b >= 0 && (bottle_flag[b] & BOTTLE_STOLEN) != 0)
  605. {
  606. /* fly away vertically */
  607. enemy_sx[i] = 0;
  608. enemy_sy[i] = -speed;
  609. }
  610. else
  611. if (bottle_flag[b] & BOTTLE_STEAL) /* steal a bottle? */
  612. {
  613. int bx, dx, dy;
  614. /* fly to target bottle */
  615. bx = bottle_x[b] * 256;
  616. if (bx > enemy_x[i])
  617. {
  618. dx = bx - enemy_x[i];
  619. dx = enemy_x[i] + dx*3/4 + (rand()%dx/4);
  620. }
  621. else
  622. {
  623. dx = enemy_x[i] - bx;
  624. dx = bx + (rand()%dx/4);
  625. }
  626. dy = BOTTLE_Y - enemy_y[i] / 256;
  627. enemy_sx[i] = (dx - enemy_x[i]) / dy;
  628. enemy_sy[i] = speed;
  629. }
  630. }
  631. else
  632. /* normal enemy reached the row above the bottles now? */
  633. if (y == (BOTTLE_Y - 2) && b >= 0 && (bottle_flag[b] & BOTTLE_STEAL) != 0)
  634. {
  635. if (x == bottle_x[b])
  636. {
  637. /* take it up or drop the bottle now */
  638. bottle_flag[b] ^= BOTTLE_STOLEN;
  639. j = 256 * ((rand()%64) + 32);
  640. enemy_sx[i] = (j - enemy_x[i]) / (BOTTLE_Y/2);
  641. enemy_sy[i] = -speed;
  642. }
  643. else
  644. {
  645. int bx;
  646. bx = bottle_x[b] * 256;
  647. enemy_sx[i] = (bx - enemy_x[i]) / 128;
  648. if (bx < enemy_x[i])
  649. enemy_sx[i] -= 128;
  650. else
  651. enemy_sx[i] += 128;
  652. enemy_sy[i] = 0;
  653. }
  654. }
  655. else
  656. /* slicer reached the bottom row? */
  657. if (y == (BOTTLE_Y + 1) && enemy_type[i] == EN_SLICER)
  658. {
  659. if (x < 1)
  660. enemy_sx[i] = speed;
  661. else
  662. if (x > 125)
  663. enemy_sx[i] = -speed;
  664. else
  665. {
  666. if (enemy_sx[i] == 0)
  667. enemy_sx[i] = (rand()%1) ? -speed : speed;
  668. enemy_sy[i] = 0;
  669. }
  670. }
  671. if (bottle_flag[b] & BOTTLE_STOLEN) /* bottle stolen? */
  672. {
  673. bottle_x[b] = x; /* move bottle with */
  674. bottle_y[b] = y + 2; /* ship (below center) */
  675. }
  676. }
  677. }
  678.  
  679. draw_ships()
  680. {
  681. int i;
  682. vz_setbase(0x7000);
  683. for (i = 0; i < 7; i++)
  684. vz_char_draw(44+i*6, 52, (i < ships) ? 2 : 0, 0x5e);
  685. vz_setbase(scr);
  686. }
  687.  
  688. draw_hiscore()
  689. {
  690. int i, n;
  691. n = hiscore;
  692. vz_setbase(0x7000);
  693. vz_char_draw(2+5*6, 58, 3, '0');
  694. for (i = 4; n > 0 && i >= 0; i--)
  695. {
  696. vz_char_draw(2+i*6, 58, 0, 0x7f); /* erase character */
  697. vz_char_draw(2+i*6, 58, 3, 0x30 + (n % 10));
  698. n = n / 10;
  699. }
  700. vz_setbase(scr);
  701. }
  702.  
  703.  
  704. draw_score(add)
  705. int add;
  706. {
  707. int i, n;
  708. score += add;
  709. n = score;
  710.  
  711. if (score >= score0)
  712. {
  713. score0 += FLAGSHIP_APPEAR;
  714. enemy_fship = 1;
  715. }
  716. if (score >= score1)
  717. {
  718. score1 += BONUSSHIP_AWARD;
  719. ships++;
  720. draw_ships();
  721. }
  722. if (score > hiscore)
  723. {
  724. hiscore = score;
  725. draw_hiscore();
  726. }
  727. vz_setbase(0x7000);
  728. vz_char_draw(2+5*6, 52, 3, '0');
  729. for (i = 4; n > 0 && i >= 0; i--)
  730. {
  731. vz_char_draw(2+i*6, 52, 0, 0x7f); /* erase character */
  732. vz_char_draw(2+i*6, 52, 3, 0x30 + (n % 10));
  733. n = n / 10;
  734. }
  735. if (add > 0)
  736. {
  737. n = add;
  738. vz_char_draw(76+5*6, 52, 2, '0');
  739. for (i = 4; n > 0 && i >= 0; i--)
  740. {
  741. vz_char_draw(76+i*6, 52, 0, 0x7f); /* erase character */
  742. vz_char_draw(76+i*6, 52, 2, 0x30 + (n % 10));
  743. n = n / 10;
  744. }
  745. add_cnt = 5;
  746. }
  747. vz_setbase(scr);
  748. }
  749.  
  750.  
  751. clear_bottle()
  752. {
  753. int i, x, y, s;
  754.  
  755. for (i = 0; i < BOTTLE_MAX; i++)
  756. {
  757. if (bottle_flag[i] == 0)
  758. continue;
  759. x = bottle_x[i];
  760. y = bottle_y[i];
  761. vz_shape(x-1,y,3,3,0,"\x40\xe0\xe0");
  762. /* bottle falling? */
  763. if (bottle_flag[i] & BOTTLE_FALLING)
  764. {
  765. bottle_y[i] += 1;
  766. bottle_dy[i] += 1; /* depth */
  767. /* ship catched a falling bottle? */
  768. if (bottle_dy[i] > 8 && hit_ship(x,y))
  769. {
  770. bottle_y[i] = BOTTLE_Y;
  771. bottle_flag[i] &= ~BOTTLE_FALLING;
  772. draw_score(25);
  773. for (s = 10; s < 120; s += 10)
  774. vz_sound(s,5);
  775. }
  776. else
  777. if (bottle_y[i] >= BOTTLE_Y)
  778. {
  779. bottle_y[i] = BOTTLE_Y;
  780. bottle_flag[i] &= ~BOTTLE_FALLING;
  781. /* bottle fell too fast? darn.. smash it.. */
  782. if (bottle_dy[i] > 8)
  783. {
  784. find_explosion(bottle_x[i],BOTTLE_Y,EXPLOSION_PIECES/2,10,2,-3);
  785. bottle_flag[i] = 0;
  786. bottle_cnt--;
  787. bottle_live--;
  788. sound2 = 10;
  789. continue;
  790. }
  791. }
  792. }
  793. }
  794. }
  795.  
  796. draw_bottle()
  797. {
  798. int i;
  799.  
  800. for (i = 0; i < BOTTLE_MAX; i++)
  801. {
  802. /* bottle is gone? */
  803. if (bottle_flag[i] == 0)
  804. continue;
  805. vz_shape(bottle_x[i]-1,bottle_y[i],3,3,1,"\x40\xe0\xe0");
  806. vz_plot(bottle_x[i],bottle_y[i]+2,cntr&3);
  807. }
  808. }
  809.  
  810. clear_ship()
  811. {
  812. vz_shape(ship_x-3,ship_y,7,4,0,"\xfe\xfe\xfe\xfe");
  813. }
  814.  
  815. draw_ship()
  816. {
  817. static int dir, shot;
  818.  
  819. if (ship_explode)
  820. return;
  821.  
  822. if ((mem[0x68ef] & 0x20) == 0) /* left (M) ? */
  823. {
  824. dir = (dir > 0) ? 0 : dir - 1;
  825. if (ship_x > 3)
  826. ship_x--;
  827. if (dir < -2 && ship_x > 3)
  828. ship_x--;
  829. if (dir < -7 && ship_x > 3)
  830. ship_x--;
  831. }
  832. else
  833. if( dir < 0 )
  834. dir = 0;
  835. if ((mem[0x68ef] & 0x08) == 0) /* right (,) ? */
  836. {
  837. dir = (dir < 0) ? 0 : dir + 1;
  838. if (ship_x < 124)
  839. ship_x++;
  840. if (dir > +2 && ship_x < 124)
  841. ship_x++;
  842. if (dir > +7 && ship_x < 124)
  843. ship_x++;
  844. }
  845. else
  846. if( dir > 0 )
  847. dir = 0;
  848. if ((mem[0x68fb] & 0x04) == 0) /* shoot (CTRL) ? */
  849. {
  850. if (!shot && ship_shot_cnt < 3)
  851. {
  852. int s;
  853.  
  854. shot = 1;
  855. s = find_shot();
  856. shot_c[s] = 3;
  857. ship_shot_cnt++;
  858. shot_x[s] = ship_x;
  859. shot_y[s] = ship_y;
  860. for (s = 1; s < 512; s <<= 1)
  861. vz_sound(s,3);
  862. }
  863. }
  864. else
  865. shot = 0;
  866. /* ...x...
  867. * ..xxx..
  868. * .xxxxx.
  869. * xxx.xxx
  870. */
  871. vz_shape(ship_x-3,ship_y,7,4,2,"\x10\x38\x7c\xee");
  872. if (ship_shot_cnt < 3)
  873. vz_plot(ship_x,ship_y,3);
  874. }
  875.  
  876. clear_shot()
  877. {
  878. int i,x,y;
  879. for (i = 0; i < SHOT_MAX; i++)
  880. {
  881. if (!shot_c[i])
  882. continue;
  883. x = shot_x[i];
  884. y = shot_y[i];
  885. vz_plot(x,y,0);
  886. vz_plot(x,y+1,0);
  887. vz_plot(x,y+2,0);
  888. }
  889. }
  890.  
  891. draw_shot()
  892. {
  893. int i, x, y, t;
  894.  
  895. for (i = 0; i < SHOT_MAX; i++)
  896. {
  897. x = shot_x[i];
  898. y = shot_y[i];
  899. if (shot_c[i] == 2) /* enemy drop bombs */
  900. {
  901. if ((y += 2) >= BOTTLE_Y)
  902. {
  903. shot_c[i] = 0;
  904. }
  905. else
  906. {
  907. if (!ship_explode && hit_ship(x,y))
  908. {
  909. shot_c[i] = 0;
  910. enemy_shot_cnt--;
  911. init_ship_explosion();
  912. }
  913. else
  914. {
  915. shot_y[i] = y;
  916. vz_plot(x,y,2);
  917. vz_plot(x,y+1,2);
  918. }
  919. }
  920. }
  921. else
  922. if (shot_c[i] == 3) /* ship shots */
  923. {
  924. if ((y -= 3) < 0)
  925. {
  926. shot_c[i] = 0;
  927. ship_shot_cnt--;
  928. }
  929. else
  930. {
  931. t = hit_enemy(x,y);
  932. if (t == 0) t = hit_enemy(x,y+1);
  933. if (t == 0) t = hit_enemy(x,y+2);
  934. if (t)
  935. {
  936. shot_c[i] = 0;
  937. ship_shot_cnt--;
  938. draw_score(t);
  939. }
  940. else
  941. {
  942. shot_y[i] = y;
  943. vz_plot(x,y,3);
  944. vz_plot(x,y+1,3);
  945. vz_plot(x,y+2,3);
  946. }
  947. }
  948. }
  949. }
  950. }
  951.  
  952. clear_explosion()
  953. {
  954. int i, j, k, x, y, c;
  955. for (i = 0; i < EXPLOSION_MAX; i++)
  956. {
  957. c = expl_cnt[i];
  958. if (!c)
  959. continue;
  960. expl_cnt[i] = c + 1;
  961. x = expl_x[i];
  962. y = expl_y[i];
  963. for (j = 0; j < expl_pieces[i]; j++)
  964. {
  965. k = i * EXPLOSION_PIECES + j;
  966. vz_plot(x+expl_dx[k]/256,y+expl_dy[k]/256,0);
  967. if (y+expl_dy[k]/256 >= 47)
  968. expl_sy[k] = -expl_sy[k];
  969. expl_dx[k] += expl_sx[k];
  970. expl_dy[k] += expl_sy[k];
  971. if (expl_sy[k] < 0)
  972. expl_sy[k] /= 2;
  973. expl_sy[k] += 32;
  974. }
  975. }
  976. }
  977.  
  978. draw_explosion()
  979. {
  980. int i, j, k, x, y, c;
  981. for (i = 0; i < EXPLOSION_MAX; i++)
  982. {
  983. c = expl_cnt[i];
  984. if (c == 0)
  985. continue;
  986. if (c > expl_max[i])
  987. {
  988. expl_cnt[i] = 0;
  989. continue;
  990. }
  991. sound2 = c * 8;
  992. x = expl_x[i];
  993. y = expl_y[i];
  994. for (j = 0; j < expl_pieces[i]; j++)
  995. {
  996. k = i * EXPLOSION_PIECES + j;
  997. vz_plot(x+expl_dx[k]/256,y+expl_dy[k]/256,(j&2)|1);
  998. }
  999. }
  1000. }
  1001.  
  1002. clear_score_add()
  1003. {
  1004. int i;
  1005. if (--add_cnt == 0)
  1006. {
  1007. vz_setbase(0x7000);
  1008. vz_char_draw(76+5*6, 52, 0, '0');
  1009. for (i = 4; i >= 0; i--)
  1010. vz_char_draw(76+i*6, 52, 0, 0x7f); /* erase character */
  1011. vz_setbase(scr);
  1012. }
  1013. }
  1014.  
  1015.  
  1016.  
  1017.  
  1018. update_once(enemies)
  1019. int enemies;
  1020. {
  1021. cntr++;
  1022. if (cntr == 0 && speed < 256)
  1023. speed++;
  1024. vz_setbase(scr);
  1025. /* remove sprites from screen buffer */
  1026. if (enemies)
  1027. clear_enemy();
  1028. clear_bottle();
  1029. clear_ship();
  1030. clear_shot();
  1031. clear_explosion();
  1032. /* draw sprites to screen buffer */
  1033. if (enemies)
  1034. draw_enemy(); /* move and draw enemies */
  1035. draw_bottle(); /* move and draw bottles */
  1036. draw_ship(); /* move and draw ship */
  1037. draw_shot(); /* move and draw shots */
  1038. draw_explosion();
  1039. if (add_cnt > 0)
  1040. clear_score_add();
  1041. vz_setbase(0x7000);
  1042. vz_soundcopy(0x7000,scr,SCRSIZE,sound1,sound2);
  1043. sound1 = 0;
  1044. sound2 = 0;
  1045. }
  1046.  
  1047. greeting()
  1048. {
  1049. int y;
  1050. vz_setbase(scr);
  1051. memset(scr,0x00,SCRSIZE);
  1052. if (cntr < 66)
  1053. y = 48 - cntr;
  1054. else
  1055. y = -18;
  1056. draw_string(2, y+ 0, 2, " Juergen Buchmueller ");
  1057. draw_string(2, y+ 6, 2, " proudly presents: ");
  1058. draw_string(2, y+12, 2, " THE RETURN OF ");
  1059. draw_string(2, y+18, (cntr&2)|1, "-* DEFENSE COMMAND *-");
  1060. if( cntr < 0 || cntr >= 96)
  1061. {
  1062. if (cntr < 0)
  1063. {
  1064. cntr++;
  1065. draw_string(38, 32, 3, "Game Over");
  1066. }
  1067. else
  1068. draw_string(8, 32, 2, "Press 'S' to start!");
  1069. vz_setbase(0x7000);
  1070. vz_soundcopy(0x7000,scr,SCRSIZE,sound1,sound2);
  1071. }
  1072. else
  1073. if (cntr < 48)
  1074. {
  1075. cntr++;
  1076. sound1 = 7 + (rand()%12);
  1077. sound1 *= sound1;
  1078. if (y & 1)
  1079. sound2 = 100;
  1080. vz_setbase(0x7000);
  1081. vz_soundcopy(0x7000,scr,SCRSIZE,sound1,sound2);
  1082. sound1 = 0;
  1083. sound2 = 0;
  1084. }
  1085. else
  1086. if (cntr < 66)
  1087. {
  1088. vz_setbase(0x7000);
  1089. vz_soundcopy(0x7000,scr,SCRSIZE,sound1,sound2);
  1090. cntr++;
  1091. }
  1092. else
  1093. if (cntr < 96)
  1094. {
  1095. if (!(cntr & 2))
  1096. draw_string(8, 32, 2, "Press 'S' to start!");
  1097. vz_setbase(0x7000);
  1098. vz_soundcopy(0x7000,scr,SCRSIZE,sound1,sound2);
  1099. cntr++;
  1100. }
  1101. }
  1102.  
  1103. /**************************************************************************
  1104. * The main loop
  1105. **************************************************************************/
  1106. main(ac,av)
  1107. int ac;
  1108. int std_seed, _std_seed;
  1109. char *av;
  1110. {
  1111. int i;
  1112. std_seed = 10;
  1113. _std_seed = 10;
  1114. mem = 0;
  1115. srand(10);
  1116.  
  1117. hiscore = 1000;
  1118.  
  1119. clg();
  1120. vz_mode(1);
  1121. vz_setbase(0x7000);
  1122. // vz_scrbase(0x7000);
  1123.  
  1124. vz_line( 0,48,127,48,2);
  1125. vz_line( 0,49,127,49,3);
  1126. vz_line( 0,50,127,50,1);
  1127.  
  1128. speed = 196;
  1129.  
  1130. asm("di\n");
  1131. cntr = 0;
  1132. for (;;)
  1133. {
  1134. do
  1135. {
  1136. greeting();
  1137. } while (vz_inch() != 'S');
  1138.  
  1139. memset(scr,0x00,SCRSIZE);
  1140. init_enemy();
  1141. init_bottle();
  1142. init_ship();
  1143. init_shot();
  1144. init_explosion();
  1145. score = 0;
  1146. score0 = FLAGSHIP_APPEAR;
  1147. score1 = BONUSSHIP_AWARD;
  1148. ships = 3;
  1149.  
  1150. while (ships > 0)
  1151. {
  1152. draw_hiscore();
  1153. draw_score(0);
  1154. draw_ships();
  1155. do
  1156. {
  1157. update_once(1);
  1158. if (vz_inch() == 3)
  1159. {
  1160. ships = 0;
  1161. break;
  1162. }
  1163. if (bottle_live == 0)
  1164. {
  1165. ships = 0;
  1166. ship_explode = 1;
  1167. }
  1168. } while (!ship_explode);
  1169. if (ship_explode)
  1170. {
  1171. ships -= 1;
  1172. draw_ships();
  1173. /* let the ship explosion happen */
  1174. for (i = 0; i < 30; i++)
  1175. {
  1176. if (ships == 0)
  1177. draw_string(38, 32, 3, "Game Over");
  1178. update_once(1);
  1179. }
  1180. if (ships > 0)
  1181. {
  1182. vz_setbase(scr);
  1183. clear_bottle();
  1184. clear_enemy();
  1185. reinit_enemy();
  1186. /* update another 30 frames */
  1187. for (i = 0; i < 30; i++)
  1188. update_once(0);
  1189. }
  1190. init_ship();
  1191. }
  1192. }
  1193. cntr = -127; // -128;
  1194. }
  1195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement