*** empty log message ***

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@77 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
driAn
2005-10-27 23:32:52 +00:00
parent 123b2f08c0
commit b113d0e05b
10 changed files with 315 additions and 33 deletions
+139 -11
View File
@@ -116,7 +116,7 @@ bool collide(dynent *d, bool spawn, float drop, float rise)
if(!o || o==d) continue;
if(!plcollide(d, o, headspace)) return false;
};
if(d!=player1) if(!plcollide(d, player1, headspace)) return false;
if(d!=player1 && d->mtype!=M_NADE) if(!plcollide(d, player1, headspace)) return false;
headspace -= 0.01f;
mmcollide(d, hi, lo); // collide with map models
@@ -232,22 +232,22 @@ void moveplayer(dynent *pl, int moveres, bool local, int curtime)
{
if(pl->onfloor || water)
{
if (pl->onfloor || !pl->vel.z)
{
if (pl->onfloor || !pl->vel.z)
{
int damage = (int)pl->startheight - (int)pl->o.z;
if (damage > 8 && local) //try adding "&& local" if falling not fixed
{
selfdamage(damage,-1,pl);
demodamage(damage, player1->o);
playsound(S_FALL1+rnd(2), &pl->o);
if (damage > 8 && local) //try adding "&& local" if falling not fixed
{
selfdamage(damage,-1,pl);
demodamage(damage, player1->o);
playsound(S_FALL1+rnd(2), &pl->o);
};
pl->startheight=pl->o.z;
};
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);
@@ -329,10 +329,138 @@ 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)
{
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;
const float speed = curtime/(water ? 2000.0f : 1000.0f)*pl->maxspeed;
const float friction = water ? 20.0f : (pl->onfloor || floating ? 6.0f : 30.0f);
const float fpsfric = friction/curtime*20.0f;
vmul(pl->vel, fpsfric-1); // slowly apply friction and direction to velocity, gives a smooth movement
vadd(pl->vel, d);
vdiv(pl->vel, fpsfric);
d = pl->vel;
vmul(d, speed); // d is now frametime based velocity vector
/* if(floating || water)
{
d.x *= (float)cos(rad(pl->pitch));
d.y *= (float)cos(rad(pl->pitch));
d.z = (float)(pl->move*sin(rad(pl->pitch)));
};*/
/*if(pl->onfloor || water)
{
if(pl->jumpnext)
{
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->timeinair>800) // if we land after long time must have been a high jump, make thud sound
{
//if(local) playsoundc(S_LAND);
//else if(pl->monsterstate) playsound(S_LAND, &pl->o);
};
pl->timeinair = 0;
}
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;
};
//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;*/
loopi(moveres) // discrete steps collision detection & sliding
{
// try move forward
pl->o.x += f*d.x;
pl->o.y += f*d.y;
pl->o.z += f*d.z;
if(collide(pl, false, drop, rise)) continue;
// player stuck, try slide along y axis
pl->blocked = true;
pl->o.x -= f*d.x;
if(collide(pl, false, drop, rise)) { pl->vel.x = -d.x; vmul(pl->vel, 0.8f); d.x = 0; continue; };
pl->o.x += f*d.x;
// still stuck, try x axis
pl->o.y -= f*d.y;
if(collide(pl, false, drop, rise)) { pl->vel.y = -d.y; vmul(pl->vel, 0.8f); d.y = 0; 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; vmul(pl->vel, 0.8f); continue; };
pl->o.z -= f*d.z;
break;
};
// 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)
{
pl->outsidemap = true;
}
else
{
sqr *s = S((int)pl->o.x, (int)pl->o.y);
pl->outsidemap = SOLID(s)
|| pl->o.z < s->floor - (s->type==FHF ? s->vdelta/4 : 0)
|| pl->o.z > s->ceil + (s->type==CHF ? s->vdelta/4 : 0);
};
// play sounds on water transitions
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;
};
};