aboutsummaryrefslogtreecommitdiff
path: root/src/GameTick.cpp
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2022-02-06 16:07:23 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2022-02-06 16:07:23 +0700
commit43c7739c47cee57e2bab1f431cf77e11ac728354 (patch)
treedbe558441c18ab9fcc0c6d7abce3f1c45b695cd6 /src/GameTick.cpp
parent9b7b654741f769866d51d5db00b2ae7da214f2e5 (diff)
downloadblackshades-43c7739c47cee57e2bab1f431cf77e11ac728354.tar.gz
Move tackling to separate function
Diffstat (limited to 'src/GameTick.cpp')
-rw-r--r--src/GameTick.cpp69
1 files changed, 35 insertions, 34 deletions
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index a096f9a..b380202 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -703,6 +703,39 @@ void attackCloseRange(Game* game, XYZ flatfacing)
}
}
+void tackle(Game* game, XYZ flatfacing)
+{
+ auto& player = game->person[0];
+ for (int i = 1; i < game->numpeople; ++i) {
+ auto& person = game->person[i];
+ if (person.skeleton.free > 0
+ || findDistancefast(person.playercoords,
+ player.playercoords + flatfacing) > 22)
+ continue;
+
+ float gLoc[] {
+ flatfacing.x / soundscalefactor / 2,
+ flatfacing.y / soundscalefactor / 2,
+ flatfacing.z / soundscalefactor / 2,
+ };
+ alSourcefv(gSourceID[headwhacksound], AL_POSITION, gLoc);
+ alSourcePlay(gSourceID[headwhacksound]);
+ person.skeleton.free = true;
+ person.longdead = 1;
+
+ for (auto& joint : person.skeleton.joints) {
+ joint.position = person.playercoords
+ + DoRotation(joint.position,
+ 0, person.playerrotation, 0);
+ joint.realoldposition = joint.position;
+ joint.velocity = player.velocity;
+ joint.velocity.x += randInt(-4, 4);
+ joint.velocity.y = randInt(-4, 4) - 10;
+ joint.velocity.z += randInt(-4, 4);
+ }
+ }
+}
+
void Game::Tick()
{
if (person[1].health <= 0 || person[0].health <= 0 || killedinnocent)
@@ -1416,40 +1449,8 @@ void Game::Tick()
}
attackCloseRange(this, flatfacing);
-
- //Tackle
- if (person[0].currentanimation == diveanim && visions == 0) {
- for (int i = 1; i < numpeople; i++) {
- if (person[i].skeleton.free > 0
- || findDistancefast(person[i].playercoords,
- person[0].playercoords
- + flatfacing) > 22)
- continue;
-
- float gLoc[] {
- flatfacing.x / soundscalefactor / 2,
- flatfacing.y / soundscalefactor / 2,
- flatfacing.z / soundscalefactor / 2,
- };
-
- alSourcefv(gSourceID[headwhacksound],
- AL_POSITION, gLoc);
- alSourcePlay(gSourceID[headwhacksound]);
- person[i].skeleton.free = 1;
- person[i].longdead = 1;
-
- for (auto& joint : person[i].skeleton.joints) {
- joint.position = DoRotation(joint.position, 0, person[i].playerrotation, 0);
- joint.position += person[i].playercoords;
- joint.realoldposition = joint.position;
- joint.velocity = person[0].velocity;
- joint.velocity.y = -10;
- joint.velocity.x += randInt(-4, 4);
- joint.velocity.y += randInt(-4, 4);
- joint.velocity.z += randInt(-4, 4);
- }
- }
- }
+ if (person[0].currentanimation == diveanim && visions == 0)
+ tackle(this, flatfacing);
// Empty magazine
if (person[0].firing && person[0].ammo <= 0) {