-
Notifications
You must be signed in to change notification settings - Fork 0
/
emitter.gd
52 lines (41 loc) · 1.29 KB
/
emitter.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
extends KinematicBody2D
const BonkerScene = preload('res://scenes/objects/bonker.tscn')
var rng : RandomNumberGenerator
var move_dir : Vector2
export var move_speed : float = 50.0
export var health : int = 1
var dying : bool = false
func _ready():
rng = RandomNumberGenerator.new()
rng.randomize()
move_dir = Vector2(rng.randf_range(-1.0, 1.0), rng.randf_range(-1.0, 1.0)).normalized()
func _physics_process(delta):
if dying:
return
var coll : KinematicCollision2D = self.move_and_collide(move_dir * move_speed * delta)
if coll:
change_dir()
func _on_spawn_timer_timeout():
if dying:
return
var new_bonker = BonkerScene.instance()
new_bonker.dir_vec = Vector2(rng.randf_range(-1.0, 1.0), rng.randf_range(-1.0, 1.0)).normalized()
new_bonker.position = self.get_global_position()
self.get_tree().get_root().get_node('sand').add_child(new_bonker)
func get_class():
return "enemy"
func take_damage(var damage_taken : int):
if dying:
return
health -= damage_taken
if health <= 0:
self.dying = true
self.visible = false
$DieSoundPlayer.play()
yield($DieSoundPlayer, "finished")
self.queue_free()
Global.score += 1
func change_dir():
move_dir = Vector2(rng.randf_range(-1.0, 1.0), rng.randf_range(-1.0, 1.0)).normalized()
func _on_emmiter_move_timer_timeout():
change_dir()