Guest User

Untitled

a guest
Dec 21st, 2024
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. class_name player
  2. extends CharacterBody2D
  3.  
  4. #sorter var
  5. @export var NormalSPEED = 200
  6.  
  7. const wall_slide_gravity = 60
  8. const dashspeed = 800
  9. const dashlenght = .1
  10.  
  11. @export var JUMP_VELOCITY = -200
  12.  
  13. var ability_can_wall_jump : bool = true
  14. var can_controll : bool = true
  15. var SPEED = NormalSPEED
  16. var is_dashing = false
  17. var can_dash = true
  18. var wall_jump_pushback = 1000
  19. var gravity = 10
  20. var is_wall_sliding = false
  21. var health = 100
  22.  
  23. @onready var animated_sprite_2d = AnimatedSprite2D
  24.  
  25. func _ready() -> void:
  26. for child in get_children():
  27. print(child.name)
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. func _physics_process(delta: float) -> void:
  37.  
  38. if not can_controll: return
  39.  
  40. jump()
  41.  
  42. wall_slide(delta)
  43.  
  44. if Input.is_action_just_pressed("prova"):
  45. ability_can_wall_jump = true
  46.  
  47.  
  48.  
  49. #if Input.is_action_just_pressed("Dash") and can_dash:
  50. #is_dashing = true
  51. #$dashtimer.start()
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. # Get the input direction and handle the movement/deceleration.
  59. # As good practice, you should replace UI actions with custom gameplay actions.
  60. var direction := Input.get_axis("move_left", "move_right")
  61.  
  62. if direction > 0:
  63. animated_sprite_2d.flip_h = false
  64. elif direction < 0:
  65. animated_sprite_2d.flip_h = true
  66.  
  67.  
  68.  
  69. if direction:
  70. if is_dashing:
  71. velocity.x = direction * dashspeed
  72. else:
  73. velocity.x = direction * SPEED
  74.  
  75. else:
  76. velocity.x = move_toward(velocity.x, 0, SPEED)
  77.  
  78.  
  79. move_and_slide()
  80.  
  81. func handle_danger() -> void:
  82. print("player Diead")
  83. visible = false
  84. can_controll = false
  85.  
  86.  
  87. reset_player()
  88.  
  89. func reset_player() -> void:
  90. position = Global.level_start_pos
  91. visible = true
  92. can_controll = true
  93.  
  94.  
  95. func _on_dashtimer_timeout() -> void:
  96. is_dashing = false
  97.  
  98.  
  99.  
  100.  
  101.  
  102. func jump():
  103. if not is_on_floor():
  104. velocity.y += gravity
  105. if Input.is_action_just_pressed("jump"):
  106. if is_on_floor():
  107. velocity.y = JUMP_VELOCITY
  108. if is_on_wall() and Input.is_action_pressed("move_right") and ability_can_wall_jump == true and can_controll == true:
  109. velocity.y = JUMP_VELOCITY
  110. velocity.x = -wall_jump_pushback
  111. if is_on_wall() and Input.is_action_pressed("move_left")and ability_can_wall_jump == true and can_controll == true:
  112. velocity.y = JUMP_VELOCITY
  113. velocity.x = wall_jump_pushback
  114.  
  115. func wall_slide(delta):
  116. if is_on_wall() and !is_on_floor():
  117. if Input.is_action_pressed("move_right") or Input.is_action_pressed("move_left"):
  118. is_wall_sliding = true
  119. else:
  120. @warning_ignore("standalone_expression")
  121. is_wall_sliding
  122. else:
  123. is_wall_sliding = false
  124.  
  125. if is_wall_sliding:
  126. velocity.y += (wall_slide_gravity * delta)
  127. velocity.y = min(velocity.y, wall_slide_gravity)
Advertisement
Add Comment
Please, Sign In to add comment