extends CharacterBody2D
const SPEED = 600.0
const JUMP_VELOCITY = -1900.0
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("Jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var run_multiplier = 1
if Input.is_action_pressed("run"):
run_multiplier = 2
else:
run_multiplier = 1
var direction := Input.get_axis("Left", "Right")
if direction:
velocity.x = direction * SPEED * run_multiplier
else:
velocity.x = move_toward(velocity.x, 0, SPEED * run_multiplier)
if velocity.x < 0:
$AnimatedSprite2D.flip_h = true
if velocity.x > 0:
$AnimatedSprite2D.flip_h = false
if velocity.x != 0:
$[Link]("walk")
else:
$[Link]("idle")
move_and_slide()
extends Node
var coins = 0
var score = 0
extends AnimatedSprite2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_area_2d_body_entered(body: Node2D) -> void:
if body.is_in_group('Player'):
[Link] += 1
[Link] += 100
queue_free() #coin disappear
print("Coin collected!") # Debugging
queue_free() # Coin disappears