diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Game.h | 2 | ||||
-rw-r--r-- | src/GameTick.cpp | 277 |
2 files changed, 97 insertions, 182 deletions
diff --git a/src/Game.h b/src/Game.h index 6123217..3ab46f8 100644 --- a/src/Game.h +++ b/src/Game.h @@ -99,8 +99,6 @@ struct Game { bool paused; bool menu; - struct XYZ aimer[2]; - double eqn[4]; float oldrot, oldrot2; diff --git a/src/GameTick.cpp b/src/GameTick.cpp index b380202..f5ec2f4 100644 --- a/src/GameTick.cpp +++ b/src/GameTick.cpp @@ -736,6 +736,101 @@ void tackle(Game* game, XYZ flatfacing) } } +void renderLaser(Game* game) +{ + auto& player = game->person[0]; + if (!player.aiming) + return; + switch (player.currentanimation) { + case walkanim: + case idleanim: + break; + default: + return; + } + + XYZ aim; + float coeff; + auto& joints = player.skeleton.joints; + auto& rotation = player.playerrotation; + switch (player.whichgun) { + case assaultrifle: + aim = DoRotation(joints[lefthand].position + - joints[righthand].position, + 0.0f, rotation - 2.5f, 0.0f); + coeff = 0.15f; + break; + case sniperrifle: + case shotgun: + aim = DoRotation(joints[lefthand].position + - joints[righthand].position, + 0.0f, rotation + 4.0f, 0.0f); + coeff = 0.4f; + break; + case handgun1: + case handgun2: + coeff = thirdperson ? 0.35f : 0.65f; + aim = DoRotation(joints[righthand].position + - joints[head].position * coeff + - joints[neck].position * (1.0 - coeff), + 0.0f, player.playerrotation - 0.9f, 0.0f); + coeff = -0.15f; + break; + default: + return; + } + + Normalise(&aim); + auto& coords = player.playercoords; + auto start = coords + + DoRotation(joints[lefthand].position, 0.0f, rotation, 0.0f) + + DoRotation(DoRotation(DoRotation(aim, 0.0f, -rotation, 0.0f), + 90.0f, 0.0f, 0.0f), + 0.0f, rotation, 0) * coeff; + auto end = start + aim * 1000.0f; + + // Blocks + int x = coords.x / block_spacing + 0.5f; + int z = coords.z / block_spacing + 0.5f; + for (int i = std::max(0, x - 2); i < std::min(num_blocks, x + 3); ++i) + for (int j = std::max(0, z - 2); j < std::min(num_blocks, z + 3); ++j) { + XYZ move = { + (float) i * block_spacing, + 0.0f, + (float) j * block_spacing, + }; + XYZ tmp {}; + auto& block = game->blocks[game->citytype[i][j]]; + auto whichtri = block.LineCheck2(start, end, + &tmp, move, game->cityrotation[i][j]*90); + if (whichtri != -1) + end = tmp; + } + XYZ tmp {camera.position.x, 0.0f, camera.position.z}; + auto whichtri = game->Bigstreet.LineCheck2(start, end, &tmp, tmp, 0); + if (whichtri != -1) + end = tmp; + + // People + float olddistance = 0.0f; + int whichhit = -1; + for (auto i = 1; i < game->numpeople; ++i) { + auto& person = game->person[i]; + if (findDistancefast(coords, person.playercoords) > 20000) + continue; + auto hit = person.BulletCollideWithPlayer(i, start, end); + if (!hit.collision) + continue; + auto distance = findDistancefast(start, hit.hitlocation); + if (distance < olddistance || whichhit == -1) { + olddistance = distance; + whichhit = i; + end = hit.hitlocation; + } + } + sprites.MakeSprite(bulletinstant, 0.4f, 1, 0, 0, start, end, 0.2f); +} + void Game::Tick() { if (person[1].health <= 0 || person[0].health <= 0 || killedinnocent) @@ -2085,186 +2180,8 @@ void Game::Tick() } } - if(lasersight&&person[0].whichgun!=grenade){ - - for(int j=0;j<numpeople;j++){ - - if(person[j].type==playertype){ - - if(person[j].aiming>=1){ - - //Firing - XYZ end, aim; - - HitStruct hitstruct,temphitstruct; - - float olddistance = 0.0f; - - float distance; - - int whichhit=-1; - - if(!zoom||j!=0){ - - if(person[j].whichgun==assaultrifle)aim=DoRotation(person[j].skeleton.joints[lefthand].position-person[j].skeleton.joints[righthand].position,0,person[j].playerrotation-2.5,0); - - if(person[j].whichgun==sniperrifle)aim=DoRotation(person[j].skeleton.joints[lefthand].position-person[j].skeleton.joints[righthand].position,0,person[j].playerrotation+4,0); - - if(person[j].whichgun==shotgun)aim=DoRotation(person[j].skeleton.joints[lefthand].position-person[j].skeleton.joints[righthand].position,0,person[j].playerrotation+4,0); - - if(person[j].whichgun==handgun1&&!thirdperson&&j==0)aim=DoRotation(person[j].skeleton.joints[righthand].position-(person[j].skeleton.joints[head].position*.65+person[j].skeleton.joints[neck].position*.35),0,person[j].playerrotation-.9,0); - - if(person[j].whichgun==handgun1&&(thirdperson||j!=0))aim=DoRotation(person[j].skeleton.joints[righthand].position-(person[j].skeleton.joints[head].position*.35+person[j].skeleton.joints[neck].position*.65),0,person[j].playerrotation-.9,0); - - if(person[j].whichgun==handgun2&&!thirdperson&&j==0)aim=DoRotation(person[j].skeleton.joints[righthand].position-(person[j].skeleton.joints[head].position*.65+person[j].skeleton.joints[neck].position*.35),0,person[j].playerrotation-.9,0); - - if(person[j].whichgun==handgun2&&(thirdperson||j!=0))aim=DoRotation(person[j].skeleton.joints[righthand].position-(person[j].skeleton.joints[head].position*.35+person[j].skeleton.joints[neck].position*.65),0,person[j].playerrotation-.9,0); - - } - - if(zoom&&j==0){ - - start=camera.position; - - aim=facing; - - } - - Normalise(&aim); - - if(person[j].whichgun==sniperrifle){ - - start=person[j].playercoords+DoRotation(person[j].skeleton.joints[lefthand].position,0,person[j].playerrotation,0); - - start-=DoRotation(DoRotation(DoRotation(aim,0,-person[j].playerrotation,0),90,0,0),0,person[j].playerrotation,0)*(0-.4); - - } - - if(person[j].whichgun==shotgun){ - - start=person[j].playercoords+DoRotation(person[j].skeleton.joints[lefthand].position,0,person[j].playerrotation,0); - - start-=DoRotation(DoRotation(DoRotation(aim,0,-person[j].playerrotation,0),90,0,0),0,person[j].playerrotation,0)*(0-.4); - - } - - if(person[j].whichgun==handgun1){ - - start=person[j].playercoords+DoRotation(person[j].skeleton.joints[rightwrist].position,0,person[j].playerrotation,0); - - start-=DoRotation(DoRotation(DoRotation(aim,0,-person[j].playerrotation,0),90,0,0),0,person[j].playerrotation,0)*(.55-.4); - - } - - if(person[j].whichgun==handgun2){ - - start=person[j].playercoords+DoRotation(person[j].skeleton.joints[rightwrist].position,0,person[j].playerrotation,0); - - start-=DoRotation(DoRotation(DoRotation(aim,0,-person[j].playerrotation,0),90,0,0),0,person[j].playerrotation,0)*(.55-.4); - - } - - if(person[j].whichgun==assaultrifle){ - - start=person[j].playercoords+DoRotation(person[j].skeleton.joints[lefthand].position,0,person[j].playerrotation,0); - - start-=DoRotation(DoRotation(DoRotation(aim,0,-person[j].playerrotation,0),90,0,0),0,person[j].playerrotation,0)*(.25-.4); - - } - - end=start+aim*1000; - - // Blocks - wallhit = {}; - beginx=(person[j].playercoords.x+block_spacing/2)/block_spacing-2; - - if(beginx<0)beginx=0; - - beginz=(person[j].playercoords.z+block_spacing/2)/block_spacing-2; - - if(beginz<0)beginz=0; - - endx=(person[j].playercoords.x+block_spacing/2)/block_spacing+2; - - if(endx>num_blocks-1)endx=num_blocks-1; - - endz=(person[j].playercoords.z+block_spacing/2)/block_spacing+2; - - if(endz>num_blocks-1)endz=num_blocks-1; - - if(beginx<endx&&beginz<endz) - - finalwallhit = {}; - for(int i=beginx;i<=endx;i++) - for(int j=beginz;j<=endz;j++){ - move = {(float) i * block_spacing, 0.0f, (float) j * block_spacing}; - whichtri=blocks[citytype[i][j]].LineCheck2(start,end,&wallhit,move,cityrotation[i][j]*90); - - if(whichtri!=-1){ - - end=wallhit; - - finalwallhit=wallhit; - - } - - } - wallhit = {camera.position.x, 0.0f, camera.position.z}; - whichtri=Bigstreet.LineCheck2(start,end,&wallhit,wallhit,0); - - if(whichtri!=-1){ - - end=wallhit; - - finalwallhit=wallhit; - - } - - //People - - whichhit=-1; - - for(int i=0;i<numpeople;i++){ - - if(i!=j&&findDistancefast(person[j].playercoords,person[i].playercoords)<20000){ - - temphitstruct=person[i].BulletCollideWithPlayer(i, start, end); - - if(temphitstruct.collision){ - - distance=findDistancefast(start,temphitstruct.hitlocation); - - if(distance<olddistance||whichhit==-1){ - - end=temphitstruct.hitlocation; - - olddistance=distance; - - hitstruct=temphitstruct; - - whichhit=i; - - } - - } - - } - - } - - aimer[0]=start; - - aimer[1]=end; - - sprites.MakeSprite(bulletinstant, .4, 1, 0, 0, aimer[0], aimer[1], .2); - - } - - } - - } - - } + if (lasersight && !zoom) + renderLaser(this); //Snow snowdelay-=multiplier; |