doing prep week 3
This commit is contained in:
parent
b8e6b3f2ce
commit
47fa82b075
@ -22,3 +22,6 @@ position = Vector2(14, -8)
|
||||
|
||||
[node name="LeftSpawn" type="Marker2D" parent="."]
|
||||
position = Vector2(-13, -8)
|
||||
|
||||
[node name="JumpBufferTimer" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
@ -3,6 +3,8 @@ extends CharacterBody2D
|
||||
|
||||
const SPEED = 300.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
#add a variable for momentum...t.w.
|
||||
@export var acceleration:int = 8
|
||||
var direction:float = 0
|
||||
@export var BUMP_POWER = 100
|
||||
enum FaceDirection{LEFT, RIGHT}
|
||||
@ -14,6 +16,8 @@ var pushEnabled:bool = false
|
||||
@onready var right_spawn = $RightSpawn
|
||||
@onready var left_spawn = $LeftSpawn
|
||||
|
||||
@onready var jump_buffer_timer: Timer = $JumpBufferTimer
|
||||
|
||||
func _physics_process(delta):
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
@ -25,7 +29,8 @@ func _physics_process(delta):
|
||||
func handle_input()->void:
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
jump_buffer_timer.start()
|
||||
|
||||
direction = Input.get_axis("moveLeft", "moveRight")
|
||||
if direction <0:
|
||||
facing=FaceDirection.LEFT
|
||||
@ -60,14 +65,20 @@ func handle_input()->void:
|
||||
%SceneManager.makeGrenade(left_spawn.global_transform, -1)
|
||||
|
||||
func handle_movement(_delta)->void:
|
||||
if direction:
|
||||
velocity.x = direction * SPEED
|
||||
#change to create some momentum.....t.w.
|
||||
if direction == 0:
|
||||
velocity.x = move_toward(velocity.x, 0, acceleration)
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
velocity.x = move_toward(velocity.x, SPEED * direction, acceleration)
|
||||
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * _delta
|
||||
|
||||
#add a buffer timer to the jump velocity............t.w.
|
||||
if is_on_floor() && jump_buffer_timer.time_left >0:
|
||||
velocity.y = JUMP_VELOCITY
|
||||
jump_buffer_timer.stop()
|
||||
|
||||
func handle_collisions()->void:
|
||||
#handle world reactions
|
||||
for i in get_slide_collision_count():
|
||||
|
||||
Loading…
Reference in New Issue
Block a user