PageRenderTime 359ms CodeModel.GetById 75ms app.highlight 253ms RepoModel.GetById 14ms app.codeStats 1ms

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