Added hitstop manager
This commit is contained in:
@@ -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 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)
|
||||
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
|
||||
|
||||
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"):
|
||||
|
||||
@@ -7,6 +7,7 @@ extends Node2D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
$Menus.show()
|
||||
pause_menu.hide()
|
||||
|
||||
#TODO Add gameplay music
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
uid://ca6ix4nt5uxp3
|
||||
@@ -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")
|
||||
Reference in New Issue
Block a user