summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCracker64 <cracker642@gmail.com>2011-01-16 06:29:49 (GMT)
committer Cracker64 <cracker642@gmail.com>2011-01-16 06:29:49 (GMT)
commitb1e09d421681ea7e3f57d0e6ee71582c8060cf04 (patch)
tree9e9a0ad3efc6dd7c5817d8b1489c013f688cbe13 /src
parent2d79fa5cfe104e6067818f13e3486ca45fe23815 (diff)
downloadpowder-b1e09d421681ea7e3f57d0e6ee71582c8060cf04.zip
powder-b1e09d421681ea7e3f57d0e6ee71582c8060cf04.tar.gz
Made GoL code work with more advanced rules with different life states, giving more interesting rules.
Diffstat (limited to 'src')
-rw-r--r--src/graphics.c29
-rw-r--r--src/powder.c37
2 files changed, 56 insertions, 10 deletions
diff --git a/src/graphics.c b/src/graphics.c
index be84b61..824cee8 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -1714,6 +1714,35 @@ void draw_parts(pixel *vid)
blendpixel(vid, nx, ny, cr, cg, cb, 255);
}
+ else if(t==PT_TEST)
+ {
+ if(parts[i].tmp==2)
+ blendpixel(vid, nx, ny, 255, 128, 0, 255);
+ else if(parts[i].tmp==1)
+ blendpixel(vid, nx, ny, 255, 255, 0, 255);
+ else
+ blendpixel(vid, nx, ny, 255, 0, 0, 255);
+ }
+ else if(t==PT_TEST2)
+ {
+ if(parts[i].tmp==2)
+ blendpixel(vid, nx, ny, 0, 100, 0, 255);
+ else
+ blendpixel(vid, nx, ny, 0, 255, 0, 255);
+ }
+ else if(t==PT_TEST3)
+ {
+ if(parts[i].tmp==4)
+ blendpixel(vid, nx, ny, 0, 0, 128, 255);
+ else if(parts[i].tmp==3)
+ blendpixel(vid, nx, ny, 0, 0, 150, 255);
+ else if(parts[i].tmp==2)
+ blendpixel(vid, nx, ny, 0, 0, 190, 255);
+ else if(parts[i].tmp==1)
+ blendpixel(vid, nx, ny, 0, 0, 230, 255);
+ else
+ blendpixel(vid, nx, ny, 0, 0, 70, 255);
+ }
else if(t==PT_DEUT)
{
diff --git a/src/powder.c b/src/powder.c
index 6b25eb4..6aa4e41 100644
--- a/src/powder.c
+++ b/src/powder.c
@@ -658,6 +658,12 @@ inline int create_part(int p, int x, int y, int t)
parts[i].tmp = (rand()%11);
if(t==PT_PQRT)
parts[i].tmp = (rand()%11);
+ if(ptypes[t].properties&PROP_LIFE) {
+ int r;
+ for(r = 0;r<NGOL;r++)
+ if(t==goltype[r])
+ parts[i].tmp = grule[r+1][9] - 1;
+ }
if(t==PT_FSEP)
parts[i].life = 50;
if(t==PT_COAL) {
@@ -1267,24 +1273,31 @@ void update_particles_i(pixel *vid, int start, int inc)
gol[nx][ny] = 0;
continue;
}
- else
+ else
for( golnum=1;golnum<NGOL;golnum++)
if(parts[r>>8].type==goltype[golnum-1])
{
- gol[nx][ny] = golnum;
- for( nnx=-1;nnx<2;nnx++)
- for( nny=-1;nny<2;nny++)//it will count itself as its own neighbor, which is needed, but will have 1 extra for delete check
- {
- gol2[((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][golnum] ++;
- gol2[((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][0] ++;
+ if(parts[r>>8].tmp == grule[golnum][9]-1) {
+ gol[nx][ny] = golnum;
+ for( nnx=-1;nnx<2;nnx++)
+ for( nny=-1;nny<2;nny++)//it will count itself as its own neighbor, which is needed, but will have 1 extra for delete check
+ {
+ gol2[((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][golnum] ++;
+ gol2[((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][0] ++;
+ }
+ } else {
+ parts[r>>8].tmp --;
+ if(parts[r>>8].tmp<=0)
+ parts[r>>8].type = PT_NONE;
}
}
}
for(nx=CELL;nx<XRES-CELL;nx++)
for(ny=CELL;ny<YRES-CELL;ny++)
{
+ r = pmap[ny][nx];
int neighbors = gol2[nx][ny][0];
- if(neighbors==0)
+ if(neighbors==0 || !(ptypes[r&0xFF].properties&PROP_LIFE || !r&0xFF))
continue;
for( golnum = 1;golnum<NGOL;golnum++)
for( goldelete = 0;goldelete<9;goldelete++)
@@ -1294,8 +1307,12 @@ void update_particles_i(pixel *vid, int start, int inc)
if(create_part(-1,nx,ny,goltype[golnum-1]))
createdsomething = 1;
}
- else if(neighbors-1==goldelete&&gol[nx][ny]==golnum&&(grule[golnum][goldelete]==0||grule[golnum][goldelete]==2))//subtract 1 because it counted itself
- parts[pmap[ny][nx]>>8].type = PT_NONE;
+ else if(neighbors-1==goldelete&&gol[nx][ny]==golnum&&(grule[golnum][goldelete]==0||grule[golnum][goldelete]==2)) {//subtract 1 because it counted itself
+ if(parts[r>>8].tmp==grule[golnum][9]-1)
+ parts[r>>8].tmp --;
+ }
+ if(parts[r>>8].tmp<=0)
+ parts[r>>8].type = PT_NONE;
}
gol2[nx][ny][0] = 0;
for( z = 1;z<NGOL;z++)