Merge pull request 'dev' (#27) from dev into Book_Cleanup
Reviewed-on: https://code.booklordofthe.dev///Booklordofthedings/GMTK-2024/pulls/27
This commit is contained in:
commit
878db579bc
3 changed files with 41 additions and 20 deletions
BIN
.DS_Store
vendored
BIN
.DS_Store
vendored
Binary file not shown.
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://ba6afuig8bqrg" path="res://levels/LevelBase.tscn" id="1_ad6qp"]
|
[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="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://b2vqx11kx16u" 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="Texture2D" uid="uid://51ffxb41mud6" 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="PackedScene" path="res://objects/EnemyMover.tscn" id="4_3fnma"]
|
||||||
|
|
||||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_e817v"]
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_e817v"]
|
||||||
texture = ExtResource("3_3ou1v")
|
texture = ExtResource("3_3ou1v")
|
||||||
|
|
|
@ -1,41 +1,62 @@
|
||||||
extends CharacterBody2D
|
extends CharacterBody2D
|
||||||
|
|
||||||
@export var speed = 340;
|
@export var speed = 340
|
||||||
@export var gravity = 50;
|
@export var gravity = 50
|
||||||
@export var jump_count = 2;
|
var jump_count = 1
|
||||||
@export var jump_strength = 100
|
@export var jump_strength = 100
|
||||||
|
var is_touching_floor : bool = true
|
||||||
var jump_count_current = 2;
|
var jump_buffer_timer : float
|
||||||
|
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
|
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 left = Input.is_action_pressed("player_left")
|
||||||
var right = Input.is_action_pressed("player_right")
|
var right = Input.is_action_pressed("player_right")
|
||||||
|
|
||||||
if left and right:
|
if left and right:
|
||||||
input_direction = input_direction
|
input_direction = 0
|
||||||
elif left:
|
elif left:
|
||||||
input_direction = -1
|
input_direction = -1
|
||||||
elif right:
|
elif right:
|
||||||
input_direction = 1
|
input_direction = 1
|
||||||
else :
|
else:
|
||||||
input_direction = 0
|
input_direction = 0
|
||||||
|
|
||||||
|
# This line updates the player's velocity
|
||||||
velocity.x = input_direction * speed
|
velocity.x = input_direction * speed
|
||||||
|
|
||||||
if is_on_floor(): # rest the jump count
|
if is_on_floor():
|
||||||
jump_count_current = jump_count
|
# reset the jump count
|
||||||
|
is_touching_floor = true
|
||||||
|
jump_count = 1
|
||||||
|
coyote_timer = 0.2
|
||||||
|
if jump_buffer_timer > 0:
|
||||||
|
Jump()
|
||||||
|
|
||||||
if Input.is_action_just_pressed("player_jump") and jump_count_current > 0:
|
if not is_on_floor():
|
||||||
velocity.y = -1 * jump_strength
|
if jump_buffer_timer > 0:
|
||||||
jump_count_current = jump_count_current-1
|
jump_buffer_timer -= delta
|
||||||
elif Input.is_action_pressed("player_jump"): #Fall less fast if we keep holding the button
|
if coyote_timer > 0.0:
|
||||||
|
coyote_timer -= delta
|
||||||
|
else:
|
||||||
|
jump_count = 0
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("player_jump"):
|
||||||
|
if jump_count > 0:
|
||||||
|
Jump()
|
||||||
|
else:
|
||||||
|
jump_buffer_timer = 0.2 # set a timer to jump again once the player has reached the ground, provided the jump is is still being held down
|
||||||
|
elif Input.is_action_pressed("player_jump"): #Fall less fast if we keep holding the button
|
||||||
velocity.y += -1 * 25
|
velocity.y += -1 * 25
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
get_input()
|
get_input(delta)
|
||||||
velocity.y += gravity
|
velocity.y += gravity
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
# print(jump_count) # Uncomment for debugging
|
||||||
|
|
||||||
|
func Jump():
|
||||||
|
velocity.y = -1 * jump_strength
|
||||||
|
jump_count = 0
|
||||||
|
is_touching_floor = false
|
||||||
|
|
Loading…
Add table
Reference in a new issue