PageRenderTime 179ms CodeModel.GetById 3ms app.highlight 158ms RepoModel.GetById 1ms app.codeStats 1ms

/FallingSandpaper/jni/collide.c

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