diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2011-05-05 19:14:35 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2011-05-05 19:14:35 (GMT) |
| commit | 5aefd0cb01facdda852960c03489991461aaed62 (patch) | |
| tree | 5d6528ecd26bc03ca18f02c1ec5c0eb5e7e7a269 /src | |
| parent | fb408ab82b8ae7a033899fc25ffcba3813549c54 (diff) | |
| download | powder-5aefd0cb01facdda852960c03489991461aaed62.zip powder-5aefd0cb01facdda852960c03489991461aaed62.tar.gz | |
Initial soap commit
Diffstat (limited to 'src')
| -rw-r--r-- | src/elements/soap.c | 108 | ||||
| -rw-r--r-- | src/graphics.c | 7 | ||||
| -rw-r--r-- | src/powder.c | 9 |
3 files changed, 124 insertions, 0 deletions
diff --git a/src/elements/soap.c b/src/elements/soap.c new file mode 100644 index 0000000..fa521a9 --- /dev/null +++ b/src/elements/soap.c @@ -0,0 +1,108 @@ +#include <element.h> + +int update_SOAP(UPDATE_FUNC_ARGS) { + int r, rx, ry, wc; + + wc = -1; + + //0x01 - bubble on/off + //0x02 - first mate yes/no + //0x04 - second mate yes/no + + if (pv[y/CELL][x/CELL]>0.5f) + parts[i].ctype |= 0x01; + + if (parts[i].ctype&0x01 == 0x01) + { + parts[i].vy -= 0.1f; + + parts[i].vy *= 0.5f; + parts[i].vx *= 0.5f; + + if(parts[i].ctype&0x02 != 0x02) + { + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if ((r>>8)>=NPART || !r) + continue; + + if ((parts[r>>8].type == PT_SOAP) && (parts[r>>8].ctype&0x01==0x01) + && (parts[r>>8].ctype&0x04!=0x04)) + { + if (parts[r>>8].ctype&0x02 == 0x02) + { + parts[i].tmp = r>>8; + parts[r>>8].tmp2 = i; + + parts[i].ctype |= 0x02; + parts[r>>8].ctype |= 0x04; + } + else + { + if (parts[i].ctype&0x02!=0x02) + { + parts[i].tmp = r>>8; + parts[r>>8].tmp2 = i; + + parts[i].ctype |= 0x02; + parts[r>>8].ctype |= 0x04; + } + } + } + + } + } + else + { + float d, dx, dy; + + dx = parts[i].x - parts[parts[i].tmp].x; + dy = parts[i].y - parts[parts[i].tmp].y; + + d = 9/(pow(dx, 2)+pow(dy, 2)+9)-0.5; + + parts[parts[i].tmp].x -= dx*d; + parts[parts[i].tmp].y -= dy*d; + + parts[i].x += dx*d; + parts[i].y += dy*d; + + if ((parts[parts[i].tmp].ctype&0x02 == 0x02) && (parts[parts[i].tmp].ctype&0x01 == 0x01)) + { + float d, dx, dy; + int ii; + + ii = parts[parts[i].tmp].tmp; + + dx = parts[ii].x - parts[parts[i].tmp].x; + dy = parts[ii].y - parts[parts[i].tmp].y; + + d = 36/(pow(dx, 2)+pow(dy, 2)+36)-0.5; + + parts[parts[i].tmp].x -= dx*d*0.5f; + parts[parts[i].tmp].y -= dy*d*0.5f; + + parts[ii].x += dx*d*0.5f; + parts[ii].y += dy*d*0.5f; + } + } + + } + else + { + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if ((r>>8)>=NPART || !r) + continue; + + } + } + + return 0; +} diff --git a/src/graphics.c b/src/graphics.c index c0fce81..fe153ec 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1495,6 +1495,13 @@ void draw_parts(pixel *vid) nx = (int)(parts[i].x+0.5f); ny = (int)(parts[i].y+0.5f); + + if (t==PT_SOAP) + { + //if ((parts[i].ctype&0x01 == 0x01) && (parts[i].ctype&0x02 == 0x02)) + // draw_line(vid, nx, ny, (int)(parts[parts[i].tmp].x+0.5f), (int)(parts[parts[i].tmp].y+0.5f), 245, 245, 220, XRES+BARSIZE); + } + if (cmode!=CM_HEAT) { if (t==PT_STKM) //Just draw head here diff --git a/src/powder.c b/src/powder.c index 6a4290d..87389e2 100644 --- a/src/powder.c +++ b/src/powder.c @@ -462,6 +462,14 @@ void kill_part(int i)//kills particle number i { ISSPAWN2 = 0; } + if (parts[i].type == PT_SOAP) + { + if (parts[i].ctype&0x02 == 0x02) + parts[parts[i].tmp].ctype ^= 0x04; + + if (parts[i].ctype&0x04 == 0x04) + parts[parts[i].tmp2].ctype ^= 0x02; + } if (x>=0 && y>=0 && x<XRES && y<YRES) { if ((pmap[y][x]>>8)==i) pmap[y][x] = 0; @@ -638,6 +646,7 @@ inline int create_part(int p, int x, int y, int t)//the function for creating a parts[i].ctype = 0; parts[i].temp = ptypes[t].heat; parts[i].tmp = 0; + parts[i].tmp2 = 0; } //now set various properties that we want at spawn. if (t==PT_ACID) |
