Advertisement
Guest User

Untitled

a guest
Feb 14th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. var velocity = Vector2()
  4.  
  5. var on_ground = false
  6.  
  7. var is_dead = false
  8.  
  9. const SPEED = 130
  10. const GRAVITY = 10
  11. const JUMP_POWER = -320
  12. const FLOOR = Vector2(0, -1)
  13. const FIREBALL = preload("res://Fireball.tscn")
  14.  
  15. func _physics_process(delta):
  16.  
  17. if is_dead == false:
  18. if Input.is_action_pressed("ui_right"):
  19. velocity.x = SPEED
  20. $AnimatedSprite.play("Run")
  21. $AnimatedSprite.flip_h = false
  22. if sign($Position2D.position.x) == -1:
  23. $Position2D.position.x *= -1
  24. elif Input.is_action_pressed("ui_left"):
  25. velocity.x = -SPEED
  26. $AnimatedSprite.play("Run")
  27. $AnimatedSprite.flip_h = true
  28. if sign($Position2D.position.x) == 1:
  29. $Position2D.position.x *= -1
  30. else:
  31. velocity.x = 0
  32. if on_ground == true:
  33. $AnimatedSprite.play("idle")
  34.  
  35.  
  36.  
  37. if Input.is_action_pressed("ui_up"):
  38. if on_ground == true:
  39. velocity.y = JUMP_POWER
  40. on_ground = false
  41.  
  42. if is_on_floor():
  43. on_ground = true
  44. else:
  45. on_ground = false
  46. if velocity.y < 0:
  47. $AnimatedSprite.play("Jump")
  48. else:
  49. $AnimatedSprite.play("Fall")
  50.  
  51. if get_slide_count() > 0:
  52. for i in range(get_slide_count()):
  53. if "KinematicBody2D" in get_slide_collision(i).collider.name:
  54. dead()
  55.  
  56. func dead():
  57. is_dead = true
  58. velocity = Vector2(0, 0)
  59. $AnimatedSprite.play("Dead")
  60. $CollisionShape2D.disabled = true
  61. $Timer.start()
  62.  
  63. velocity.y += GRAVITY
  64. velocity = move_and_slide(velocity, FLOOR)
  65.  
  66.  
  67.  
  68. if Input.is_action_just_pressed("ui_focus_next"):
  69. var fireball = FIREBALL.instance()
  70. if sign($Position2D.position.x) == 1:
  71. fireball.set_fireball_direction(1)
  72. else:
  73. fireball.set_fireball_direction(-1)
  74. get_parent().add_child(fireball)
  75. fireball.position = $Position2D.global_position
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. func _on_Timer_timeout():
  83. get_tree().change_scene("res://TitleScreen.tscn")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement