Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class_name player
- extends CharacterBody2D
- #sorter var
- @export var NormalSPEED = 200
- const wall_slide_gravity = 60
- const dashspeed = 800
- const dashlenght = .1
- @export var JUMP_VELOCITY = -200
- var ability_can_wall_jump : bool = true
- var can_controll : bool = true
- var SPEED = NormalSPEED
- var is_dashing = false
- var can_dash = true
- var wall_jump_pushback = 1000
- var gravity = 10
- var is_wall_sliding = false
- var health = 100
- @onready var animated_sprite_2d = AnimatedSprite2D
- func _ready() -> void:
- for child in get_children():
- print(child.name)
- func _physics_process(delta: float) -> void:
- if not can_controll: return
- jump()
- wall_slide(delta)
- if Input.is_action_just_pressed("prova"):
- ability_can_wall_jump = true
- #if Input.is_action_just_pressed("Dash") and can_dash:
- #is_dashing = true
- #$dashtimer.start()
- # Get the input direction and handle the movement/deceleration.
- # As good practice, you should replace UI actions with custom gameplay actions.
- var direction := Input.get_axis("move_left", "move_right")
- if direction > 0:
- animated_sprite_2d.flip_h = false
- elif direction < 0:
- animated_sprite_2d.flip_h = true
- if direction:
- if is_dashing:
- velocity.x = direction * dashspeed
- else:
- velocity.x = direction * SPEED
- else:
- velocity.x = move_toward(velocity.x, 0, SPEED)
- move_and_slide()
- func handle_danger() -> void:
- print("player Diead")
- visible = false
- can_controll = false
- reset_player()
- func reset_player() -> void:
- position = Global.level_start_pos
- visible = true
- can_controll = true
- func _on_dashtimer_timeout() -> void:
- is_dashing = false
- func jump():
- if not is_on_floor():
- velocity.y += gravity
- if Input.is_action_just_pressed("jump"):
- if is_on_floor():
- velocity.y = JUMP_VELOCITY
- if is_on_wall() and Input.is_action_pressed("move_right") and ability_can_wall_jump == true and can_controll == true:
- velocity.y = JUMP_VELOCITY
- velocity.x = -wall_jump_pushback
- if is_on_wall() and Input.is_action_pressed("move_left")and ability_can_wall_jump == true and can_controll == true:
- velocity.y = JUMP_VELOCITY
- velocity.x = wall_jump_pushback
- func wall_slide(delta):
- if is_on_wall() and !is_on_floor():
- if Input.is_action_pressed("move_right") or Input.is_action_pressed("move_left"):
- is_wall_sliding = true
- else:
- @warning_ignore("standalone_expression")
- is_wall_sliding
- else:
- is_wall_sliding = false
- if is_wall_sliding:
- velocity.y += (wall_slide_gravity * delta)
- velocity.y = min(velocity.y, wall_slide_gravity)
Advertisement
Add Comment
Please, Sign In to add comment