diff options
| author | jacksonmj <jacksonmj@jacksonmj.none> | 2011-01-07 14:13:13 (GMT) |
|---|---|---|
| committer | jacksonmj <jacksonmj@jacksonmj.none> | 2011-01-07 14:14:35 (GMT) |
| commit | 1ab4d328a64c096aecc618dd4d15359cb620bd51 (patch) | |
| tree | 827a7d7882526fe8e6b76986e340100542c04d77 /src | |
| parent | ed8c0031f4899ea4d1bf0b1ad15620bef735dbae (diff) | |
| download | powder-1ab4d328a64c096aecc618dd4d15359cb620bd51.zip powder-1ab4d328a64c096aecc618dd4d15359cb620bd51.tar.gz | |
Start function pointers
Diffstat (limited to 'src')
| -rw-r--r-- | src/elements/none.c | 5 | ||||
| -rw-r--r-- | src/elements/pcln.c | 42 | ||||
| -rw-r--r-- | src/elements/phot.c | 7 | ||||
| -rw-r--r-- | src/elements/pste.c | 7 | ||||
| -rw-r--r-- | src/elements/stkm.c | 403 | ||||
| -rw-r--r-- | src/elements/stkm2.c | 404 | ||||
| -rw-r--r-- | src/powder.c | 858 |
7 files changed, 875 insertions, 851 deletions
diff --git a/src/elements/none.c b/src/elements/none.c new file mode 100644 index 0000000..fc9f9a9 --- /dev/null +++ b/src/elements/none.c @@ -0,0 +1,5 @@ +#include <powder.h> + +int update_(UPDATE_FUNC_ARGS) { + +} diff --git a/src/elements/pcln.c b/src/elements/pcln.c new file mode 100644 index 0000000..38af102 --- /dev/null +++ b/src/elements/pcln.c @@ -0,0 +1,42 @@ +#include <powder.h> + +int update_PCLN(UPDATE_FUNC_ARGS) { + if (!parts[i].ctype) + for (nx=-1; nx<2; nx++) + for (ny=-1; ny<2; ny++) + if (x+nx>=0 && y+ny>0 && + x+nx<XRES && y+ny<YRES && + pmap[y+ny][x+nx] && + (pmap[y+ny][x+nx]&0xFF)!=PT_CLNE && + (pmap[y+ny][x+nx]&0xFF)!=PT_PCLN && + (pmap[y+ny][x+nx]&0xFF)!=PT_BCLN && + (pmap[y+ny][x+nx]&0xFF)!=PT_SPRK && + (pmap[y+ny][x+nx]&0xFF)!=PT_NSCN && + (pmap[y+ny][x+nx]&0xFF)!=PT_PSCN && + (pmap[y+ny][x+nx]&0xFF)!=PT_STKM && + (pmap[y+ny][x+nx]&0xFF)!=PT_STKM2 && + (pmap[y+ny][x+nx]&0xFF)!=0xFF) + parts[i].ctype = pmap[y+ny][x+nx]&0xFF; + if (parts[i].ctype && parts[i].life==10) { + if (parts[i].ctype==PT_PHOT) { + for (nx=-1; nx<2; nx++) { + for (ny=-1; ny<2; ny++) { + int r = create_part(-1, x+nx, y+ny, parts[i].ctype); + if (r!=-1) { + parts[r].vx = nx*3; + parts[r].vy = ny*3; + } + } + } + } + else if (ptypes[parts[i].ctype].properties&PROP_LIFE) { + for (nx=-1; nx<2; nx++) { + for (ny=-1; ny<2; ny++) { + create_part(-1, x+nx, y+ny, parts[i].ctype); + } + } + } else { + create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype); + } + } +} diff --git a/src/elements/phot.c b/src/elements/phot.c new file mode 100644 index 0000000..cebff96 --- /dev/null +++ b/src/elements/phot.c @@ -0,0 +1,7 @@ +#include <powder.h> + +int update_PHOT(UPDATE_FUNC_ARGS) { + // TODO + + return 0; +} diff --git a/src/elements/pste.c b/src/elements/pste.c new file mode 100644 index 0000000..89f965c --- /dev/null +++ b/src/elements/pste.c @@ -0,0 +1,7 @@ +#include <powder.h> + +int update_PSTE(UPDATE_FUNC_ARGS) { + if (parts[i].temp>747.0f) + parts[i].type = PT_BRCK; + return 0; +} diff --git a/src/elements/stkm.c b/src/elements/stkm.c new file mode 100644 index 0000000..0402d93 --- /dev/null +++ b/src/elements/stkm.c @@ -0,0 +1,403 @@ +#include <powder.h> + +int update_SPAWN(UPDATE_FUNC_ARGS) { + if (death) + { + playerspawn = create_part(-1,x,y,PT_STKM); + isplayer = 1; + death = 0; + } + return 0; +} + +int update_STKM(UPDATE_FUNC_ARGS) { + int r; + float pp, d; + float dt = 0.9;///(FPSB*FPSB); //Delta time in square + //Tempirature handling + if (parts[i].temp<243) + parts[i].life -= 1; + if ((parts[i].temp<309.6f) && (parts[i].temp>=243)) + parts[i].temp += 1; + + //Death + if (parts[i].life<1 || death || (pv[y/CELL][x/CELL]>=4.5f && player[2] != SPC_AIR) ) //If his HP is less that 0 or there is very big wind... + { + for (r=-2; r<=1; r++) + { + create_part(-1, x+r, y-2, player[2]); + create_part(-1, x+r+1, y+2, player[2]); + create_part(-1, x-2, y+r+1, player[2]); + create_part(-1, x+2, y+r, player[2]); + } + kill_part(i); //Kill him + return 1; + } + + parts[i].vy += -0.7*dt; //Head up! + + //Verlet integration + pp = 2*player[3]-player[5]+player[19]*dt*dt;; + player[5] = player[3]; + player[3] = pp; + pp = 2*player[4]-player[6]+player[20]*dt*dt;; + player[6] = player[4]; + player[4] = pp; + + pp = 2*player[7]-player[9]+player[21]*dt*dt;; + player[9] = player[7]; + player[7] = pp; + pp = 2*player[8]-player[10]+(player[22]+1)*dt*dt;; + player[10] = player[8]; + player[8] = pp; + + pp = 2*player[11]-player[13]+player[23]*dt*dt;; + player[13] = player[11]; + player[11] = pp; + pp = 2*player[12]-player[14]+player[24]*dt*dt;; + player[14] = player[12]; + player[12] = pp; + + pp = 2*player[15]-player[17]+player[25]*dt*dt;; + player[17] = player[15]; + player[15] = pp; + pp = 2*player[16]-player[18]+(player[26]+1)*dt*dt;; + player[18] = player[16]; + player[16] = pp; + + //Setting acceleration to 0 + player[19] = 0; + player[20] = 0; + + player[21] = 0; + player[22] = 0; + + player[23] = 0; + player[24] = 0; + + player[25] = 0; + player[26] = 0; + + //Go left + if (((int)(player[0])&0x01) == 0x01 && pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS) + { + if (pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID + && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG) + { + if (pmap[(int)(player[8]-1)][(int)(player[7])]) + { + player[21] = -3; + player[22] = -2; + player[19] = -2; + } + + if (pmap[(int)(player[16]-1)][(int)(player[15])]) + { + player[25] = -3; + player[26] = -2; + player[23] = -2; + } + } + else + { + if (pmap[(int)(player[8]-1)][(int)(player[7])]) //It should move another way in liquids + { + player[21] = -1; + player[22] = -1; + player[19] = -1; + } + + if (pmap[(int)(player[16]-1)][(int)(player[15])]) + { + player[25] = -1; + player[26] = -1; + player[23] = -1; + } + } + } + + //Go right + if (((int)(player[0])&0x02) == 0x02 && pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS) + { + if (pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID + && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG) + { + if (pmap[(int)(player[8]-1)][(int)(player[7])]) + { + player[21] = 3; + player[22] = -2; + player[19] = 2; + } + + if (pmap[(int)(player[16]-1)][(int)(player[15])]) + { + player[25] = 3; + player[26] = -2; + player[23] = 2; + } + } + else + { + if (pmap[(int)(player[8]-1)][(int)(player[7])]) + { + player[21] = 1; + player[22] = -1; + player[19] = 1; + } + + if (pmap[(int)(player[16]-1)][(int)(player[15])]) + { + player[25] = 1; + player[26] = -1; + player[23] = 1; + } + + } + } + + //Jump + if (((int)(player[0])&0x04) == 0x04 && (pstates[pmap[(int)(player[8]-0.5)][(int)(player[7])]&0xFF].state != ST_GAS || pstates[pmap[(int)(player[16]-0.5)][(int)(player[15])]&0xFF].state != ST_GAS)) + { + if (pmap[(int)(player[8]-0.5)][(int)(player[7])] || pmap[(int)(player[16]-0.5)][(int)(player[15])]) + { + parts[i].vy = -5; + player[22] -= 1; + player[26] -= 1; + } + } + + //Charge detector wall if foot inside + if (bmap[(int)(player[8]+0.5)/CELL][(int)(player[7]+0.5)/CELL]==WL_DETECT) + set_emap((int)player[7]/CELL, (int)player[8]/CELL); + if (bmap[(int)(player[16]+0.5)/CELL][(int)(player[15]+0.5)/CELL]==WL_DETECT) + set_emap((int)(player[15]+0.5)/CELL, (int)(player[16]+0.5)/CELL); + + //Searching for particles near head + for (nx = -2; nx <= 2; nx++) + for (ny = 0; ny>=-2; ny--) + { + if (!pmap[ny+y][nx+x] || (pmap[ny+y][nx+x]>>8)>=NPART) + continue; + if (ptypes[pmap[ny+y][nx+x]&0xFF].falldown!=0 || (pmap[ny+y][nx+x]&0xFF) == PT_NEUT || (pmap[ny+y][nx+x]&0xFF) == PT_PHOT) + { + player[2] = pmap[ny+y][nx+x]&0xFF; //Current element + } + if ((pmap[ny+y][nx+x]&0xFF) == PT_PLNT && parts[i].life<100) //Plant gives him 5 HP + { + if (parts[i].life<=95) + parts[i].life += 5; + else + parts[i].life = 100; + kill_part(pmap[ny+y][nx+x]>>8); + } + + if ((pmap[ny+y][nx+x]&0xFF) == PT_NEUT) + { + parts[i].life -= (102-parts[i].life)/2; + kill_part(pmap[ny+y][nx+x]>>8); + } + if (bmap[(ny+y)/CELL][(nx+x)/CELL]==WL_FAN) + player[2] = SPC_AIR; + } + + //Head position + nx = x + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01); + ny = y - 3*(player[1] == 0); + + //Spawn + if (((int)(player[0])&0x08) == 0x08) + { + ny -= 2*(rand()%2)+1; + r = pmap[ny][nx]; + if (!((r>>8)>=NPART)) + { + if (pstates[r&0xFF].state == ST_SOLID) + { + create_part(-1, nx, ny, PT_SPRK); + } + else + { + if (player[2] == SPC_AIR) + create_parts(nx + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01), ny, 4, 4, SPC_AIR); + else + create_part(-1, nx, ny, player[2]); + + r = pmap[ny][nx]; + if ( ((r>>8) < NPART) && (r>>8)>=0 && player[2] != PT_PHOT && player[2] != SPC_AIR) + parts[r>>8].vx = parts[r>>8].vx + 5*((((int)player[1])&0x02) == 0x02) - 5*(((int)(player[1])&0x01) == 0x01); + if (((r>>8) < NPART) && (r>>8)>=0 && player[2] == PT_PHOT) + { + int random = abs(rand()%3-1)*3; + if (random==0) + { + parts[r>>8].life = 0; + parts[r>>8].type = PT_NONE; + } + else + { + parts[r>>8].vy = 0; + parts[r>>8].vx = (((((int)player[1])&0x02) == 0x02) - (((int)(player[1])&0x01) == 0x01))*random; + } + } + + } + } + } + + //Simulation of joints + d = 25/(pow((player[3]-player[7]), 2) + pow((player[4]-player[8]), 2)+25) - 0.5; //Fast distance + player[7] -= (player[3]-player[7])*d; + player[8] -= (player[4]-player[8])*d; + player[3] += (player[3]-player[7])*d; + player[4] += (player[4]-player[8])*d; + + d = 25/(pow((player[11]-player[15]), 2) + pow((player[12]-player[16]), 2)+25) - 0.5; + player[15] -= (player[11]-player[15])*d; + player[16] -= (player[12]-player[16])*d; + player[11] += (player[11]-player[15])*d; + player[12] += (player[12]-player[16])*d; + + d = 36/(pow((player[3]-parts[i].x), 2) + pow((player[4]-parts[i].y), 2)+36) - 0.5; + parts[i].vx -= (player[3]-parts[i].x)*d; + parts[i].vy -= (player[4]-parts[i].y)*d; + player[3] += (player[3]-parts[i].x)*d; + player[4] += (player[4]-parts[i].y)*d; + + d = 36/(pow((player[11]-parts[i].x), 2) + pow((player[12]-parts[i].y), 2)+36) - 0.5; + parts[i].vx -= (player[11]-parts[i].x)*d; + parts[i].vy -= (player[12]-parts[i].y)*d; + player[11] += (player[11]-parts[i].x)*d; + player[12] += (player[12]-parts[i].y)*d; + + //Side collisions checking + for (nx = -3; nx <= 3; nx++) + { + r = pmap[(int)(player[16]-2)][(int)(player[15]+nx)]; + if (r && pstates[r&0xFF].state != ST_GAS && pstates[r&0xFF].state != ST_LIQUID) + player[15] -= nx; + + r = pmap[(int)(player[8]-2)][(int)(player[7]+nx)]; + if (r && pstates[r&0xFF].state != ST_GAS && pstates[r&0xFF].state != ST_LIQUID) + player[7] -= nx; + } + + //Collision checks + for (ny = -2-(int)parts[i].vy; ny<=0; ny++) + { + r = pmap[(int)(player[8]+ny)][(int)(player[7]+0.5)]; //This is to make coding more pleasant :-) + + //For left leg + if (r && (r&0xFF)!=PT_STKM) + { + if (pstates[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) //Liquid checks //Liquid checks + { + if (parts[i].y<(player[8]-10)) + parts[i].vy = 1*dt; + else + parts[i].vy = 0; + if (abs(parts[i].vx)>1) + parts[i].vx *= 0.5*dt; + } + else + { + if (pstates[r&0xFF].state != ST_GAS) + { + player[8] += ny-1; + parts[i].vy -= 0.5*parts[i].vy*dt; + } + } + player[9] = player[7]; + } + + r = pmap[(int)(player[16]+ny)][(int)(player[15]+0.5)]; + + //For right leg + if (r && (r&0xFF)!=PT_STKM) + { + if (pstates[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) + { + if (parts[i].y<(player[16]-10)) + parts[i].vy = 1*dt; + else + parts[i].vy = 0; + if (abs(parts[i].vx)>1) + parts[i].vx *= 0.5*dt; + } + else + { + if (pstates[r&0xFF].state != ST_GAS) + { + player[16] += ny-1; + parts[i].vy -= 0.5*parts[i].vy*dt; + } + } + player[17] = player[15]; + } + + //If it falls too fast + if (parts[i].vy>=30) + { + parts[i].y -= (10+ny)*dt; + parts[i].vy = -10*dt; + } + + } + + //Keeping legs distance + if (pow((player[7] - player[15]), 2)<16 && pow((player[8]-player[16]), 2)<1) + { + player[21] -= 0.2; + player[25] += 0.2; + } + + if (pow((player[3] - player[11]), 2)<16 && pow((player[4]-player[12]), 2)<1) + { + player[19] -= 0.2; + player[23] += 0.2; + } + + //If legs touch something + r = pmap[(int)(player[8]+0.5)][(int)(player[7]+0.5)]; + if ((r&0xFF)==PT_SPRK && r && (r>>8)<NPART) //If on charge + { + parts[i].life -= (int)(rand()/1000)+38; + } + + if (r>0 && (r>>8)<NPART) //If hot or cold + { + if (parts[r>>8].temp>=323 || parts[r>>8].temp<=243) + { + parts[i].life -= 2; + player[26] -= 1; + } + } + + if ((r&0xFF)==PT_ACID) //If on acid + parts[i].life -= 5; + + if ((r&0xFF)==PT_PLUT) //If on plut + parts[i].life -= 1; + + r = pmap[(int)(player[16]+0.5)][(int)(player[15]+0.5)]; + if ((r&0xFF)==PT_SPRK && r && (r>>8)<NPART) //If on charge + { + parts[i].life -= (int)(rand()/1000)+38; + } + + if (r>0 && (r>>8)<NPART) //If hot or cold + { + if (parts[r>>8].temp>=323 || parts[r>>8].temp<=243) + { + parts[i].life -= 2; + player[22] -= 1; + } + } + + if ((r&0xFF)==PT_ACID) //If on acid + parts[i].life -= 5; + + if ((r&0xFF)==PT_PLUT) //If on plut + parts[i].life -= 1; + + isplayer = 1; +} diff --git a/src/elements/stkm2.c b/src/elements/stkm2.c new file mode 100644 index 0000000..89cec10 --- /dev/null +++ b/src/elements/stkm2.c @@ -0,0 +1,404 @@ +#include <powder.h> + +int update_SPAWN2(UPDATE_FUNC_ARGS) { + if (death2) + { + player2spawn = create_part(-1,x,y,PT_STKM2); + isplayer2 = 1; + death2 = 0; + } + return 0; +} + +int update_STKM2(UPDATE_FUNC_ARGS) { + int r; + float pp, d; + float dt = 0.9;///(FPSB*FPSB); //Delta time in square + //Tempirature handling + if (parts[i].temp<243) + parts[i].life -= 1; + if ((parts[i].temp<309.6f) && (parts[i].temp>=243)) + parts[i].temp += 1; + + //Death + if (parts[i].life<1 || death2 || (pv[y/CELL][x/CELL]>=4.5f && player2[2] != SPC_AIR) ) //If his HP is less that 0 or there is very big wind... + { + for (r=-2; r<=1; r++) + { + create_part(-1, x+r, y-2, player2[2]); + create_part(-1, x+r+1, y+2, player2[2]); + create_part(-1, x-2, y+r+1, player2[2]); + create_part(-1, x+2, y+r, player2[2]); + } + kill_part(i); //Kill him + return 1; + } + + parts[i].vy += -0.7*dt; //Head up! + + //Verlet integration + pp = 2*player2[3]-player2[5]+player2[19]*dt*dt;; + player2[5] = player2[3]; + player2[3] = pp; + pp = 2*player2[4]-player2[6]+player2[20]*dt*dt;; + player2[6] = player2[4]; + player2[4] = pp; + + pp = 2*player2[7]-player2[9]+player2[21]*dt*dt;; + player2[9] = player2[7]; + player2[7] = pp; + pp = 2*player2[8]-player2[10]+(player2[22]+1)*dt*dt;; + player2[10] = player2[8]; + player2[8] = pp; + + pp = 2*player2[11]-player2[13]+player2[23]*dt*dt;; + player2[13] = player2[11]; + player2[11] = pp; + pp = 2*player2[12]-player2[14]+player2[24]*dt*dt;; + player2[14] = player2[12]; + player2[12] = pp; + + pp = 2*player2[15]-player2[17]+player2[25]*dt*dt;; + player2[17] = player2[15]; + player2[15] = pp; + pp = 2*player2[16]-player2[18]+(player2[26]+1)*dt*dt;; + player2[18] = player2[16]; + player2[16] = pp; + + //Setting acceleration to 0 + player2[19] = 0; + player2[20] = 0; + + player2[21] = 0; + player2[22] = 0; + + player2[23] = 0; + player2[24] = 0; + + player2[25] = 0; + player2[26] = 0; + + //Go left + if (((int)(player2[0])&0x01) == 0x01 && pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS) + { + if (pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID + && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG) + { + if (pmap[(int)(player2[8]-1)][(int)(player2[7])]) + { + player2[21] = -3; + player2[22] = -2; + player2[19] = -2; + } + + if (pmap[(int)(player2[16]-1)][(int)(player2[15])]) + { + player2[25] = -3; + player2[26] = -2; + player2[23] = -2; + } + } + else + { + if (pmap[(int)(player2[8]-1)][(int)(player2[7])]) //It should move another way in liquids + { + player2[21] = -1; + player2[22] = -1; + player2[19] = -1; + } + + if (pmap[(int)(player2[16]-1)][(int)(player2[15])]) + { + player2[25] = -1; + player2[26] = -1; + player2[23] = -1; + } + } + } + + //Go right + if (((int)(player2[0])&0x02) == 0x02 && pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS) + { + if (pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID + && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG) + { + if (pmap[(int)(player2[8]-1)][(int)(player2[7])]) + { + player2[21] = 3; + player2[22] = -2; + player2[19] = 2; + } + + if (pmap[(int)(player2[16]-1)][(int)(player2[15])]) + { + player2[25] = 3; + player2[26] = -2; + player2[23] = 2; + } + } + else + { + if (pmap[(int)(player2[8]-1)][(int)(player2[7])]) + { + player2[21] = 1; + player2[22] = -1; + player2[19] = 1; + } + + if (pmap[(int)(player2[16]-1)][(int)(player2[15])]) + { + player2[25] = 1; + player2[26] = -1; + player2[23] = 1; + } + + } + } + + //Jump + if (((int)(player2[0])&0x04) == 0x04 && (pstates[pmap[(int)(player2[8]-0.5)][(int)(player2[7])]&0xFF].state != ST_GAS || pstates[pmap[(int)(player2[16]-0.5)][(int)(player2[15])]&0xFF].state != ST_GAS)) + { + if (pmap[(int)(player2[8]-0.5)][(int)(player2[7])] || pmap[(int)(player2[16]-0.5)][(int)(player2[15])]) + { + parts[i].vy = -5; + player2[22] -= 1; + player2[26] -= 1; + } + } + + //Charge detector wall if foot inside + if (bmap[(int)(player2[8]+0.5)/CELL][(int)(player2[7]+0.5)/CELL]==WL_DETECT) + set_emap((int)player2[7]/CELL, (int)player2[8]/CELL); + if (bmap[(int)(player2[16]+0.5)/CELL][(int)(player2[15]+0.5)/CELL]==WL_DETECT) + set_emap((int)(player2[15]+0.5)/CELL, (int)(player2[16]+0.5)/CELL); + + //Searching for particles near head + for (nx = -2; nx <= 2; nx++) + for (ny = 0; ny>=-2; ny--) + { + if (!pmap[ny+y][nx+x] || (pmap[ny+y][nx+x]>>8)>=NPART) + continue; + if (ptypes[pmap[ny+y][nx+x]&0xFF].falldown!=0 || (pmap[ny+y][nx+x]&0xFF) == PT_NEUT || (pmap[ny+y][nx+x]&0xFF) == PT_PHOT) + { + player2[2] = pmap[ny+y][nx+x]&0xFF; //Current element + } + if ((pmap[ny+y][nx+x]&0xFF) == PT_PLNT && parts[i].life<100) //Plant gives him 5 HP + { + if (parts[i].life<=95) + parts[i].life += 5; + else + parts[i].life = 100; + kill_part(pmap[ny+y][nx+x]>>8); + } + + if ((pmap[ny+y][nx+x]&0xFF) == PT_NEUT) + { + parts[i].life -= (102-parts[i].life)/2; + kill_part(pmap[ny+y][nx+x]>>8); + } + if (bmap[(ny+y)/CELL][(nx+x)/CELL]==WL_FAN) + player2[2] = SPC_AIR; + } + + //Head position + nx = x + 3*((((int)player2[1])&0x02) == 0x02) - 3*((((int)player2[1])&0x01) == 0x01); + ny = y - 3*(player2[1] == 0); + + //Spawn + if (((int)(player2[0])&0x08) == 0x08) + { + ny -= 2*(rand()%2)+1; + r = pmap[ny][nx]; + if (!((r>>8)>=NPART)) + { + if (pstates[r&0xFF].state == ST_SOLID) + { + create_part(-1, nx, ny, PT_SPRK); + } + else + { + if (player2[2] == SPC_AIR) + create_parts(nx + 3*((((int)player2[1])&0x02) == 0x02) - 3*((((int)player2[1])&0x01) == 0x01), ny, 4, 4, SPC_AIR); + else + create_part(-1, nx, ny, player2[2]); + + r = pmap[ny][nx]; + if ( ((r>>8) < NPART) && (r>>8)>=0 && player2[2] != PT_PHOT && player2[2] != SPC_AIR) + parts[r>>8].vx = parts[r>>8].vx + 5*((((int)player2[1])&0x02) == 0x02) - 5*(((int)(player2[1])&0x01) == 0x01); + if (((r>>8) < NPART) && (r>>8)>=0 && player2[2] == PT_PHOT) + { + int random = abs(rand()%3-1)*3; + if (random==0) + { + parts[r>>8].life = 0; + parts[r>>8].type = PT_NONE; + } + else + { + parts[r>>8].vy = 0; + parts[r>>8].vx = (((((int)player2[1])&0x02) == 0x02) - (((int)(player2[1])&0x01) == 0x01))*random; + } + } + + } + } + } + + //Simulation of joints + d = 25/(pow((player2[3]-player2[7]), 2) + pow((player2[4]-player2[8]), 2)+25) - 0.5; //Fast distance + player2[7] -= (player2[3]-player2[7])*d; + player2[8] -= (player2[4]-player2[8])*d; + player2[3] += (player2[3]-player2[7])*d; + player2[4] += (player2[4]-player2[8])*d; + + d = 25/(pow((player2[11]-player2[15]), 2) + pow((player2[12]-player2[16]), 2)+25) - 0.5; + player2[15] -= (player2[11]-player2[15])*d; + player2[16] -= (player2[12]-player2[16])*d; + player2[11] += (player2[11]-player2[15])*d; + player2[12] += (player2[12]-player2[16])*d; + + d = 36/(pow((player2[3]-parts[i].x), 2) + pow((player2[4]-parts[i].y), 2)+36) - 0.5; + parts[i].vx -= (player2[3]-parts[i].x)*d; + parts[i].vy -= (player2[4]-parts[i].y)*d; + player2[3] += (player2[3]-parts[i].x)*d; + player2[4] += (player2[4]-parts[i].y)*d; + + d = 36/(pow((player2[11]-parts[i].x), 2) + pow((player2[12]-parts[i].y), 2)+36) - 0.5; + parts[i].vx -= (player2[11]-parts[i].x)*d; + parts[i].vy -= (player2[12]-parts[i].y)*d; + player2[11] += (player2[11]-parts[i].x)*d; + player2[12] += (player2[12]-parts[i].y)*d; + + //Side collisions checking + for (nx = -3; nx <= 3; nx++) + { + r = pmap[(int)(player2[16]-2)][(int)(player2[15]+nx)]; + if (r && pstates[r&0xFF].state != ST_GAS && pstates[r&0xFF].state != ST_LIQUID) + player2[15] -= nx; + + r = pmap[(int)(player2[8]-2)][(int)(player2[7]+nx)]; + if (r && pstates[r&0xFF].state != ST_GAS && pstates[r&0xFF].state != ST_LIQUID) + player2[7] -= nx; + } + + //Collision checks + for (ny = -2-(int)parts[i].vy; ny<=0; ny++) + { + r = pmap[(int)(player2[8]+ny)][(int)(player2[7]+0.5)]; //This is to make coding more pleasant :-) + + //For left leg + if (r && (r&0xFF)!=PT_STKM2) + { + if (pstates[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) //Liquid checks //Liquid checks + { + if (parts[i].y<(player2[8]-10)) + parts[i].vy = 1*dt; + else + parts[i].vy = 0; + if (abs(parts[i].vx)>1) + parts[i].vx *= 0.5*dt; + } + else + { + if (pstates[r&0xFF].state != ST_GAS) + { + player2[8] += ny-1; + parts[i].vy -= 0.5*parts[i].vy*dt; + } + } + player2[9] = player2[7]; + } + + r = pmap[(int)(player2[16]+ny)][(int)(player2[15]+0.5)]; + + //For right leg + if (r && (r&0xFF)!=PT_STKM2) + { + if (pstates[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) + { + if (parts[i].y<(player2[16]-10)) + parts[i].vy = 1*dt; + else + parts[i].vy = 0; + if (abs(parts[i].vx)>1) + parts[i].vx *= 0.5*dt; + } + else + { + if (pstates[r&0xFF].state != ST_GAS) + { + player2[16] += ny-1; + parts[i].vy -= 0.5*parts[i].vy*dt; + } + } + player2[17] = player2[15]; + } + + //If it falls too fast + if (parts[i].vy>=30) + { + parts[i].y -= (10+ny)*dt; + parts[i].vy = -10*dt; + } + + } + + //Keeping legs distance + if (pow((player2[7] - player2[15]), 2)<16 && pow((player2[8]-player2[16]), 2)<1) + { + player2[21] -= 0.2; + player2[25] += 0.2; + } + + if (pow((player2[3] - player2[11]), 2)<16 && pow((player2[4]-player2[12]), 2)<1) + { + player2[19] -= 0.2; + player2[23] += 0.2; + } + + //If legs touch something + r = pmap[(int)(player2[8]+0.5)][(int)(player2[7]+0.5)]; + if ((r&0xFF)==PT_SPRK && r && (r>>8)<NPART) //If on charge + { + parts[i].life -= (int)(rand()/1000)+38; + } + + if (r>0 && (r>>8)<NPART) //If hot or cold + { + if (parts[r>>8].temp>=323 || parts[r>>8].temp<=243) + { + parts[i].life -= 2; + player2[26] -= 1; + } + } + + if ((r&0xFF)==PT_ACID) //If on acid + parts[i].life -= 5; + + if ((r&0xFF)==PT_PLUT) //If on plut + parts[i].life -= 1; + + r = pmap[(int)(player2[16]+0.5)][(int)(player2[15]+0.5)]; + if ((r&0xFF)==PT_SPRK && r && (r>>8)<NPART) //If on charge + { + parts[i].life -= (int)(rand()/1000)+38; + } + + if (r>0 && (r>>8)<NPART) //If hot or cold + { + if (parts[r>>8].temp>=323 || parts[r>>8].temp<=243) + { + parts[i].life -= 2; + player2[22] -= 1; + } + } + + if ((r&0xFF)==PT_ACID) //If on acid + parts[i].life -= 5; + + if ((r&0xFF)==PT_PLUT) //If on plut + parts[i].life -= 1; + + isplayer2 = 1; + return 0; +} diff --git a/src/powder.c b/src/powder.c index 4fd4dd9..282cb3a 100644 --- a/src/powder.c +++ b/src/powder.c @@ -58,7 +58,7 @@ static void photoelectric_effect(int nx, int ny) 0 = No move/Bounce 2 = Both particles occupy the same space. */ -static int eval_move(int pt, int nx, int ny, unsigned *rr) +int eval_move(int pt, int nx, int ny, unsigned *rr) { unsigned r; @@ -125,9 +125,6 @@ static int eval_move(int pt, int nx, int ny, unsigned *rr) return 1; } -static void create_cherenkov_photon(int pp); -static void create_gain_photon(int pp); - int try_move(int i, int x, int y, int nx, int ny) { unsigned r, e; @@ -1339,11 +1336,6 @@ void update_particles_i(pixel *vid, int start, int inc) lx = parts[i].x; ly = parts[i].y; t = parts[i].type; - if (ptypes[t].update_func) - { - if (ptypes[t].update_func (i)) - goto killed; - } //printf("parts[%d].type: %d\n", i, parts[i].type); @@ -1687,9 +1679,6 @@ void update_particles_i(pixel *vid, int start, int inc) parts[i].vy = rr*sinf(rrr); create_part(i, x, y, t); } - if (t==PT_PSTE) - if (parts[i].temp>747.0f) - t = parts[i].type = PT_BRCK; if (t==PT_SPRK&&parts[i].ctype==PT_ETRD&&parts[i].life==1) { nearp = nearest_part(i, PT_ETRD); @@ -4053,804 +4042,6 @@ killed: if (parts[i].type == PT_NONE) continue; } - if (t==PT_STKM) - { - float dt = 0.9;///(FPSB*FPSB); //Delta time in square - //Tempirature handling - if (parts[i].temp<243) - parts[i].life -= 1; - if ((parts[i].temp<309.6f) && (parts[i].temp>=243)) - parts[i].temp += 1; - - //Death - if (parts[i].life<1 || death == 1 || (pv[y/CELL][x/CELL]>=4.5f && player[2] != SPC_AIR) ) //If his HP is less that 0 or there is very big wind... - { - for (r=-2; r<=1; r++) - { - create_part(-1, x+r, y-2, player[2]); - create_part(-1, x+r+1, y+2, player[2]); - create_part(-1, x-2, y+r+1, player[2]); - create_part(-1, x+2, y+r, player[2]); - } - kill_part(i); //Kill him - goto killed; - } - - parts[i].vy += -0.7*dt; //Head up! - - //Verlet integration - pp = 2*player[3]-player[5]+player[19]*dt*dt;; - player[5] = player[3]; - player[3] = pp; - pp = 2*player[4]-player[6]+player[20]*dt*dt;; - player[6] = player[4]; - player[4] = pp; - - pp = 2*player[7]-player[9]+player[21]*dt*dt;; - player[9] = player[7]; - player[7] = pp; - pp = 2*player[8]-player[10]+(player[22]+1)*dt*dt;; - player[10] = player[8]; - player[8] = pp; - - pp = 2*player[11]-player[13]+player[23]*dt*dt;; - player[13] = player[11]; - player[11] = pp; - pp = 2*player[12]-player[14]+player[24]*dt*dt;; - player[14] = player[12]; - player[12] = pp; - - pp = 2*player[15]-player[17]+player[25]*dt*dt;; - player[17] = player[15]; - player[15] = pp; - pp = 2*player[16]-player[18]+(player[26]+1)*dt*dt;; - player[18] = player[16]; - player[16] = pp; - - //Setting acceleration to 0 - player[19] = 0; - player[20] = 0; - - player[21] = 0; - player[22] = 0; - - player[23] = 0; - player[24] = 0; - - player[25] = 0; - player[26] = 0; - - //Go left - if (((int)(player[0])&0x01) == 0x01 && pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS) - { - if (pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID - && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG) - { - if (pmap[(int)(player[8]-1)][(int)(player[7])]) - { - player[21] = -3; - player[22] = -2; - player[19] = -2; - } - - if (pmap[(int)(player[16]-1)][(int)(player[15])]) - { - player[25] = -3; - player[26] = -2; - player[23] = -2; - } - } - else - { - if (pmap[(int)(player[8]-1)][(int)(player[7])]) //It should move another way in liquids - { - player[21] = -1; - player[22] = -1; - player[19] = -1; - } - - if (pmap[(int)(player[16]-1)][(int)(player[15])]) - { - player[25] = -1; - player[26] = -1; - player[23] = -1; - } - } - } - - //Go right - if (((int)(player[0])&0x02) == 0x02 && pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS) - { - if (pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID - && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG) - { - if (pmap[(int)(player[8]-1)][(int)(player[7])]) - { - player[21] = 3; - player[22] = -2; - player[19] = 2; - } - - if (pmap[(int)(player[16]-1)][(int)(player[15])]) - { - player[25] = 3; - player[26] = -2; - player[23] = 2; - } - } - else - { - if (pmap[(int)(player[8]-1)][(int)(player[7])]) - { - player[21] = 1; - player[22] = -1; - player[19] = 1; - } - - if (pmap[(int)(player[16]-1)][(int)(player[15])]) - { - player[25] = 1; - player[26] = -1; - player[23] = 1; - } - - } - } - - //Jump - if (((int)(player[0])&0x04) == 0x04 && (pstates[pmap[(int)(player[8]-0.5)][(int)(player[7])]&0xFF].state != ST_GAS || pstates[pmap[(int)(player[16]-0.5)][(int)(player[15])]&0xFF].state != ST_GAS)) - { - if (pmap[(int)(player[8]-0.5)][(int)(player[7])] || pmap[(int)(player[16]-0.5)][(int)(player[15])]) - { - parts[i].vy = -5; - player[22] -= 1; - player[26] -= 1; - } - } - - //Charge detector wall if foot inside - if (bmap[(int)(player[8]+0.5)/CELL][(int)(player[7]+0.5)/CELL]==WL_DETECT) - set_emap((int)player[7]/CELL, (int)player[8]/CELL); - if (bmap[(int)(player[16]+0.5)/CELL][(int)(player[15]+0.5)/CELL]==WL_DETECT) - set_emap((int)(player[15]+0.5)/CELL, (int)(player[16]+0.5)/CELL); - - //Searching for particles near head - for (nx = -2; nx <= 2; nx++) - for (ny = 0; ny>=-2; ny--) - { - if (!pmap[ny+y][nx+x] || (pmap[ny+y][nx+x]>>8)>=NPART) - continue; - if (ptypes[pmap[ny+y][nx+x]&0xFF].falldown!=0 || (pmap[ny+y][nx+x]&0xFF) == PT_NEUT || (pmap[ny+y][nx+x]&0xFF) == PT_PHOT) - { - player[2] = pmap[ny+y][nx+x]&0xFF; //Current element - } - if ((pmap[ny+y][nx+x]&0xFF) == PT_PLNT && parts[i].life<100) //Plant gives him 5 HP - { - if (parts[i].life<=95) - parts[i].life += 5; - else - parts[i].life = 100; - kill_part(pmap[ny+y][nx+x]>>8); - } - - if ((pmap[ny+y][nx+x]&0xFF) == PT_NEUT) - { - parts[i].life -= (102-parts[i].life)/2; - kill_part(pmap[ny+y][nx+x]>>8); - } - if (bmap[(ny+y)/CELL][(nx+x)/CELL]==WL_FAN) - player[2] = SPC_AIR; - } - - //Head position - nx = x + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01); - ny = y - 3*(player[1] == 0); - - //Spawn - if (((int)(player[0])&0x08) == 0x08) - { - ny -= 2*(rand()%2)+1; - r = pmap[ny][nx]; - if (!((r>>8)>=NPART)) - { - if (pstates[r&0xFF].state == ST_SOLID) - { - create_part(-1, nx, ny, PT_SPRK); - } - else - { - if (player[2] == SPC_AIR) - create_parts(nx + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01), ny, 4, 4, SPC_AIR); - else - create_part(-1, nx, ny, player[2]); - - r = pmap[ny][nx]; - if ( ((r>>8) < NPART) && (r>>8)>=0 && player[2] != PT_PHOT && player[2] != SPC_AIR) - parts[r>>8].vx = parts[r>>8].vx + 5*((((int)player[1])&0x02) == 0x02) - 5*(((int)(player[1])&0x01) == 0x01); - if (((r>>8) < NPART) && (r>>8)>=0 && player[2] == PT_PHOT) - { - int random = abs(rand()%3-1)*3; - if (random==0) - { - parts[r>>8].life = 0; - parts[r>>8].type = PT_NONE; - } - else - { - parts[r>>8].vy = 0; - parts[r>>8].vx = (((((int)player[1])&0x02) == 0x02) - (((int)(player[1])&0x01) == 0x01))*random; - } - } - - } - } - } - - //Simulation of joints - d = 25/(pow((player[3]-player[7]), 2) + pow((player[4]-player[8]), 2)+25) - 0.5; //Fast distance - player[7] -= (player[3]-player[7])*d; - player[8] -= (player[4]-player[8])*d; - player[3] += (player[3]-player[7])*d; - player[4] += (player[4]-player[8])*d; - - d = 25/(pow((player[11]-player[15]), 2) + pow((player[12]-player[16]), 2)+25) - 0.5; - player[15] -= (player[11]-player[15])*d; - player[16] -= (player[12]-player[16])*d; - player[11] += (player[11]-player[15])*d; - player[12] += (player[12]-player[16])*d; - - d = 36/(pow((player[3]-parts[i].x), 2) + pow((player[4]-parts[i].y), 2)+36) - 0.5; - parts[i].vx -= (player[3]-parts[i].x)*d; - parts[i].vy -= (player[4]-parts[i].y)*d; - player[3] += (player[3]-parts[i].x)*d; - player[4] += (player[4]-parts[i].y)*d; - - d = 36/(pow((player[11]-parts[i].x), 2) + pow((player[12]-parts[i].y), 2)+36) - 0.5; - parts[i].vx -= (player[11]-parts[i].x)*d; - parts[i].vy -= (player[12]-parts[i].y)*d; - player[11] += (player[11]-parts[i].x)*d; - player[12] += (player[12]-parts[i].y)*d; - - //Side collisions checking - for (nx = -3; nx <= 3; nx++) - { - r = pmap[(int)(player[16]-2)][(int)(player[15]+nx)]; - if (r && pstates[r&0xFF].state != ST_GAS && pstates[r&0xFF].state != ST_LIQUID) - player[15] -= nx; - - r = pmap[(int)(player[8]-2)][(int)(player[7]+nx)]; - if (r && pstates[r&0xFF].state != ST_GAS && pstates[r&0xFF].state != ST_LIQUID) - player[7] -= nx; - } - - //Collision checks - for (ny = -2-(int)parts[i].vy; ny<=0; ny++) - { - r = pmap[(int)(player[8]+ny)][(int)(player[7]+0.5)]; //This is to make coding more pleasant :-) - - //For left leg - if (r && (r&0xFF)!=PT_STKM) - { - if (pstates[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) //Liquid checks //Liquid checks - { - if (parts[i].y<(player[8]-10)) - parts[i].vy = 1*dt; - else - parts[i].vy = 0; - if (abs(parts[i].vx)>1) - parts[i].vx *= 0.5*dt; - } - else - { - if (pstates[r&0xFF].state != ST_GAS) - { - player[8] += ny-1; - parts[i].vy -= 0.5*parts[i].vy*dt; - } - } - player[9] = player[7]; - } - - r = pmap[(int)(player[16]+ny)][(int)(player[15]+0.5)]; - - //For right leg - if (r && (r&0xFF)!=PT_STKM) - { - if (pstates[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) - { - if (parts[i].y<(player[16]-10)) - parts[i].vy = 1*dt; - else - parts[i].vy = 0; - if (abs(parts[i].vx)>1) - parts[i].vx *= 0.5*dt; - } - else - { - if (pstates[r&0xFF].state != ST_GAS) - { - player[16] += ny-1; - parts[i].vy -= 0.5*parts[i].vy*dt; - } - } - player[17] = player[15]; - } - - //If it falls too fast - if (parts[i].vy>=30) - { - parts[i].y -= (10+ny)*dt; - parts[i].vy = -10*dt; - } - - } - - //Keeping legs distance - if (pow((player[7] - player[15]), 2)<16 && pow((player[8]-player[16]), 2)<1) - { - player[21] -= 0.2; - player[25] += 0.2; - } - - if (pow((player[3] - player[11]), 2)<16 && pow((player[4]-player[12]), 2)<1) - { - player[19] -= 0.2; - player[23] += 0.2; - } - - //If legs touch something - r = pmap[(int)(player[8]+0.5)][(int)(player[7]+0.5)]; - if ((r&0xFF)==PT_SPRK && r && (r>>8)<NPART) //If on charge - { - parts[i].life -= (int)(rand()/1000)+38; - } - - if (r>0 && (r>>8)<NPART) //If hot or cold - { - if (parts[r>>8].temp>=323 || parts[r>>8].temp<=243) - { - parts[i].life -= 2; - player[26] -= 1; - } - } - - if ((r&0xFF)==PT_ACID) //If on acid - parts[i].life -= 5; - - if ((r&0xFF)==PT_PLUT) //If on plut - parts[i].life -= 1; - - r = pmap[(int)(player[16]+0.5)][(int)(player[15]+0.5)]; - if ((r&0xFF)==PT_SPRK && r && (r>>8)<NPART) //If on charge - { - parts[i].life -= (int)(rand()/1000)+38; - } - - if (r>0 && (r>>8)<NPART) //If hot or cold - { - if (parts[r>>8].temp>=323 || parts[r>>8].temp<=243) - { - parts[i].life -= 2; - player[22] -= 1; - } - } - - if ((r&0xFF)==PT_ACID) //If on acid - parts[i].life -= 5; - - if ((r&0xFF)==PT_PLUT) //If on plut - parts[i].life -= 1; - - isplayer = 1; - } - if (t==PT_STKM2) - { - float dt = 0.9;///(FPSB*FPSB); //Delta time in square - //Tempirature handling - if (parts[i].temp<243) - parts[i].life -= 1; - if ((parts[i].temp<309.6f) && (parts[i].temp>=243)) - parts[i].temp += 1; - - //Death - if (parts[i].life<1 || death2 == 1 || (pv[y/CELL][x/CELL]>=4.5f && player2[2] != SPC_AIR) ) //If his HP is less that 0 or there is very big wind... - { - for (r=-2; r<=1; r++) - { - create_part(-1, x+r, y-2, player2[2]); - create_part(-1, x+r+1, y+2, player2[2]); - create_part(-1, x-2, y+r+1, player2[2]); - create_part(-1, x+2, y+r, player2[2]); - } - kill_part(i); //Kill him - goto killed; - } - - parts[i].vy += -0.7*dt; //Head up! - - //Verlet integration - pp = 2*player2[3]-player2[5]+player2[19]*dt*dt;; - player2[5] = player2[3]; - player2[3] = pp; - pp = 2*player2[4]-player2[6]+player2[20]*dt*dt;; - player2[6] = player2[4]; - player2[4] = pp; - - pp = 2*player2[7]-player2[9]+player2[21]*dt*dt;; - player2[9] = player2[7]; - player2[7] = pp; - pp = 2*player2[8]-player2[10]+(player2[22]+1)*dt*dt;; - player2[10] = player2[8]; - player2[8] = pp; - - pp = 2*player2[11]-player2[13]+player2[23]*dt*dt;; - player2[13] = player2[11]; - player2[11] = pp; - pp = 2*player2[12]-player2[14]+player2[24]*dt*dt;; - player2[14] = player2[12]; - player2[12] = pp; - - pp = 2*player2[15]-player2[17]+player2[25]*dt*dt;; - player2[17] = player2[15]; - player2[15] = pp; - pp = 2*player2[16]-player2[18]+(player2[26]+1)*dt*dt;; - player2[18] = player2[16]; - player2[16] = pp; - - //Setting acceleration to 0 - player2[19] = 0; - player2[20] = 0; - - player2[21] = 0; - player2[22] = 0; - - player2[23] = 0; - player2[24] = 0; - - player2[25] = 0; - player2[26] = 0; - - //Go left - if (((int)(player2[0])&0x01) == 0x01 && pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS) - { - if (pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID - && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG) - { - if (pmap[(int)(player2[8]-1)][(int)(player2[7])]) - { - player2[21] = -3; - player2[22] = -2; - player2[19] = -2; - } - - if (pmap[(int)(player2[16]-1)][(int)(player2[15])]) - { - player2[25] = -3; - player2[26] = -2; - player2[23] = -2; - } - } - else - { - if (pmap[(int)(player2[8]-1)][(int)(player2[7])]) //It should move another way in liquids - { - player2[21] = -1; - player2[22] = -1; - player2[19] = -1; - } - - if (pmap[(int)(player2[16]-1)][(int)(player2[15])]) - { - player2[25] = -1; - player2[26] = -1; - player2[23] = -1; - } - } - } - - //Go right - if (((int)(player2[0])&0x02) == 0x02 && pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS) - { - if (pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID - && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG) - { - if (pmap[(int)(player2[8]-1)][(int)(player2[7])]) - { - player2[21] = 3; - player2[22] = -2; - player2[19] = 2; - } - - if (pmap[(int)(player2[16]-1)][(int)(player2[15])]) - { - player2[25] = 3; - player2[26] = -2; - player2[23] = 2; - } - } - else - { - if (pmap[(int)(player2[8]-1)][(int)(player2[7])]) - { - player2[21] = 1; - player2[22] = -1; - player2[19] = 1; - } - - if (pmap[(int)(player2[16]-1)][(int)(player2[15])]) - { - player2[25] = 1; - player2[26] = -1; - player2[23] = 1; - } - - } - } - - //Jump - if (((int)(player2[0])&0x04) == 0x04 && (pstates[pmap[(int)(player2[8]-0.5)][(int)(player2[7])]&0xFF].state != ST_GAS || pstates[pmap[(int)(player2[16]-0.5)][(int)(player2[15])]&0xFF].state != ST_GAS)) - { - if (pmap[(int)(player2[8]-0.5)][(int)(player2[7])] || pmap[(int)(player2[16]-0.5)][(int)(player2[15])]) - { - parts[i].vy = -5; - player2[22] -= 1; - player2[26] -= 1; - } - } - - //Charge detector wall if foot inside - if (bmap[(int)(player2[8]+0.5)/CELL][(int)(player2[7]+0.5)/CELL]==WL_DETECT) - set_emap((int)player2[7]/CELL, (int)player2[8]/CELL); - if (bmap[(int)(player2[16]+0.5)/CELL][(int)(player2[15]+0.5)/CELL]==WL_DETECT) - set_emap((int)(player2[15]+0.5)/CELL, (int)(player2[16]+0.5)/CELL); - - //Searching for particles near head - for (nx = -2; nx <= 2; nx++) - for (ny = 0; ny>=-2; ny--) - { - if (!pmap[ny+y][nx+x] || (pmap[ny+y][nx+x]>>8)>=NPART) - continue; - if (ptypes[pmap[ny+y][nx+x]&0xFF].falldown!=0 || (pmap[ny+y][nx+x]&0xFF) == PT_NEUT || (pmap[ny+y][nx+x]&0xFF) == PT_PHOT) - { - player2[2] = pmap[ny+y][nx+x]&0xFF; //Current element - } - if ((pmap[ny+y][nx+x]&0xFF) == PT_PLNT && parts[i].life<100) //Plant gives him 5 HP - { - if (parts[i].life<=95) - parts[i].life += 5; - else - parts[i].life = 100; - kill_part(pmap[ny+y][nx+x]>>8); - } - - if ((pmap[ny+y][nx+x]&0xFF) == PT_NEUT) - { - parts[i].life -= (102-parts[i].life)/2; - kill_part(pmap[ny+y][nx+x]>>8); - } - if (bmap[(ny+y)/CELL][(nx+x)/CELL]==WL_FAN) - player2[2] = SPC_AIR; - } - - //Head position - nx = x + 3*((((int)player2[1])&0x02) == 0x02) - 3*((((int)player2[1])&0x01) == 0x01); - ny = y - 3*(player2[1] == 0); - - //Spawn - if (((int)(player2[0])&0x08) == 0x08) - { - ny -= 2*(rand()%2)+1; - r = pmap[ny][nx]; - if (!((r>>8)>=NPART)) - { - if (pstates[r&0xFF].state == ST_SOLID) - { - create_part(-1, nx, ny, PT_SPRK); - } - else - { - if (player2[2] == SPC_AIR) - create_parts(nx + 3*((((int)player2[1])&0x02) == 0x02) - 3*((((int)player2[1])&0x01) == 0x01), ny, 4, 4, SPC_AIR); - else - create_part(-1, nx, ny, player2[2]); - - r = pmap[ny][nx]; - if ( ((r>>8) < NPART) && (r>>8)>=0 && player2[2] != PT_PHOT && player2[2] != SPC_AIR) - parts[r>>8].vx = parts[r>>8].vx + 5*((((int)player2[1])&0x02) == 0x02) - 5*(((int)(player2[1])&0x01) == 0x01); - if (((r>>8) < NPART) && (r>>8)>=0 && player2[2] == PT_PHOT) - { - int random = abs(rand()%3-1)*3; - if (random==0) - { - parts[r>>8].life = 0; - parts[r>>8].type = PT_NONE; - } - else - { - parts[r>>8].vy = 0; - parts[r>>8].vx = (((((int)player2[1])&0x02) == 0x02) - (((int)(player2[1])&0x01) == 0x01))*random; - } - } - - } - } - } - - //Simulation of joints - d = 25/(pow((player2[3]-player2[7]), 2) + pow((player2[4]-player2[8]), 2)+25) - 0.5; //Fast distance - player2[7] -= (player2[3]-player2[7])*d; - player2[8] -= (player2[4]-player2[8])*d; - player2[3] += (player2[3]-player2[7])*d; - player2[4] += (player2[4]-player2[8])*d; - - d = 25/(pow((player2[11]-player2[15]), 2) + pow((player2[12]-player2[16]), 2)+25) - 0.5; - player2[15] -= (player2[11]-player2[15])*d; - player2[16] -= (player2[12]-player2[16])*d; - player2[11] += (player2[11]-player2[15])*d; - player2[12] += (player2[12]-player2[16])*d; - - d = 36/(pow((player2[3]-parts[i].x), 2) + pow((player2[4]-parts[i].y), 2)+36) - 0.5; - parts[i].vx -= (player2[3]-parts[i].x)*d; - parts[i].vy -= (player2[4]-parts[i].y)*d; - player2[3] += (player2[3]-parts[i].x)*d; - player2[4] += (player2[4]-parts[i].y)*d; - - d = 36/(pow((player2[11]-parts[i].x), 2) + pow((player2[12]-parts[i].y), 2)+36) - 0.5; - parts[i].vx -= (player2[11]-parts[i].x)*d; - parts[i].vy -= (player2[12]-parts[i].y)*d; - player2[11] += (player2[11]-parts[i].x)*d; - player2[12] += (player2[12]-parts[i].y)*d; - - //Side collisions checking - for (nx = -3; nx <= 3; nx++) - { - r = pmap[(int)(player2[16]-2)][(int)(player2[15]+nx)]; - if (r && pstates[r&0xFF].state != ST_GAS && pstates[r&0xFF].state != ST_LIQUID) - player2[15] -= nx; - - r = pmap[(int)(player2[8]-2)][(int)(player2[7]+nx)]; - if (r && pstates[r&0xFF].state != ST_GAS && pstates[r&0xFF].state != ST_LIQUID) - player2[7] -= nx; - } - - //Collision checks - for (ny = -2-(int)parts[i].vy; ny<=0; ny++) - { - r = pmap[(int)(player2[8]+ny)][(int)(player2[7]+0.5)]; //This is to make coding more pleasant :-) - - //For left leg - if (r && (r&0xFF)!=PT_STKM2) - { - if (pstates[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) //Liquid checks //Liquid checks - { - if (parts[i].y<(player2[8]-10)) - parts[i].vy = 1*dt; - else - parts[i].vy = 0; - if (abs(parts[i].vx)>1) - parts[i].vx *= 0.5*dt; - } - else - { - if (pstates[r&0xFF].state != ST_GAS) - { - player2[8] += ny-1; - parts[i].vy -= 0.5*parts[i].vy*dt; - } - } - player2[9] = player2[7]; - } - - r = pmap[(int)(player2[16]+ny)][(int)(player2[15]+0.5)]; - - //For right leg - if (r && (r&0xFF)!=PT_STKM2) - { - if (pstates[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) - { - if (parts[i].y<(player2[16]-10)) - parts[i].vy = 1*dt; - else - parts[i].vy = 0; - if (abs(parts[i].vx)>1) - parts[i].vx *= 0.5*dt; - } - else - { - if (pstates[r&0xFF].state != ST_GAS) - { - player2[16] += ny-1; - parts[i].vy -= 0.5*parts[i].vy*dt; - } - } - player2[17] = player2[15]; - } - - //If it falls too fast - if (parts[i].vy>=30) - { - parts[i].y -= (10+ny)*dt; - parts[i].vy = -10*dt; - } - - } - - //Keeping legs distance - if (pow((player2[7] - player2[15]), 2)<16 && pow((player2[8]-player2[16]), 2)<1) - { - player2[21] -= 0.2; - player2[25] += 0.2; - } - - if (pow((player2[3] - player2[11]), 2)<16 && pow((player2[4]-player2[12]), 2)<1) - { - player2[19] -= 0.2; - player2[23] += 0.2; - } - - //If legs touch something - r = pmap[(int)(player2[8]+0.5)][(int)(player2[7]+0.5)]; - if ((r&0xFF)==PT_SPRK && r && (r>>8)<NPART) //If on charge - { - parts[i].life -= (int)(rand()/1000)+38; - } - - if (r>0 && (r>>8)<NPART) //If hot or cold - { - if (parts[r>>8].temp>=323 || parts[r>>8].temp<=243) - { - parts[i].life -= 2; - player2[26] -= 1; - } - } - - if ((r&0xFF)==PT_ACID) //If on acid - parts[i].life -= 5; - - if ((r&0xFF)==PT_PLUT) //If on plut - parts[i].life -= 1; - - r = pmap[(int)(player2[16]+0.5)][(int)(player2[15]+0.5)]; - if ((r&0xFF)==PT_SPRK && r && (r>>8)<NPART) //If on charge - { - parts[i].life -= (int)(rand()/1000)+38; - } - - if (r>0 && (r>>8)<NPART) //If hot or cold - { - if (parts[r>>8].temp>=323 || parts[r>>8].temp<=243) - { - parts[i].life -= 2; - player2[22] -= 1; - } - } - - if ((r&0xFF)==PT_ACID) //If on acid - parts[i].life -= 5; - - if ((r&0xFF)==PT_PLUT) //If on plut - parts[i].life -= 1; - - isplayer2 = 1; - } - if (t==PT_SPAWN) - { - if (death==1) - { - playerspawn = create_part(-1,x,y,PT_STKM); - isplayer = 1; - } - death = 0; - } - if (t==PT_SPAWN2) - { - if (death2==1) - { - player2spawn = create_part(-1,x,y,PT_STKM2); - isplayer2 = 1; - } - death2 = 0; - } if (t==PT_CLNE) { if (!parts[i].ctype) @@ -4895,47 +4086,6 @@ killed: } } - if (parts[i].type==PT_PCLN) - { - if (!parts[i].ctype) - for (nx=-1; nx<2; nx++) - for (ny=-1; ny<2; ny++) - if (x+nx>=0 && y+ny>0 && - x+nx<XRES && y+ny<YRES && - pmap[y+ny][x+nx] && - (pmap[y+ny][x+nx]&0xFF)!=PT_CLNE && - (pmap[y+ny][x+nx]&0xFF)!=PT_PCLN && - (pmap[y+ny][x+nx]&0xFF)!=PT_BCLN && - (pmap[y+ny][x+nx]&0xFF)!=PT_SPRK && - (pmap[y+ny][x+nx]&0xFF)!=PT_NSCN && - (pmap[y+ny][x+nx]&0xFF)!=PT_PSCN && - (pmap[y+ny][x+nx]&0xFF)!=PT_STKM && - (pmap[y+ny][x+nx]&0xFF)!=PT_STKM2 && - (pmap[y+ny][x+nx]&0xFF)!=0xFF) - parts[i].ctype = pmap[y+ny][x+nx]&0xFF; - if (parts[i].ctype && parts[i].life==10) { - if (parts[i].ctype==PT_PHOT) { - for (nx=-1; nx<2; nx++) { - for (ny=-1; ny<2; ny++) { - r = create_part(-1, x+nx, y+ny, parts[i].ctype); - if (r!=-1) { - parts[r].vx = nx*3; - parts[r].vy = ny*3; - } - } - } - } - else if (ptypes[parts[i].ctype].properties&PROP_LIFE) { - for (nx=-1; nx<2; nx++) { - for (ny=-1; ny<2; ny++) { - create_part(-1, x+nx, y+ny, parts[i].ctype); - } - } - } else { - create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype); - } - } - } if (t==PT_YEST) { if (parts[i].temp>303&&parts[i].temp<317) { @@ -4965,6 +4115,12 @@ killed: continue; } + if (ptypes[t].update_func) + { + if ((*(ptypes[t].update_func))(i,x,y,nx,ny,lx,ly)) + continue; + } + if (parts[i].type == PT_PHOT) { rt = pmap[ny][nx] & 0xFF; |
