/TheElements/jni/collide.c

http://thelements.googlecode.com/ · C · 1739 lines · 1377 code · 196 blank · 166 comment · 646 complexity · b55cf2c2f758472da8d3c734753854a6 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]; //not sure what this does
  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], element[fp]); //set the bitmapcolor
  380. return;
  381. }
  382. }
  383. }
  384. }
  385. int random = rand() % 2;
  386. random = random * 2 - 1;
  387. if (allcoords[olxf + random][olyf + 1] == -1 && olxf + random
  388. > 1 && olyf + 1 < maxy && olxf + random < maxx) // left down
  389. {
  390. allcoords[olxf][olyf] = -1;
  391. //clear old spot
  392. setBitmapColor(olxf, olyf, 3);
  393. allcoords[olxf + random][olyf + 1] = fp;
  394. setBitmapColor(olxf + random, olyf + 1, element[fp]); //set new spot
  395. y[fp] = olyf + 1;
  396. x[fp] = olxf + random;
  397. }
  398. else if (allcoords[olxf - random][olyf + 1] == -1 && olxf
  399. - random > 1 && olyf + 1 < maxy && olxf - random < maxx) // left down
  400. {
  401. allcoords[olxf][olyf] = -1;
  402. setBitmapColor(olxf, olyf, 3);
  403. allcoords[olxf - random][olyf + 1] = fp;
  404. setBitmapColor(olxf - random, olyf + 1, element[fp]); //set new spot
  405. y[fp] = olyf + 1;
  406. x[fp] = olxf - random;
  407. }
  408. else if (allcoords[olxf + random][olyf] == -1 && olxf + random
  409. < maxx && olxf + random > 1) // right
  410. {
  411. allcoords[olxf][olyf] = -1;
  412. setBitmapColor(olxf, olyf, 3);
  413. allcoords[olxf + random][olyf] = fp;
  414. setBitmapColor(olxf + random, olyf, element[fp]); //set new spot
  415. y[fp] = olyf;
  416. x[fp] = olxf + random;
  417. }
  418. else if (allcoords[olxf - random][olyf] == -1 && olxf - random
  419. < maxx && olxf - random > 1) // right
  420. {
  421. allcoords[olxf][olyf] = -1;
  422. setBitmapColor(olxf, olyf, 3);
  423. allcoords[olxf - random][olyf] = fp;
  424. setBitmapColor(olxf - random, olyf, element[fp]); //set new spot
  425. y[fp] = olyf;
  426. x[fp] = olxf - random;
  427. }
  428. else
  429. {
  430. y[fp] = olyf;
  431. x[fp] = olxf;
  432. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  433. setBitmapColor((int) x[fp], (int) y[fp], element[fp]);
  434. }
  435. }
  436. }
  437. }
  438. else if (type == 9) //Hot(Magma, Fire) - Ice
  439. {
  440. if (element[fp] == 6 || (element[fp] == 22
  441. && colliseelement1[element[sp]] == 6) || (element[sp] == 22
  442. && colliseelement1[element[fp]] != 6)) //fp is ice
  443. {
  444. //This should almost never happen
  445. element[fp] = 1; //Change ice to water
  446. //Put it back
  447. x[fp] = olxf;
  448. y[fp] = olyf;
  449. }
  450. else //sp is ice
  451. {
  452. element[sp] = 1; //Change ice to water
  453. setBitmapColor((int) x[sp], (int) y[sp], 1);
  454. //Put hot back
  455. x[fp] = olxf;
  456. y[fp] = olyf;
  457. }
  458. }
  459. else if (type == 10) //Anything - Generator collision
  460. {
  461. if (element[fp] != 7)
  462. {
  463. //Change the generator to spawner
  464. element[sp] = 8;
  465. spawn[sp] = element[fp]; //Set the spawn element
  466. //Delete the old point
  467. allcoords[olxf][olyf] = -1;
  468. setBitmapColor(olxf, olyf, 3);
  469. //Delete fp
  470. x[fp] = 0;
  471. y[fp] = 0;
  472. element[fp] = 0;
  473. xvel[fp] = 0;
  474. yvel[fp] = 0;
  475. set[fp] = 0;
  476. avail[loq] = fp;
  477. loq++;
  478. }
  479. else
  480. {
  481. //Change the generator to spawner
  482. element[fp] = 8;
  483. spawn[fp] = element[sp]; //Set the spawn element
  484. //Delete the old point
  485. allcoords[olxf][olyf] = -1;
  486. setBitmapColor(olxf, olyf, 3);
  487. //Delete sp
  488. x[sp] = 0;
  489. y[sp] = 0;
  490. element[sp] = 0;
  491. xvel[sp] = 0;
  492. yvel[sp] = 0;
  493. set[sp] = 0;
  494. avail[loq] = sp;
  495. loq++;
  496. }
  497. }
  498. else if (type == 11) //Hot - Explosive generic
  499. {
  500. if (element[fp] == 5 || element[fp] == 11 || (element[fp] == 22
  501. && (colliseelement1[element[sp]] == 5
  502. || colliseelement1[element[sp]] == 11)) || (element[sp]
  503. == 22 && !(colliseelement1[element[fp]] == 5
  504. || colliseelement1[element[fp]] == 11)))
  505. {
  506. //Delete the old point
  507. allcoords[olxf][olyf] = -1;
  508. setBitmapColor(olxf, olyf, 3);
  509. //Set the new location of the fire
  510. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  511. setBitmapColor((int) x[fp], (int) y[fp], element[fp]);
  512. //Delete sp
  513. x[sp] = 0;
  514. y[sp] = 0;
  515. element[sp] = 0;
  516. xvel[sp] = 0;
  517. yvel[sp] = 0;
  518. set[sp] = 0;
  519. avail[loq] = sp;
  520. loq++;
  521. int random = rand() % 10;
  522. random -= 5;
  523. xvel[fp] = random; //xvel is a random int from -5 to 5
  524. random = rand() % 10;
  525. random -= 5;
  526. yvel[fp] = random; //yvel is a random int from -5 to 5
  527. //Look at all the points around the explosion, if explosive change to fire and add velocity,
  528. // if flammable, just change to fire, if empty, change to fire and add velocity
  529. int i, j, xfp = (int) x[fp], yfp = (int) y[fp], a;
  530. for (i = -2; i <= 2; i++)
  531. {
  532. for (j = -2; j <= 2; j++)
  533. {
  534. if (xfp + i > 1 && xfp + i < maxx && yfp + j > 1 && yfp + j
  535. < maxy && !(i == 0 && j == 0))
  536. {
  537. a = allcoords[xfp + i][yfp + j]; //The allcoords at the prospective point
  538. if (a != -1 && collision[element[a]][5] == 6)
  539. {
  540. element[a] = 5;
  541. setBitmapColor(xfp + i, yfp + j, 5);
  542. }
  543. else if (a != -1 && collision[element[a]][5] == 11)
  544. {
  545. element[a] = 5;
  546. setBitmapColor(xfp + i, yfp + j, 5);
  547. int random = rand() % 10;
  548. random -= 5;
  549. xvel[a] = random; //xvel is a random int from -5 to 5
  550. random = rand() % 10;
  551. random -= 5;
  552. yvel[a] = random; //yvel is a random int from -5 to 5
  553. }
  554. else if (a == -1)
  555. {
  556. CreatePoint(xfp + i, yfp + j, 5);
  557. }
  558. }
  559. }
  560. }
  561. }
  562. else
  563. {
  564. //Delete the old point
  565. allcoords[olxf][olyf] = -1;
  566. setBitmapColor(olxf, olyf, 3);
  567. //Delete fp
  568. x[fp] = 0;
  569. y[fp] = 0;
  570. element[fp] = 0;
  571. xvel[fp] = 0;
  572. yvel[fp] = 0;
  573. set[fp] = 0;
  574. avail[loq] = fp;
  575. loq++;
  576. //Set sp
  577. allcoords[(int) x[sp]][(int) y[sp]] = sp;
  578. setBitmapColor((int) x[sp], (int) y[sp], element[sp]);
  579. int random = rand() % 10;
  580. random -= 5;
  581. xvel[sp] = random; //xvel is a random int from -5 to 5
  582. random = rand() % 10;
  583. random -= 5;
  584. yvel[sp] = random; //yvel is a random int from -5 to 5
  585. int i, j, xsp = x[sp], ysp = y[sp], a;
  586. for (i = -2; i <= 2; i++)
  587. {
  588. for (j = -2; j <= 2; j++)
  589. {
  590. if (xsp + i > 1 && xsp + i < maxx && ysp + j > 1 && ysp + j
  591. < maxy && !(i == 0 && j == 0))
  592. {
  593. a = allcoords[xsp + i][ysp + j];
  594. if (a != -1 && collision[element[a]][5] == 6)
  595. {
  596. element[a] = 5;
  597. setBitmapColor(xsp + i, ysp + j, 5);
  598. }
  599. else if (a != -1 && collision[element[a]][5] == 11)
  600. {
  601. element[a] = 5;
  602. setBitmapColor(xsp + i, ysp + j, 5);
  603. int random = rand() % 10;
  604. random -= 5;
  605. xvel[a] = random; //xvel is a random int from -5 to 5
  606. random = rand() % 10;
  607. random -= 5;
  608. yvel[a] = random; //yvel is a random int from -5 to 5
  609. }
  610. else if (a == -1)
  611. {
  612. CreatePoint(xsp + i, ysp + j, 5);
  613. }
  614. }
  615. }
  616. }
  617. }
  618. }
  619. else if (type == 12) //Water - Magma Collision
  620. {
  621. if (element[fp] == 10 || (element[fp] == 22
  622. && colliseelement1[element[sp]] == 10) || (element[sp] == 22
  623. && colliseelement1[element[fp]] != 10)) //fp is magma
  624. {
  625. //Move the water to magma's location and make it steam
  626. element[sp] = 18;
  627. x[sp] = olxf;
  628. y[sp] = olyf;
  629. allcoords[olxf][olyf] = sp;
  630. setBitmapColor(olxf, olyf, 18);
  631. element[fp] = 11; //Make the magma into stone
  632. setBitmapColor((int) x[fp], (int) y[fp], 11); //Set the color
  633. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  634. if (rand() % 3 == 0) //1/3 chance
  635. {
  636. DeletePoint(fp); //Delete magma
  637. }
  638. }
  639. else //sp is magma
  640. {
  641. element[sp] = 11; //Change magma to stone
  642. setBitmapColor((int) x[sp], (int) y[sp], 11); //Set the color
  643. //Change water to steam
  644. element[fp] = 18;
  645. //Move it back
  646. allcoords[olxf][olyf] = fp;
  647. setBitmapColor(olxf, olyf, 18);
  648. x[fp] = olxf;
  649. y[fp] = olyf;
  650. if (rand() % 3 == 0) //1/3 chance
  651. {
  652. DeletePoint(sp); //Delete magma
  653. }
  654. }
  655. }
  656. else if (type == 13) //Hot(Magma, Fire) - Stone Collision
  657. {
  658. if (element[fp] == 11 || (element[fp] == 22
  659. && colliseelement1[element[sp]] == 11) || (element[sp] == 22
  660. && colliseelement1[element[fp]] != 11)) //fp is stone
  661. {
  662. if (rand() % 10 == 0) //1/10 chance
  663. {
  664. x[fp] = olxf;
  665. y[fp] = olyf;
  666. allcoords[(int) x[fp]][(int) y[fp]] = fp; //Move the stone back
  667. element[fp] = 10; //Change stone to magma
  668. setBitmapColor((int) x[fp], (int) y[fp], 10); //Set the color also
  669. }
  670. else
  671. {
  672. //Clear old spot
  673. allcoords[olxf][olyf] = -1;
  674. setBitmapColor(olxf, olyf, 3);
  675. y[sp] = olyf; //Stone replaces Hot (switch)
  676. x[sp] = olxf;
  677. allcoords[olxf][olyf] = sp;
  678. setBitmapColor(olxf, olyf, element[sp]);
  679. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  680. setBitmapColor((int) x[fp], (int) y[fp], element[fp]);
  681. //Set a random xvel
  682. xvel[sp] = rand() % 3 - 1;
  683. }
  684. }
  685. else
  686. {
  687. //Either way, move fp back
  688. x[fp] = olxf;
  689. y[fp] = olyf;
  690. allcoords[olxf][olyf] = fp;
  691. setBitmapColor(olxf, olyf, element[fp]);
  692. if (rand() % 10 == 0) //1/10 chance
  693. {
  694. element[sp] = 10; //Change stone to magma
  695. setBitmapColor((int) x[sp], (int) y[sp], 10); //Set the color also
  696. allcoords[(int) x[sp]][(int) y[sp]] = sp;
  697. }
  698. //Set a random xvel
  699. xvel[fp] = rand() % 3 - 1;
  700. }
  701. }
  702. else if (type == 14) //Stone - Stone
  703. {
  704. y[fp] = olyf; // First particle goes back to where it was before
  705. x[fp] = olxf;
  706. allcoords[(int) x[fp]][(int) y[fp]] = fp;
  707. setBitmapColor((int) x[fp], (int) y[fp], element[fp]);
  708. }
  709. else if (type == 15) // C4 - hot
  710. {
  711. if (element[fp] == 12 || (element[fp] == 22
  712. && colliseelement1[element[sp]] == 12) || (element[sp] == 22
  713. && colliseelement1[element[fp]] != 12)) //fp is C4
  714. {
  715. //Put back the C4
  716. x[fp] = olxf;
  717. y[fp] = olyf;
  718. //allcoords[olxs][olys] = sp;
  719. //setBitmapColor(olxs,olys,element[sp]);
  720. //Change C4 to fire
  721. element[fp] = 5;
  722. setBitmapColor((int) x[fp], (int) y[fp], 5);
  723. int txpos = (int) x[fp], typos = (int) y[fp]; //temporary x and ypositions for quick calcs
  724. //this section is for explosion, giving velocities to particles around explosion
  725. int i, j; //counters, i is the x, j is the y
  726. int tpart, telement; //temp particle index /element
  727. for (i = -0; i <= 0; i++)
  728. {
  729. for (j = -0; j <= 0; j++)
  730. {
  731. if (txpos + i < maxx && txpos + i > 1 && typos + j < maxy
  732. && typos + j > 1) //if within bounds
  733. {
  734. tpart = allcoords[txpos + i][typos + j];
  735. if ( tpart >= TPoints )
  736. {
  737. //__android_log_write(ANDROID_LOG_ERROR,"DemoActivity","C4-Hot Error");
  738. break;
  739. }
  740. if (tpart >= 0 // used to be != -1, this might be getting some bad input somehow and then sending a bad index so changed
  741. && (fallvel[element[tpart]] != 0
  742. || element[tpart] == 15
  743. || element[tpart] == 21)) //if there's a particle there & it's not immovable
  744. {
  745. if (abs(xvel[tpart]) < 20)
  746. {
  747. xvel[tpart] += 1 * i / abs(i);
  748. }
  749. if (abs(yvel[tpart]) < 20)
  750. {
  751. yvel[tpart] += 1 * j / abs(j);
  752. }
  753. }
  754. }
  755. }
  756. }
  757. //Look at all the points around the explosion, if explosive change to fire and add velocity,
  758. // if flammable, just change to fire, if empty, change to fire and add velocity
  759. int a; //Temp allcoords
  760. for (i = -2; i <= 2; i++)
  761. {
  762. for (j = -2; j <= 2; j++)
  763. {
  764. if (txpos + i > 1 && txpos + i < maxx && typos + j > 1
  765. && typos + j < maxy)
  766. {
  767. a = allcoords[txpos + i][typos + j]; //The allcoords at the prospective point
  768. if (a != -1 && collision[element[a]][5] == 6)
  769. {
  770. element[a] = 5;
  771. setBitmapColor(txpos + i, typos + j, 5);
  772. }
  773. else if (a != -1 && (collision[element[a]][5] == 11
  774. || collision[element[a]][5] == 15))
  775. {
  776. element[a] = 5;
  777. setBitmapColor(txpos + i, typos + j, 5);
  778. int random = rand() % 11;
  779. random -= 5;
  780. xvel[a] = random; //xvel is a random int from -5 to 5
  781. random = rand() % 11; //mod 11 goes from 0 to 10
  782. random -= 5;
  783. yvel[a] = random; //yvel is a random int from -5 to 5
  784. }
  785. else if (a == -1)
  786. {
  787. CreatePoint(txpos + i, typos + j, 5);
  788. }
  789. }
  790. }
  791. }
  792. }
  793. else //sp is C4
  794. {
  795. //__android_log_write(ANDROID_LOG_ERROR,"DemoActivity","C4-Hot 2");
  796. //put back the hot
  797. x[fp] = olxf;
  798. y[fp] = olyf;
  799. int spelement = element[sp];
  800. //change C4 to fire
  801. element[sp] = 5;
  802. setBitmapColor((int) x[sp], (int) y[sp], 5);
  803. int txpos = (int) x[sp], typos = (int) y[sp]; //temporary x and ypositions for quick calcs
  804. //this section is for explosion, giving velocities to particles around explosion
  805. int i, j; //counters, i is the x, j is the y
  806. int tpart, telement; //temp particle index /element
  807. for (i = -2 * exploness[spelement]; i <= 2 * exploness[spelement]; i++)
  808. {
  809. for (j = -2 * exploness[spelement]; j <= 2
  810. * exploness[spelement]; j++)
  811. {
  812. if (txpos + i < maxx && txpos + i > 1 && typos + j < maxy
  813. && typos + j > 1) //if within bounds
  814. {
  815. tpart = allcoords[txpos + i][typos + j];
  816. if (tpart != -1
  817. && (fallvel[element[tpart]] != 0
  818. || element[tpart] == 15
  819. || element[tpart] == 21)) //if there's a particle there
  820. {
  821. if (abs(xvel[tpart]) < exploness[spelement])
  822. {
  823. xvel[tpart] += ((1 / i) * 3) + i / abs(i);
  824. }
  825. if (abs(yvel[tpart]) < exploness[spelement])
  826. {
  827. yvel[tpart] += ((1 / j) * 3) + j / abs(j);
  828. }
  829. }
  830. }
  831. }
  832. }
  833. //Look at all the points around the explosion, if explosive change to fire and add velocity,
  834. // if flammable, just change to fire, if empty, change to fire and add velocity
  835. int a; //Temp allcoords
  836. for (i = -2; i <= 2; i++)
  837. {
  838. for (j = -2; j <= 2; j++)
  839. {
  840. if (txpos + i > 1 && txpos + i < maxx && typos + j > 1
  841. && typos + j < maxy)
  842. {
  843. a = allcoords[txpos + i][typos + j]; //The allcoords at the prospective point
  844. if (a != -1 && collision[element[a]][5] == 6)
  845. {
  846. element[a] = 5;
  847. setBitmapColor(txpos + i, typos + j, 5);
  848. }
  849. else if (a != -1 && (collision[element[a]][5] == 11
  850. || collision[element[a]][5] == 15))
  851. {
  852. element[a] = 5;
  853. setBitmapColor(txpos + i, typos + j, 5);
  854. int random = rand() % 11; //mod 11 goes from 0 to 10
  855. random -= 5;
  856. xvel[a] = random; //xvel is a random int from -5 to 5
  857. random = rand() % 11;
  858. random -= 5;
  859. yvel[a] = random; //yvel is a random int from -5 to 5
  860. }
  861. else if (a == -1)
  862. {
  863. CreatePoint(txpos + i, typos + j, 5);
  864. }
  865. }
  866. }
  867. }
  868. }
  869. }
  870. else if (type == 16) // C4++ - hot
  871. {
  872. //__android_log_write(ANDROID_LOG_ERROR,"DemoActivity","C4++-Hot");
  873. if (element[fp] == 13 || (element[fp] == 22
  874. && colliseelement1[element[sp]] == 13) || (element[sp] == 22
  875. && colliseelement1[element[fp]] != 13)) //fp is C4++
  876. {
  877. //Put back the hot
  878. x[sp] = olxs;
  879. y[sp] = olys;
  880. allcoords[olxs][olys] = sp;
  881. setBitmapColor(olxs, olys, element[sp]);
  882. //Change C4++ to fire
  883. element[fp] = 5;
  884. setBitmapColor((int) x[fp], (int) y[fp], 5);
  885. int txpos = (int) x[fp], typos = (int) y[fp]; //temporary x and ypositions for quick calcs
  886. //this section is for explosion, giving velocities to particles around explosion
  887. int i, j; //counters, i is the x, j is the y
  888. int tpart, telement; //temp particle index /element
  889. for (i = -0; i <= 0; i++)
  890. {
  891. for (j = -0; j <= 0; j++)
  892. {
  893. if (txpos + i < maxx && txpos + i > 1 && typos + j < maxy
  894. && typos + j > 1) //if within bounds
  895. {
  896. tpart = allcoords[txpos + i][typos + j];
  897. if (tpart != -1
  898. && (fallvel[element[tpart]] != 0
  899. || element[tpart] == 15
  900. || element[tpart] == 21)) //if there's a particle there & it's not immovable
  901. {
  902. if (abs(xvel[tpart]) < 20)
  903. {
  904. xvel[tpart] += ((1 / i) * 0) + 1 * i / abs(i);
  905. }
  906. if (abs(yvel[tpart]) < 20)
  907. {
  908. yvel[tpart] += ((1 / j) * 0) + 1 * j / abs(j);
  909. }
  910. }
  911. }
  912. }
  913. }
  914. //Look at all the points around the explosion, if explosive change to fire and add velocity,
  915. // if flammable, just change to fire, if empty, change to fire and add velocity
  916. int a; //Temp allcoords
  917. for (i = -2; i <= 2; i++)
  918. {
  919. for (j = -2; j <= 2; j++)
  920. {
  921. if (txpos + i > 1 && txpos + i < maxx && typos + j > 1
  922. && typos + j < maxy)
  923. {
  924. a = allcoords[txpos + i][typos + j]; //The allcoords at the prospective point
  925. if (a != -1 && collision[element[a]][5] == 6)
  926. {
  927. element[a] = 5;
  928. setBitmapColor(txpos + i, typos + j, 5);
  929. }
  930. else if (a != -1 && (collision[element[a]][5] == 11
  931. || collision[element[a]][5] == 15
  932. || collision[element[a]][5] == 16))
  933. {
  934. element[a] = 5; //change a to fire
  935. setBitmapColor(txpos + i, typos + j, 5); //change color of a to that of fire
  936. int random = rand() % 11; // mod 11 goes from 0 to 10
  937. random -= 5;
  938. xvel[a] = random; //xvel is a random int from -5 to 5
  939. random = rand() % 11;
  940. random -= 5;
  941. yvel[a] = random; //yvel is a random int from -5 to 5
  942. }
  943. else if (a == -1)
  944. {
  945. CreatePoint(txpos + i, typos + j, 5);
  946. }
  947. }
  948. }
  949. }
  950. }
  951. else //sp is C4++
  952. {
  953. //__android_log_write(ANDROID_LOG_ERROR,"DemoActivity","C4++-Hot 2");
  954. //put back the hot
  955. x[fp] = olxf;
  956. y[fp] = olyf;
  957. int spelement = element[sp];
  958. //change C4++ to fire
  959. element[sp] = 5;
  960. setBitmapColor((int) x[sp], (int) y[sp], 5);
  961. int txpos = (int) x[sp], typos = (int) y[sp]; //temporary x and ypositions for quick calcs
  962. //this section is for explosion, giving velocities to particles around explosion
  963. int i, j; //counters, i is the x, j is the y
  964. int tpart, telement; //temp particle index /element
  965. //__android_log_write(ANDROID_LOG_ERROR,"DemoActivity","C4++-Hot 2 Part 1");
  966. for (i = -2 * exploness[spelement]; i <= 2 * exploness[spelement]; i++)
  967. {
  968. for (j = -2 * exploness[spelement]; j <= 2
  969. * exploness[spelement]; j++)
  970. {
  971. if (txpos + i < maxx && txpos + i > 1 && typos + j < maxy
  972. && typos + j > 1) //if within bounds
  973. {
  974. tpart = allcoords[txpos + i][typos + j];
  975. //__android_log_print(ANDROID_LOG_ERROR,"DemoActivity","tpart: [%d]",tpart );
  976. if (tpart >= 0
  977. && (fallvel[element[tpart]] != 0
  978. || element[tpart] == 15
  979. || element[tpart] == 21)) //if there's a particle there
  980. {
  981. if (abs(xvel[tpart]) < exploness[spelement])
  982. {
  983. xvel[tpart] += ((1 / i) * 3) + i / abs(i);
  984. }
  985. if (abs(yvel[tpart]) < exploness[spelement])
  986. {
  987. yvel[tpart] += ((1 / j) * 3) + j / abs(j);
  988. }
  989. }
  990. }
  991. }
  992. }
  993. //Look at all the points around the explosion, if explosive change to fire and add velocity,
  994. // if flammable, just change to fire, if empty, change to fire and add velocity
  995. //__android_log_write(ANDROID_LOG_ERROR,"DemoActivity","C4++-Hot 2 Part 2");
  996. int a; //Temp allcoords
  997. for (i = -2; i <= 2; i++)
  998. {
  999. for (j = -2; j <= 2; j++)
  1000. {
  1001. if (txpos + i > 1 && txpos + i < maxx && typos + j > 1
  1002. && typos + j < maxy)
  1003. {
  1004. a = allcoords[txpos + i][typos + j]; //The allcoords at the prospective point
  1005. if (a != -1 && collision[element[a]][5] == 6)
  1006. {
  1007. element[a] = 5;
  1008. setBitmapColor(txpos + i, typos + j, 5);
  1009. }
  1010. else if (a != -1 && (collision[element[a]][5] == 11
  1011. || collision[element[a]][5] == 15
  1012. || collision[element[a]][5] == 16))
  1013. {
  1014. element[a] = 5;
  1015. setBitmapColor(txpos + i, typos + j, 5);
  1016. int random = rand() % 11; //mod 11 goes from 0 to 10
  1017. random -= 5;
  1018. xvel[a] = random; //xvel is a random int from -5 to 5
  1019. random = rand() % 11; //mod 11 goes from 0 to 10
  1020. random -= 5;
  1021. yvel[a] = random; //yvel is a random int from -5 to 5
  1022. }
  1023. else if (a == -1)
  1024. {
  1025. CreatePoint(txpos + i, typos + j, 5);
  1026. }
  1027. }
  1028. }
  1029. }
  1030. //__android_log_write(ANDROID_LOG_ERROR,"DemoActivity","C4++-Hot 2 Part 3");
  1031. }
  1032. }
  1033. else if (type == 17) //Magma - Destructible Wall
  1034. {
  1035. //We can assume that fp is magma since wall doesn't move
  1036. //move magma back
  1037. //TODO: Edit this to allow a Destructible wall - Magma collision
  1038. x[fp] = olxf;
  1039. y[fp] = olyf;
  1040. allcoords[olxf][olyf] = fp;
  1041. setBitmapColor(olxf, olyf, element[fp]);
  1042. if (rand() % 10 == 0) //1/10 chance
  1043. {
  1044. element[sp] = 10; //Change wall to magma
  1045. setBitmapColor((int) x[sp], (int) y[sp], 10); //Set the color also
  1046. allcoords[(int) x[sp]][(int) y[sp]] = sp;
  1047. }
  1048. //Set a random xvel to magma
  1049. xvel[fp] = rand() % 3 - 1;
  1050. }
  1051. else if (type == 18) //Acid - Meltable
  1052. {
  1053. int xfp = x[fp], yfp = y[fp];
  1054. if (element[fp] == 17 || (element[fp] == 22
  1055. && colliseelement1[element[sp]] == 17) || (element[sp] == 22
  1056. && colliseelement1[element[fp]] != 17)) //fp is acid
  1057. {
  1058. if (rand() % 3 != 0) //2/3 chance
  1059. {
  1060. //Acid burns away sp
  1061. //Delete the old point
  1062. allcoords[olxf][olyf] = -1;
  1063. setBitmapColor(olxf, olyf, 3);
  1064. //Set the new point
  1065. allcoords[xfp][yfp] = fp;
  1066. setBitmapColor(xfp, yfp, element[fp]);
  1067. //Delete sp
  1068. x[sp] = 0;
  1069. y[sp] = 0;
  1070. element[sp] = 0;
  1071. xvel[sp] = 0;
  1072. yvel[sp] = 0;
  1073. set[sp] = 0;
  1074. avail[loq] = sp;
  1075. loq++;
  1076. }
  1077. else if (rand() % 2 == 0) //Otherwise, 1/6 total
  1078. {
  1079. //Acid is neutralized
  1080. //Delete the old point
  1081. allcoords[olxf][olyf] = -1;
  1082. setBitmapColor(olxf, olyf, 3);
  1083. //Delete fp
  1084. x[fp] = 0;
  1085. y[fp] = 0;
  1086. element[fp] = 0;
  1087. xvel[fp] = 0;
  1088. yvel[fp] = 0;
  1089. set[fp] = 0;
  1090. avail[loq] = fp;
  1091. loq++;
  1092. }
  1093. else //Otherwise, 1/6 total
  1094. {
  1095. //Acid bounces
  1096. x[fp] = olxf;
  1097. y[fp] = olyf;
  1098. }
  1099. }
  1100. else //sp is acid
  1101. {
  1102. if (rand() % 3 != 0) //2/3 chance
  1103. {
  1104. //Acid burns away fp
  1105. //Delete the old point
  1106. allcoords[olxf][olyf] = -1;
  1107. setBitmapColor(olxf, olyf, 3);
  1108. //Delete fp
  1109. x[fp] = 0;
  1110. y[fp] = 0;
  1111. element[fp] = 0;
  1112. xvel[fp] = 0;
  1113. yvel[fp] = 0;
  1114. set[fp] = 0;
  1115. avail[loq] = fp;
  1116. loq++;
  1117. }
  1118. else if (rand() % 2 == 0) //Otherwise, 1/6 total
  1119. {
  1120. //Acid is neutralized
  1121. //Delete the old point
  1122. allcoords[olxf][olyf] = -1;
  1123. setBitmapColor(olxf, olyf, 3);
  1124. //Set the new point
  1125. allcoords[xfp][yfp] = fp;
  1126. setBitmapColor(xfp, yfp, element[fp]);
  1127. //Delete sp
  1128. x[sp] = 0;
  1129. y[sp] = 0;
  1130. element[sp] = 0;
  1131. xvel[sp] = 0;
  1132. yvel[sp] = 0;
  1133. set[sp] = 0;
  1134. avail[loq] = sp;
  1135. loq++;
  1136. }
  1137. else //Otherwise, 1/6 total
  1138. {
  1139. //Other particle bounces bounces
  1140. x[fp] = olxf;
  1141. y[fp] = olyf;
  1142. }
  1143. }
  1144. }
  1145. else if (type == 19) //Acid - Water
  1146. {
  1147. int xfp = x[fp], yfp = y[fp];
  1148. //Acid goes away 1/3 of the time, otherwise bounce back
  1149. if (element[fp] == 17 || (element[fp] == 22
  1150. && colliseelement1[element[sp]] == 17) || (element[sp] == 22
  1151. && colliseelement1[element[fp]] != 17)) //fp is acid
  1152. {
  1153. if (rand() % 3 == 0)
  1154. {
  1155. //Delete the old point
  1156. allcoords[olxf][olyf] = -1;
  1157. setBitmapColor(olxf, olyf, 3);
  1158. //Delete fp
  1159. x[fp] = 0;
  1160. y[fp] = 0;
  1161. element[fp] = 0;
  1162. xvel[fp] = 0;
  1163. yvel[fp] = 0;
  1164. set[fp] = 0;
  1165. avail[loq] = fp;
  1166. loq++;
  1167. }
  1168. else
  1169. {
  1170. //Move the point back
  1171. x[fp] = olxf;
  1172. y[fp] = olyf;
  1173. }
  1174. }
  1175. else //sp is acid
  1176. {
  1177. if (rand() % 3 == 0)
  1178. {
  1179. //Delete the old point
  1180. allcoords[olxf][olyf] = -1;
  1181. setBitmapColor(olxf, olyf, 3);
  1182. //Set the new point
  1183. allcoords[xfp][yfp] = fp;
  1184. setBitmapColor(xfp, yfp, element[fp]);
  1185. //Delete sp
  1186. x[sp] = 0;
  1187. y[sp] = 0;
  1188. element[sp] = 0;
  1189. xvel[sp] = 0;
  1190. yvel[sp] = 0;
  1191. set[sp] = 0;
  1192. avail[loq] = sp;
  1193. loq++;
  1194. }
  1195. else
  1196. {
  1197. //Move the water back
  1198. x[fp] = olxf;
  1199. y[fp] = olyf;
  1200. }
  1201. }
  1202. }
  1203. else if (type == 20) //Steam - Ice/Water
  1204. {
  1205. if (rand() % 200 == 0) //1/200 chance for steam to condense
  1206. {
  1207. if (element[fp] == 18 || (element[fp] == 22
  1208. && colliseelement1[element[sp]] == 18) || (element[sp]
  1209. == 22 && colliseelement1[element[fp]] != 18)) //fp is steam
  1210. {
  1211. //Change the steam to water
  1212. element[fp] = 1;
  1213. //Move it back
  1214. x[fp] = olxf;
  1215. y[fp] = olyf;
  1216. allcoords[olxf][olyf] = fp;
  1217. setBitmapColor(olxf, olyf, 1);
  1218. }
  1219. else //sp is steam
  1220. {
  1221. //Change the steam to water
  1222. element[sp] = 1;
  1223. //Move fp back
  1224. x[fp] = olxf;
  1225. y[fp] = olyf;
  1226. allcoords[olxf][olyf] = fp;
  1227. setBitmapColor(olxf, olyf, element[fp]);
  1228. }
  1229. }
  1230. else //Just bounce around the water/ice
  1231. {
  1232. if (element[fp] == 18 || (element[fp] == 22
  1233. && colliseelement1[element[sp]] == 18)) //fp is steam
  1234. {
  1235. //Move it back
  1236. x[fp] = olxf;
  1237. y[fp] = olyf;
  1238. allcoords[olxf][olyf] = fp;
  1239. setBitmapColor(olxf, olyf, 18);
  1240. //Add a random x velocity
  1241. xvel[fp] += rand() % 7 - 3; //-3 to 3
  1242. }
  1243. else //sp is steam
  1244. {
  1245. int xfp = x[fp], yfp = y[fp]; //Set some temp variables
  1246. //Switch places
  1247. x[sp] = olxf;
  1248. y[sp] = olyf;
  1249. allcoords[olxf][olyf] = sp;
  1250. setBitmapColor(olxf, olyf, 18);
  1251. allcoords[xfp][yfp] = fp;
  1252. setBitmapColor(xfp, yfp, element[fp]);
  1253. }
  1254. }
  1255. }
  1256. else if (type == 21) //Steam - Steam
  1257. {
  1258. if (rand() % 1000 == 0)//1/5 chance
  1259. {
  1260. //Make the two steams "condense" into water
  1261. int xsp = x[sp], ysp = y[sp]; //Some temp variables
  1262. //Move fp back
  1263. x[fp] = olxf;
  1264. y[fp] = olyf;
  1265. //Change the elements
  1266. element[fp] = 1;
  1267. element[sp] = 1;
  1268. //Set the bitmap and allcoords
  1269. allcoords[olxf][olyf] = fp;
  1270. setBitmapColor(olxf, olyf, 1);
  1271. allcoords[xsp][ysp] = sp;
  1272. setBitmapColor(xsp, ysp, 1);
  1273. }
  1274. else //Make fp bounce off
  1275. {
  1276. //Move fp back
  1277. x[fp] = olxf;
  1278. y[fp] = olyf;
  1279. allcoords[olxf][olyf] = fp;
  1280. setBitmapColor(olxf, olyf, 18);
  1281. //Add a random x velocity
  1282. xvel[fp] += rand() % 7 - 3; //-3 to 3
  1283. //Add a random y velocity
  1284. yvel[fp] += rand() % 5 - 2; //-2 to 2
  1285. }
  1286. }
  1287. else if (type == 22) //Steam - Other
  1288. {
  1289. int xfp = x[fp], yfp = y[fp];
  1290. if (element[fp] == 18 || (element[fp] == 22
  1291. && colliseelement1[element[sp]] == 18) || (element[sp] == 22
  1292. && colliseelement1[element[fp]] != 18)) //fp is steam
  1293. {
  1294. //Move the steam back
  1295. allcoords[olxf][olyf] = fp;
  1296. setBitmapColor(olxf, olyf, element[sp]);
  1297. x[fp] = olxf;
  1298. y[fp] = olyf;
  1299. //Set a random x velocity
  1300. xvel[fp] = rand() % 7 - 3; //-3 to 3
  1301. }
  1302. else //sp is steam
  1303. {
  1304. //Move the steam to the old spot
  1305. allcoords[olxf][olyf] = sp;
  1306. setBitmapColor(olxf, olyf, element[sp]);
  1307. x[sp] = olxf;
  1308. y[sp] = olyf;
  1309. //Set the new spot
  1310. allcoords[xfp][yfp] = fp;
  1311. setBitmapColor(xfp, yfp, element[fp]);
  1312. //Set a random x velocity
  1313. xvel[sp] = rand() % 7 - 3; //-3 to 3
  1314. }
  1315. }
  1316. else if (type == 23) //Water - Fire
  1317. {
  1318. if (element[fp] == 5 || (element[fp] == 22
  1319. && colliseelement1[element[sp]] == 5) || (element[sp] == 22
  1320. && colliseelement1[element[fp]] != 5)) //fp is fire
  1321. {
  1322. //Delete the old point
  1323. allcoords[olxf][olyf] = -1;
  1324. setBitmapColor(olxf, olyf, 3);
  1325. //Delete the fire
  1326. x[fp] = 0;
  1327. y[fp] = 0;
  1328. element[fp] = 0;
  1329. xvel[fp] = 0;
  1330. yvel[fp] = 0;
  1331. set[fp] = 0;
  1332. avail[loq] = fp;
  1333. loq++;
  1334. //Change the water to steam
  1335. element[sp] = 18;
  1336. //Change the bitmap color
  1337. setBitmapColor(x[sp], y[sp], 18);
  1338. }
  1339. else //sp is fire
  1340. {
  1341. int xfp = x[fp], yfp = y[fp]; //Set temp variables
  1342. //Delete sp(fire)
  1343. DeletePoint(sp);
  1344. //Delete the old point
  1345. allcoords[olxf][olyf] = -1;
  1346. setBitmapColor(olxf, olyf, 3);
  1347. //Change the water to steam
  1348. element[fp] = 18;
  1349. //Set the new location of water
  1350. allcoords[xfp][yfp] = fp;
  1351. setBitmapColor(xfp, yfp, 18);
  1352. }
  1353. }
  1354. else if (type == 24) //Salt - Water
  1355. {
  1356. if (element[fp] == 19 || (element[fp] == 22
  1357. && colliseelement1[element[sp]] == 19)) //fp is salt
  1358. {
  1359. //Delete the old point
  1360. allcoords[olxf][olyf] = -1;
  1361. setBitmapColor(olxf, olyf, 3);
  1362. //Delete fp
  1363. x[fp] = 0;
  1364. y[fp] = 0;
  1365. element[fp] = 0;
  1366. xvel[fp] = 0;
  1367. yvel[fp] = 0;
  1368. set[fp] = 0;
  1369. avail[loq] = fp;
  1370. loq++;
  1371. //Change the element of sp to Salt-water
  1372. element[sp] = 20;
  1373. setBitmapColor(x[sp], y[sp], 20);
  1374. }
  1375. else //sp is salt
  1376. {
  1377. //Delete the old point
  1378. allcoords[olxf][olyf] = -1;
  1379. setBitmapColor(olxf, olyf, 3);
  1380. DeletePoint(sp); //Delete the salt
  1381. int xfp = x[fp], yfp = y[fp]; //Some temp variables
  1382. //Set the new coordinates
  1383. allcoords[xfp][yfp] = fp;
  1384. setBitmapColor(xfp, yfp, element[fp]);
  1385. }
  1386. }
  1387. else if (type == 25) //Salt - Ice
  1388. {
  1389. if (element[fp] == 6 || (element[fp] == 22
  1390. && colliseelement1[element[sp]] == 6) || (element[sp] == 22
  1391. && colliseelement1[element[fp]] != 6)) //fp is ice
  1392. {
  1393. //Move fp back
  1394. x[fp] = olxf;
  1395. y[fp] = olyf;
  1396. //Change the element to water
  1397. element[fp] = 1;
  1398. //Set the bitmap stuff
  1399. allcoords[olxf][olyf] = fp;
  1400. setBitmapColor(olxf, olyf, 1);
  1401. }
  1402. else //sp is ice
  1403. {
  1404. //Move fp back
  1405. x[fp] = olxf;
  1406. y[fp] = olyf;
  1407. allcoords[olxf][olyf] = fp;
  1408. setBitmapColor(olxf, olyf, element[fp]);
  1409. //Change the element to water
  1410. element[sp] = 1;
  1411. //Set the bitmap stuff
  1412. setBitmapColor(x[sp], y[sp], 1);
  1413. }
  1414. }
  1415. else if (type == 26) //Salt-water - Plant
  1416. {
  1417. if (element[fp] == 4 || (element[fp] == 22
  1418. && colliseelement1[element[sp]] == 4) || (element[sp] == 22
  1419. && colliseelement1[element[fp]] != 4)) //fp is plant
  1420. {
  1421. //Move fp back
  1422. x[fp] = olxf;
  1423. y[fp] = olyf;
  1424. //Change the element to sand
  1425. element[fp] = 0;
  1426. //Set the bitmap stuff
  1427. allcoords[olxf][olyf] = fp;
  1428. setBitmapColor(olxf, olyf, 0);
  1429. }
  1430. else //sp is plant
  1431. {
  1432. //Move fp back
  1433. x[fp] = olxf;
  1434. y[fp] = olyf;
  1435. allcoords[olxf][olyf] = fp;
  1436. setBitmapColor(olxf, olyf, element[fp]);
  1437. //Change the element to sand
  1438. element[sp] = 0;
  1439. //Set the bitmap stuff
  1440. setBitmapColor(x[sp], y[sp], 0);
  1441. }
  1442. }
  1443. else if (type == 27) //Magma - Sand
  1444. {
  1445. if (element[fp] == 10 || (element[fp] == 22
  1446. && colliseelement1[element[sp]] == 10) || (element[sp] == 22
  1447. && colliseelement1[element[fp]] != 10)) //fp is magma
  1448. {
  1449. //Move fp back
  1450. x[fp] = olxf;
  1451. y[fp] = olyf;
  1452. //Change the element to glass
  1453. element[sp] = 21;
  1454. //Set the bitmap stuff
  1455. setBitmapColor(x[sp], y[sp], 21);
  1456. }
  1457. else //sp is magma
  1458. {
  1459. //Move fp back
  1460. x[fp] = olxf;
  1461. y[fp] = olyf;
  1462. //Change the element to glass
  1463. element[fp] = 21;
  1464. setBitmapColor(x[fp], y[fp], 21);
  1465. }
  1466. }
  1467. else if (type == 28) //Water - Sand
  1468. {
  1469. if (element[fp] == 1 || (element[fp] == 22
  1470. && colliseelement1[element[sp]] == 1) || (element[sp] == 22
  1471. && colliseelement1[element[fp]] != 1)) //fp is water
  1472. {
  1473. //Delete the old point
  1474. allcoords[olxf][olyf] = -1;
  1475. setBitmapColor(olxf, olyf, 3);
  1476. //Delete the water
  1477. x[fp] = 0;
  1478. y[fp] = 0;
  1479. element[fp] = 0;
  1480. xvel[fp] = 0;
  1481. yvel[fp] = 0;
  1482. set[fp] = 0;
  1483. avail[loq] = fp;
  1484. loq++;
  1485. element[sp] = 23; // set the sand to be mud
  1486. setBitmapColor(x[sp], y[sp], element[sp]); // change the color of the sand particle location to be mud
  1487. }
  1488. else //sp is water
  1489. {
  1490. //Delete the old point
  1491. allcoords[olxf][olyf] = -1;
  1492. setBitmapColor(olxf, olyf, 3);
  1493. DeletePoint(sp); //delete the water
  1494. element[fp] = 23; //set the sand to be mud
  1495. int xfp = x[fp], yfp = y[fp]; //Some temp variables
  1496. //Set the new coordinates
  1497. allcoords[xfp][yfp] = fp;
  1498. setBitmapColor(xfp, yfp, element[fp]);
  1499. }
  1500. }
  1501. else if (type == 29)
  1502. { //Mud - Fire
  1503. if (element[fp] == 23 || (element[fp] == 22
  1504. && colliseelement1[element[sp]] == 23) || (element[sp] == 22
  1505. && colliseelement1[element[fp]] != 23))
  1506. { //sp is mud
  1507. //Delete the old point
  1508. allcoords[olxf][olyf] = -1;
  1509. setBitmapColor(olxf, olyf, 3);
  1510. DeletePoint(sp); //delete the fire
  1511. element[fp] = 0; //change the mud to sand
  1512. int xfp = x[fp], yfp = y[fp]; //Some temp variables
  1513. allcoords[xfp][yfp] = fp;
  1514. setBitmapColor(xfp, yfp, element[fp]); //update the color of mud
  1515. }
  1516. else
  1517. { // fp is fire
  1518. //Delete the old point
  1519. allcoords[olxf][olyf] = -1;
  1520. setBitmapColor(olxf, olyf, 3);
  1521. //Delete the fire
  1522. x[fp] = 0;
  1523. y[fp] = 0;
  1524. element[fp] = 0;
  1525. xvel[fp] = 0;
  1526. yvel[fp] = 0;
  1527. set[fp] = 0;
  1528. avail[loq] = fp;
  1529. loq++;
  1530. element[sp] = 0;
  1531. setBitmapColor(x[sp], y[sp], element[sp]);
  1532. }
  1533. }
  1534. else if (type == 30)
  1535. { //Mud - Magma
  1536. x[fp] = olxf; //send the fp back
  1537. y[fp] = olyf;
  1538. element[fp] = 11; //change fp to stone (it really doesn't matter which one we are changing to what
  1539. element[sp] = 18; //change sp to steam
  1540. setBitmapColor(y[fp], y[fp], element[fp]); //update colors
  1541. setBitmapColor(x[sp], y[sp], element[sp]);
  1542. }
  1543. }