From 5392dfe51b897dc43d31adfad1db9ed0978be343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Thu, 17 Feb 2022 16:08:57 +0700 Subject: Group bleeding rendering code together --- src/GameTick.cpp | 68 ++++++++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 37 deletions(-) (limited to 'src/GameTick.cpp') diff --git a/src/GameTick.cpp b/src/GameTick.cpp index 64d8614..dfc84de 100644 --- a/src/GameTick.cpp +++ b/src/GameTick.cpp @@ -736,14 +736,41 @@ void tackle(Game* game, XYZ flatfacing) } } -void renderBloodSprite(Game* game, size_t i) +void bleed(Game* game, size_t i) { auto& person = game->person[i]; - if (person.bleeding <= 0) + if (person.health < 0.0f && person.longdead < 0.0f + && !person.firstlongdead && person.type != zombietype) { + int x = person.whichblockx, y = person.whichblocky; + auto rot = game->cityrotation[x][y] * 90; + auto overpoint = person.skeleton.joints[abdomen].position; + overpoint.y += 3000; + auto underpoint = person.skeleton.joints[abdomen].position; + underpoint.y -= 3000; + XYZ temp; + XYZ move {(float) x * block_spacing, 0.0f, (float) y * block_spacing, }; + auto whichtri = game->sidewalkcollide.LineCheck2(overpoint, + underpoint, &temp, move, rot); + + XYZ normish {0.0f, 1.0f, 0.0f}; + if (whichtri >= 0) { + decals.MakeDecal(bloodpool, temp, 12, normish, + whichtri, &game->sidewalkcollide, move, rot); + } else { + temp = person.skeleton.joints[abdomen].position; + temp.y = -0.5f; + decals.MakeDecal(bloodpool, temp, 12, normish, + 0, &game->sidewalkcollide, {}, 0); + } + person.firstlongdead = true; + return; + } + + if (person.bleeding <= 0.0f) return; person.bleeding -= multiplier; person.bleeddelay -= multiplier * 10; - if (person.bleeddelay > 0) + if (person.bleeddelay > 0.0f) return; person.bleeddelay = 1.0f; XYZ loc = (person.bjoint1->position + person.bjoint2->position) / 2.0f; @@ -942,39 +969,6 @@ void Game::Tick() //People for(int i=0;i=0){ - decals.MakeDecal(bloodpool,temp,12,normish, whichtri, &sidewalkcollide, move, cityrotation[person[i].whichblockx][person[i].whichblocky]*90); - } - if(whichtri==-1){ - temp=person[i].skeleton.joints[abdomen].position; - temp.y=-.5; - move = {}; - decals.MakeDecal(bloodpool,temp,12,normish, 0, &sidewalkcollide, move, 0); - } - - person[i].firstlongdead=1; - - } - - } - if(person[i].health<100&&person[i].type!=zombietype){ person[i].health-=multiplier*120; } @@ -1010,7 +1004,7 @@ void Game::Tick() if(person[i].maxhealth>100)person[i].maxhealth=100; } - renderBloodSprite(this, i); + bleed(this, i); if (!person[i].skeleton.free) { recoil(this, i); -- cgit v1.2.3