diff options
author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-12-11 22:00:15 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-12-11 22:03:54 +0700 |
commit | 521320a29e168396e8812b3acf1cf9d3e287537c (patch) | |
tree | f9a59adc680061bc30623d150c9b86565f96512e /src/GameTick.cpp | |
parent | f4076dc5d99a4f6d590c27d7089492ff40a7abcd (diff) | |
download | blackshades-2.4.6.tar.gz |
Covert misc Game methods to C 2.4.6
Diffstat (limited to 'src/GameTick.cpp')
-rw-r--r-- | src/GameTick.cpp | 115 |
1 files changed, 52 insertions, 63 deletions
diff --git a/src/GameTick.cpp b/src/GameTick.cpp index c4fff12..cd206ae 100644 --- a/src/GameTick.cpp +++ b/src/GameTick.cpp @@ -46,28 +46,34 @@ extern Decals decals; #define maxfallvel 40 -void Game::Splat(int k) +void Splat(Game* game, int k) { if (k && visions) return; - auto& skeleton = person[k].skeleton; + auto& person = game->person[k]; + if (person.velocity.y > -maxfallvel) { + person.velocity.y = 0; + return; + } + + auto& skeleton = person.skeleton; skeleton.free = 1; skeleton.offset = 0; - person[k].health = 0; - person[k].longdead = person[k].bleeding = person[k].bleeddelay = 1; - person[k].DoAnimations(k); + person.health = 0; + person.longdead = person.bleeding = person.bleeddelay = 1; + person.DoAnimations(k); auto& joints = skeleton.joints; auto& head_joint = joints[head]; - person[k].bjoint1 = &head_joint; - person[k].bjoint2 = joints + neck; + person.bjoint1 = &head_joint; + person.bjoint2 = joints + neck; for (auto& joint : joints) { joint.position = DoRotation(joint.position + joint.offset, 0, - person[k].playerrotation, 0) + person[k].playercoords; + person.playerrotation, 0) + person.playercoords; joint.realoldposition = joint.position; - joint.velocity = {0, person[k].velocity.y, 0}; + joint.velocity = {0, person.velocity.y, 0}; } auto soundpos = head_joint.position - camera.position; @@ -80,28 +86,28 @@ void Game::Splat(int k) alSourcePlay(gSourceID[headwhacksound]); } -void Game::updateSong() +void updateSong(Game* game) { if (environment == rainy_environment) alSourcePlay(gSourceID[rainsound]); else alSourcePause(gSourceID[rainsound]); - alSourceStop(gSourceID[whichsong]); - alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 0); - alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 0); + alSourceStop(gSourceID[game->whichsong]); + alSourcef(gSourceID[game->whichsong], AL_MIN_GAIN, 0); + alSourcef(gSourceID[game->whichsong], AL_MAX_GAIN, 0); - if (type == zombie_type) - whichsong = zombiesong; - else if (person[0].whichgun == knife) - whichsong = knifesong; + if (game->type == zombie_type) + game->whichsong = zombiesong; + else if (game->person[0].whichgun == knife) + game->whichsong = knifesong; else - whichsong = shootsong; + game->whichsong = shootsong; - alSourcef(gSourceID[whichsong], AL_PITCH, 1); - alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 1); - alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 1); - alSourcePlay(gSourceID[whichsong]); + alSourcef(gSourceID[game->whichsong], AL_PITCH, 1); + alSourcef(gSourceID[game->whichsong], AL_MIN_GAIN, 1); + alSourcef(gSourceID[game->whichsong], AL_MAX_GAIN, 1); + alSourcePlay(gSourceID[game->whichsong]); } void click(Game* game, int button, int action, int mods) @@ -131,7 +137,7 @@ void click(Game* game, int button, int action, int mods) switch (game->mouseoverbutton) { case 1: - game->updateSong(); + updateSong(game); game->flashr = game->flashg = game->flashb = 1.0f; game->flashamount = 1.0f; alSourcePlay(gSourceID[soulinsound]); @@ -346,7 +352,7 @@ void look(Game* game, double xpos, double ypos) } } -void Game::setListener(XYZ& facing) +void setListener(Game* game, XYZ facing) { XYZ upvector {0, 0, -1}; upvector = DoRotation(upvector, -camera.rotation2 + 90, 0, 0); @@ -359,13 +365,13 @@ void Game::setListener(XYZ& facing) alListenerfv(AL_ORIENTATION, ori); } -XYZ Game::aimPlayer() +XYZ aimPlayer(Game* game) { - auto& joints = person[0].skeleton.joints; + auto& joints = game->person[0].skeleton.joints; auto point = joints[lefthand].position - joints[righthand].position; float aimrot = 0.0f, aimrot2 = 0.0f; - switch (person[0].whichgun) { + switch (game->person[0].whichgun) { case assaultrifle: aimrot = -2.5f; break; @@ -387,13 +393,14 @@ XYZ Game::aimPlayer() } return DoRotation(point, aimrot2, - person[0].playerrotation + aimrot, 0); + game->person[0].playerrotation + aimrot, 0); } -XYZ Game::aimBot(int j) +XYZ aimBot(Game* game, int j) { + auto& bot = game->person[j]; float inaccuracy = 0.0f; - switch (person[j].whichgun) { + switch (bot.whichgun) { case handgun1: case handgun2: inaccuracy = 8.0f; @@ -406,10 +413,11 @@ XYZ Game::aimBot(int j) inaccuracy = 2.0f; break; } - if (person[person[j].killtarget].skeleton.free) + + auto& target = game->person[bot.killtarget]; + if (target.skeleton.free) inaccuracy *= 3; - auto& target = person[person[j].killtarget]; auto& joints = target.skeleton.joints; XYZ aim = joints[abdomen].position; if (target.skeleton.free) @@ -419,12 +427,12 @@ XYZ Game::aimBot(int j) + target.playercoords; auto& lefthandpos = joints[lefthand].position; - aim -= person[j].playercoords - + DoRotation(lefthandpos, 0, person[j].playerrotation, 0); + aim -= bot.playercoords + + DoRotation(lefthandpos, 0, bot.playerrotation, 0); return DoRotation( - DoRotation(DoRotation(aim, 0, -person[j].playerrotation, 0), + DoRotation(DoRotation(aim, 0, -bot.playerrotation, 0), randFloat() * inaccuracy, randFloat() * inaccuracy, 0), - 0, person[j].playerrotation, 0); + 0, bot.playerrotation, 0); } void Game::Tick() @@ -458,7 +466,7 @@ void Game::Tick() setMenu(this, beatgame = true); gameinprogress = 0; } else { - updateSong(); + updateSong(this); initGame(this); } } @@ -470,7 +478,7 @@ void Game::Tick() flashr = flashg = flashb = 0; alSourcePlay(gSourceID[soulinsound]); - updateSong(); + updateSong(this); initGame(this); } @@ -570,15 +578,9 @@ void Game::Tick() whichtri=sidewalkcollide.LineCheck2(overpoint,underpoint,&collpoint,move,cityrotation[i][j]*90); if(whichtri!=-1&&person[k].playercoords.y<=collpoint.y&&person[k].velocity.y<=0){ - person[k].playercoords.y=collpoint.y; - person[k].onground=1; - - if(person[k].velocity.y<-maxfallvel)Splat(k); - - else person[k].velocity.y=0; - + Splat(this, k); } if(whichtri!=-1){ @@ -638,34 +640,21 @@ void Game::Tick() whichtri=blockroofs[citytype[i][j]].LineCheck2(overpoint,underpoint,&collpoint,move,cityrotation[i][j]*90); if(whichtri!=-1&&person[k].playercoords.y<=collpoint.y&&person[k].velocity.y<=0){ - person[k].playercoords.y=collpoint.y; - person[k].onground=1; - - if(person[k].velocity.y<-maxfallvel)Splat(k); - - else person[k].velocity.y=0; - + Splat(this, k); } if(whichtri!=-1)inblock=1; - } - } - } - } if (person[k].playercoords.y <= 0) { person[k].onground = 1; person[k].playercoords.y = 0; - if (person[k].velocity.y<-maxfallvel) - Splat(k); - else - person[k].velocity.y = 0; + Splat(this, k); if (k == 0) onblockx = onblocky = -1; } @@ -1768,9 +1757,9 @@ void Game::Tick() for (int p = 0; p < numshots; p++) { XYZ aim; if (j) - aim = aimBot(j); + aim = aimBot(this, j); else if (!zoom) - aim = aimPlayer(); + aim = aimPlayer(this); else aim = facing; Normalise(&aim); @@ -2902,7 +2891,7 @@ void Game::Tick() psychicpower+=multiplier*5; if(psychicpower>10)psychicpower=10; - setListener(facing); + setListener(this, facing); if (score < 0) score = 0; } |