Added hitstop manager

This commit is contained in:
2026-06-27 23:10:54 +03:00
parent fef98da4e0
commit f8fbc206e8
8 changed files with 50 additions and 8 deletions
+11 -5
View File
@@ -25,6 +25,8 @@ extends CharacterBody2D
var _slow_down_tween: Tween
var _wall_normal: = 0.0
@onready var state_machine : StateMachine = $StateMachine
@@ -47,13 +49,17 @@ func _physics_process(delta: float) -> void:
velocity.y = 0.0
if not is_on_floor():
var gravity_factor := gravity_factor_jump if velocity.y < 0.0 else gravity_factor_fall
if is_on_wall():
_wall_normal = signf(velocity.x)
print("On wall! ", velocity.x, " ", Engine.get_frames_drawn())
else:
var gravity_factor := gravity_factor_jump if velocity.y < 0.0 else gravity_factor_fall
if velocity.y < 0.0 and not Input.is_action_pressed("jump"):
velocity.y *= gravity_factor_passive_jump
if velocity.y < 0.0 and not Input.is_action_pressed("jump"):
velocity.y *= gravity_factor_passive_jump
velocity += get_gravity() * gravity_factor * delta
velocity.y = clampf(velocity.y, -jump_max_fall_speed, jump_max_fall_speed)
velocity += get_gravity() * gravity_factor * delta
velocity.y = clampf(velocity.y, -jump_max_fall_speed, jump_max_fall_speed)
if Input.is_action_just_pressed("jump"):
+1
View File
@@ -7,6 +7,7 @@ extends Node2D
func _ready() -> void:
$Menus.show()
pause_menu.hide()
#TODO Add gameplay music
+1
View File
@@ -10,6 +10,7 @@ script = ExtResource("1_o2mui")
[node name="Player" parent="." unique_id=763780926 instance=ExtResource("2_r0ht6")]
[node name="Menus" type="Control" parent="." unique_id=1464185162]
visible = false
layout_mode = 3
anchors_preset = 0
offset_right = 640.0
+12 -1
View File
@@ -4,6 +4,9 @@
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_bhunq"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_bhunq"]
size = Vector2(20, 2000)
[node name="TestLevel" unique_id=1001045799 instance=ExtResource("1_46m3m")]
[node name="Player" parent="." index="0" unique_id=763780926]
@@ -11,9 +14,17 @@ position = Vector2(0, -30)
[node name="StaticBody2D" type="StaticBody2D" parent="." index="1" unique_id=1113871341]
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D" index="0" unique_id=2097094532]
[node name="CollisionShape2D1" type="CollisionShape2D" parent="StaticBody2D" index="0" unique_id=2097094532]
shape = SubResource("WorldBoundaryShape2D_bhunq")
[node name="CollisionShape2D2" type="CollisionShape2D" parent="StaticBody2D" index="1" unique_id=304230873]
position = Vector2(-200, -1000)
shape = SubResource("RectangleShape2D_bhunq")
[node name="CollisionShape2D3" type="CollisionShape2D" parent="StaticBody2D" index="2" unique_id=771125145]
position = Vector2(0, -1100)
shape = SubResource("RectangleShape2D_bhunq")
[node name="Menus" parent="." index="2" unique_id=1464185162]
offset_left = -320.0
offset_top = -210.0
+15
View File
@@ -0,0 +1,15 @@
class_name CHitstopManager
extends Node
const NORMAL_TIME_SCALE = 1.0
@export var hitstop_duration := 0.1
@export var hitstop_time_scale := 0.0
func hitstop() -> void:
Engine.time_scale = hitstop_time_scale
await get_tree().create_timer(hitstop_duration, true, true, true).timeout
Engine.time_scale = NORMAL_TIME_SCALE
+1
View File
@@ -0,0 +1 @@
uid://ca6ix4nt5uxp3
+6
View File
@@ -0,0 +1,6 @@
[gd_scene format=3 uid="uid://ba262w3ebkyo1"]
[ext_resource type="Script" uid="uid://ca6ix4nt5uxp3" path="res://game/managers/hitstop_manager.gd" id="1_n7h4l"]
[node name="HitstopManager" type="Node" unique_id=669581391]
script = ExtResource("1_n7h4l")
+1
View File
@@ -24,6 +24,7 @@ buses/default_bus_layout="uid://c2chib4gm7ni4"
SoundManager="*uid://b5wqc1hgwcdm4"
SettingsManager="*uid://cuyv26utj07j4"
HitstopManager="*uid://ba262w3ebkyo1"
[debug]