Gravity control by Moach

This commit is contained in:
Simon 2011-01-04 13:35:16 +00:00
parent f0d9882b03
commit 3a2bc76643
5 changed files with 66 additions and 10 deletions

View File

@ -28,6 +28,9 @@
#define YRES 384 #define YRES 384
#define NPART XRES*YRES #define NPART XRES*YRES
#define XCNTR 306
#define YCNTR 192
#define MAX_DISTANCE sqrt(pow(XRES, 2)+pow(YRES, 2)) #define MAX_DISTANCE sqrt(pow(XRES, 2)+pow(YRES, 2))
#define MAXSIGNS 16 #define MAXSIGNS 16

View File

@ -125,6 +125,7 @@ extern int svf_publish;
extern char svf_id[16]; extern char svf_id[16];
extern char svf_name[64]; extern char svf_name[64];
extern char svf_tags[256]; extern char svf_tags[256];
extern char svf_description[255];
extern void *svf_last; extern void *svf_last;
extern int svf_lsize; extern int svf_lsize;

View File

@ -652,6 +652,8 @@ extern float player[27];
extern float player2[27]; extern float player2[27];
extern int gravityMode;
extern particle *parts; extern particle *parts;
extern particle *cb_parts; extern particle *cb_parts;

View File

@ -477,6 +477,7 @@ int parse_save(void *save, int size, int replace, int x0, int y0)
if(replace) if(replace)
{ {
gravityMode = 1;
memset(bmap, 0, sizeof(bmap)); memset(bmap, 0, sizeof(bmap));
memset(emap, 0, sizeof(emap)); memset(emap, 0, sizeof(emap));
memset(signs, 0, sizeof(signs)); memset(signs, 0, sizeof(signs));
@ -1515,6 +1516,29 @@ int main(int argc, char *argv[])
else else
GRID_MODE = (GRID_MODE+1)%10; GRID_MODE = (GRID_MODE+1)%10;
} }
if(sdl_key=='w') //Gravity, by Moach
{
++gravityMode; // cycle gravity mode
itc = 51;
switch (gravityMode)
{
default:
gravityMode = 0;
case 0:
strcpy(itc_msg, "Gravity: Off");
break;
case 1:
strcpy(itc_msg, "Gravity: Vertical");
break;
case 2:
strcpy(itc_msg, "Gravity: Radial");
break;
}
}
if(sdl_key=='t') if(sdl_key=='t')
VINE_MODE = !VINE_MODE; VINE_MODE = !VINE_MODE;
if(sdl_key==SDLK_SPACE) if(sdl_key==SDLK_SPACE)
@ -2033,6 +2057,8 @@ int main(int argc, char *argv[])
svf_id[0] = 0; svf_id[0] = 0;
svf_name[0] = 0; svf_name[0] = 0;
svf_tags[0] = 0; svf_tags[0] = 0;
svf_description[0] = 0;
gravityMode = 1;
memset(fire_bg, 0, XRES*YRES*PIXELSIZE); memset(fire_bg, 0, XRES*YRES*PIXELSIZE);
memset(fire_r, 0, sizeof(fire_r)); memset(fire_r, 0, sizeof(fire_r));

View File

@ -12,6 +12,8 @@ float player2[27];
particle *parts; particle *parts;
particle *cb_parts; particle *cb_parts;
int gravityMode = 1; // starts enabled in "vertical" mode...
unsigned char bmap[YRES/CELL][XRES/CELL]; unsigned char bmap[YRES/CELL][XRES/CELL];
unsigned char emap[YRES/CELL][XRES/CELL]; unsigned char emap[YRES/CELL][XRES/CELL];
@ -1073,6 +1075,8 @@ void update_particles_i(pixel *vid, int start, int inc)
float c_heat = 0.0f; float c_heat = 0.0f;
int h_count = 0; int h_count = 0;
int starti = (start*-1); int starti = (start*-1);
float pGravX, pGravY, pGravD;
if(sys_pause&&!framerender) if(sys_pause&&!framerender)
return; return;
if(ISGRAV==1) if(ISGRAV==1)
@ -1500,16 +1504,36 @@ void update_particles_i(pixel *vid, int start, int inc)
} }
else else
{ {
if(t==PT_ANAR) //Gravity mode by Moach
{ switch (gravityMode)
parts[i].vx -= ptypes[t].advection*vx[y/CELL][x/CELL]; {
parts[i].vy -= ptypes[t].advection*vy[y/CELL][x/CELL] + ptypes[t].gravity; default:
} case 0:
else{ pGravX = pGravY = 0.0f;
parts[i].vx += ptypes[t].advection*vx[y/CELL][x/CELL]; break;
parts[i].vy += ptypes[t].advection*vy[y/CELL][x/CELL] + ptypes[t].gravity; case 1:
pGravX = 0.0f;
pGravY = ptypes[t].gravity;
break;
case 2:
} pGravD = 0.01f - hypotf((x - XCNTR), (y - YCNTR));
pGravX = ptypes[t].gravity * ((float)(x - XCNTR) / pGravD);
pGravY = ptypes[t].gravity * ((float)(y - YCNTR) / pGravD);
}
if(t==PT_ANAR)
{
parts[i].vx -= ptypes[t].advection*vx[y/CELL][x/CELL] + pGravX;
parts[i].vy -= ptypes[t].advection*vy[y/CELL][x/CELL] + pGravY;
}
else{
parts[i].vx += ptypes[t].advection*vx[y/CELL][x/CELL] + pGravX;
parts[i].vy += ptypes[t].advection*vy[y/CELL][x/CELL] + pGravY;
}
} }
if(ptypes[t].diffusion) if(ptypes[t].diffusion)