Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

691 lines
18 KiB

  1. //-----------------------------------------------------------------------------
  2. // BomberRun by George Allan
  3. //-----------------------------------------------------------------------------
  4. global score = 0;
  5. global height = 23;
  6. global gframe = 0;
  7. global detec = table();
  8. global killStars = 0;
  9. global playerx = 0;
  10. global playery = 0;
  11. global fireCnt = 0;
  12. global fireMax = 3;
  13. global clearExplo = 0;
  14. //-----------------------------------------------------------------------------
  15. //-----------------------------------------------------------------------------
  16. global sync = function() {
  17. time = TICK();
  18. wait = (1./30.) - time;
  19. if(wait > 0) {
  20. sleep(wait);
  21. }
  22. TICK();
  23. global gframe = gframe + 1;
  24. };
  25. //-----------------------------------------------------------------------------
  26. //-----------------------------------------------------------------------------
  27. global star = function() {
  28. global detec;
  29. global killStars;
  30. frame = 0;
  31. while (1) {
  32. x = randint(1,79);
  33. y = randint(2,height);
  34. // On top of a building ?
  35. if (y < detec[x]-1) {
  36. // Print Star for a while
  37. t = randint(50,100);
  38. for (i=0;i<t;i=i+1) {
  39. // Choose a twinkle color
  40. if (randint(0,2) == 0) {
  41. CATTRIB(CA.F_RED|CA.F_BLUE|CA.F_GREEN | CA.B_BLUE);
  42. }
  43. else {
  44. CATTRIB(CA.F_RED|CA.F_GREEN | CA.B_BLUE);
  45. }
  46. // Pop !
  47. if (i>t-2) {
  48. XYTEXT(x,y,",");
  49. }
  50. else {
  51. XYTEXT(x,y,".");
  52. }
  53. // Sync to the master frame
  54. while (frame == gframe) {
  55. yield();
  56. if (killStars) {
  57. exit();
  58. }
  59. }
  60. frame = gframe;
  61. }
  62. // Clear Star
  63. CATTRIB(CA.F_BLUE | CA.B_BLUE);
  64. XYTEXT(x,y," ");
  65. }
  66. yield();
  67. if (killStars) {
  68. exit();
  69. }
  70. }
  71. };
  72. //-----------------------------------------------------------------------------
  73. //-----------------------------------------------------------------------------
  74. global particle = function(x, y) {
  75. global detec;
  76. global clearExplo;
  77. pcoltab = table(CA.F_RED|CA.F_INTENSITY, CA.F_RED|CA.F_GREEN|CA.F_INTENSITY, CA.F_RED|CA.F_GREEN|CA.F_BLUE|CA.F_INTENSITY);
  78. pfrtab = table(".", "+", "*");
  79. xmom = randfloat(-1.0,1.0);
  80. // ymom = randfloat(-0.2,-2.0);
  81. ymom = randfloat(-2.0,-0.2);
  82. xpos = x.Float();
  83. ypos = y.Float();
  84. frame = -1;
  85. time = randint(10,40);
  86. from = time;
  87. frint = randint(0,3);
  88. while (1) {
  89. if (y < detec[x]) {
  90. CATTRIB(CA.F_BLUE | CA.B_BLUE);
  91. XYTEXT(x,y," ");
  92. }
  93. xpos = xpos + xmom;
  94. ypos = ypos + ymom;
  95. ymom = ymom + 0.15f;
  96. x = xpos.Int();
  97. y = ypos.Int();
  98. // On Screen
  99. if ( y >= height || y < 0 || x < 0 || x > 79) {
  100. exit();
  101. }
  102. // Out of Time ?
  103. time = time - 1;
  104. if (time < 0 || clearExplo) {
  105. exit();
  106. }
  107. if (y < detec[x]) {
  108. fr = (time*3) / from;
  109. CATTRIB(pcoltab[fr] | CA.B_BLUE);
  110. XYTEXT(x,y,pfrtab[frint]);
  111. }
  112. // Sync to the master frame
  113. while (frame == gframe) {
  114. yield();
  115. }
  116. frame = gframe;
  117. }
  118. };
  119. //-----------------------------------------------------------------------------
  120. //-----------------------------------------------------------------------------
  121. global explode = function(x, y) {
  122. global particle;
  123. for (i=0;i<10;i=i+1) {
  124. thread(particle, x, y);
  125. }
  126. };
  127. //-----------------------------------------------------------------------------
  128. //-----------------------------------------------------------------------------
  129. global bullet = function() {
  130. global detec;
  131. global playerx;
  132. global playery;
  133. global score;
  134. global gframe;
  135. global fireCnt;
  136. global score;
  137. global explode;
  138. firex = playerx;
  139. firey = playery+1;
  140. fireHTG = 4;
  141. frame = gframe;
  142. score = score - 10;
  143. while (1) {
  144. // Detection
  145. if (firey > height-1 || fireHTG <= 0) {
  146. fireCnt = fireCnt - 1;
  147. exit();
  148. }
  149. else {
  150. // If okay - display
  151. CATTRIB(CA.F_RED|CA.F_GREEN|CA.F_BLUE|CA.F_INTENSITY | CA.B_BLUE);
  152. XYTEXT(firex,firey,"\31");
  153. }
  154. // Sync to the master frame
  155. while (frame == gframe) {
  156. yield();
  157. }
  158. frame = gframe;
  159. // Clear Bullet
  160. CATTRIB(CA.F_BLUE | CA.B_BLUE);
  161. XYTEXT(firex,firey," ");
  162. firey = firey + 1;
  163. first = 0;
  164. // Detection
  165. if (detec[firex] < firey) {
  166. score = score + 10;
  167. detec[firex] = firey;
  168. fireHTG = fireHTG - 1;
  169. // Boom !
  170. explode(firex,firey);
  171. }
  172. }
  173. };
  174. //-----------------------------------------------------------------------------
  175. //-----------------------------------------------------------------------------
  176. game = function() {
  177. global detec;
  178. global killStars;
  179. global star;
  180. global bullet;
  181. global playerx;
  182. global playery;
  183. global fireCnt;
  184. global fireMax;
  185. global score;
  186. global explode;
  187. killStars = 0;
  188. allgone = 0;
  189. for (i=0;i<30;i=i+1) {
  190. thread(star);
  191. }
  192. CATTRIB(CA.F_BLUE | CA.B_BLUE);
  193. CLS();
  194. coltab = table(CA.B_GREEN|CA.B_RED, CA.B_BLUE|CA.B_RED, CA.B_BLUE|CA.B_GREEN, CA.B_GREEN);
  195. coltabfore = table(CA.F_GREEN|CA.F_RED, CA.F_BLUE|CA.F_RED, CA.F_BLUE|CA.F_GREEN, CA.F_GREEN);
  196. btypes = table("\254", "\58", "\124");
  197. ttypes = table("\191", "\194", "\218");
  198. // Clear Collision
  199. for (i=0;i<=150;i=i+1) {
  200. detec[i] = height;
  201. }
  202. // Buildings
  203. for (x=0;x<80;x=x+1) {
  204. // Calc Height
  205. rand = 10;
  206. if (x < 30) {
  207. rand = x / 3;
  208. }
  209. if (x > 50) {
  210. rand = (80-x) / 3;
  211. }
  212. if (x < 10) {
  213. rand = 0;
  214. }
  215. if (x > 70) {
  216. rand = 0;
  217. }
  218. rand = randint(0,rand);
  219. if (rand > 1) {
  220. // Detection
  221. detec[x] = height-rand;
  222. // Random Building Color
  223. col = randint(0,4);
  224. // Random Top
  225. if (randint(0,10) < 2) {
  226. CATTRIB(coltabfore[col] | CA.B_BLUE);
  227. ttype = randint(0,3);
  228. XYTEXT(x,height-rand-1,ttypes[ttype]);
  229. }
  230. // The Main Building
  231. btype = randint(0,3);
  232. CATTRIB(coltab[col] | CA.F_BLACK);
  233. for (y=height-rand;y<height;y=y+1) {
  234. if (randint(0,5) < 2) {
  235. CATTRIB(coltab[col] | CA.F_RED | CA.F_GREEN | CA.F_INTENSITY);
  236. XYTEXT(x,y,btypes[btype]);
  237. CATTRIB(coltab[col] | CA.F_BLACK);
  238. }
  239. else {
  240. XYTEXT(x,y,btypes[btype]);
  241. }
  242. }
  243. }
  244. }
  245. CATTRIB(CA.F_GREEN | CA.B_BLACK);
  246. for (x=0;x<80;x=x+1) {
  247. XYTEXT(x,height,"\178");
  248. }
  249. playerx = 2;
  250. playery = 3;
  251. anim = 0;
  252. playermove = 0;
  253. fireOkay = 0;
  254. landingtimer = 0;
  255. while(!ISPRESSED('Q')) {
  256. // Flattened already ?
  257. allgone = 1;
  258. for (i=0;i<80;i=i+1) {
  259. if (detec[i] != height) {
  260. allgone = 0;
  261. }
  262. }
  263. // Add Loads of stars
  264. if (ISPRESSED('S')) {
  265. for (i=0;i<30;i=i+1) {
  266. thread(star);
  267. }
  268. }
  269. // Score
  270. CATTRIB(CA.F_BLUE | CA.F_GREEN | CA.F_INTENSITY | CA.B_BLUE);
  271. XY(35,1);
  272. print("Score ", score);
  273. // Show Memeory Usage
  274. if (ISPRESSED('M')) {
  275. XY(1,2);
  276. print("Memory ", sysGetMemoryUsage());
  277. }
  278. if (ISPRESSED(' ')) {
  279. if (fireCnt < fireMax && (fireOkay || fireMax == 50)) {
  280. thread(bullet);
  281. fireCnt = fireCnt + 1;
  282. }
  283. fireOkay = 0;
  284. }
  285. else {
  286. fireOkay = 1;
  287. }
  288. // Clear Player
  289. CATTRIB(CA.F_BLUE | CA.B_BLUE);
  290. XYTEXT(playerx-2,playery," ");
  291. // Auto Pilot landing
  292. if (allgone && playery < height-1) {
  293. landingtimer = landingtimer + 1;
  294. if (landingtimer > 10) {
  295. landingtimer = 0;
  296. playery = playery + 1;
  297. }
  298. }
  299. // Move and reposition if reach the side of the screen
  300. playerx = playerx+1;
  301. if (playerx > 79) {
  302. playerx = 2;
  303. playery = playery + 1;
  304. }
  305. // Not too low
  306. if (playery > height-1) {
  307. playery = height-1;
  308. }
  309. // Print at new position
  310. CATTRIB(CA.F_RED|CA.F_GREEN|CA.F_BLUE|CA.F_INTENSITY | CA.B_BLUE);
  311. XYTEXT(playerx-2,playery,"\200");
  312. XYTEXT(playerx-1,playery,"\205");
  313. XYTEXT(playerx,playery,"\254");
  314. // Landed !!!
  315. if (playerx == 60 && playery == height-1) {
  316. for (i=0;i<60;i=i+1) {
  317. sync();
  318. }
  319. // Completion bonus - based on fireMax
  320. if (score != 50) {
  321. score = score + (6-fireMax) * 1000;
  322. }
  323. niceone();
  324. return;
  325. }
  326. // Hit a building (ignores arieals)
  327. if (detec[playerx+1] <= playery) {
  328. sync();
  329. y0 = playery;
  330. y1 = playery;
  331. y2 = playery;
  332. x = playerx;
  333. // Dramatic Pause !
  334. for (i=0;i<20;i=i+1) {
  335. XYTEXT(x-2,y0,"\200");
  336. XYTEXT(x-1,y1,"\205");
  337. XYTEXT(x-0,y2,"\254");
  338. sync();
  339. }
  340. done = 0;
  341. while (!done) {
  342. done = 1;
  343. // Clear
  344. CATTRIB(CA.F_BLUE | CA.B_BLUE);
  345. XYTEXT(x-2,y0," ");
  346. XYTEXT(x-1,y1," ");
  347. XYTEXT(x-0,y2," ");
  348. // Move
  349. if (y0 < detec[x-2]-1) {
  350. y0 = y0 + 1;
  351. done = 0;
  352. }
  353. if (y1 < detec[x-1]-1) {
  354. y1 = y1 + 1;
  355. done = 0;
  356. }
  357. if (y2 < detec[x-0]-1) {
  358. y2 = y2 + 1;
  359. done = 0;
  360. }
  361. // Print
  362. CATTRIB(CA.F_RED|CA.F_GREEN|CA.F_BLUE|CA.F_INTENSITY | CA.B_BLUE);
  363. XYTEXT(x-2,y0,"\200");
  364. XYTEXT(x-1,y1,"\205");
  365. XYTEXT(x-0,y2,"\254");
  366. sync();
  367. }
  368. for (i=0;i<60;i=i+1) {
  369. XYTEXT(x-2,y0,"\200");
  370. XYTEXT(x-1,y1,"\205");
  371. XYTEXT(x-0,y2,"\254");
  372. sync();
  373. }
  374. gameover();
  375. return;
  376. }
  377. else {
  378. if (anim == 1) {
  379. XYTEXT(playerx+1,playery,"\217");
  380. anim = 0;
  381. }
  382. else {
  383. XYTEXT(playerx+1,playery,"\191");
  384. anim = 1;
  385. }
  386. }
  387. // Next Frame
  388. sync();
  389. }
  390. };
  391. //-----------------------------------------------------------------------------
  392. //-----------------------------------------------------------------------------
  393. titlescreen = function() {
  394. global killStars = 1;
  395. global fireMax = 0;
  396. global score = 0;
  397. global detec;
  398. global clearExplo = 0;
  399. for (i=0;i<81;i=i+1) {
  400. detec[i] = height;
  401. }
  402. CATTRIB(0);
  403. CLS();
  404. CATTRIB(CA.F_RED);
  405. CURSOR(0,0);
  406. maxtab = 12;
  407. tabindex = 0;
  408. tctab = table( CA.F_RED|CA.F_BLUE|CA.F_GREEN | CA.F_INTENSITY,
  409. CA.F_GREEN | CA.F_INTENSITY | CA.F_INTENSITY,
  410. CA.F_BLUE,
  411. CA.F_GREEN | CA.F_INTENSITY,
  412. CA.F_RED|CA.F_GREEN | CA.F_INTENSITY,
  413. CA.F_RED|CA.F_BLUE|CA.F_GREEN | CA.F_INTENSITY,
  414. CA.F_BLUE | CA.F_INTENSITY,
  415. CA.F_BLUE | CA.F_INTENSITY,
  416. CA.F_RED|CA.F_BLUE|CA.F_GREEN,
  417. CA.F_BLUE,
  418. CA.F_BLUE | CA.F_INTENSITY,
  419. CA.F_RED|CA.F_GREEN | CA.F_INTENSITY );
  420. maxtab2 = 8;
  421. tabindex2 = 0;
  422. tctab2 = table( CA.F_RED|CA.F_BLUE|CA.F_GREEN | CA.F_INTENSITY,
  423. CA.F_RED|CA.F_BLUE|CA.F_GREEN | CA.F_INTENSITY,
  424. CA.F_RED|CA.F_BLUE|CA.F_GREEN | CA.F_INTENSITY,
  425. CA.F_RED|CA.F_GREEN | CA.F_INTENSITY,
  426. CA.F_RED | CA.F_INTENSITY,
  427. CA.F_RED,
  428. CA.F_RED | CA.F_INTENSITY,
  429. CA.F_RED|CA.F_GREEN | CA.F_INTENSITY );
  430. // Flush Keyboard !?
  431. ISPRESSED(' ');
  432. ISPRESSED(' ');
  433. ISPRESSED(' ');
  434. while(!fireMax) {
  435. // Start in which mode
  436. if (ISPRESSED('1')) { fireMax = 1; }
  437. if (ISPRESSED('2')) { fireMax = 2; }
  438. if (ISPRESSED('3')) { fireMax = 3; }
  439. if (ISPRESSED('4')) { fireMax = 4; }
  440. if (ISPRESSED('5')) { fireMax = 5; }
  441. if (ISPRESSED(' ')) { fireMax = 3; }
  442. if (ISPRESSED('C')) { fireMax = 50; }
  443. if (ISPRESSED(27)) { threadKillAll(true); } // Kill all threads when ESC is pressed
  444. // Title Color
  445. tabindex = tabindex + 1;
  446. if (tabindex >= maxtab) {
  447. tabindex = 0;
  448. }
  449. CATTRIB(tctab[tabindex]);
  450. CLS();
  451. XYTEXT(4,2,` ________ ______ ________ `);
  452. XYTEXT(4,3,` ___ __ )____________ ______ /________________ __ \___ ________ `);
  453. XYTEXT(4,4,` __ __ | __ \_ __ ``__ \_ __ \ _ \_ ___/_ /_/ / / / /_ __ \ `);
  454. XYTEXT(4,5,` _ /_/ // /_/ / / / / / / /_/ / __/ / _ _, _// /_/ /_ / / / `);
  455. XYTEXT(4,6,` /_____/ \____//_/ /_/ /_//_.___/\___//_/ /_/ |_| \__,_/ /_/ /_/ `);
  456. // Text Color
  457. tabindex2 = tabindex2 + 1;
  458. if (tabindex2 >= maxtab2) {
  459. tabindex2 = 0;
  460. }
  461. CATTRIB(tctab2[tabindex2]);
  462. XYTEXT(12,8, " Written in GameMonkey by Happy ");
  463. XYTEXT(12,11, " Flatten the city by dropping bombs (spacebar)");
  464. XYTEXT(12,12, " Destory all buildings to land saftley");
  465. XYTEXT(12,13, " Score 10 points for each builing piece destoryed");
  466. XYTEXT(12,14, " Loose 10 points for each bomb dropped");
  467. XYTEXT(12,15, " Landing bonus is based on difficulty setting");
  468. XYTEXT(12,18, " Press 'Space' to play at standard level");
  469. XYTEXT(12,19, " Press 1-5 to choose difficulty (number of bombs)");
  470. XYTEXT(12,20, "Press 'C' to play the cheat version (hold the spacebar!)");
  471. XYTEXT(12,21, " Press 'Q' to to quit during play");
  472. XYTEXT(12,22, " Press ESC to exit game now");
  473. x = randint(2,78);
  474. y = randint(2,height-2);
  475. explode(x,y);
  476. sync();
  477. }
  478. clearExplo = 1;
  479. sync();
  480. sync();
  481. clearExplo = 0;
  482. };
  483. //-----------------------------------------------------------------------------
  484. //-----------------------------------------------------------------------------
  485. global niceone = function() {
  486. global killStars = 0;
  487. global detec;
  488. global score;
  489. global clearExplo = 0;
  490. global fireMax;
  491. for (i=0;i<500;i=i+1) {
  492. thread(star);
  493. }
  494. for (i=0;i<200;i=i+1) {
  495. CATTRIB(CA.F_RED|CA.F_GREEN|CA.F_BLUE|CA.F_INTENSITY|CA.B_BLUE);
  496. CLS();
  497. XYTEXT(1,7,` .__ __. __ ______ _______ ______ .__ __. _______ __ __ __ `);
  498. XYTEXT(1,8,` | \ | || | / | ____| / __ \ | \ | || ____| | || || | `);
  499. XYTEXT(1,9,` | \| || || ,----' |__ | | | || \| || |__ | || || | `);
  500. XYTEXT(1,10,` | . `` || || | | __| | | | || . `` || __| | || || | `);
  501. XYTEXT(1,11,` | |\ || || ``----. |____ | ``--' || |\ || |____ |__||__||__| `);
  502. XYTEXT(1,12,` |__| \__||__| \______|_______| \______/ |__| \__||_______| (__)(__)(__) `);
  503. XY(1,15);
  504. if (score < 0) {
  505. print(" You score is to crap too mention !");
  506. }
  507. else if (score < 1500) {
  508. print(" Your score is a average", score);
  509. }
  510. else if (score < 3000) {
  511. print(" Your score is a respectable", score);
  512. }
  513. else {
  514. print(" Your score is an awesome", score);
  515. }
  516. if (fireMax == 50) {
  517. XY(1,17);
  518. print(" --- Now try again without cheating ;) ---");
  519. }
  520. x = randint(2,78);
  521. y = randint(2,height-2);
  522. explode(x,y);
  523. sync();
  524. }
  525. };
  526. //-----------------------------------------------------------------------------
  527. //-----------------------------------------------------------------------------
  528. global gameover = function() {
  529. global killStars = 1;
  530. global detec;
  531. global score;
  532. global clearExplo = 1;
  533. CATTRIB(CA.F_RED|CA.F_INTENSITY);
  534. for (i=height+15;i>-15;i=i-1) {
  535. CLS();
  536. y = i;
  537. if (y >= 0 && y <= height) { XYTEXT(8,y,` _______ ___ .___ ___. _______ `); }
  538. y = y + 1;
  539. if (y >= 0 && y <= height) { XYTEXT(8,y,` / _____| / \ | \/ || ____| `); }
  540. y = y + 1;
  541. if (y >= 0 && y <= height) { XYTEXT(8,y,` | | __ / ^ \ | \ / || |__ `); }
  542. y = y + 1;
  543. if (y >= 0 && y <= height) { XYTEXT(8,y,` | | |_ | / /_\ \ | |\/| || __| `); }
  544. y = y + 1;
  545. if (y >= 0 && y <= height) { XYTEXT(8,y,` | |__| | / _____ \ | | | || |____ `); }
  546. y = y + 1;
  547. if (y >= 0 && y <= height) { XYTEXT(8,y,` \______|/__/ _\__\|__|__|__||_______| `); }
  548. y = y + 1;
  549. if (y >= 0 && y <= height) { XYTEXT(8,y,` / __ \ \ \ / /| ____| _ \ `); }
  550. y = y + 1;
  551. if (y >= 0 && y <= height) { XYTEXT(8,y,` | | | | \ \/ / | |__ | |_) | `); }
  552. y = y + 1;
  553. if (y >= 0 && y <= height) { XYTEXT(8,y,` | | | | \ / | __| | / `); }
  554. y = y + 1;
  555. if (y >= 0 && y <= height) { XYTEXT(8,y,` | ``--' | \ / | |____| |\ \----. `); }
  556. y = y + 1;
  557. if (y >= 0 && y <= height) { XYTEXT(8,y,` \______/ \__/ |_______| _| ``._____| `); }
  558. y = y + 1;
  559. sync();
  560. }
  561. };
  562. //-----------------------------------------------------------------------------
  563. // and finaly - the main loop !
  564. //-----------------------------------------------------------------------------
  565. while (1) {
  566. titlescreen();
  567. game();
  568. }
  569. //-----------------------------------------------------------------------------
  570. //-----------------------------------------------------------------------------