Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. const MOVE_SPEED = 150
  4. const STAMINA_REC_SPEED = 5
  5. const BULLET_SCENE = preload("res://objects/bullet/Bullet.tscn")
  6. var stamina = 100
  7.  
  8. func _ready():
  9. yield(get_tree(), "idle_frame")
  10. get_tree().call_group("zombies", "set_player", self)
  11.  
  12. func _physics_process(delta):
  13. move(delta)
  14.  
  15. var look_vec = get_global_mouse_position() - global_position
  16. global_rotation = atan2(look_vec.y, look_vec.x)
  17.  
  18. if Input.is_action_just_pressed("shoot"):
  19. var b = BULLET_SCENE.instance()
  20. b.position(look_vec)
  21. get_parent().add_child(b)
  22. b.set_position(get_node("Position2D").get_global_position())
  23.  
  24. func sprint(delta):
  25. if Input.is_action_pressed("sprint"):
  26. if stamina <= 0:
  27. stamina = 0
  28. print(stamina)
  29. return false
  30. stamina -= STAMINA_REC_SPEED * 4 * delta
  31. print(stamina)
  32. return true
  33. if stamina >= 100:
  34. stamina = 100
  35. else:
  36. stamina += STAMINA_REC_SPEED * delta
  37. print(stamina)
  38. return false
  39.  
  40. func move(delta):
  41. var speed = MOVE_SPEED
  42. if sprint(delta):
  43. speed = MOVE_SPEED * 2
  44. var move_vec = Vector2()
  45. if Input.is_action_pressed("move_up"):
  46. move_vec.y -= 1
  47. if Input.is_action_pressed("move_down"):
  48. move_vec.y += 1
  49. if Input.is_action_pressed("move_left"):
  50. move_vec.x -= 1
  51. if Input.is_action_pressed("move_right"):
  52. move_vec.x += 1
  53. move_vec = move_vec.normalized()
  54. move_and_collide(move_vec * speed * delta)
  55.  
  56. func kill():
  57. get_tree().reload_current_scene()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement