From 75ef04bc3374141e8a266bf03f5ee6d69c5237aa Mon Sep 17 00:00:00 2001 From: realtradam Date: Sun, 23 Jan 2022 03:19:44 -0500 Subject: fixed delta issues --- src/init.rb | 1 + src/logic.rb | 17 ++++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/init.rb b/src/init.rb index 26f9cca..a79a2df 100644 --- a/src/init.rb +++ b/src/init.rb @@ -1,6 +1,7 @@ Rl.init_window(900, 675, 'Da Game') Rl.init_audio_device if Rl.platform == 'web' +Rl.target_fps = 60 WHITE = Rl::Color.new(255,255,255,255) BLACK = Rl::Color.new(0,0,0,255) diff --git a/src/logic.rb b/src/logic.rb index fffcf7d..4558bd3 100644 --- a/src/logic.rb +++ b/src/logic.rb @@ -40,8 +40,8 @@ end rotation: 0 ), FECS::Cmp::Movement.new( - deceleration: 2.25, - acceleration: 3, + deceleration: 200, + acceleration: 500, max_speed: 300, ), FECS::Cmp::Hitbox.new( @@ -94,14 +94,15 @@ FECS::Scn::Play.add( end # Add normalized speed - velocity_cmp.x += input_x * movement_cmp.acceleration - velocity_cmp.y += input_y * movement_cmp.acceleration + velocity_cmp.x += input_x * movement_cmp.acceleration * Rl.frame_time + + velocity_cmp.y += input_y * movement_cmp.acceleration * Rl.frame_time # Get magnitude velocity_mag = Math.sqrt((velocity_cmp.x**2) + (velocity_cmp.y**2)) # If going slower then deceleration - if velocity_mag < movement_cmp.deceleration + if velocity_mag <= (movement_cmp.deceleration * Rl.frame_time) # Set to 0 velocity_cmp.x = 0 velocity_cmp.y = 0 @@ -111,8 +112,10 @@ FECS::Scn::Play.add( velocity_y_mag = velocity_cmp.y / velocity_mag # Add deceleration - velocity_cmp.x -= velocity_x_mag * movement_cmp.deceleration - velocity_cmp.y -= velocity_y_mag * movement_cmp.deceleration + velocity_cmp.x -= velocity_x_mag * movement_cmp.deceleration * Rl.frame_time + + velocity_cmp.y -= velocity_y_mag * movement_cmp.deceleration * Rl.frame_time + velocity_mag = Math.sqrt((velocity_cmp.x**2) + (velocity_cmp.y**2)) -- cgit v1.2.3