git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@858 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
driAn
2007-03-23 20:44:17 +00:00
parent 8a6d454761
commit c423ba443e
3 changed files with 67 additions and 66 deletions
+40 -45
View File
@@ -159,50 +159,6 @@ bool collide(physent *d, bool spawn, float drop, float rise)
return true;
}
inline void detectcollision(physent *pl, vec &d, int moveres, float drop, float rise)
{
const float f = 1.0f/moveres;
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;
if(pl->type==ENT_CAMERA) return;
// player stuck, try slide along y axis
pl->o.x -= f*d.x;
if(collide(pl, false, drop, rise))
{
d.x = 0;
if(pl->type==ENT_BOUNCE) { pl->vel.x = -pl->vel.x; pl->vel.mul(0.7f); }
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->type==ENT_BOUNCE) { pl->vel.y = -pl->vel.y; pl->vel.mul(0.7f); }
continue;
};
pl->o.y += f*d.y;
// try just dropping down
pl->o.x -= f*d.x;
pl->o.y -= f*d.y;
if(collide(pl, false, drop, rise))
{
d.y = d.x = 0;
continue;
};
pl->o.z -= f*d.z;
if(pl->type==ENT_BOUNCE) { pl->vel.z = -pl->vel.z; pl->vel.mul(0.5f); }
break;
};
};
VARP(maxroll, 0, 0, 20);
// main physics routine, moves a player/monster for a curtime step
@@ -320,7 +276,46 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime)
rise = speed/moveres/1.2f; // extra smoothness when lifting up stairs
};
detectcollision(pl, d, moveres, drop, rise);
const float f = 1.0f/moveres;
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;
if(pl->type==ENT_CAMERA) return;
// player stuck, try slide along y axis
pl->o.x -= f*d.x;
if(collide(pl, false, drop, rise))
{
d.x = 0;
if(pl->type==ENT_BOUNCE) { pl->vel.x = -pl->vel.x; pl->vel.mul(0.7f); }
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->type==ENT_BOUNCE) { pl->vel.y = -pl->vel.y; pl->vel.mul(0.7f); }
continue;
};
pl->o.y += f*d.y;
// try just dropping down
pl->o.x -= f*d.x;
pl->o.y -= f*d.y;
if(collide(pl, false, drop, rise))
{
d.y = d.x = 0;
continue;
};
pl->o.z -= f*d.z;
if(pl->type==ENT_BOUNCE) { pl->vel.z = -pl->vel.z; pl->vel.mul(0.5f); }
break;
};
if(pl->type==ENT_CAMERA) return;
else if(pl->type!=ENT_BOUNCE)
+18 -14
View File
@@ -606,7 +606,7 @@ void renderbounceents()
{
t -= p->timetolife-2000;
z -= t*t/4000000000.0f*t;
}
};
break;
};
};
@@ -617,7 +617,7 @@ void renderbounceents()
VARP(gibnum, 0, 6, 1000);
VARP(gibttl, 0, 5000, 15000);
VARP(gibspeed, 1, 5, 20);
VARP(gibspeed, 1, 30, 100);
void addgib(playerent *d)
{
@@ -630,27 +630,31 @@ void addgib(playerent *d)
p->owner = d;
p->millis = lastmillis;
p->timetolife = gibttl+rnd(10)*100;
p->bouncestate = GIB;
p->gravity = 20;
p->o = d->o;
p->o.z -= d->aboveeye;
float gibvelangle = (float) rnd(360);
float speed = (float) gibspeed;
p->vel.x = sinf(gibvelangle)*speed*rnd(1000)/1000.0f;
p->vel.y = cosf(gibvelangle)*speed*rnd(1000)/1000.0f;
p->vel.z = speed*rnd(1000)/1000.0f;
p->vel.div(10.0f);
p->yaw = (float)rnd(360);
p->pitch = (float)rnd(360);
p->yaw = (float)rnd(360);
p->pitch = (float)rnd(360);
p->rotspeed = 3.0f;
p->maxspeed = 30.0f;
p->rotspeed = 3.0f;
const float angle = (float)rnd(360);
const float speed = (float)gibspeed;
p->vel.x = sinf(RAD*angle)*rnd(1000)/1000.0f;
p->vel.y = cosf(RAD*angle)*rnd(1000)/1000.0f;
p->vel.z = rnd(1000)/1000.0f;
p->vel.mul(gibspeed/100.0f);
};
};
// fixme
void gibtest() { playerent t = *player1; t.o.x = worldpos.x; t.o.y = worldpos.y; addgib(&t); }
COMMAND(gibtest, ARG_NONE);
void loadingscreen()
{
static Texture *logo = NULL;
+9 -7
View File
@@ -360,7 +360,6 @@ void throw_nade(playerent *d, const vec &vel, bounceent *p)
p->bouncestate = NADE_THROWED;
d->thrownademillis = lastmillis;
d->inhandnade = NULL;
if(d==player1)
@@ -374,16 +373,17 @@ void throw_nade(playerent *d, bounceent *p)
{
if(!d || !p) return;
float speed = cosf(RAD*d->pitch);
vec vel;
vel.z = sinf(RAD*d->pitch);
vel.x = sinf(RAD*d->yaw)*speed;
vel.y = -cosf(RAD*d->yaw)*speed;
vel.mul(1.7f);
const float speed = cosf(RAD*d->pitch);
vec vel(sinf(RAD*d->yaw)*speed, -cosf(RAD*d->yaw)*speed, sinf(RAD*d->pitch));
vel.mul(1.5f);
throw_nade(d, vel, p);
};
// fixme
VAR(grenadespeed, 0, 27, 100);
VAR(grenaderot, 0, 60, 100);
bounceent *new_nade(playerent *d, int millis = 0)
{
bounceent *p = newbounceent();
@@ -391,6 +391,8 @@ bounceent *new_nade(playerent *d, int millis = 0)
p->millis = lastmillis;
p->timetolife = 2000-millis;
p->bouncestate = NADE_ACTIVATED;
p->maxspeed = (float)grenadespeed;
p->rotspeed = grenaderot/10.0f;
d->inhandnade = p;
d->thrownademillis = 0;