extends CharacterBody2D
@export var SPEED : int = 150
@export var JUMP_FORCE : int = 300
@export var GRAVITY : int = 900
const max_jumps = 2
@export var current_jumps = 1
@export var is_Attacking = false
func _physics_process(delta):
run()
Rotate
omdraaien()
Gravity
zwaartekracht(delta)
Jump
jump()
attack
attack()
move_and_slide()
func run():
var direction = Input.get_axis("ui_left","ui_right")
if direction:
velocity.x = SPEED * direction
if is_on_floor() and is_Attacking == false:
$AnimatedSprite2D.play("run")
else:
velocity.x = 0
if is_on_floor() and is_Attacking == false:
$AnimatedSprite2D.play("idle")
func omdraaien():
var direction = Input.get_axis("ui_left","ui_right")
if direction == 1:
$AnimatedSprite2D.flip_h = false
elif direction == -1:
$AnimatedSprite2D.flip_h = true
func zwaartekracht(delta):
if not is_on_floor():
velocity.y += GRAVITY * delta
if velocity.y > 0 and is_Attacking == false:
$AnimatedSprite2D.play("fall")
func jump():
if Input.is_action_just_pressed("Jump"):
if current_jumps < max_jumps and is_Attacking == false:
velocity.y -= JUMP_FORCE
$AnimatedSprite2D.play("jump")
current_jumps += 1
$AnimatedSprite2D.play("jump_double")
if is_on_floor():
current_jumps = 1
func attack():
if Input.is_action_just_pressed("Attack"):
$AnimatedSprite2D.play("attack")
is_Attacking = true
func _on_animated_sprite_2d_animation_finished():
if $AnimatedSprite2D.play == "attack":
is_Attacking = false