123456789101112131415161718192021222324252627282930313233343536373839404142 |
- extends KinematicBody2D
- export var vida = 2
- export var speed = 70
- export var type = 1
- func damage(arg, id):
- vida += arg
- if vida <= 0:
- get_tree().get_nodes_in_group('enemy_authority')[0].death_count(id)
- queue_free()
- var motion = Vector2()
- var target
- onready var reaction_time = int(rand_range(20,60))
- var dir_buffer = 0
- var tick = 0
- export var tickrate = 4
- func _physics_process(delta):
- tick += 1
- type = 0 if motion.x == 0 else 1
- if fmod(tick,tickrate) == 0:
- if target == null: _ready()
- if target == null: return
- dir_buffer += 1
- if fmod(dir_buffer,reaction_time) == 0:
- if is_instance_valid(target): motion.x = (target.global_position - global_position).normalized().x * speed
- motion.y += 15
- if motion.y > 0 and is_on_floor(): motion.y = 0
- move_and_slide(motion*tickrate,Vector2.UP)
- func _on_Area2D_body_entered(body):
- print(body)
- if body.is_in_group('players'):
- var array = get_tree().get_nodes_in_group('players')
- array.shuffle()
- if array.size() > 0:
- target = array[0]
- pass # Replace with function body.
|