Advertisement
chris33556

beat-em up sprite script

Jun 20th, 2022
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. extends KinematicBody2D
  2. #---------------------------VARIABLES-------------------------------------------
  3. var MAX_SPEED = 250
  4. var JUMP_SPEED = 25
  5. var GRAVITY =35
  6. var z = 0
  7. var JumpMultiplyer = 35
  8. var Jumping = false
  9. var punch = false
  10. var flyingPunch = false
  11. var velocity = Vector2()
  12.  
  13.  
  14. onready var animatedSprite = $AnimatedSprite
  15.  
  16. #-------------------------JUMP + ANIMATION -------------------------------------
  17. # warning-ignore:unused_argument
  18. func _physics_process(delta):
  19. var input_vector = get_input_axis()
  20. print(Jumping)
  21. if Input.is_action_just_pressed("jump") and Jumping == false:
  22. animatedSprite.animation = "jump_right"
  23. Jumping = true
  24. z += -JUMP_SPEED * JumpMultiplyer
  25.  
  26. if Input.is_action_just_pressed("air_attack"):
  27. flyingPunch = true
  28. animatedSprite.animation = "FlyingPunch"
  29.  
  30. if z > 23 * JumpMultiplyer:
  31. Jumping = false
  32. z = 0
  33. velocity.y = 0
  34.  
  35. if Jumping == true:
  36. z += GRAVITY
  37. velocity.y = z
  38. #--------------------------------walk_animation---------------------------------
  39.  
  40. elif input_vector != Vector2.ZERO:
  41. if Jumping == false:
  42. #if !punch:
  43. animatedSprite.animation = "WalkRight"
  44. velocity = input_vector * MAX_SPEED
  45. #------------------------------Punch_animation-----------------------------------
  46.  
  47. elif Input.is_action_just_pressed("punch"):
  48. punch = true
  49. #animatedSprite.speed_scale = 0.5
  50. animatedSprite.animation = "punch"
  51.  
  52.  
  53. #-----------------------------Idle_animation------------------------------------
  54. else:
  55. animatedSprite.animation = "IdleRight"
  56. Jumping = false
  57. flyingPunch = false
  58. punch = false
  59. velocity = Vector2()
  60.  
  61. velocity = move_and_slide(velocity, Vector2())
  62.  
  63.  
  64. #-------------------MOVEMENT_INPUT--------------------------------------------
  65. func get_input_axis():
  66. var input_vector = Vector2()
  67. if !Jumping:
  68. punch = false
  69. input_vector.x = int(Input.is_action_pressed("ui_right")) - int(Input.is_action_pressed("ui_left"))
  70. input_vector.y = int(Input.is_action_pressed("ui_down")) - int(Input.is_action_pressed("ui_up"))
  71.  
  72. if input_vector.x > 0:
  73. animatedSprite.flip_h = false
  74. elif input_vector.x < 0:
  75. animatedSprite.flip_h = true
  76.  
  77. return input_vector
  78.  
  79. #velocity = velocity.clamped(MAX_SPEED)
  80.  
  81.  
  82.  
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement