From 543394bd194faea231c0350deded644d938be83d Mon Sep 17 00:00:00 2001 From: zymsbgt <91821082+zymsbgt@users.noreply.github.com> Date: Sat, 17 Aug 2024 22:26:53 +0800 Subject: [PATCH] added coyote timer --- .DS_Store | Bin 6148 -> 6148 bytes gmtk_2024/levels/TestingField.tscn | 6 ++--- gmtk_2024/scripts/player_movement.gd | 38 ++++++++++++++++++--------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.DS_Store b/.DS_Store index f6bd939917fe6e6c854c51a624e88c2881f70afe..0466bd59253a30ecfeadfb47fd0b25f01ef4c0f7 100644 GIT binary patch delta 334 zcmZoMXfc=|#>B)qu~2NHo}wrl0|Nsi1A_nqLncEyLmopuLlHyj=8KHW8BIY_Tnu_Z z;Y@}SWNFWw{N$vZ{3M_}P#m9X z!pg?Z!Op?W5gVM5UmjeNSW;T-lvorE;)Uer=On?{iAiCZspatkBF_1FC5f4NsYPH7 znJKA2B{AWdc`5njPWh#IDaByD!4L@!P7cm^0f}nYYI8Fk1!E(_S{;RILqlUD9R*Wk z!A4ToZP(pE}*M{fD!0;GwlD(#6vtLE delta 87 zcmZoMXfc=|#>B`mu~2NHo}wrV0|Nsi1A_nqLkUB%XHI@{Qcix-#KPr_ER!9WHf%n{ oY|FCw12Z4fW_AvK4xqNp51GF+Pv#e~15g*AhLxS0JOCgFaQ7m diff --git a/gmtk_2024/levels/TestingField.tscn b/gmtk_2024/levels/TestingField.tscn index 29c5ceb..9c3b61b 100644 --- a/gmtk_2024/levels/TestingField.tscn +++ b/gmtk_2024/levels/TestingField.tscn @@ -2,9 +2,9 @@ [ext_resource type="PackedScene" uid="uid://ba6afuig8bqrg" path="res://levels/LevelBase.tscn" id="1_ad6qp"] [ext_resource type="Shader" path="res://shaders/scrolling.gdshader" id="2_60gse"] -[ext_resource type="Texture2D" uid="uid://c4r7ka8jkgcau" path="res://textures/Level 01.png" id="2_gi0pl"] -[ext_resource type="Texture2D" uid="uid://b13adrmbk7mt0" path="res://textures/level01-spritesheet.png" id="3_3ou1v"] -[ext_resource type="PackedScene" uid="uid://vtwswrkfkgas" path="res://objects/EnemyMover.tscn" id="4_3fnma"] +[ext_resource type="Texture2D" uid="uid://b2vqx11kx16u" path="res://textures/Level 01.png" id="2_gi0pl"] +[ext_resource type="Texture2D" uid="uid://51ffxb41mud6" path="res://textures/level01-spritesheet.png" id="3_3ou1v"] +[ext_resource type="PackedScene" path="res://objects/EnemyMover.tscn" id="4_3fnma"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_e817v"] texture = ExtResource("3_3ou1v") diff --git a/gmtk_2024/scripts/player_movement.gd b/gmtk_2024/scripts/player_movement.gd index 54d84c2..fc44d85 100644 --- a/gmtk_2024/scripts/player_movement.gd +++ b/gmtk_2024/scripts/player_movement.gd @@ -1,20 +1,20 @@ extends CharacterBody2D -@export var speed = 340; -@export var gravity = 50; -@export var jump_count = 2; +@export var speed = 340 +@export var gravity = 50 +var jump_count = 1 @export var jump_strength = 100 - -var jump_count_current = 2; +var is_touching_floor : bool = true +var coyote_timer : float = 0.2 # 200 millisecond buffer var input_direction = 0 #To keep track of which direction we where moving in last frame -func get_input(): +func get_input(delta): var left = Input.is_action_pressed("player_left") var right = Input.is_action_pressed("player_right") if left and right: - input_direction = input_direction + input_direction = 0 elif left: input_direction = -1 elif right: @@ -22,20 +22,32 @@ func get_input(): else : input_direction = 0 + # This line updates the player's velocity velocity.x = input_direction * speed - if is_on_floor(): # rest the jump count - jump_count_current = jump_count + if is_on_floor(): + # reset the jump count + is_touching_floor = true + jump_count = 1 + coyote_timer = 0.2 - if Input.is_action_just_pressed("player_jump") and jump_count_current > 0: + if not is_on_floor(): + if coyote_timer > 0.0: + coyote_timer -= delta + else: + jump_count = 0 + + if Input.is_action_just_pressed("player_jump") and jump_count > 0: velocity.y = -1 * jump_strength - jump_count_current = jump_count_current-1 - elif Input.is_action_pressed("player_jump"): #Fall less fast if we keep holding the button + jump_count = 0 + is_touching_floor = false + elif Input.is_action_pressed("player_jump"): #Fall less fast if we keep holding the button velocity.y += -1 * 25 func _physics_process(delta): - get_input() + get_input(delta) velocity.y += gravity move_and_slide() + print(jump_count)