Enemy.gd 1015 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. if fmod(tick,tickrate) == 0:
  19. if target == null: _ready()
  20. if target == null: return
  21. dir_buffer += 1
  22. if fmod(dir_buffer,reaction_time) == 0:
  23. if is_instance_valid(target): motion.x = (target.global_position - global_position).normalized().x * speed
  24. motion.y += 15
  25. if motion.y > 0 and is_on_floor(): motion.y = 0
  26. move_and_slide(motion*tickrate,Vector2.UP)
  27. func _on_Area2D_body_entered(body):
  28. print(body)
  29. if body.is_in_group('players'):
  30. var array = get_tree().get_nodes_in_group('players')
  31. array.shuffle()
  32. if array.size() > 0:
  33. target = array[0]
  34. pass # Replace with function body.