/FallingSandpaper/jni/collide.c

http://thelements.googlecode.com/ · C · 1728 lines · 1374 code · 196 blank · 158 comment · 647 complexity · 5c56a6bc6da55f1e6265f9414aa3378b MD5 · raw file

  1. /*
  2. * collide.c
  3. * ----------------------------
  4. * Defines the collide function, which is the
  5. * heart of our app. It processes all the collisions by
  6. * type number. It alone is several hundred lines
  7. * long, thus the need for a separate file.
  8. */
  9. #include "collide.h"
  10. void collide(int fp, int sp)//first particle and second particle
  11. {
  12. int temporary = collision[22][0];
  13. int olyf = oldy[fp];
  14. int olxf = oldx[fp];
  15. int olxs = oldx[sp];
  16. int olys = oldy[sp];
  17. int type = collision[element[fp]][element[sp]];
  18. //Solid - Solid generic collision
  19. if (type == 0)
  20. {
  21. y[fp] = olyf; // First particle goes back to where it was before
  22. x[fp] = olxf;
  23. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  24. setBitmapColor((int) x[fp], (int) y[fp], element[fp]);
  25. xvel[fp] += (rand() % 3) - 1;
  26. // no change in allcoords
  27. }
  28. //Solid - Liquid generic collision
  29. else if (type == 1)
  30. {
  31. if (density[element[fp]] >= density[element[sp]])
  32. {
  33. y[sp] = olyf; // Solid replaces Liquid (switch)
  34. x[sp] = olxf;
  35. allcoords[(int) x[sp]][(int) y[sp]] = sp;
  36. setBitmapColor((int) x[sp], (int) y[sp], element[sp]);
  37. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  38. setBitmapColor((int) x[fp], (int) y[fp], element[fp]);
  39. }
  40. else
  41. {
  42. int ycounter;
  43. int xcounter;
  44. if (element[fp] == 1 || (element[fp] == 22 && colliseelement1[4]
  45. == 1))
  46. {
  47. for (ycounter = -1; ycounter <= 1; ycounter++)
  48. {
  49. for (xcounter = -1; xcounter <= 1; xcounter++)
  50. {
  51. if (element[allcoords[olxf + xcounter][olyf + ycounter]]
  52. == 4)
  53. { // if there's anythign around that point that's plant
  54. int random = rand() % 2;
  55. random = random * 2 - 1;
  56. if (random == 1)
  57. {
  58. y[fp] = olyf; //put the water particle back
  59. x[fp] = olxf;
  60. element[fp] = 4; // change it to plant
  61. allcoords[(int) x[fp]][(int) y[fp]] = fp; //set the allcoords
  62. setBitmapColor((int) x[fp], (int) y[fp],
  63. element[fp]); //set the bitmapcolor
  64. return;
  65. }
  66. }
  67. }
  68. }
  69. }
  70. int random = rand() % 2;
  71. random = random * 2 - 1;
  72. if (allcoords[olxf + random][olyf + 1] == -1 && olxf + random > 1
  73. && olyf + 1 < maxy && olxf + random < maxx) // left down
  74. {
  75. allcoords[olxf][olyf] = -1;
  76. //clear old spot
  77. setBitmapColor(olxf, olyf, 3);
  78. allcoords[olxf + random][olyf + 1] = fp;
  79. setBitmapColor(olxf + random, olyf + 1, element[fp]); //set new spot
  80. y[fp] = olyf + 1;
  81. x[fp] = olxf + random;
  82. }
  83. else if (allcoords[olxf - random][olyf + 1] == -1 && olxf - random
  84. > 1 && olyf + 1 < maxy && olxf - random < maxx) // left down
  85. {
  86. allcoords[olxf][olyf] = -1;
  87. setBitmapColor(olxf, olyf, 3);
  88. allcoords[olxf - random][olyf + 1] = fp;
  89. setBitmapColor(olxf - random, olyf + 1, element[fp]); //set new spot
  90. y[fp] = olyf + 1;
  91. x[fp] = olxf - random;
  92. }
  93. else if (allcoords[olxf + random][olyf] == -1 && olxf + random
  94. < maxx && olxf + random > 1) // right
  95. {
  96. allcoords[olxf][olyf] = -1;
  97. setBitmapColor(olxf, olyf, 3);
  98. allcoords[olxf + random][olyf] = fp;
  99. setBitmapColor(olxf + random, olyf, element[fp]); //set new spot
  100. y[fp] = olyf;
  101. x[fp] = olxf + random;
  102. }
  103. else if (allcoords[olxf - random][olyf] == -1 && olxf - random
  104. < maxx && olxf - random > 1) // right
  105. {
  106. allcoords[olxf][olyf] = -1;
  107. setBitmapColor(olxf, olyf, 3);
  108. allcoords[olxf - random][olyf] = fp;
  109. setBitmapColor(olxf - random, olyf, element[fp]); //set new spot
  110. y[fp] = olyf;
  111. x[fp] = olxf - random;
  112. }
  113. else
  114. {
  115. y[fp] = olyf;
  116. x[fp] = olxf;
  117. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  118. setBitmapColor((int) x[fp], (int) y[fp], element[fp]);
  119. }
  120. random = rand() % 7 - 3;
  121. xvel[fp] = random;
  122. }
  123. }
  124. //Liquid - Liquid generic collision
  125. else if (type == 3)
  126. {
  127. int ycounter;
  128. int xcounter;
  129. if (element[fp] == 1 || (element[fp] == 22
  130. && colliseelement1[element[sp]] == 1) || (element[sp] == 22
  131. && colliseelement1[fp] != 1))
  132. {
  133. for (ycounter = -1; ycounter <= 1; ycounter++)
  134. {
  135. for (xcounter = -1; xcounter <= 1; xcounter++)
  136. {
  137. if (element[allcoords[olxf + xcounter][olyf + ycounter]]
  138. == 4)
  139. { // if there's anythign around that point that's plant
  140. int random = rand() % 2;
  141. random = random * 2 - 1;
  142. if (random == 1)
  143. {
  144. y[fp] = olyf; //put the water particle back
  145. x[fp] = olxf;
  146. element[fp] = 4; // change it to plant
  147. allcoords[(int) x[fp]][(int) y[fp]] = fp; //set the allcoords
  148. setBitmapColor((int) x[fp], (int) y[fp],
  149. element[fp]); //set the bitmapcolor
  150. return;
  151. }
  152. }
  153. }
  154. }
  155. }
  156. int random = rand() % 2;
  157. random = random * 2 - 1;
  158. if (density[element[fp]] > density[element[sp]])
  159. {
  160. y[sp] = olyf; // Denser liquid replaces other one (switch)
  161. x[sp] = olxf;
  162. allcoords[(int) x[sp]][(int) y[sp]] = sp;
  163. setBitmapColor((int) x[sp], (int) y[sp], element[sp]);
  164. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  165. setBitmapColor((int) x[fp], (int) y[fp], element[fp]);
  166. }
  167. else if (allcoords[olxf + random][olyf + 1] == -1 && olxf + random > 1
  168. && olyf + 1 < maxy && olxf + random < maxx) // left down
  169. {
  170. allcoords[olxf][olyf] = -1;
  171. setBitmapColor(olxf, olyf, 3);
  172. allcoords[olxf + random][olyf + 1] = fp;
  173. setBitmapColor(olxf + random, olyf + 1, element[fp]); //set new spot
  174. y[fp] = olyf + 1;
  175. x[fp] = olxf + random;
  176. }
  177. else if (allcoords[olxf - random][olyf + 1] == -1 && olxf - random > 1
  178. && olyf + 1 < maxy && olxf - random < maxx) // left down
  179. {
  180. allcoords[olxf][olyf] = -1;
  181. setBitmapColor(olxf, olyf, 3);
  182. allcoords[olxf - random][olyf + 1] = fp;
  183. setBitmapColor(olxf - random, olyf + 1, element[fp]); //set new spot
  184. y[fp] = olyf + 1;
  185. x[fp] = olxf - random;
  186. }
  187. else if (allcoords[olxf + random][olyf] == -1 && olxf + random < maxx
  188. && olxf + random > 1) // right
  189. {
  190. allcoords[olxf][olyf] = -1;
  191. setBitmapColor(olxf, olyf, 3);
  192. allcoords[olxf + random][olyf] = fp;
  193. setBitmapColor(olxf + random, olyf, element[fp]); //set new spot
  194. y[fp] = olyf;
  195. x[fp] = olxf + random;
  196. }
  197. else if (allcoords[olxf - random][olyf] == -1 && olxf - random < maxx
  198. && olxf - random > 1) // right
  199. {
  200. allcoords[olxf][olyf] = -1;
  201. setBitmapColor(olxf, olyf, 3);
  202. allcoords[olxf - random][olyf] = fp;
  203. setBitmapColor(olxf - random, olyf, element[fp]); //set new spot
  204. y[fp] = olyf;
  205. x[fp] = olxf - random;
  206. }
  207. else
  208. {
  209. y[fp] = olyf;
  210. x[fp] = olxf;
  211. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  212. setBitmapColor((int) x[fp], (int) y[fp], element[fp]);
  213. }
  214. random = rand() % 7 - 3;
  215. xvel[fp] = random;
  216. }
  217. else if (type == 4) //Water plant
  218. {
  219. int random = rand() % 3;
  220. y[fp] = olyf; //put the water particle back
  221. x[fp] = olxf;
  222. if (random == 1)
  223. {
  224. element[fp] = 4; // change it to plant
  225. allcoords[(int) x[fp]][(int) y[fp]] = fp; //set the allcoords
  226. setBitmapColor((int) x[fp], (int) y[fp], element[fp]); //set the bitmapcolor
  227. }
  228. }
  229. else if (type == 5) //Nonflammable fire
  230. {
  231. int xfp = x[fp], yfp = y[fp];
  232. if (element[fp] == 5 || (element[fp] == 22
  233. && colliseelement1[element[sp]] == 5)) //fp is fire
  234. {
  235. //Move the fire back
  236. allcoords[olxf][olyf] = fp;
  237. setBitmapColor(olxf, olyf, element[fp]);
  238. x[fp] = olxf;
  239. y[fp] = olyf;
  240. //Add a random x velocity
  241. xvel[fp] += rand() % 7 - 3; //-3 to 3
  242. }
  243. else //sp is fire
  244. {
  245. //Move the fire to the old spot
  246. allcoords[olxf][olyf] = sp;
  247. setBitmapColor(olxf, olyf, element[sp]);
  248. x[sp] = olxf;
  249. y[sp] = olyf;
  250. //Set the new spot
  251. allcoords[xfp][yfp] = fp;
  252. setBitmapColor(xfp, yfp, element[fp]);
  253. //Add a random x velocity for the fire
  254. xvel[sp] += rand() % 7 - 3; //-3 to 3
  255. }
  256. }
  257. else if (type == 6) //Flammable Hot
  258. {
  259. if (element[fp] == 5 || element[fp] == 10 || (element[fp] == 22
  260. && (colliseelement1[element[sp]] == 5
  261. || colliseelement1[element[sp]] == 10)) || (element[sp]
  262. == 22 && (colliseelement1[element[fp]] != 5
  263. && colliseelement1[element[fp]] != 10))) //fp is Hot
  264. {
  265. int xfp = (int) x[fp];
  266. int yfp = (int) y[fp];
  267. int counter;
  268. //Clear the spot the fire came from
  269. allcoords[olxf][olyf] = -1;
  270. setBitmapColor(olxf, olyf, 3);
  271. //Set the new location to be fire
  272. element[fp] = 5;
  273. setBitmapColor(xfp, yfp, 5);
  274. allcoords[xfp][yfp] = fp;
  275. //Delete flammable (sp)
  276. x[sp] = 0;
  277. y[sp] = 0;
  278. element[sp] = 0;
  279. xvel[sp] = 0;
  280. yvel[sp] = 0;
  281. set[sp] = 0;
  282. avail[loq] = sp;
  283. loq++;
  284. }
  285. else //The flammable is fp
  286. {
  287. int xsp = (int) x[sp];
  288. int ysp = (int) y[sp];
  289. int counter;
  290. //Delete the old place
  291. allcoords[olxf][olyf] = -1;
  292. setBitmapColor(olxf, olyf, 3);
  293. //Don't need to do this
  294. setBitmapColor(xsp, ysp, element[sp]);
  295. allcoords[xsp][ysp] = sp;
  296. //Delete the flammable (fp)
  297. x[fp] = 0;
  298. y[fp] = 0;
  299. element[fp] = 0;
  300. xvel[fp] = 0;
  301. yvel[fp] = 0;
  302. set[fp] = 0;
  303. avail[loq] = fp;
  304. loq++;
  305. }
  306. }
  307. //Fire - Fire generic collision
  308. else if (type == 7)
  309. {
  310. //Delete the old point
  311. allcoords[olxf][olyf] = -1;
  312. setBitmapColor(olxf, olyf, 3);
  313. int counter;
  314. //Delete fp
  315. x[fp] = 0;
  316. y[fp] = 0;
  317. element[fp] = 0;
  318. xvel[fp] = 0;
  319. yvel[fp] = 0;
  320. set[fp] = 0;
  321. avail[loq] = fp;
  322. loq++;
  323. }
  324. else if (type == 8) //Ice - Water collision
  325. {
  326. int random = rand() % 3;
  327. if (random == 0)
  328. {
  329. if (element[fp] == 1 || (element[fp] == 22
  330. && colliseelement1[element[sp]] == 1) || (element[sp] == 22
  331. && colliseelement1[element[fp]] != 1)) //fp is water
  332. {
  333. x[fp] = olxf; //Move it back
  334. y[fp] = olyf;
  335. element[fp] = 6; //Set it to ice
  336. allcoords[(int) x[fp]][(int) y[fp]] = fp; //Set the allcoords
  337. setBitmapColor((int) x[fp], (int) y[fp], 6); //Change the color
  338. }
  339. else
  340. {
  341. x[fp] = olxf; //Move the first particle back
  342. y[fp] = olyf;
  343. element[sp] = 6; //Change the water to ice
  344. setBitmapColor((int) x[fp], (int) y[fp], 6); //Change the color
  345. allcoords[(int) x[fp]][(int) y[fp]] = fp; //Set allcoords
  346. setBitmapColor((int) x[fp], (int) y[fp], element[fp]); //Set bitmap color
  347. }
  348. }
  349. else
  350. {
  351. if (density[element[fp]] >= density[element[sp]])
  352. {
  353. y[sp] = olyf; // Solid replaces Liquid (switch)
  354. x[sp] = olxf;
  355. allcoords[(int) x[sp]][(int) y[sp]] = sp;
  356. setBitmapColor((int) x[sp], (int) y[sp], element[sp]);
  357. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  358. setBitmapColor((int) x[fp], (int) y[fp], element[fp]);
  359. }
  360. else
  361. {
  362. int ycounter;
  363. int xcounter;
  364. for (ycounter = -1; ycounter <= 1; ycounter++)
  365. {
  366. for (xcounter = -1; xcounter <= 1; xcounter++)
  367. {
  368. if (element[allcoords[olxf + xcounter][olyf + ycounter]]
  369. == 4)
  370. { // if there's anythign around that point that's plant
  371. int random = rand() % 2;
  372. random = random * 2 - 1;
  373. if (random == 1)
  374. {
  375. y[fp] = olyf; //put the water particle back
  376. x[fp] = olxf;
  377. element[fp] = 4; // change it to plant
  378. allcoords[(int) x[fp]][(int) y[fp]] = fp; //set the allcoords
  379. setBitmapColor((int) x[fp], (int) y[fp],
  380. element[fp]); //set the bitmapcolor
  381. return;
  382. }
  383. }
  384. }
  385. }
  386. int random = rand() % 2;
  387. random = random * 2 - 1;
  388. if (allcoords[olxf + random][olyf + 1] == -1 && olxf + random
  389. > 1 && olyf + 1 < maxy && olxf + random < maxx) // left down
  390. {
  391. allcoords[olxf][olyf] = -1;
  392. //clear old spot
  393. setBitmapColor(olxf, olyf, 3);
  394. allcoords[olxf + random][olyf + 1] = fp;
  395. setBitmapColor(olxf + random, olyf + 1, element[fp]); //set new spot
  396. y[fp] = olyf + 1;
  397. x[fp] = olxf + random;
  398. }
  399. else if (allcoords[olxf - random][olyf + 1] == -1 && olxf
  400. - random > 1 && olyf + 1 < maxy && olxf - random < maxx) // left down
  401. {
  402. allcoords[olxf][olyf] = -1;
  403. setBitmapColor(olxf, olyf, 3);
  404. allcoords[olxf - random][olyf + 1] = fp;
  405. setBitmapColor(olxf - random, olyf + 1, element[fp]); //set new spot
  406. y[fp] = olyf + 1;
  407. x[fp] = olxf - random;
  408. }
  409. else if (allcoords[olxf + random][olyf] == -1 && olxf + random
  410. < maxx && olxf + random > 1) // right
  411. {
  412. allcoords[olxf][olyf] = -1;
  413. setBitmapColor(olxf, olyf, 3);
  414. allcoords[olxf + random][olyf] = fp;
  415. setBitmapColor(olxf + random, olyf, element[fp]); //set new spot
  416. y[fp] = olyf;
  417. x[fp] = olxf + random;
  418. }
  419. else if (allcoords[olxf - random][olyf] == -1 && olxf - random
  420. < maxx && olxf - random > 1) // right
  421. {
  422. allcoords[olxf][olyf] = -1;
  423. setBitmapColor(olxf, olyf, 3);
  424. allcoords[olxf - random][olyf] = fp;
  425. setBitmapColor(olxf - random, olyf, element[fp]); //set new spot
  426. y[fp] = olyf;
  427. x[fp] = olxf - random;
  428. }
  429. else
  430. {
  431. y[fp] = olyf;
  432. x[fp] = olxf;
  433. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  434. setBitmapColor((int) x[fp], (int) y[fp], element[fp]);
  435. }
  436. }
  437. }
  438. }
  439. else if (type == 9) //Hot(Magma, Fire) - Ice
  440. {
  441. if (element[fp] == 6 || (element[fp] == 22
  442. && colliseelement1[element[sp]] == 6) || (element[sp] == 22
  443. && colliseelement1[element[fp]] != 6)) //fp is ice
  444. {
  445. //This should almost never happen
  446. element[fp] = 1; //Change ice to water
  447. //Put it back
  448. x[fp] = olxf;
  449. y[fp] = olyf;
  450. }
  451. else //sp is ice
  452. {
  453. element[sp] = 1; //Change ice to water
  454. setBitmapColor((int) x[sp], (int) y[sp], 1);
  455. //Put hot back
  456. x[fp] = olxf;
  457. y[fp] = olyf;
  458. }
  459. }
  460. else if (type == 10) //Anything - Generator collision
  461. {
  462. if (element[fp] != 7)
  463. {
  464. //Change the generator to spawner
  465. element[sp] = 8;
  466. spawn[sp] = element[fp]; //Set the spawn element
  467. //Delete the old point
  468. allcoords[olxf][olyf] = -1;
  469. setBitmapColor(olxf, olyf, 3);
  470. //Delete fp
  471. x[fp] = 0;
  472. y[fp] = 0;
  473. element[fp] = 0;
  474. xvel[fp] = 0;
  475. yvel[fp] = 0;
  476. set[fp] = 0;
  477. avail[loq] = fp;
  478. loq++;
  479. }
  480. else
  481. {
  482. //Change the generator to spawner
  483. element[fp] = 8;
  484. spawn[fp] = element[sp]; //Set the spawn element
  485. //Delete the old point
  486. allcoords[olxf][olyf] = -1;
  487. setBitmapColor(olxf, olyf, 3);
  488. //Delete sp
  489. x[sp] = 0;
  490. y[sp] = 0;
  491. element[sp] = 0;
  492. xvel[sp] = 0;
  493. yvel[sp] = 0;
  494. set[sp] = 0;
  495. avail[loq] = sp;
  496. loq++;
  497. }
  498. }
  499. else if (type == 11) //Hot - Explosive generic
  500. {
  501. if (element[fp] == 5 || element[fp] == 11 || (element[fp] == 22
  502. && (colliseelement1[element[sp]] == 5
  503. || colliseelement1[element[sp]] == 11)) || (element[sp]
  504. == 22 && !(colliseelement1[element[fp]] == 5
  505. || colliseelement1[element[fp]] == 11)))
  506. {
  507. //Delete the old point
  508. allcoords[olxf][olyf] = -1;
  509. setBitmapColor(olxf, olyf, 3);
  510. //Set the new location of the fire
  511. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  512. setBitmapColor((int) x[fp], (int) y[fp], element[fp]);
  513. //Delete sp
  514. x[sp] = 0;
  515. y[sp] = 0;
  516. element[sp] = 0;
  517. xvel[sp] = 0;
  518. yvel[sp] = 0;
  519. set[sp] = 0;
  520. avail[loq] = sp;
  521. loq++;
  522. int random = rand() % 10;
  523. random -= 5;
  524. xvel[fp] = random; //xvel is a random int from -5 to 5
  525. random = rand() % 10;
  526. random -= 5;
  527. yvel[fp] = random; //yvel is a random int from -5 to 5
  528. //Look at all the points around the explosion, if explosive change to fire and add velocity,
  529. // if flammable, just change to fire, if empty, change to fire and add velocity
  530. int i, j, xfp = (int) x[fp], yfp = (int) y[fp], a;
  531. for (i = -2; i <= 2; i++)
  532. {
  533. for (j = -2; j <= 2; j++)
  534. {
  535. if (xfp + i > 1 && xfp + i < maxx && yfp + j > 1 && yfp + j
  536. < maxy && !(i == 0 && j == 0))
  537. {
  538. a = allcoords[xfp + i][yfp + j]; //The allcoords at the prospective point
  539. if (a != -1 && collision[element[a]][5] == 6)
  540. {
  541. element[a] = 5;
  542. setBitmapColor(xfp + i, yfp + j, 5);
  543. }
  544. else if (a != -1 && collision[element[a]][5] == 11)
  545. {
  546. element[a] = 5;
  547. setBitmapColor(xfp + i, yfp + j, 5);
  548. int random = rand() % 10;
  549. random -= 5;
  550. xvel[a] = random; //xvel is a random int from -5 to 5
  551. random = rand() % 10;
  552. random -= 5;
  553. yvel[a] = random; //yvel is a random int from -5 to 5
  554. }
  555. else if (a == -1)
  556. {
  557. CreatePoint(xfp + i, yfp + j, 5);
  558. }
  559. }
  560. }
  561. }
  562. }
  563. else
  564. {
  565. //Delete the old point
  566. allcoords[olxf][olyf] = -1;
  567. setBitmapColor(olxf, olyf, 3);
  568. //Delete fp
  569. x[fp] = 0;
  570. y[fp] = 0;
  571. element[fp] = 0;
  572. xvel[fp] = 0;
  573. yvel[fp] = 0;
  574. set[fp] = 0;
  575. avail[loq] = fp;
  576. loq++;
  577. //Set sp
  578. allcoords[(int) x[sp]][(int) y[sp]] = sp;
  579. setBitmapColor((int) x[sp], (int) y[sp], element[sp]);
  580. int random = rand() % 10;
  581. random -= 5;
  582. xvel[sp] = random; //xvel is a random int from -5 to 5
  583. random = rand() % 10;
  584. random -= 5;
  585. yvel[sp] = random; //yvel is a random int from -5 to 5
  586. int i, j, xsp = x[sp], ysp = y[sp], a;
  587. for (i = -2; i <= 2; i++)
  588. {
  589. for (j = -2; j <= 2; j++)
  590. {
  591. if (xsp + i > 1 && xsp + i < maxx && ysp + j > 1 && ysp + j
  592. < maxy && !(i == 0 && j == 0))
  593. {
  594. a = allcoords[xsp + i][ysp + j];
  595. if (a != -1 && collision[element[a]][5] == 6)
  596. {
  597. element[a] = 5;
  598. setBitmapColor(xsp + i, ysp + j, 5);
  599. }
  600. else if (a != -1 && collision[element[a]][5] == 11)
  601. {
  602. element[a] = 5;
  603. setBitmapColor(xsp + i, ysp + j, 5);
  604. int random = rand() % 10;
  605. random -= 5;
  606. xvel[a] = random; //xvel is a random int from -5 to 5
  607. random = rand() % 10;
  608. random -= 5;
  609. yvel[a] = random; //yvel is a random int from -5 to 5
  610. }
  611. else if (a == -1)
  612. {
  613. CreatePoint(xsp + i, ysp + j, 5);
  614. }
  615. }
  616. }
  617. }
  618. }
  619. }
  620. else if (type == 12) //Water - Magma Collision
  621. {
  622. if (element[fp] == 10 || (element[fp] == 22
  623. && colliseelement1[element[sp]] == 10) || (element[sp] == 22
  624. && colliseelement1[element[fp]] != 10)) //fp is magma
  625. {
  626. //Move the water to magma's location and make it steam
  627. element[sp] = 18;
  628. x[sp] = olxf;
  629. y[sp] = olyf;
  630. allcoords[olxf][olyf] = sp;
  631. setBitmapColor(olxf, olyf, 18);
  632. element[fp] = 11; //Make the magma into stone
  633. setBitmapColor((int) x[fp], (int) y[fp], 11); //Set the color
  634. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  635. if (rand() % 3 == 0) //1/3 chance
  636. {
  637. DeletePoint(fp); //Delete magma
  638. }
  639. }
  640. else //sp is magma
  641. {
  642. element[sp] = 11; //Change magma to stone
  643. setBitmapColor((int) x[sp], (int) y[sp], 11); //Set the color
  644. //Change water to steam
  645. element[fp] = 18;
  646. //Move it back
  647. allcoords[olxf][olyf] = fp;
  648. setBitmapColor(olxf, olyf, 18);
  649. x[fp] = olxf;
  650. y[fp] = olyf;
  651. if (rand() % 3 == 0) //1/3 chance
  652. {
  653. DeletePoint(sp); //Delete magma
  654. }
  655. }
  656. }
  657. else if (type == 13) //Hot(Magma, Fire) - Stone Collision
  658. {
  659. if (element[fp] == 11 || (element[fp] == 22
  660. && colliseelement1[element[sp]] == 11) || (element[sp] == 22
  661. && colliseelement1[element[fp]] != 11)) //fp is stone
  662. {
  663. if (rand() % 10 == 0) //1/10 chance
  664. {
  665. x[fp] = olxf;
  666. y[fp] = olyf;
  667. allcoords[(int) x[fp]][(int) y[fp]] = fp; //Move the stone back
  668. element[fp] = 10; //Change stone to magma
  669. setBitmapColor((int) x[fp], (int) y[fp], 10); //Set the color also
  670. }
  671. else
  672. {
  673. //Clear old spot
  674. allcoords[olxf][olyf] = -1;
  675. setBitmapColor(olxf, olyf, 3);
  676. y[sp] = olyf; //Stone replaces Hot (switch)
  677. x[sp] = olxf;
  678. allcoords[olxf][olyf] = sp;
  679. setBitmapColor(olxf, olyf, element[sp]);
  680. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  681. setBitmapColor((int) x[fp], (int) y[fp], element[fp]);
  682. //Set a random xvel
  683. xvel[sp] = rand() % 3 - 1;
  684. }
  685. }
  686. else
  687. {
  688. //Either way, move fp back
  689. x[fp] = olxf;
  690. y[fp] = olyf;
  691. allcoords[olxf][olyf] = fp;
  692. setBitmapColor(olxf, olyf, element[fp]);
  693. if (rand() % 10 == 0) //1/10 chance
  694. {
  695. element[sp] = 10; //Change stone to magma
  696. setBitmapColor((int) x[sp], (int) y[sp], 10); //Set the color also
  697. allcoords[(int) x[sp]][(int) y[sp]] = sp;
  698. }
  699. //Set a random xvel
  700. xvel[fp] = rand() % 3 - 1;
  701. }
  702. }
  703. else if (type == 14) //Stone - Stone
  704. {
  705. y[fp] = olyf; // First particle goes back to where it was before
  706. x[fp] = olxf;
  707. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  708. setBitmapColor((int) x[fp], (int) y[fp], element[fp]);
  709. }
  710. else if (type == 15) // C4 - hot
  711. {
  712. if (element[fp] == 12 || (element[fp] == 22
  713. && colliseelement1[element[sp]] == 12) || (element[sp] == 22
  714. && colliseelement1[element[fp]] != 12)) //fp is C4
  715. {
  716. //Put back the C4
  717. x[fp] = olxf;
  718. y[fp] = olyf;
  719. //allcoords[olxs][olys] = sp;
  720. //setBitmapColor(olxs,olys,element[sp]);
  721. //Change C4 to fire
  722. element[fp] = 5;
  723. setBitmapColor((int) x[fp], (int) y[fp], 5);
  724. int txpos = (int) x[fp], typos = (int) y[fp]; //temporary x and ypositions for quick calcs
  725. //this section is for explosion, giving velocities to particles around explosion
  726. int i, j; //counters, i is the x, j is the y
  727. int tpart, telement; //temp particle index /element
  728. for (i = -0; i <= 0; i++)
  729. {
  730. for (j = -0; j <= 0; j++)
  731. {
  732. if (txpos + i < maxx && txpos + i > 1 && typos + j < maxy
  733. && typos + j > 1) //if within bounds
  734. {
  735. tpart = allcoords[txpos + i][typos + j];
  736. if (tpart != -1
  737. && (fallvel[element[tpart]] != 0
  738. || element[tpart] == 15
  739. || element[tpart] == 21)) //if there's a particle there & it's not immovable
  740. {
  741. if (abs(xvel[tpart]) < 20)
  742. {
  743. xvel[tpart] += 1 * i / abs(i);
  744. }
  745. if (abs(yvel[tpart]) < 20)
  746. {
  747. yvel[tpart] += 1 * j / abs(j);
  748. }
  749. }
  750. }
  751. }
  752. }
  753. //Look at all the points around the explosion, if explosive change to fire and add velocity,
  754. // if flammable, just change to fire, if empty, change to fire and add velocity
  755. int a; //Temp allcoords
  756. for (i = -2; i <= 2; i++)
  757. {
  758. for (j = -2; j <= 2; j++)
  759. {
  760. if (txpos + i > 1 && txpos + i < maxx && typos + j > 1
  761. && typos + j < maxy)
  762. {
  763. a = allcoords[txpos + i][typos + j]; //The allcoords at the prospective point
  764. if (a != -1 && collision[element[a]][5] == 6)
  765. {
  766. element[a] = 5;
  767. setBitmapColor(txpos + i, typos + j, 5);
  768. }
  769. else if (a != -1 && (collision[element[a]][5] == 11
  770. || collision[element[a]][5] == 15))
  771. {
  772. element[a] = 5;
  773. setBitmapColor(txpos + i, typos + j, 5);
  774. int random = rand() % 11;
  775. random -= 5;
  776. xvel[a] = random; //xvel is a random int from -5 to 5
  777. random = rand() % 11; //mod 11 goes from 0 to 10
  778. random -= 5;
  779. yvel[a] = random; //yvel is a random int from -5 to 5
  780. }
  781. else if (a == -1)
  782. {
  783. CreatePoint(txpos + i, typos + j, 5);
  784. }
  785. }
  786. }
  787. }
  788. }
  789. else //sp is C4
  790. {
  791. //put back the hot
  792. x[fp] = olxf;
  793. y[fp] = olyf;
  794. int spelement = element[sp];
  795. //change C4 to fire
  796. element[sp] = 5;
  797. setBitmapColor((int) x[sp], (int) y[sp], 5);
  798. int txpos = (int) x[sp], typos = (int) y[sp]; //temporary x and ypositions for quick calcs
  799. //this section is for explosion, giving velocities to particles around explosion
  800. int i, j; //counters, i is the x, j is the y
  801. int tpart, telement; //temp particle index /element
  802. for (i = -2 * exploness[spelement]; i <= 2 * exploness[spelement]; i++)
  803. {
  804. for (j = -2 * exploness[spelement]; j <= 2
  805. * exploness[spelement]; j++)
  806. {
  807. if (txpos + i < maxx && txpos + i > 1 && typos + j < maxy
  808. && typos + j > 1) //if within bounds
  809. {
  810. tpart = allcoords[txpos + i][typos + j];
  811. if (tpart != -1
  812. && (fallvel[element[tpart]] != 0
  813. || element[tpart] == 15
  814. || element[tpart] == 21)) //if there's a particle there
  815. {
  816. if (abs(xvel[tpart]) < exploness[spelement])
  817. {
  818. xvel[tpart] += ((1 / i) * 3) + i / abs(i);
  819. }
  820. if (abs(yvel[tpart]) < exploness[spelement])
  821. {
  822. yvel[tpart] += ((1 / j) * 3) + j / abs(j);
  823. }
  824. }
  825. }
  826. }
  827. }
  828. //Look at all the points around the explosion, if explosive change to fire and add velocity,
  829. // if flammable, just change to fire, if empty, change to fire and add velocity
  830. int a; //Temp allcoords
  831. for (i = -2; i <= 2; i++)
  832. {
  833. for (j = -2; j <= 2; j++)
  834. {
  835. if (txpos + i > 1 && txpos + i < maxx && typos + j > 1
  836. && typos + j < maxy)
  837. {
  838. a = allcoords[txpos + i][typos + j]; //The allcoords at the prospective point
  839. if (a != -1 && collision[element[a]][5] == 6)
  840. {
  841. element[a] = 5;
  842. setBitmapColor(txpos + i, typos + j, 5);
  843. }
  844. else if (a != -1 && (collision[element[a]][5] == 11
  845. || collision[element[a]][5] == 15))
  846. {
  847. element[a] = 5;
  848. setBitmapColor(txpos + i, typos + j, 5);
  849. int random = rand() % 11; //mod 11 goes from 0 to 10
  850. random -= 5;
  851. xvel[a] = random; //xvel is a random int from -5 to 5
  852. random = rand() % 11;
  853. random -= 5;
  854. yvel[a] = random; //yvel is a random int from -5 to 5
  855. }
  856. else if (a == -1)
  857. {
  858. CreatePoint(txpos + i, typos + j, 5);
  859. }
  860. }
  861. }
  862. }
  863. }
  864. }
  865. else if (type == 16) // C4++ - hot
  866. {
  867. if (element[fp] == 13 || (element[fp] == 22
  868. && colliseelement1[element[sp]] == 13) || (element[sp] == 22
  869. && colliseelement1[element[fp]] != 13)) //fp is C4++
  870. {
  871. //Put back the hot
  872. x[sp] = olxs;
  873. y[sp] = olys;
  874. allcoords[olxs][olys] = sp;
  875. setBitmapColor(olxs, olys, element[sp]);
  876. //Change C4++ to fire
  877. element[fp] = 5;
  878. setBitmapColor((int) x[fp], (int) y[fp], 5);
  879. int txpos = (int) x[fp], typos = (int) y[fp]; //temporary x and ypositions for quick calcs
  880. //this section is for explosion, giving velocities to particles around explosion
  881. int i, j; //counters, i is the x, j is the y
  882. int tpart, telement; //temp particle index /element
  883. for (i = -0; i <= 0; i++)
  884. {
  885. for (j = -0; j <= 0; j++)
  886. {
  887. if (txpos + i < maxx && txpos + i > 1 && typos + j < maxy
  888. && typos + j > 1) //if within bounds
  889. {
  890. tpart = allcoords[txpos + i][typos + j];
  891. if (tpart != -1
  892. && (fallvel[element[tpart]] != 0
  893. || element[tpart] == 15
  894. || element[tpart] == 21)) //if there's a particle there & it's not immovable
  895. {
  896. if (abs(xvel[tpart]) < 20)
  897. {
  898. xvel[tpart] += ((1 / i) * 0) + 1 * i / abs(i);
  899. }
  900. if (abs(yvel[tpart]) < 20)
  901. {
  902. yvel[tpart] += ((1 / j) * 0) + 1 * j / abs(j);
  903. }
  904. }
  905. }
  906. }
  907. }
  908. //Look at all the points around the explosion, if explosive change to fire and add velocity,
  909. // if flammable, just change to fire, if empty, change to fire and add velocity
  910. int a; //Temp allcoords
  911. for (i = -2; i <= 2; i++)
  912. {
  913. for (j = -2; j <= 2; j++)
  914. {
  915. if (txpos + i > 1 && txpos + i < maxx && typos + j > 1
  916. && typos + j < maxy)
  917. {
  918. a = allcoords[txpos + i][typos + j]; //The allcoords at the prospective point
  919. if (a != -1 && collision[element[a]][5] == 6)
  920. {
  921. element[a] = 5;
  922. setBitmapColor(txpos + i, typos + j, 5);
  923. }
  924. else if (a != -1 && (collision[element[a]][5] == 11
  925. || collision[element[a]][5] == 15
  926. || collision[element[a]][5] == 16))
  927. {
  928. element[a] = 5; //change a to fire
  929. setBitmapColor(txpos + i, typos + j, 5); //change color of a to that of fire
  930. int random = rand() % 11; // mod 11 goes from 0 to 10
  931. random -= 5;
  932. xvel[a] = random; //xvel is a random int from -5 to 5
  933. random = rand() % 11;
  934. random -= 5;
  935. yvel[a] = random; //yvel is a random int from -5 to 5
  936. }
  937. else if (a == -1)
  938. {
  939. CreatePoint(txpos + i, typos + j, 5);
  940. }
  941. }
  942. }
  943. }
  944. }
  945. else //sp is C4++
  946. {
  947. //put back the hot
  948. x[fp] = olxf;
  949. y[fp] = olyf;
  950. int spelement = element[sp];
  951. //change C4++ to fire
  952. element[sp] = 5;
  953. setBitmapColor((int) x[sp], (int) y[sp], 5);
  954. int txpos = (int) x[sp], typos = (int) y[sp]; //temporary x and ypositions for quick calcs
  955. //this section is for explosion, giving velocities to particles around explosion
  956. int i, j; //counters, i is the x, j is the y
  957. int tpart, telement; //temp particle index /element
  958. for (i = -2 * exploness[spelement]; i <= 2 * exploness[spelement]; i++)
  959. {
  960. for (j = -2 * exploness[spelement]; j <= 2
  961. * exploness[spelement]; j++)
  962. {
  963. if (txpos + i < maxx && txpos + i > 1 && typos + j < maxy
  964. && typos + j > 1) //if within bounds
  965. {
  966. tpart = allcoords[txpos + i][typos + j];
  967. if (tpart != -1
  968. && (fallvel[element[tpart]] != 0
  969. || element[tpart] == 15
  970. || element[tpart] == 21)) //if there's a particle there
  971. {
  972. if (abs(xvel[tpart]) < exploness[spelement])
  973. {
  974. xvel[tpart] += ((1 / i) * 3) + i / abs(i);
  975. }
  976. if (abs(yvel[tpart]) < exploness[spelement])
  977. {
  978. yvel[tpart] += ((1 / j) * 3) + j / abs(j);
  979. }
  980. }
  981. }
  982. }
  983. }
  984. //Look at all the points around the explosion, if explosive change to fire and add velocity,
  985. // if flammable, just change to fire, if empty, change to fire and add velocity
  986. int a; //Temp allcoords
  987. for (i = -2; i <= 2; i++)
  988. {
  989. for (j = -2; j <= 2; j++)
  990. {
  991. if (txpos + i > 1 && txpos + i < maxx && typos + j > 1
  992. && typos + j < maxy)
  993. {
  994. a = allcoords[txpos + i][typos + j]; //The allcoords at the prospective point
  995. if (a != -1 && collision[element[a]][5] == 6)
  996. {
  997. element[a] = 5;
  998. setBitmapColor(txpos + i, typos + j, 5);
  999. }
  1000. else if (a != -1 && (collision[element[a]][5] == 11
  1001. || collision[element[a]][5] == 15
  1002. || collision[element[a]][5] == 16))
  1003. {
  1004. element[a] = 5;
  1005. setBitmapColor(txpos + i, typos + j, 5);
  1006. int random = rand() % 11; //mod 11 goes from 0 to 10
  1007. random -= 5;
  1008. xvel[a] = random; //xvel is a random int from -5 to 5
  1009. random = rand() % 11; //mod 11 goes from 0 to 10
  1010. random -= 5;
  1011. yvel[a] = random; //yvel is a random int from -5 to 5
  1012. }
  1013. else if (a == -1)
  1014. {
  1015. CreatePoint(txpos + i, typos + j, 5);
  1016. }
  1017. }
  1018. }
  1019. }
  1020. }
  1021. }
  1022. else if (type == 17) //Magma - Destructible Wall
  1023. {
  1024. //We can assume that fp is magma since wall doesn't move
  1025. //move magma back
  1026. //TODO: Edit this to allow a Destructible wall - Magma collision
  1027. x[fp] = olxf;
  1028. y[fp] = olyf;
  1029. allcoords[olxf][olyf] = fp;
  1030. setBitmapColor(olxf, olyf, element[fp]);
  1031. if (rand() % 10 == 0) //1/10 chance
  1032. {
  1033. element[sp] = 10; //Change wall to magma
  1034. setBitmapColor((int) x[sp], (int) y[sp], 10); //Set the color also
  1035. allcoords[(int) x[sp]][(int) y[sp]] = sp;
  1036. }
  1037. //Set a random xvel to magma
  1038. xvel[fp] = rand() % 3 - 1;
  1039. }
  1040. else if (type == 18) //Acid - Meltable
  1041. {
  1042. int xfp = x[fp], yfp = y[fp];
  1043. if (element[fp] == 17 || (element[fp] == 22
  1044. && colliseelement1[element[sp]] == 17) || (element[sp] == 22
  1045. && colliseelement1[element[fp]] != 17)) //fp is acid
  1046. {
  1047. if (rand() % 3 != 0) //2/3 chance
  1048. {
  1049. //Acid burns away sp
  1050. //Delete the old point
  1051. allcoords[olxf][olyf] = -1;
  1052. setBitmapColor(olxf, olyf, 3);
  1053. //Set the new point
  1054. allcoords[xfp][yfp] = fp;
  1055. setBitmapColor(xfp, yfp, element[fp]);
  1056. //Delete sp
  1057. x[sp] = 0;
  1058. y[sp] = 0;
  1059. element[sp] = 0;
  1060. xvel[sp] = 0;
  1061. yvel[sp] = 0;
  1062. set[sp] = 0;
  1063. avail[loq] = sp;
  1064. loq++;
  1065. }
  1066. else if (rand() % 2 == 0) //Otherwise, 1/6 total
  1067. {
  1068. //Acid is neutralized
  1069. //Delete the old point
  1070. allcoords[olxf][olyf] = -1;
  1071. setBitmapColor(olxf, olyf, 3);
  1072. //Delete fp
  1073. x[fp] = 0;
  1074. y[fp] = 0;
  1075. element[fp] = 0;
  1076. xvel[fp] = 0;
  1077. yvel[fp] = 0;
  1078. set[fp] = 0;
  1079. avail[loq] = fp;
  1080. loq++;
  1081. }
  1082. else //Otherwise, 1/6 total
  1083. {
  1084. //Acid bounces
  1085. x[fp] = olxf;
  1086. y[fp] = olyf;
  1087. }
  1088. }
  1089. else //sp is acid
  1090. {
  1091. if (rand() % 3 != 0) //2/3 chance
  1092. {
  1093. //Acid burns away fp
  1094. //Delete the old point
  1095. allcoords[olxf][olyf] = -1;
  1096. setBitmapColor(olxf, olyf, 3);
  1097. //Delete fp
  1098. x[fp] = 0;
  1099. y[fp] = 0;
  1100. element[fp] = 0;
  1101. xvel[fp] = 0;
  1102. yvel[fp] = 0;
  1103. set[fp] = 0;
  1104. avail[loq] = fp;
  1105. loq++;
  1106. }
  1107. else if (rand() % 2 == 0) //Otherwise, 1/6 total
  1108. {
  1109. //Acid is neutralized
  1110. //Delete the old point
  1111. allcoords[olxf][olyf] = -1;
  1112. setBitmapColor(olxf, olyf, 3);
  1113. //Set the new point
  1114. allcoords[xfp][yfp] = fp;
  1115. setBitmapColor(xfp, yfp, element[fp]);
  1116. //Delete sp
  1117. x[sp] = 0;
  1118. y[sp] = 0;
  1119. element[sp] = 0;
  1120. xvel[sp] = 0;
  1121. yvel[sp] = 0;
  1122. set[sp] = 0;
  1123. avail[loq] = sp;
  1124. loq++;
  1125. }
  1126. else //Otherwise, 1/6 total
  1127. {
  1128. //Other particle bounces bounces
  1129. x[fp] = olxf;
  1130. y[fp] = olyf;
  1131. }
  1132. }
  1133. }
  1134. else if (type == 19) //Acid - Water
  1135. {
  1136. int xfp = x[fp], yfp = y[fp];
  1137. //Acid goes away 1/3 of the time, otherwise bounce back
  1138. if (element[fp] == 17 || (element[fp] == 22
  1139. && colliseelement1[element[sp]] == 17) || (element[sp] == 22
  1140. && colliseelement1[element[fp]] != 17)) //fp is acid
  1141. {
  1142. if (rand() % 3 == 0)
  1143. {
  1144. //Delete the old point
  1145. allcoords[olxf][olyf] = -1;
  1146. setBitmapColor(olxf, olyf, 3);
  1147. //Delete fp
  1148. x[fp] = 0;
  1149. y[fp] = 0;
  1150. element[fp] = 0;
  1151. xvel[fp] = 0;
  1152. yvel[fp] = 0;
  1153. set[fp] = 0;
  1154. avail[loq] = fp;
  1155. loq++;
  1156. }
  1157. else
  1158. {
  1159. //Move the point back
  1160. x[fp] = olxf;
  1161. y[fp] = olyf;
  1162. }
  1163. }
  1164. else //sp is acid
  1165. {
  1166. if (rand() % 3 == 0)
  1167. {
  1168. //Delete the old point
  1169. allcoords[olxf][olyf] = -1;
  1170. setBitmapColor(olxf, olyf, 3);
  1171. //Set the new point
  1172. allcoords[xfp][yfp] = fp;
  1173. setBitmapColor(xfp, yfp, element[fp]);
  1174. //Delete sp
  1175. x[sp] = 0;
  1176. y[sp] = 0;
  1177. element[sp] = 0;
  1178. xvel[sp] = 0;
  1179. yvel[sp] = 0;
  1180. set[sp] = 0;
  1181. avail[loq] = sp;
  1182. loq++;
  1183. }
  1184. else
  1185. {
  1186. //Move the water back
  1187. x[fp] = olxf;
  1188. y[fp] = olyf;
  1189. }
  1190. }
  1191. }
  1192. else if (type == 20) //Steam - Ice/Water
  1193. {
  1194. if (rand() % 200 == 0) //1/200 chance for steam to condense
  1195. {
  1196. if (element[fp] == 18 || (element[fp] == 22
  1197. && colliseelement1[element[sp]] == 18) || (element[sp]
  1198. == 22 && colliseelement1[element[fp]] != 18)) //fp is steam
  1199. {
  1200. //Change the steam to water
  1201. element[fp] = 1;
  1202. //Move it back
  1203. x[fp] = olxf;
  1204. y[fp] = olyf;
  1205. allcoords[olxf][olyf] = fp;
  1206. setBitmapColor(olxf, olyf, 1);
  1207. }
  1208. else //sp is steam
  1209. {
  1210. //Change the steam to water
  1211. element[sp] = 1;
  1212. //Move fp back
  1213. x[fp] = olxf;
  1214. y[fp] = olyf;
  1215. allcoords[olxf][olyf] = fp;
  1216. setBitmapColor(olxf, olyf, element[fp]);
  1217. }
  1218. }
  1219. else //Just bounce around the water/ice
  1220. {
  1221. if (element[fp] == 18 || (element[fp] == 22
  1222. && colliseelement1[element[sp]] == 18)) //fp is steam
  1223. {
  1224. //Move it back
  1225. x[fp] = olxf;
  1226. y[fp] = olyf;
  1227. allcoords[olxf][olyf] = fp;
  1228. setBitmapColor(olxf, olyf, 18);
  1229. //Add a random x velocity
  1230. xvel[fp] += rand() % 7 - 3; //-3 to 3
  1231. }
  1232. else //sp is steam
  1233. {
  1234. int xfp = x[fp], yfp = y[fp]; //Set some temp variables
  1235. //Switch places
  1236. x[sp] = olxf;
  1237. y[sp] = olyf;
  1238. allcoords[olxf][olyf] = sp;
  1239. setBitmapColor(olxf, olyf, 18);
  1240. allcoords[xfp][yfp] = fp;
  1241. setBitmapColor(xfp, yfp, element[fp]);
  1242. }
  1243. }
  1244. }
  1245. else if (type == 21) //Steam - Steam
  1246. {
  1247. if (rand() % 1000 == 0)//1/5 chance
  1248. {
  1249. //Make the two steams "condense" into water
  1250. int xsp = x[sp], ysp = y[sp]; //Some temp variables
  1251. //Move fp back
  1252. x[fp] = olxf;
  1253. y[fp] = olyf;
  1254. //Change the elements
  1255. element[fp] = 1;
  1256. element[sp] = 1;
  1257. //Set the bitmap and allcoords
  1258. allcoords[olxf][olyf] = fp;
  1259. setBitmapColor(olxf, olyf, 1);
  1260. allcoords[xsp][ysp] = sp;
  1261. setBitmapColor(xsp, ysp, 1);
  1262. }
  1263. else //Make fp bounce off
  1264. {
  1265. //Move fp back
  1266. x[fp] = olxf;
  1267. y[fp] = olyf;
  1268. allcoords[olxf][olyf] = fp;
  1269. setBitmapColor(olxf, olyf, 18);
  1270. //Add a random x velocity
  1271. xvel[fp] += rand() % 7 - 3; //-3 to 3
  1272. //Add a random y velocity
  1273. yvel[fp] += rand() % 5 - 2; //-2 to 2
  1274. }
  1275. }
  1276. else if (type == 22) //Steam - Other
  1277. {
  1278. int xfp = x[fp], yfp = y[fp];
  1279. if (element[fp] == 18 || (element[fp] == 22
  1280. && colliseelement1[element[sp]] == 18) || (element[sp] == 22
  1281. && colliseelement1[element[fp]] != 18)) //fp is steam
  1282. {
  1283. //Move the steam back
  1284. allcoords[olxf][olyf] = fp;
  1285. setBitmapColor(olxf, olyf, element[sp]);
  1286. x[fp] = olxf;
  1287. y[fp] = olyf;
  1288. //Set a random x velocity
  1289. xvel[fp] = rand() % 7 - 3; //-3 to 3
  1290. }
  1291. else //sp is steam
  1292. {
  1293. //Move the steam to the old spot
  1294. allcoords[olxf][olyf] = sp;
  1295. setBitmapColor(olxf, olyf, element[sp]);
  1296. x[sp] = olxf;
  1297. y[sp] = olyf;
  1298. //Set the new spot
  1299. allcoords[xfp][yfp] = fp;
  1300. setBitmapColor(xfp, yfp, element[fp]);
  1301. //Set a random x velocity
  1302. xvel[sp] = rand() % 7 - 3; //-3 to 3
  1303. }
  1304. }
  1305. else if (type == 23) //Water - Fire
  1306. {
  1307. if (element[fp] == 5 || (element[fp] == 22
  1308. && colliseelement1[element[sp]] == 5) || (element[sp] == 22
  1309. && colliseelement1[element[fp]] != 5)) //fp is fire
  1310. {
  1311. //Delete the old point
  1312. allcoords[olxf][olyf] = -1;
  1313. setBitmapColor(olxf, olyf, 3);
  1314. //Delete the fire
  1315. x[fp] = 0;
  1316. y[fp] = 0;
  1317. element[fp] = 0;
  1318. xvel[fp] = 0;
  1319. yvel[fp] = 0;
  1320. set[fp] = 0;
  1321. avail[loq] = fp;
  1322. loq++;
  1323. //Change the water to steam
  1324. element[sp] = 18;
  1325. //Change the bitmap color
  1326. setBitmapColor(x[sp], y[sp], 18);
  1327. }
  1328. else //sp is fire
  1329. {
  1330. int xfp = x[fp], yfp = y[fp]; //Set temp variables
  1331. //Delete sp(fire)
  1332. DeletePoint(sp);
  1333. //Delete the old point
  1334. allcoords[olxf][olyf] = -1;
  1335. setBitmapColor(olxf, olyf, 3);
  1336. //Change the water to steam
  1337. element[fp] = 18;
  1338. //Set the new location of water
  1339. allcoords[xfp][yfp] = fp;
  1340. setBitmapColor(xfp, yfp, 18);
  1341. }
  1342. }
  1343. else if (type == 24) //Salt - Water
  1344. {
  1345. if (element[fp] == 19 || (element[fp] == 22
  1346. && colliseelement1[element[sp]] == 19)) //fp is salt
  1347. {
  1348. //Delete the old point
  1349. allcoords[olxf][olyf] = -1;
  1350. setBitmapColor(olxf, olyf, 3);
  1351. //Delete fp
  1352. x[fp] = 0;
  1353. y[fp] = 0;
  1354. element[fp] = 0;
  1355. xvel[fp] = 0;
  1356. yvel[fp] = 0;
  1357. set[fp] = 0;
  1358. avail[loq] = fp;
  1359. loq++;
  1360. //Change the element of sp to Salt-water
  1361. element[sp] = 20;
  1362. setBitmapColor(x[sp], y[sp], 20);
  1363. }
  1364. else //sp is salt
  1365. {
  1366. //Delete the old point
  1367. allcoords[olxf][olyf] = -1;
  1368. setBitmapColor(olxf, olyf, 3);
  1369. DeletePoint(sp); //Delete the salt
  1370. int xfp = x[fp], yfp = y[fp]; //Some temp variables
  1371. //Set the new coordinates
  1372. allcoords[xfp][yfp] = fp;
  1373. setBitmapColor(xfp, yfp, element[fp]);
  1374. }
  1375. }
  1376. else if (type == 25) //Salt - Ice
  1377. {
  1378. if (element[fp] == 6 || (element[fp] == 22
  1379. && colliseelement1[element[sp]] == 6) || (element[sp] == 22
  1380. && colliseelement1[element[fp]] != 6)) //fp is ice
  1381. {
  1382. //Move fp back
  1383. x[fp] = olxf;
  1384. y[fp] = olyf;
  1385. //Change the element to water
  1386. element[fp] = 1;
  1387. //Set the bitmap stuff
  1388. allcoords[olxf][olyf] = fp;
  1389. setBitmapColor(olxf, olyf, 1);
  1390. }
  1391. else //sp is ice
  1392. {
  1393. //Move fp back
  1394. x[fp] = olxf;
  1395. y[fp] = olyf;
  1396. allcoords[olxf][olyf] = fp;
  1397. setBitmapColor(olxf, olyf, element[fp]);
  1398. //Change the element to water
  1399. element[sp] = 1;
  1400. //Set the bitmap stuff
  1401. setBitmapColor(x[sp], y[sp], 1);
  1402. }
  1403. }
  1404. else if (type == 26) //Salt-water - Plant
  1405. {
  1406. if (element[fp] == 4 || (element[fp] == 22
  1407. && colliseelement1[element[sp]] == 4) || (element[sp] == 22
  1408. && colliseelement1[element[fp]] != 4)) //fp is plant
  1409. {
  1410. //Move fp back
  1411. x[fp] = olxf;
  1412. y[fp] = olyf;
  1413. //Change the element to sand
  1414. element[fp] = 0;
  1415. //Set the bitmap stuff
  1416. allcoords[olxf][olyf] = fp;
  1417. setBitmapColor(olxf, olyf, 0);
  1418. }
  1419. else //sp is plant
  1420. {
  1421. //Move fp back
  1422. x[fp] = olxf;
  1423. y[fp] = olyf;
  1424. allcoords[olxf][olyf] = fp;
  1425. setBitmapColor(olxf, olyf, element[fp]);
  1426. //Change the element to sand
  1427. element[sp] = 0;
  1428. //Set the bitmap stuff
  1429. setBitmapColor(x[sp], y[sp], 0);
  1430. }
  1431. }
  1432. else if (type == 27) //Magma - Sand
  1433. {
  1434. if (element[fp] == 10 || (element[fp] == 22
  1435. && colliseelement1[element[sp]] == 10) || (element[sp] == 22
  1436. && colliseelement1[element[fp]] != 10)) //fp is magma
  1437. {
  1438. //Move fp back
  1439. x[fp] = olxf;
  1440. y[fp] = olyf;
  1441. //Change the element to glass
  1442. element[sp] = 21;
  1443. //Set the bitmap stuff
  1444. setBitmapColor(x[sp], y[sp], 21);
  1445. }
  1446. else //sp is magma
  1447. {
  1448. //Move fp back
  1449. x[fp] = olxf;
  1450. y[fp] = olyf;
  1451. //Change the element to glass
  1452. element[fp] = 21;
  1453. setBitmapColor(x[fp], y[fp], 21);
  1454. }
  1455. }
  1456. else if (type == 28) //Water - Sand
  1457. {
  1458. if (element[fp] == 1 || (element[fp] == 22
  1459. && colliseelement1[element[sp]] == 1) || (element[sp] == 22
  1460. && colliseelement1[element[fp]] != 1)) //fp is water
  1461. {
  1462. //Delete the old point
  1463. allcoords[olxf][olyf] = -1;
  1464. setBitmapColor(olxf, olyf, 3);
  1465. //Delete the water
  1466. x[fp] = 0;
  1467. y[fp] = 0;
  1468. element[fp] = 0;
  1469. xvel[fp] = 0;
  1470. yvel[fp] = 0;
  1471. set[fp] = 0;
  1472. avail[loq] = fp;
  1473. loq++;
  1474. element[sp] = 23; // set the sand to be mud
  1475. setBitmapColor(x[sp], y[sp], element[sp]); // change the color of the sand particle location to be mud
  1476. }
  1477. else //sp is water
  1478. {
  1479. //Delete the old point
  1480. allcoords[olxf][olyf] = -1;
  1481. setBitmapColor(olxf, olyf, 3);
  1482. DeletePoint(sp); //delete the water
  1483. element[fp] = 23; //set the sand to be mud
  1484. int xfp = x[fp], yfp = y[fp]; //Some temp variables
  1485. //Set the new coordinates
  1486. allcoords[xfp][yfp] = fp;
  1487. setBitmapColor(xfp, yfp, element[fp]);
  1488. }
  1489. }
  1490. else if (type == 29)
  1491. { //Mud - Fire
  1492. if (element[fp] == 23 || (element[fp] == 22
  1493. && colliseelement1[element[sp]] == 23) || (element[sp] == 22
  1494. && colliseelement1[element[fp]] != 23))
  1495. { //sp is mud
  1496. //Delete the old point
  1497. allcoords[olxf][olyf] = -1;
  1498. setBitmapColor(olxf, olyf, 3);
  1499. DeletePoint(sp); //delete the fire
  1500. element[fp] = 0; //change the mud to sand
  1501. int xfp = x[fp], yfp = y[fp]; //Some temp variables
  1502. allcoords[xfp][yfp] = fp;
  1503. setBitmapColor(xfp, yfp, element[fp]); //update the color of mud
  1504. }
  1505. else
  1506. { // fp is fire
  1507. //Delete the old point
  1508. allcoords[olxf][olyf] = -1;
  1509. setBitmapColor(olxf, olyf, 3);
  1510. //Delete the fire
  1511. x[fp] = 0;
  1512. y[fp] = 0;
  1513. element[fp] = 0;
  1514. xvel[fp] = 0;
  1515. yvel[fp] = 0;
  1516. set[fp] = 0;
  1517. avail[loq] = fp;
  1518. loq++;
  1519. element[sp] = 0;
  1520. setBitmapColor(x[sp], y[sp], element[sp]);
  1521. }
  1522. }
  1523. else if (type == 30)
  1524. { //Mud - Magma
  1525. x[fp] = olxf; //send the fp back
  1526. y[fp] = olyf;
  1527. element[fp] = 11; //change fp to stone (it really doesn't matter which one we are changing to what
  1528. element[sp] = 18; //change sp to steam
  1529. setBitmapColor(y[fp], y[fp], element[fp]); //update colors
  1530. setBitmapColor(x[sp], y[sp], element[sp]);
  1531. }
  1532. }