Skip to content

Commit

Permalink
used max/min instead of ifs
Browse files Browse the repository at this point in the history
  • Loading branch information
honzi committed Dec 9, 2024
1 parent 2c01423 commit 428cd0b
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions js/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,14 +642,13 @@ function webgl_controls_keyboard(id){
let turn = 0;
if(core_mouse['down-2']){
const half = webgl.drawingBufferWidth / 2;
let mouse = (core_mouse['x'] - half) / half * core_storage_data['mouse-horizontal'];
if(mouse > 1){
mouse = 1;

}else if(mouse < -1){
mouse = -1;
}
turn = vehicle['turn-speed'] * mouse;
turn = vehicle['turn-speed'] * Math.max(
Math.min(
(core_mouse['x'] - half) / half * core_storage_data['mouse-horizontal'],
1
),
-1
);

}else{
if(core_keys[core_storage_data['move-←']]['state']){
Expand Down

0 comments on commit 428cd0b

Please sign in to comment.