git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@102 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
driAn
2006-01-08 13:38:30 +00:00
parent 679ba2ef64
commit a2346e9584
19 changed files with 1975 additions and 1917 deletions
+61 -62
View File
@@ -132,9 +132,9 @@ bool collide(dynent *d, bool spawn, float drop, float rise)
const float space = d->o.z-d->eyeheight-lo;
if(space<0)
{
if(space>-0.01)
{
d->o.z = lo+d->eyeheight; // stick on step
if(space>-0.01)
{
d->o.z = lo+d->eyeheight; // stick on step
}
else if(space>-1.26f) d->o.z += rise; // rise thru stair
else return false;
@@ -200,7 +200,7 @@ void moveplayer(dynent *pl, int moveres, bool local, int curtime)
d.x = (float)(pl->move*cos(rad(pl->yaw-90)));
d.y = (float)(pl->move*sin(rad(pl->yaw-90)));
d.z = (float) pl->bounce ? pl->vel.z : 0;
d.z = (float) pl->bounce ? pl->vel.z : 0;
if(floating || water)
{
@@ -249,8 +249,8 @@ void moveplayer(dynent *pl, int moveres, bool local, int curtime)
if(pl->jumpnext)
{
pl->jumpnext = false;
pl->vel.z = 1.7f; // physics impulse upwards
pl->jumpnext = false;
pl->vel.z = 1.7f; // physics impulse upwards
if(water) { pl->vel.x /= 8; pl->vel.y /= 8; }; // dampen velocity change even harder, gives correct water feel
if(local) playsoundc(S_JUMP);
else if(pl->monsterstate) playsound(S_JUMP, &pl->o);
@@ -260,7 +260,7 @@ void moveplayer(dynent *pl, int moveres, bool local, int curtime)
if(local) playsoundc(S_LAND);
else if(pl->monsterstate) playsound(S_LAND, &pl->o);
};
pl->timeinair = 0;
pl->timeinair = 0;
if(pl->bounce) pl->vel.z *= 0.7f;
}
else
@@ -270,11 +270,10 @@ void moveplayer(dynent *pl, int moveres, bool local, int curtime)
const float gravity = pl->bounce ? pl->gravity : 20;
const float f = 1.0f/moveres;
float dropf = ((gravity-1)+pl->timeinair/15.0f); // incorrect, but works fine
float dropf = pl->bounce ? ((gravity-1)+pl->timeinair/14.0f) : ((gravity-1)+pl->timeinair/15.0f); // incorrect, but works fine
if(water) { dropf = 5; pl->timeinair = 0; }; // float slowly down in water
const float drop = dropf*curtime/gravity/100/moveres; // at high fps, gravity kicks in too fast
const float rise = speed/moveres/1.2f; // extra smoothness when lifting up stairs
float drop = dropf*curtime/gravity/100/moveres; // at high fps, gravity kicks in too fast
const float rise = speed/moveres/1.2f; // extra smoothness when lifting up stairs␍
loopi(moveres) // discrete steps collision detection & sliding
{
// try move forward
@@ -285,30 +284,30 @@ void moveplayer(dynent *pl, int moveres, bool local, int curtime)
// player stuck, try slide along y axis
pl->blocked = true;
pl->o.x -= f*d.x;
if(collide(pl, false, drop, rise))
{
d.x = 0;
if(pl->bounce) pl->vel.x = -pl->vel.x;
continue;
if(collide(pl, false, drop, rise))
{
d.x = 0;
if(pl->bounce) pl->vel.x = -pl->vel.x;
continue;
};
pl->o.x += f*d.x;
// still stuck, try x axis
pl->o.y -= f*d.y;
if(collide(pl, false, drop, rise))
{
d.y = 0;
if(pl->bounce) pl->vel.y = -pl->vel.y;
continue;
if(collide(pl, false, drop, rise))
{
d.y = 0;
if(pl->bounce) pl->vel.y = -pl->vel.y;
continue;
};
pl->o.y += f*d.y;
// try just dropping down
pl->moving = false;
pl->o.x -= f*d.x;
pl->o.y -= f*d.y;
if(collide(pl, false, drop, rise))
{
d.y = d.x = 0;
continue;
if(collide(pl, false, drop, rise))
{
d.y = d.x = 0;
continue;
};
pl->o.z -= f*d.z;
break;
@@ -347,27 +346,27 @@ void moveplayer(dynent *pl, int moveres, bool local, int curtime)
if(!pl->inwater && water) { playsound(S_SPLASH2, &pl->o); pl->vel.z = 0; }
else if(pl->inwater && !water) playsound(S_SPLASH1, &pl->o);
pl->inwater = water;
};
};
void moveplayer(dynent *pl, int moveres, bool local)
{
loopi(physicsrepeat) moveplayer(pl, moveres, local, i ? curtime/physicsrepeat : curtime-curtime/physicsrepeat*(physicsrepeat-1));
};
void movephysent(physent *pl)
{
int moveres = 2;
bool local=true;
loopj(physicsrepeat)
void movephysent(physent *pl)
{
int moveres = 2;
bool local=true;
loopj(physicsrepeat)
{
const bool water = hdr.waterlevel>pl->o.z-0.5f;
const bool water = hdr.waterlevel>pl->o.z-0.5f;
const bool floating = (editmode && local);
vec d; // vector of direction we ideally want to move in
d = pl->vel;
d = pl->vel;
const float speed = curtime/(water ? 2000.0f : 1000.0f)*pl->maxspeed;
const float friction = water ? 20.0f : (pl->onfloor || floating ? 6.0f : 30.0f);
@@ -377,7 +376,7 @@ void movephysent(physent *pl)
vadd(pl->vel, d);
vdiv(pl->vel, fpsfric);
d = pl->vel;
vmul(d, speed); // d is now frametime based velocity vector
vmul(d, speed); // d is now frametime based velocity vector
/* if(floating || water)
@@ -386,7 +385,7 @@ void movephysent(physent *pl)
d.y *= (float)cos(rad(pl->pitch));
d.z = (float)(pl->move*sin(rad(pl->pitch)));
};*/
/*if(pl->onfloor || water)
{
if(pl->jumpnext)
@@ -406,33 +405,33 @@ void movephysent(physent *pl)
else
{
pl->timeinair += curtime;
};*/
if(pl->onfloor)
{
pl->timeinair = 0;
vmul(pl->vel, 0.8f);
}
else
{
pl->timeinair += curtime;
pl->pitch = (lastmillis-pl->millis) % 360;
pl->yaw = pl->pitch;
};
};*/
if(pl->onfloor)
{
pl->timeinair = 0;
vmul(pl->vel, 0.8f);
}
else
{
pl->timeinair += curtime;
pl->pitch = (lastmillis-pl->millis) % 360;
pl->yaw = pl->pitch;
};
//const float speed = curtime/(water ? 2000.0f : 1000.0f)*pl->maxspeed;
const float gravity = 20;
const float f = 1.0f/moveres;
float dropf = pl->timeinair/15.0f; // incorrect, but works fine
if(water) { dropf = 5; pl->timeinair = 0; }; // float slowly down in water
const float drop = dropf*curtime/gravity/100/moveres; // at high fps, gravity kicks in too fast
const float rise = speed/moveres/1.2f; // extra smoothness when lifting up stairs
// if(pl->mtype = M_NADE)printf("%i\n", pl->onfloor);
/* d.x -= d.x/50.0f*curtime;
d.y -= d.y/50.0f*curtime;*/
// if(pl->mtype = M_NADE)printf("%i\n", pl->onfloor);
/* d.x -= d.x/50.0f*curtime;
d.y -= d.y/50.0f*curtime;*/
loopi(moveres) // discrete steps collision detection & sliding
{
@@ -460,8 +459,8 @@ void movephysent(physent *pl)
};
// detect wether player is outside map, used for skipping zbuffer clear mostly
if(pl->o.x < 0 || pl->o.x >= ssize || pl->o.y <0 || pl->o.y > ssize)
{
@@ -479,6 +478,6 @@ void movephysent(physent *pl)
if(!pl->inwater && water) { playsound(S_SPLASH2, &pl->o); pl->vel.z = 0; }
else if(pl->inwater && !water) playsound(S_SPLASH1, &pl->o);
pl->inwater = water;
};
pl->inwater = water;
};
};