Advertisement
Guest User

playerscriptgd

a guest
Oct 2nd, 2023
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. extends actor
  2.  
  3.  
  4. export var stomp_impulse: = 1400.0
  5.  
  6. func _on_EnemyDetector_area_entered(area: Area2D) -> void:
  7. _velocity = calculate_stomp_velocity(_velocity, stomp_impulse)
  8.  
  9. func _on_EnemyDetector_body_entered(body):
  10. die()
  11.  
  12.  
  13. func _physics_process(delta: float) -> void:
  14. var is_jump_interrupted: = Input.is_action_just_released("jump") and _velocity.y < 0.0
  15. var direction: = get_direction()
  16. _velocity = calculate_move_velocity(_velocity, direction, speed, is_jump_interrupted)
  17. _velocity = move_and_slide(_velocity, FLOOR_NORMAL)
  18.  
  19.  
  20. func get_direction () -> Vector2:
  21. return Vector2(
  22. Input.get_action_strength("move_right") - Input.get_action_strength("move_left"),
  23. -1.0 if Input.is_action_just_pressed("jump") and is_on_floor() else 0.0
  24.  
  25. )
  26.  
  27. #func get_direction() -> Vector2:
  28. # var move_direction = Vector2(
  29. # Input.get_action_strength("move_right") - Input.get_action_strength("move_left"), -1.0 if Input.is_action_just_pressed("jump") and is_on_floor() else 0.0
  30. # )
  31. # if move_direction.x != 0:
  32. # $player.play("walk")
  33. # $player.flip_h = move_direction.x < 0
  34. # else:
  35. # $player.play("iddle")
  36. # return move_direction
  37.  
  38.  
  39.  
  40. func calculate_move_velocity(
  41. linear_velocity: Vector2,
  42. direction: Vector2,
  43. speed: Vector2,
  44. is_jump_interrupted: bool
  45. ) -> Vector2:
  46. var out: = linear_velocity
  47. out.x = speed.x * direction.x
  48. out.y += gravity * get_physics_process_delta_time()
  49. if direction.y == -1.0:
  50. out.y = speed.y * direction.y
  51. if is_jump_interrupted:
  52. out.y = 0.0
  53. return out
  54.  
  55.  
  56. func calculate_stomp_velocity(linear_velocity: Vector2, impulse: float) -> Vector2:
  57. var out: = linear_velocity
  58. out.y = -impulse
  59. return out
  60.  
  61.  
  62. func die() -> void:
  63. PlayerData.deaths += 1
  64. queue_free()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement