-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMissile.tscn
119 lines (83 loc) · 2.45 KB
/
Missile.tscn
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
[gd_scene load_steps=5 format=2]
[ext_resource path="res://assets/marker.png" type="Texture" id=1]
[ext_resource path="res://assets/sounds/Missle_Launch-Kibblesbob-2118796725.wav" type="AudioStream" id=2]
[ext_resource path="res://assets/patriot.png" type="Texture" id=3]
[sub_resource type="GDScript" id=1]
script/source = "# Missile Scene
extends Node2D
var Explode = preload(\"res://Explode.tscn\")
var rng = RandomNumberGenerator.new()
const explode_start = 2
const explode_decay = 1.8
const explode_end = 2.7
const max_size = 0.5
var defend_color setget set_color
var phase = 0
var boom_size = Vector2(0, 0)
var start_loc setget set_start
var end_loc = Vector2(0, 0)
var cur_loc = null
var missile_speed setget set_speed
var time = 0
var missile_dir = Vector2(0,0)
func _ready():
if missile_speed == 0:
missile_speed = 15
$Patriot.position = start_loc
var velocity = start_loc.direction_to(end_loc)
var angle = rad2deg(velocity.angle()) + 90
$Patriot.set_rotation_degrees(angle)
$LaunchSound.play()
func _process(delta):
time += delta
if phase == 0:
move_missile()
elif phase == 1:
on_explode()
if time > explode_end:
on_end()
flicker_marker()
func _draw():
if cur_loc != null && phase == 0:
draw_line(start_loc, cur_loc, defend_color)
func on_explode():
$Marker.visible = false
var new_explode = Explode.instance()
new_explode.position = $Marker.position
add_child(new_explode)
phase = 2
func move_missile():
var old_position = $Patriot.position
var velocity = start_loc.direction_to(end_loc) * missile_speed
cur_loc = old_position + velocity
flicker_marker()
$Patriot.position = cur_loc
update()
if cur_loc.y < end_loc.y:
phase = 1
$Patriot.visible = false
func flicker_marker():
var red = rng.randf_range(.2, 1)
var green = rng.randf_range(.2, 1)
$Marker.self_modulate = Color(red, green, 200)
func on_end():
queue_free()
# get_parent().remove_child(self)
func set_start(new_value):
start_loc = new_value - position
func set_speed(new_value):
missile_speed = new_value
func set_color(new_value):
defend_color = new_value
"
[node name="Missile" type="Node2D"]
script = SubResource( 1 )
[node name="Marker" type="Sprite" parent="."]
scale = Vector2( 0.5, 0.5 )
texture = ExtResource( 1 )
[node name="Patriot" type="Sprite" parent="."]
scale = Vector2( 0.3, 0.301324 )
texture = ExtResource( 3 )
[node name="LaunchSound" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource( 2 )
volume_db = -23.2