860 |
double r1 = a1.radius; |
double r1 = a1.radius; |
861 |
double m1 = a1.mass; |
double m1 = a1.mass; |
862 |
|
|
|
if (!actor1->is_on_floor() || actor1->is_dead()) |
|
|
return; |
|
|
|
|
863 |
unsigned s=level->actorlist.size(); |
unsigned s=level->actorlist.size(); |
864 |
for (unsigned j=0; j<s; ++j) |
for (unsigned j=0; j<s; ++j) |
865 |
{ |
{ |
867 |
if (actor2 == actor1) |
if (actor2 == actor1) |
868 |
continue; |
continue; |
869 |
|
|
|
if (!actor2->is_on_floor() || actor2->is_dead()) |
|
|
continue; |
|
|
|
|
870 |
|
|
871 |
ActorInfo &a2 = *actor2->get_actorinfo(); |
ActorInfo &a2 = *actor2->get_actorinfo(); |
872 |
V2 p2 = a2.pos; |
V2 p2 = a2.pos; |
882 |
a1.pos = a1.oldpos; // Reset actor position |
a1.pos = a1.oldpos; // Reset actor position |
883 |
|
|
884 |
bool collisionp = (v2-v1)*(p2-p1) < 0; |
bool collisionp = (v2-v1)*(p2-p1) < 0; |
885 |
|
bool reboundp = (!actor1->is_dead() && !actor2->is_dead() && |
886 |
|
(actor1->is_on_floor() == actor2->is_on_floor())); |
887 |
|
// if (!actor1->is_on_floor() || actor1->is_dead()) |
888 |
|
// return; |
889 |
|
|
890 |
|
// if (!actor2->is_on_floor() || actor2->is_dead()) |
891 |
|
// continue; |
892 |
|
|
893 |
if (collisionp) { |
if (collisionp) { |
894 |
double m2 = a2.mass; |
double m2 = a2.mass; |
895 |
double M = m1+m2; |
double M = m1+m2; |
898 |
|
|
899 |
actor1->on_hit(actor2); |
actor1->on_hit(actor2); |
900 |
actor2->on_hit(actor1); |
actor2->on_hit(actor1); |
901 |
|
|
902 |
a1.vel += -v1 + (v2*(2*m2) + v1*(m1-m2)) / M; |
if (reboundp) { |
903 |
a2.vel += -v2 + (v1*(2*m1) + v2*(m2-m1)) / M; |
a1.vel += -v1 + (v2*(2*m2) + v1*(m1-m2)) / M; |
904 |
|
a2.vel += -v2 + (v1*(2*m1) + v2*(m2-m1)) / M; |
905 |
a1.vel *= restitution; |
|
906 |
a2.vel *= restitution; |
a1.vel *= restitution; |
907 |
sound::PlaySound("ballcollision"); |
a2.vel *= restitution; |
908 |
|
sound::PlaySound("ballcollision"); |
909 |
|
} |
910 |
} |
} |
911 |
} |
} |
912 |
} |
} |
954 |
dt = dt > rest_time? rest_time : dt; |
dt = dt > rest_time? rest_time : dt; |
955 |
} |
} |
956 |
} |
} |
|
a->think(dtime); |
|
957 |
} |
} |
958 |
|
|
959 |
|
|
1637 |
ai->forceacc = V2(); |
ai->forceacc = V2(); |
1638 |
tick_actor(*i, timestep); |
tick_actor(*i, timestep); |
1639 |
} |
} |
1640 |
|
(*i)->think(timestep); |
1641 |
} |
} |
1642 |
|
|
1643 |
// Handle delayed impulses |
// Handle delayed impulses |