aboutsummaryrefslogtreecommitdiff
path: root/src/GameTick.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/GameTick.cpp')
-rw-r--r--src/GameTick.cpp154
1 files changed, 68 insertions, 86 deletions
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index 760db74..c8b1111 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -124,6 +124,7 @@ void Game::updateSong()
void Game::handleMenu()
{
+ Point mouseloc;
GetMouse(&mouseloc);
float mousex = (float) mouseloc.h * 640 / screenwidth;
float mousey = 480 - (float) mouseloc.v * 480 / screenheight;
@@ -150,7 +151,6 @@ void Game::handleMenu()
initGame(this);
}
- GetMouse(&mouseloc);
if (visions)
alSourcePlay(gSourceID[visionsound]);
@@ -173,49 +173,40 @@ void Game::handleMenu()
}
}
-void Game::mouseLook()
+void look(Game* game, double xpos, double ypos)
{
- if ((person[0].aimamount <= 0
- && person[0].targetanimation != crouchanim)) {
- camera.rotation = camera.visrotation;
- camera.rotation2 = camera.visrotation2;
- mousesensitivity = usermousesensitivity;
- } else if (person[0].aimamount >= 1 && !zoom) {
- mousesensitivity = usermousesensitivity * 0.8;
- }
+ if (game->menu)
+ return;
+
+ int width, height;
+ const auto window = glfwGetCurrentContext();
+ glfwGetWindowSize(window, &width, &height);
+ int xcenter = width / 2, ycenter = height / 2;
+ glfwSetCursorPos(window, xcenter, ycenter); // we shouldn't need this
+
+ auto& player = game->person[0];
+ auto factor = game->mouse_sensitivity;
+ if (player.aimamount >= 1)
+ factor *= (game->zoom) ? 0.05 : 0.8;
if (slomo == 2)
- mousesensitivity *= 0.6;
-
- GetMouseRel(&mouseloc);
- auto factor = mousesensitivity / 1.3888;
- mouserotation = mouseloc.h * factor;
- mouserotation2 = mouseloc.v * factor;
- if (abs(mouseloc.h) < 400)
- camera.rotation += mouserotation;
- if (abs(mouseloc.v) < 200)
- camera.rotation2 += mouserotation2;
-
- auto hrot = factor * 500;
- if (mouseloc.h > 400)
- camera.rotation += mouserotation - hrot;
- if (mouseloc.h < -400)
- camera.rotation += mouserotation + hrot;
-
- auto vrot = factor * 300;
- if (mouseloc.v > 200)
- camera.rotation2 += mouserotation2 - vrot;
- if (mouseloc.v < -200)
- camera.rotation2 += mouserotation2 + vrot;
- camera.rotation2 = min(max(camera.rotation2, -89.0f), 89.0f);
+ factor *= 0.6;
+
+ camera.rotation += (xpos - xcenter) * factor;
+ camera.rotation2 += (ypos - ycenter) * factor;
- // Smooth
+ // Smoothen camera movements
camera.rotation = camera.rotation * 0.7 + camera.oldrotation * 0.3;
+ camera.oldrotation = camera.rotation;
+ player.playerrotation = 180 - camera.rotation;
+
camera.rotation2 = camera.rotation2 * 0.7 + camera.oldrotation2 * 0.3;
+ camera.rotation2 = min(max(camera.rotation2, -89.0f), 89.0f);
+ camera.oldrotation2 = camera.rotation2;
- if (zoom || visions || person[0].aimamount <= 0
- || person[0].whichgun == nogun
- || person[0].whichgun == grenade
- || person[0].whichgun == knife) {
+ if (game->zoom || visions || player.aimamount <= 0
+ || player.whichgun == nogun
+ || player.whichgun == grenade
+ || player.whichgun == knife) {
camera.visrotation = camera.rotation;
camera.visrotation2 = camera.rotation2;
} else {
@@ -224,10 +215,6 @@ void Game::mouseLook()
camera.visrotation2 = min(camera.rotation2 + 15,
max(camera.rotation2 - 15, camera.visrotation2));
}
-
- person[0].playerrotation = 180 - camera.rotation;
- camera.oldrotation = camera.rotation;
- camera.oldrotation2 = camera.rotation2;
}
void Game::setListener(XYZ& facing)
@@ -380,8 +367,6 @@ void Game::Tick()
flatfacing.y = 0;
Normalise(&flatfacing);
- mouseLook();
-
//Check collision with buildings
int beginx,endx;
int beginz,endz;
@@ -959,47 +944,48 @@ void Game::Tick()
}
- if(person[i].skeleton.free==0){
- //Gun
- if(person[i].type==playertype||person[i].type==eviltype){
- if(i==0){
- if(person[i].whichgun==shotgun)person[i].recoil-=multiplier*4;
- if(person[i].whichgun==sniperrifle)person[i].recoil-=multiplier*2;
- if(person[i].whichgun==handgun1)person[i].recoil-=multiplier*5;
- if(person[i].whichgun==handgun2)person[i].recoil-=multiplier*5;
- if(person[i].whichgun==assaultrifle)person[i].recoil-=multiplier*10;
- }
-
- if(i!=0){
- if(person[i].whichgun==shotgun)person[i].recoil-=multiplier*1;
- if(person[i].whichgun==sniperrifle)person[i].recoil-=multiplier*1;
- if(person[i].whichgun==handgun1)person[i].recoil-=multiplier*2;
- if(person[i].whichgun==handgun2)person[i].recoil-=multiplier*2;
- if(person[i].whichgun==assaultrifle)person[i].recoil-=multiplier*10;
+ if (!person[i].skeleton.free) {
+ // Gun
+ switch (person[i].type) {
+ case playertype:
+ switch (person[i].whichgun) {
+ case shotgun:
+ person[i].recoil -= multiplier * 4;
+ break;
+ case sniperrifle:
+ person[i].recoil -= multiplier * 2;
+ break;
+ case handgun1:
+ case handgun2:
+ person[i].recoil -= multiplier * 5;
+ break;
+ case assaultrifle:
+ person[i].recoil-=multiplier * 10;
+ break;
}
-
- if(person[i].recoil<0)person[i].recoil=0;
-
- if(i==0){
- oldzoom = zoom;
- if(zoom){
- mousesensitivity=.05*usermousesensitivity;
- if(person[i].targetanimation!=crouchanim||person[i].currentanimation!=crouchanim||person[i].aiming<1){
- zoom=0;
- }
- if(visions==1)zoom=0;
- }
-
- if(person[i].currentanimation==crouchanim&&person[i].targetanimation==crouchanim&&person[i].aiming>=1&&person[i].whichgun==sniperrifle){
- zoom=1;
- if(zoom&&!oldzoom)camera.rotation2-=6;
- }
-
- if(!zoom)mousesensitivity=1*usermousesensitivity;
-
- if(person[i].whichgun!=sniperrifle)zoom=0;
+ 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) {
+ case shotgun:
+ case sniperrifle:
+ person[i].recoil -= multiplier * 1;
+ break;
+ case handgun1:
+ case handgun2:
+ person[i].recoil -= multiplier * 2;
+ break;
+ case assaultrifle:
+ person[i].recoil-=multiplier * 10;
+ break;
}
+ break;
}
+ if (person[i].recoil < 0)
+ person[i].recoil = 0;
//Zombie eat
if(i > 0
@@ -3336,10 +3322,6 @@ void Game::Tick()
psychicpower+=multiplier*5;
if(psychicpower>10)psychicpower=10;
- if (paused || person[0].currentanimation== diveanim
- || person[0].currentanimation == throwanim)
- GetMouse(&mouseloc);
-
setListener(facing);
if (score < 0)
score = 0;