diff options
Diffstat (limited to 'src/GameTick.cpp')
-rw-r--r-- | src/GameTick.cpp | 458 |
1 files changed, 199 insertions, 259 deletions
diff --git a/src/GameTick.cpp b/src/GameTick.cpp index c8b1111..8bea7cf 100644 --- a/src/GameTick.cpp +++ b/src/GameTick.cpp @@ -122,54 +122,196 @@ void Game::updateSong() alSourcePlay(gSourceID[whichsong]); } -void Game::handleMenu() +void click(Game* game, int button, int action, int mods) { - Point mouseloc; - GetMouse(&mouseloc); - float mousex = (float) mouseloc.h * 640 / screenwidth; - float mousey = 480 - (float) mouseloc.v * 480 / screenheight; - - int button = Button(); - oldmouseoverbutton = mouseoverbutton; - mouseoverbutton = 0; - if (mousex > 120 && mousex < 560 && button && !oldbutton) { - if (mousey > 235 && mousey < 305) - mouseoverbutton = 1; - else if (mousey > 112 && mousey < 182) - mouseoverbutton = 2; + if (game->menu) { + if (button != GLFW_MOUSE_BUTTON_LEFT || action != GLFW_PRESS) + return; + double xpos, ypos; + auto window = glfwGetCurrentContext(); + glfwGetCursorPos(window, &xpos, &ypos); + double mousex = xpos * 640 / game->screenwidth; + double mousey = 480 - ypos * 480 / game->screenheight; + + game->mouseoverbutton = 0; + if (mousex > 120 && mousex < 560) { + if (mousey > 235 && mousey < 305) + game->mouseoverbutton = 1; + else if (mousey > 112 && mousey < 182) + game->mouseoverbutton = 2; + } + + switch (game->mouseoverbutton) { + case 1: + game->updateSong(); + game->flashr = game->flashg = game->flashb = 1.0f; + game->flashamount = 1.0f; + alSourcePlay(gSourceID[soulinsound]); + + if (!game->gameinprogress) { + game->mission = 0; + initGame(game); + } + + if (visions) + alSourcePlay(gSourceID[visionsound]); + + game->gameinprogress = true; + setMenu(game, false); + break; + case 2: + if (game->gameinprogress) { + game->flashr = game->flashg = game->flashb = 1.0f; + game->flashamount = 1.0f; + game->gameinprogress = false; + } else { + game->flashamount = game->flashr = 1.0f; + game->flashg = game->flashb = 0.0f; + glfwSetWindowShouldClose(window, true); + } + + alSourcePlay(gSourceID[losesound]); + game->saveHighScore(); + break; + } + return; } - oldbutton = button; - switch (mouseoverbutton) { - case 1: - updateSong(); - flashamount = flashr = flashg = flashb = 1; - alSourcePlay(gSourceID[soulinsound]); + auto& player = game->person[0]; + auto& weapon = player.whichgun; - if (!gameinprogress) { - mission = 0; - initGame(this); + if (visions) { + if (action == GLFW_PRESS) + alSourcePlay(gSourceID[soulinsound]); + return; + } + + XYZ facing {0, 0, -1}; + facing = DoRotation(facing, -camera.rotation2, 0, 0); + facing = DoRotation(facing, 0, -camera.rotation, 0); + + XYZ flatfacing = facing; + flatfacing.y = 0; + Normalise(&flatfacing); + + // Gun whacking or knife slashing + if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS + && player.attackframe < 0 + && (!player.aiming || player.ammo <= 0 + || weapon == nogun || weapon == knife || weapon == grenade + || player.targetanimation == joganim) + && player.targetanimation != diveanim + && player.targetanimation != throwanim) { + bool attacking = false; + float closedistance = 0.0f; + for (int i = 1; i < game->numpeople; ++i) { + auto& person = game->person[i]; + if (person.type == viptype || person.skeleton.free) + continue; + auto distance = findDistancefast(person.playercoords, + player.playercoords + flatfacing); + if (distance > 12 + (weapon == knife) * 10) + continue; + if (closedistance == 0 || distance < closedistance) { + attacking = true; + player.killtarget = i; + closedistance = distance; + } } - if (visions) - alSourcePlay(gSourceID[visionsound]); + if (attacking) { + player.attacktarget = 0; + player.attackframe = 0; + game->whacked = false; + return; + } + } - gameinprogress = 1; - setMenu(this, false); - break; - case 2: - if (gameinprogress) { - flashamount = flashr = flashg = flashb = 1; - gameinprogress = 0; - } else { - flashamount = flashr = 1; - flashg = flashb = 0; - glfwSetWindowShouldClose(glfwGetCurrentContext(), true); + // Disarming + if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS + && player.attackframe < 0 + && (!player.aiming || weapon == nogun || weapon == knife) + && (player.targetanimation == idleanim + || player.targetanimation == walkanim + || player.targetanimation == joganim)) { + bool attacking = false; + float closedistance = 0.0f; + for (int i = 1; i < game->numpeople; ++i) { + auto& person = game->person[i]; + if (person.skeleton.free || person.whichgun == nogun) + continue; + auto distance = findDistancefast(person.playercoords, + player.playercoords + flatfacing); + if (distance > 12) + continue; + attacking = true; + if (closedistance == 0 || distance < closedistance) { + player.killtarget = i; + closedistance = distance; + } } - alSourcePlay(gSourceID[losesound]); - saveHighScore(); - break; + if (attacking) { + auto& target = game->person[player.killtarget]; + weapon = target.whichgun; + player.ammo = target.ammo; + player.aiming = true; + target.whichgun = nogun; + target.killtarget = -1; + + target.targetframe = player.targetframe = 0; + target.targetanimation = player.targetanimation = throwanim; + target.target = player.target = 1; + target.playercoords = player.playercoords; + target.playerrotation = player.playerrotation; + target.speed = player.speed = 1; + target.speedmult = 1; + game->score += 150; + return; + } + } + + // Pulling gun trigger + if (player.aiming && player.targetanimation != joganim + && weapon != nogun && weapon != knife && weapon != grenade) { + if (button == GLFW_MOUSE_BUTTON_RIGHT && weapon == sniperrifle) + game->zoom = action == GLFW_PRESS; + else if (button == GLFW_MOUSE_BUTTON_LEFT) + player.firing = action == GLFW_PRESS; + else if (button == GLFW_MOUSE_BUTTON_MIDDLE && game->debug) + player.firing = player.grenphase = action == GLFW_PRESS; + return; + } + + // Grenade + if (weapon == grenade && player.ammo > 0 + && player.reloading <= 0 && player.attackframe < 0) { + auto& skeleton = player.skeleton; + auto& hand = skeleton.joints[skeleton.jointlabels[righthand]]; + auto soundsrc = (DoRotation(hand.position, 0, player.playerrotation, 0) + + player.playercoords - camera.position) / soundscalefactor; + float gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z}; + if (player.grenphase) { + if (button == GLFW_MOUSE_BUTTON_LEFT + && action == GLFW_RELEASE) { // throw + player.grenphase = false; + player.attackframe = 0; + player.attacktarget = 0; + player.killtarget = 0; + } else if (button == GLFW_MOUSE_BUTTON_RIGHT + && action == GLFW_PRESS) { // put pin back + player.grenphase = false; + alSourcefv(gSourceID[pinreplacesound], AL_POSITION, gLoc); + alSourcePlay(gSourceID[pinreplacesound]); + } + } else { + if (button == GLFW_MOUSE_BUTTON_LEFT + && action == GLFW_PRESS) { // pull pin + player.grenphase = true; + alSourcefv(gSourceID[pinpullsound], AL_POSITION, gLoc); + alSourcePlay(gSourceID[pinpullsound]); + } + } } } @@ -305,11 +447,6 @@ XYZ Game::aimBot(int j) void Game::Tick() { - if (this->menu) { - handleMenu(); - return; - } - if (person[1].health <= 0 || person[0].health <= 0 || killedinnocent) losedelay -= multiplier / 6; else @@ -963,10 +1100,6 @@ void Game::Tick() person[i].recoil-=multiplier * 10; break; } - this->zoom = person[0].whichgun == sniperrifle - && person[0].aiming >=1 && !visions - && person[0].currentanimation == crouchanim - && person[0].targetanimation == crouchanim; break; case eviltype: switch (person[i].whichgun) { @@ -1519,184 +1652,6 @@ void Game::Tick() } } - // Grenade - if (Button() && person[0].whichgun == grenade && person[0].ammo > 0 - && person[0].reloading <= 0 && person[0].attackframe < 0 - && person[0].targetanimation != crouchanim - && person[0].grenphase == 0) { - person[0].grenphase = 1; - auto soundsrc = (DoRotation(person[0].skeleton.joints[person[0].skeleton.jointlabels[righthand]].position, 0, person[0].playerrotation, 0) - + person[0].playercoords - camera.position) / soundscalefactor; - float gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z}; - alSourcefv(gSourceID[pinpullsound], AL_POSITION, gLoc); - alSourcePlay(gSourceID[pinpullsound]); - } - - if (!Button() && person[0].whichgun == grenade - && person[0].grenphase == 1) { - person[0].grenphase = 0; - person[0].attackframe = 0; - person[0].attacktarget = 0; - person[0].killtarget = 0; - } - - if (person[0].targetanimation == crouchanim - && person[0].grenphase == 1) { - person[0].grenphase = 0; - auto soundsrc = (DoRotation(person[0].skeleton.joints[person[0].skeleton.jointlabels[righthand]].position, 0, person[0].playerrotation, 0) - + person[0].playercoords - camera.position) / soundscalefactor; - float gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z}; - alSourcefv(gSourceID[pinreplacesound], AL_POSITION, gLoc); - alSourcePlay(gSourceID[pinreplacesound]); - } - - // Get gun - if (Button() && !oldbutton && person[0].currentanimation == crouchanim - && (person[0].aiming == 0 || person[0].whichgun == grenade - || person[0].whichgun == knife || person[0].whichgun == nogun)) { - bool switched = false; - for (int i = 1; i < max_people && !switched; i++) { - if (!person[i].skeleton.free - || findDistancefast(person[0].playercoords, - person[i].averageloc) > 200) - continue; - - auto soundsrc = (person[0].playercoords - - camera.position) / soundscalefactor; - float gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z}; - alSourcefv(gSourceID[clicksound], AL_POSITION, gLoc); - alSourcePlay(gSourceID[clicksound]); - - auto tmp_gun = person[0].whichgun; - person[0].whichgun = person[i].whichgun; - person[i].whichgun = tmp_gun; - - auto tmp_ammo = person[0].ammo; - person[0].ammo = person[i].ammo; - person[i].ammo = tmp_ammo; - - switched = true; - person[0].aiming = 1; - person[0].aimamount = 0; - } - } - - //Throw - - if(Button()&&person[0].attackframe<0&&((person[0].whichgun==nogun||person[0].aiming==0)&&person[0].whichgun!=knife)&&person[0].currentanimation!=crouchanim&&person[0].targetanimation!=crouchanim&&person[0].targetanimation!=throwanim&&visions==0){ - - if(person[0].targetanimation==idleanim||person[0].targetanimation==walkanim){ - - bool attacking=0; - - person[0].killtarget=-1; - - float closedistance=-1; - - for(int i=1;i<numpeople;i++){ - - if(person[i].skeleton.free<1&&(person[i].whichgun!=nogun)&&findDistancefast(person[i].playercoords,person[0].playercoords+flatfacing)<12){ - - attacking=1; - - if(person[0].killtarget==-1||findDistancefast(person[i].playercoords,person[0].playercoords)<closedistance){ - - person[0].killtarget=i; - - closedistance=findDistancefast(person[i].playercoords,person[0].playercoords); - - } - - } - - } - - if(attacking){ - - score+=150; - - person[0].aiming=1; - - person[0].whichgun=person[person[0].killtarget].whichgun; - - person[0].ammo=person[person[0].killtarget].ammo; - - person[person[0].killtarget].whichgun=nogun; - - person[person[0].killtarget].killtarget=-1; - - person[0].targetframe=0; - - person[0].targetanimation=throwanim; - - person[0].target=1; - - person[0].speed=1; - - person[person[0].killtarget].targetframe=0; - - person[person[0].killtarget].targetanimation=thrownanim; - - person[person[0].killtarget].target=1; - - person[person[0].killtarget].playercoords=person[0].playercoords; - - person[person[0].killtarget].playerrotation=person[0].playerrotation; - - person[person[0].killtarget].speed=person[0].speed; - - person[person[0].killtarget].speedmult=1; - - } - - } - - } - - //Gun whacking - - if(Button()&&(person[0].aiming==0||person[0].ammo<=0||person[0].whichgun==nogun||person[0].whichgun==knife||person[0].targetanimation==joganim)&&person[0].currentanimation!=crouchanim&&person[0].targetanimation!=throwanim&&person[0].whichgun!=grenade&&person[0].targetanimation!=crouchanim&&visions==0){ - - if(person[0].attackframe==-1||person[person[0].killtarget].skeleton.free==1){ - - bool attacking=0; - - person[0].killtarget=-1; - - float closedistance=-1; - - for(int i=1;i<numpeople;i++){ - - if(person[i].existing&&person[i].type!=viptype&&person[i].skeleton.free<1&&findDistancefast(person[i].playercoords,person[0].playercoords+flatfacing)<12+(person[0].whichgun==knife)*10){ - - if(person[0].killtarget==-1||findDistancefast(person[i].playercoords,person[0].playercoords)<closedistance){ - - attacking=1; - - person[0].killtarget=i; - - closedistance=findDistancefast(person[i].playercoords,person[0].playercoords); - - } - - } - - } - - if(attacking){ - - person[0].attacktarget=0; - - person[0].attackframe=0; - - } - - whacked=0; - - } - - } - XYZ velocity; if(person[0].attackframe>1||(person[0].attackframe>=0&&person[0].currentanimation==joganim)){ @@ -1841,32 +1796,16 @@ void Game::Tick() } } - // Fire/wing - bool firing = false; - if (!Button()) { - oldbutton = 0; - } else if (oldbutton) { - } else if (person[0].ammo <= 0 && person[0].aiming - && person[0].targetanimation != joganim - && person[0].whichgun != nogun - && person[0].whichgun != knife - && person[0].whichgun != grenade) { - auto& coords = person[0].playercoords; + // Empty magazine + if (person[0].firing && person[0].ammo <= 0) { float gLoc[] { - coords.x / soundscalefactor, - coords.y / soundscalefactor, - coords.z / soundscalefactor, + person[0].playercoords.x / soundscalefactor, + person[0].playercoords.y / soundscalefactor, + person[0].playercoords.z / soundscalefactor, }; alSourcefv(gSourceID[clicksound], AL_POSITION, gLoc); alSourcePlay(gSourceID[clicksound]); - oldbutton = 1; - } else if (visions == 1) { - alSourcePlay(gSourceID[soulinsound]); - } else { - firing = true; - // Assault rifles are automatic. - if (person[0].whichgun != assaultrifle) - oldbutton = 1; + person[0].firing = false; } XYZ wallhit; @@ -1878,7 +1817,7 @@ void Game::Tick() int hitpoly = 0; float hitrotation = 0.0f; Model* model = NULL; - + for (int j = 0; j < numpeople; j++) { if (j && person[j].type != eviltype) continue; @@ -1887,9 +1826,9 @@ void Game::Tick() || person[j].reloading > 0 || person[j].targetanimation == joganim || person[j].aimamount < 1) - firing = false; + person[j].firing = false; else if (j) - firing = person[j].whichgun != nogun + person[j].firing = person[j].whichgun != nogun && person[j].whichgun != knife && person[j].killtargetvisible && person[j].shotdelay < 0; @@ -1914,8 +1853,10 @@ void Game::Tick() person[j].aiming = 0; } - if (!firing || person[j].aiming < 1 || person[j].recoil > 0) + if (!person[j].firing || person[j].aiming < 1 || person[j].recoil > 0) continue; + if (j != 0 || person[j].whichgun != assaultrifle) + person[j].firing = false; person[j].shotdelay = shotdelayamount / difficulty; HitStruct hitstruct, temphitstruct; @@ -1953,6 +1894,12 @@ void Game::Tick() + DoRotation(person[j].skeleton.joints[aimjoint].position, 0, person[j].playerrotation, 0); + if (j == 0 && person[j].grenphase) { + person[j].grenphase = false; + sprites.MakeSprite(grenadesprite, 1, 1, 1, 1, + start, aim * 200, 1.01); + } + auto startsub = DoRotation(aim, 0, -person[j].playerrotation, 0); startsub = DoRotation(startsub, 90, 0, 0); @@ -2021,12 +1968,6 @@ void Game::Tick() } XYZ end {start + aim * 1000}; - if (debug && j == 0 && IsKeyDown(GLFW_KEY_G)) { - sprites.MakeSprite(grenadesprite, 1, 1, 1, 1, - start, aim * 200, 1.01); - continue; - } - int bulletstrength=1; int firstpass=-1; bool penetrate; @@ -2624,7 +2565,6 @@ void Game::Tick() if(person[j].aiming>=1){ //Firing - XYZ end, aim; HitStruct hitstruct,temphitstruct; |