Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3.  
  4. const SPEED = 60
  5. const GRAVITY = 10
  6. const JUMP_POWER = -250
  7. const FLOOR = Vector2(0, -1)
  8.  
  9. const FIREBALL = preload("res://Fireball.tscn")
  10.  
  11. var velocity = Vector2()
  12.  
  13. var on_ground = false
  14.  
  15. var is_attacking = false
  16.  
  17. func _physics_process(delta):
  18.  
  19.  
  20. if Input.is_action_pressed("ui_right"):
  21. if is_attacking == false || is_on_floor() == false:
  22. velocity.x = SPEED
  23. if is_attacking == false:
  24. $AnimatedSprite.play("run")
  25. $AnimatedSprite.flip_h = false
  26. $Position2D.position.x = 1
  27. elif Input.is_action_pressed("ui_left"):
  28. if is_attacking == false || is_on_floor() == false:
  29. velocity.x = -SPEED
  30. $AnimatedSprite.play("run")
  31. $AnimatedSprite.flip_h = true
  32. $Position2D.position.x = -1
  33. else:
  34. velocity.x = 0
  35. if on_ground == true && is_attacking == false:
  36. $AnimatedSprite.play("idle")
  37.  
  38. if Input.is_action_pressed("ui_up"):
  39. if is_attacking == false:
  40. if on_ground == true:
  41. velocity.y = JUMP_POWER
  42. on_ground = false
  43.  
  44. if Input.is_action_just_pressed("ui_focus_next") && is_attacking == false:
  45. if is_on_floor():
  46. velocity.x = 0
  47. is_attacking = true
  48. $AnimatedSprite.play("attack")
  49. var fireball = FIREBALL.instance()
  50. if sign($Position2D.position.x) == 1:
  51. fireball.set_fireball_direction(1)
  52. else:
  53. fireball.set_fireball_direction(-1)
  54. get_parent().add_child(fireball)
  55. fireball.global_position = $Position2D.global_position
  56.  
  57. velocity.y += GRAVITY
  58.  
  59. if is_on_floor():
  60. if on_ground == false:
  61. is_attacking = false
  62. on_ground = true
  63. else:
  64. if is_attacking == false:
  65. on_ground = false
  66. if velocity.y < 0:
  67. $AnimatedSprite.play("jump")
  68. else:
  69. $AnimatedSprite.play("fall")
  70.  
  71. velocity = move_and_slide(velocity, FLOOR)
  72.  
  73. func _on_AnimatedSprite_animation_finished():
  74. is_attacking = false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement