This repository has been archived by the owner on Aug 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswarm_attacker.gd
60 lines (53 loc) · 1.57 KB
/
swarm_attacker.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
extends Node2D
var projectile = preload("res://Bullets/EnemyBullet.tscn")
onready var timer = Timer.new()
var shooting:bool = false
signal shooting_finished
var locked_target:bool
var lock_on:bool = true
func _ready():
add_child(timer)
func attack(projectile_count:int, projectile_speed:float, lock:bool=true):
lock_on=lock
$AnimationPlayer.play("spawn")
yield($AnimationPlayer, "animation_finished")
shoot_pat1(projectile_count, projectile_speed)
yield(self, "shooting_finished")
$AnimationPlayer.play("despawn")
yield($AnimationPlayer, "animation_finished")
queue_free()
var shooted:int = 0
func start_pattern(projectile_count:int, projectile_speed:float):
timer.disconnect("timeout", self, "start_pattern")
timer.wait_time = .1
shooting = true
shooted = 0
#timer.start()
func _process(_delta):
if shooting and not player_stats.dead:
if timer.is_stopped():
if shooted < 10:
var p = get_tree().get_nodes_in_group("player")
timer.start()
if len(p) > 0 and not locked_target:
look_at(p[0].position)
if lock_on:
locked_target = true
shoot()
shooted += 1
else:
shooting = false
emit_signal("shooting_finished")
func shoot_pat1(projectile_count:int, projectile_speed:float):
#timer.stop()
#timer.wait_time = 0
timer.one_shot = true
timer.connect("timeout", self, "start_pattern")
start_pattern(projectile_count, projectile_speed)
#timer.start()
func shoot():
if visible:
var i = BulletSystem.fire(projectile, $shoot_point.global_position, rotation_degrees+rand_range(-15, 15), 1000, get_parent())
i.damage = 10
else:
return