Enemy.gd 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. extends KinematicBody2D
  2. export var vida = 2
  3. export var speed = 70
  4. export var type = 1
  5. func damage(arg, id):
  6. vida += arg
  7. if vida <= 0:
  8. get_tree().get_nodes_in_group('enemy_authority')[0].death_count(id)
  9. queue_free()
  10. var motion = Vector2()
  11. var target
  12. onready var reaction_time = int(rand_range(20,60))
  13. var dir_buffer = 0
  14. var tick = 0
  15. export var tickrate = 4
  16. func _physics_process(delta):
  17. tick += 1
  18. type = 0 if motion.x == 0 else 1
  19. if fmod(tick,tickrate) == 0:
  20. if target == null: _ready()
  21. if target == null: return
  22. dir_buffer += 1
  23. if fmod(dir_buffer,reaction_time) == 0:
  24. if is_instance_valid(target): motion.x = (target.global_position - global_position).normalized().x * speed
  25. motion.y += 15
  26. if motion.y > 0 and is_on_floor(): motion.y = 0
  27. move_and_slide(motion*tickrate,Vector2.UP)
  28. func _on_Area2D_body_entered(body):
  29. print(body)
  30. if body.is_in_group('players'):
  31. var array = get_tree().get_nodes_in_group('players')
  32. array.shuffle()
  33. if array.size() > 0:
  34. target = array[0]
  35. pass # Replace with function body.