summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsavask <savask@yandex.ru>2011-04-30 13:41:15 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-05-05 19:24:42 (GMT)
commitf0c5960b563e4cbb3efe928df363e82a62d78e3a (patch)
treee3622245a922545343610a902ab11ae5530dbac1 /src
parent3ea306cc771bbaefa01058c810fc1dd041a17641 (diff)
downloadpowder-f0c5960b563e4cbb3efe928df363e82a62d78e3a.zip
powder-f0c5960b563e4cbb3efe928df363e82a62d78e3a.tar.gz
Some work on bubbles. Added "bubble x,y" command to console.
Also made them save like regular soap.
Diffstat (limited to 'src')
-rw-r--r--src/console.c26
-rw-r--r--src/elements/soap.c85
-rw-r--r--src/main.c4
3 files changed, 104 insertions, 11 deletions
diff --git a/src/console.c b/src/console.c
index 634e679..e926328 100644
--- a/src/console.c
+++ b/src/console.c
@@ -1108,6 +1108,32 @@ int process_command_old(pixel *vid_buf, char *console, char *console_error)
strcpy(console_error, "Could not create particle");
}
}
+ else if (strcmp(console2, "bubble")==0 && console3[0])
+ {
+ if (console_parse_coords(console3, &nx, &ny, console_error))
+ {
+ int first, rem1, rem2;
+
+ first = create_part(-1, nx+18, ny, PT_SOAP);
+ rem1 = first;
+
+ for (i = 1; i<=30; i++)
+ {
+ rem2 = create_part(-1, nx+18*cosf(i/5.0), ny+18*sinf(i/5.0), PT_SOAP);
+
+ parts[rem1].ctype = 7;
+ parts[rem1].tmp = rem2;
+ parts[rem2].tmp2 = rem1;
+
+ rem1 = rem2;
+ }
+
+ parts[rem1].ctype = 7;
+ parts[rem1].tmp = first;
+ parts[first].tmp2 = rem1;
+ parts[first].ctype = 7;
+ }
+ }
else if ((strcmp(console2, "delete")==0 || strcmp(console2, "kill")==0) && console3[0])
{
if (console_parse_partref(console3, &i, console_error))
diff --git a/src/elements/soap.c b/src/elements/soap.c
index 838b16c..0496bd2 100644
--- a/src/elements/soap.c
+++ b/src/elements/soap.c
@@ -29,9 +29,6 @@ int update_SOAP(UPDATE_FUNC_ARGS)
{
if (parts[i].life<=0)
{
- if ((parts[i].ctype&6) == 0)
- parts[i].ctype = 0;
-
if ((parts[i].ctype&6) != 6 && parts[i].ctype>1)
{
int target;
@@ -54,9 +51,11 @@ int update_SOAP(UPDATE_FUNC_ARGS)
}
}
+ if ((parts[i].ctype&6) != 6)
+ parts[i].ctype = 0;
+
if ((parts[i].ctype&6) == 6 && (parts[parts[i].tmp].ctype&6) == 6 && parts[parts[i].tmp].tmp == i)
detach(i);
-
}
parts[i].vy -= 0.1f;
@@ -74,12 +73,6 @@ int update_SOAP(UPDATE_FUNC_ARGS)
if ((r>>8)>=NPART || !r)
continue;
- if ((r&0xFF) != PT_SOAP || (parts[r>>8].ctype == 0 && (r&0xFF) == PT_SOAP))
- {
- detach(i);
- continue;
- }
-
if ((parts[r>>8].type == PT_SOAP) && ((parts[r>>8].ctype&1) == 1)
&& ((parts[r>>8].ctype&4) != 4))
{
@@ -105,6 +98,49 @@ int update_SOAP(UPDATE_FUNC_ARGS)
}
}
}
+ else
+ {
+ if (parts[i].life<=0)
+ 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 (((r&0xFF) != PT_SOAP && (r&0xFF) != PT_GLAS)
+ || (parts[r>>8].ctype == 0 && (r&0xFF) == PT_SOAP
+ && (abs(parts[r>>8].vx)<2 || abs(parts[r>>8].vy)<2)))
+ {
+ detach(i);
+ continue;
+ }
+
+ if ((r&0xFF) == PT_SOAP && parts[r>>8].ctype == 1)
+ {
+ int buf;
+
+ buf = parts[i].tmp;
+
+ parts[i].tmp = r>>8;
+ parts[buf].tmp2 = r>>8;
+ parts[r>>8].tmp2 = i;
+ parts[r>>8].tmp = buf;
+ parts[r>>8].ctype = 7;
+ }
+
+ if ((r&0xFF) == PT_SOAP && parts[r>>8].ctype == 7 && parts[i].tmp != r>>8 && parts[i].tmp2 != r>>8)
+ {
+ int buf;
+
+ parts[parts[i].tmp].tmp2 = parts[r>>8].tmp2;
+ parts[parts[r>>8].tmp2].tmp = parts[i].tmp;
+ parts[r>>8].tmp2 = i;
+ parts[i].tmp = r>>8;
+ }
+ }
+ }
if((parts[i].ctype&2) == 2)
{
@@ -146,8 +182,35 @@ int update_SOAP(UPDATE_FUNC_ARGS)
if (pv[y/CELL][x/CELL]>0.5f || pv[y/CELL][x/CELL]<(-0.5f))
{
parts[i].ctype = 1;
- parts[i].life = 5;
+ parts[i].life = 10;
}
+
+ 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 ((r&0xFF) == PT_OIL)
+ {
+ parts[i].vy -= 0.1f;
+
+ parts[i].vy *= 0.5f;
+ parts[i].vx *= 0.5f;
+
+ float ax, ay;
+
+ ax = (parts[i].vx + parts[r>>8].vx)/2;
+ ay = (parts[i].vy + parts[r>>8].vy)/2;
+
+ parts[i].vx = ax;
+ parts[i].vy = ay;
+ parts[r>>8].vx = ax;
+ parts[r>>8].vy = ay;
+ }
+ }
}
return 0;
diff --git a/src/main.c b/src/main.c
index 92a9fdd..e2bf9d0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -667,6 +667,8 @@ int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char
parts[k].type = j;
if (j == PT_PHOT)
parts[k].ctype = 0x3fffffff;
+ if (j == PT_SOAP)
+ parts[k].ctype = 0;
parts[k].x = (float)x;
parts[k].y = (float)y;
m[(x-x0)+(y-y0)*w] = k+1;
@@ -681,6 +683,8 @@ int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char
parts[fp[i]].tmp = 50;
if (j == PT_PHOT)
parts[fp[i]].ctype = 0x3fffffff;
+ if (j == PT_SOAP)
+ parts[k].ctype = 0;
parts[fp[i]].x = (float)x;
parts[fp[i]].y = (float)y;
m[(x-x0)+(y-y0)*w] = fp[i]+1;