Advertisement
Guest User

Untitled

a guest
Jun 19th, 2025
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. extends CharacterBody2D
  2.  
  3. @export var yes = 1
  4.  
  5. var up
  6. var down
  7. var left
  8. var right
  9. var input = Vector2.ZERO
  10. var speed
  11. var zoom_minimum= Vector2(2, 2)
  12. var zoom_maximum= Vector2(.5, .5)
  13. var zoom_speed= Vector2(.08, .08)
  14. var dashing = false
  15. var can_dash = true
  16. var direction
  17.  
  18. @onready var camera = $Camera2D
  19.  
  20. const move_speed: int = 6000
  21. const max_speed = 2100
  22. const accel = 1800
  23. const friction = 2500
  24. const dash_speed = 9000
  25.  
  26. #Movement
  27. func _physics_process(delta):
  28. player_movement(delta)
  29.  
  30. func get_input():
  31. input.x = int(Input.is_action_pressed("right")) - int(Input.is_action_pressed("left"))
  32. input.y = int(Input.is_action_pressed("down")) - int(Input.is_action_pressed("up"))
  33. return input.normalized()
  34.  
  35. func _input(_delta):
  36. if Input.is_action_pressed("plus"):
  37. if camera.zoom < zoom_minimum:
  38. camera.zoom += zoom_speed
  39. if Input.is_action_pressed("minus"):
  40. if camera.zoom > zoom_maximum:
  41. camera.zoom -= zoom_speed
  42.  
  43. if Input.is_action_just_pressed("dashing") and can_dash:
  44. dashing = true
  45. can_dash = false
  46. $dash_timer.start()
  47. $dash_again_timer.start()
  48.  
  49. func player_movement(delta):
  50. input = get_input()
  51. if input == Vector2.ZERO:
  52. if velocity.length() > (friction * delta):
  53. velocity -= velocity.normalized() * (friction * delta)
  54. else:
  55. velocity = Vector2.ZERO
  56. else:
  57. velocity += (input * accel * delta * 2)
  58. velocity = velocity.limit_length(max_speed)
  59. if direction:
  60. if dashing:
  61. velocity = input + dash_speed
  62. else:
  63. velocity = input + speed
  64.  
  65. #animation I hate it so much
  66. if velocity == Vector2.ZERO:
  67. pass
  68. else:
  69. $AnimationTree.set("parameters/Idle/blend_position", velocity)
  70. $AnimationTree.set("parameters/Walk/blend_position", velocity)
  71. move_and_slide()
  72.  
  73. #make it stop dashing
  74. func _on_dash_timer_timeout():
  75. dashing = false
  76.  
  77. func _on_dash_again_timer_timeout():
  78. can_dash = true
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement