PageRenderTime 121ms CodeModel.GetById 40ms app.highlight 7ms RepoModel.GetById 53ms app.codeStats 1ms

/FallingSandpaper/jni/points.c

http://thelements.googlecode.com/
C | 92 lines | 65 code | 16 blank | 11 comment | 9 complexity | cada10206265cb55b96d1e620a73da2e MD5 | raw file
 1/*
 2 * points.c
 3 * ----------------------------
 4 * Defines functions for manipulating data
 5 * for individual points, such as adding and
 6 * deleting points.
 7 */
 8
 9#include "points.h"
10
11void CreatePoint(int k, int l, int e)
12{
13	int i;
14	if (loq > 0)
15	{
16		loq--;
17		i = avail[loq];
18		avail[loq] = -1;
19		x[i] = k;
20		y[i] = l;
21
22		allcoords[k][l] = i;
23
24		// Set the element of the point
25		element[i] = e;
26
27		//velocity setting part - all start at 0
28
29		xvel[i] = 0;
30		yvel[i] = 0;
31		frozen[i] = 0;
32
33		setBitmapColor(k, l, e);
34
35		set[i] = 1;
36
37		unFreezeParticles(k, l);
38	}
39}
40void DeletePoint(int partnum)
41{
42	int tempx = x[partnum];
43	int tempy = y[partnum];
44	unFreezeParticles(tempx, tempy);
45	setBitmapColor((int) x[partnum], (int) y[partnum], 3);
46	allcoords[(int) x[partnum]][(int) y[partnum]] = -1;
47	//cleaning up
48	x[partnum] = 0;
49	y[partnum] = 0;
50	frozen[partnum] = 0;
51	element[partnum] = 0;
52	xvel[partnum] = 0;
53	yvel[partnum] = 0;
54	set[partnum] = 0;
55	avail[loq] = partnum;
56	loq++;
57
58}
59
60void setBitmapColor(int xpos, int ypos, int element)
61{
62	colors[3 * (xpos + ypos * 512)] = red[element];
63	colors[3 * (xpos + ypos * 512) + 1] = green[element];
64	colors[3 * (xpos + ypos * 512) + 2] = blue[element];
65}
66
67//this function unfreezes particles around a point
68void unFreezeParticles(int xcentre, int ycentre)
69{
70	int ix;
71	int jy;
72	for (ix = -1; ix <= 1; ix++)
73	{
74		for (jy = -1; jy <= 1; jy++)
75		{
76
77			int tempx = xcentre + ix;
78			int tempy = ycentre + jy;
79			if (tempx < maxx && tempx > 0 && tempy < maxy && tempy > 0)
80			{
81
82				int atemp = allcoords[tempx][tempy];
83
84				if (atemp != -1)
85				{
86					frozen[atemp] = 0; //reset the freeze counter
87				}
88			}
89
90		}
91	}
92}