diff --git a/scripts/enemy.gd b/scripts/enemy.gd index f4f7d5d..260a37f 100644 --- a/scripts/enemy.gd +++ b/scripts/enemy.gd @@ -1,12 +1,19 @@ -class_name Enemy extends RigidBody2D +class_name Enemy extends StaticBody2D +# used StaticBody to get around gravity, probably a better way -# there is probably a better built-in to use here +# there is probably a better built-in to use here, maybe not for static body @export var direction:int = 1 const SPEED = 1 +var drop = false func _ready(): - pass # Replace with function body. + pass + +func go_down(): + drop = true func _process(_delta): - var x = get_transform().get_origin().x move_local_x(SPEED * direction) + if drop: + move_local_y(SPEED * 5) + drop = false diff --git a/scripts/game-controller.gd b/scripts/game-controller.gd index c0626d0..3906775 100644 --- a/scripts/game-controller.gd +++ b/scripts/game-controller.gd @@ -11,13 +11,15 @@ func _process(_delta): # detect when one enemy goes too far var change_dir = false for child in game_node.get_children(): - if child is RigidBody2D: + if child is Enemy: var x = child.transform.get_origin().x - if x < 0 or x > 300: # not using collision detection properly + if x < 0 or x > 600: # not using collision detection properly change_dir = true break + # change directions of all enemies if change_dir: for child in game_node.get_children(): - if child is RigidBody2D: - child.mydirection *= -1 + if child is Enemy: + child.direction *= -1 + child.go_down() diff --git a/space-invaders.tscn b/space-invaders.tscn index 0d45dd7..8c33b54 100644 --- a/space-invaders.tscn +++ b/space-invaders.tscn @@ -11,7 +11,7 @@ size = Vector2(60, 20) [sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_qlrl5"] -[sub_resource type="RectangleShape2D" id="RectangleShape2D_5oyi1"] +[sub_resource type="RectangleShape2D" id="RectangleShape2D_kv2i2"] [node name="Game" type="Node2D" unique_id=1637093307] script = ExtResource("1_kv2i2") @@ -81,11 +81,272 @@ metadata/_edit_group_ = true rotation = -1.5555981 shape = SubResource("WorldBoundaryShape2D_qlrl5") -[node name="enemy" type="RigidBody2D" parent="." unique_id=1639975968] -position = Vector2(47, 257) +[node name="enemy" type="StaticBody2D" parent="." unique_id=368173764] +position = Vector2(61, 134) script = ExtResource("2_kxkvm") metadata/_edit_group_ = true -[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy" unique_id=47752407] -shape = SubResource("RectangleShape2D_5oyi1") -debug_color = Color(0.54979414, 0.56277347, 0.10956033, 0.41960785) +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy" unique_id=644160547] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy2" type="StaticBody2D" parent="." unique_id=726027381] +position = Vector2(315, 134) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy2" unique_id=1821108836] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy3" type="StaticBody2D" parent="." unique_id=1193535475] +position = Vector2(263, 134) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy3" unique_id=1111163947] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy4" type="StaticBody2D" parent="." unique_id=302269803] +position = Vector2(213, 135) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy4" unique_id=1334284773] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy5" type="StaticBody2D" parent="." unique_id=460782298] +position = Vector2(109, 134) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy5" unique_id=436870710] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy6" type="StaticBody2D" parent="." unique_id=1547837257] +position = Vector2(160, 135) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy6" unique_id=1667857899] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy7" type="StaticBody2D" parent="." unique_id=258647370] +position = Vector2(357, 134) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy7" unique_id=733618965] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy8" type="StaticBody2D" parent="." unique_id=493889689] +position = Vector2(399, 134) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy8" unique_id=1232831963] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy9" type="StaticBody2D" parent="." unique_id=475706607] +position = Vector2(444, 136) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy9" unique_id=480339972] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy10" type="StaticBody2D" parent="." unique_id=1896867077] +position = Vector2(492, 133) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy10" unique_id=52803408] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy11" type="StaticBody2D" parent="." unique_id=1655161071] +position = Vector2(62, 83) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy11" unique_id=227922379] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy12" type="StaticBody2D" parent="." unique_id=2086147549] +position = Vector2(316, 83) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy12" unique_id=1316695271] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy13" type="StaticBody2D" parent="." unique_id=736358622] +position = Vector2(264, 83) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy13" unique_id=1944424486] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy14" type="StaticBody2D" parent="." unique_id=344956909] +position = Vector2(214, 84) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy14" unique_id=1006326999] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy15" type="StaticBody2D" parent="." unique_id=1421351877] +position = Vector2(110, 83) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy15" unique_id=1021838885] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy16" type="StaticBody2D" parent="." unique_id=1373777720] +position = Vector2(161, 84) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy16" unique_id=1700365134] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy17" type="StaticBody2D" parent="." unique_id=49641413] +position = Vector2(358, 83) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy17" unique_id=225437419] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy18" type="StaticBody2D" parent="." unique_id=509642523] +position = Vector2(400, 83) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy18" unique_id=1639587716] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy19" type="StaticBody2D" parent="." unique_id=270729399] +position = Vector2(445, 85) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy19" unique_id=618865773] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy20" type="StaticBody2D" parent="." unique_id=1595649490] +position = Vector2(493, 82) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy20" unique_id=103533710] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy21" type="StaticBody2D" parent="." unique_id=166279462] +position = Vector2(61, 36) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy21" unique_id=839820698] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy22" type="StaticBody2D" parent="." unique_id=1714668594] +position = Vector2(315, 36) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy22" unique_id=1254157303] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy23" type="StaticBody2D" parent="." unique_id=1089921364] +position = Vector2(263, 36) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy23" unique_id=468627351] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy24" type="StaticBody2D" parent="." unique_id=428547248] +position = Vector2(213, 37) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy24" unique_id=1222961253] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy25" type="StaticBody2D" parent="." unique_id=779740520] +position = Vector2(109, 36) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy25" unique_id=1626708704] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy26" type="StaticBody2D" parent="." unique_id=1526777589] +position = Vector2(160, 37) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy26" unique_id=1926583115] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy27" type="StaticBody2D" parent="." unique_id=1020855623] +position = Vector2(357, 36) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy27" unique_id=1453554228] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy28" type="StaticBody2D" parent="." unique_id=1643848861] +position = Vector2(399, 36) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy28" unique_id=862239129] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy29" type="StaticBody2D" parent="." unique_id=1685025434] +position = Vector2(444, 38) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy29" unique_id=379292630] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785) + +[node name="enemy30" type="StaticBody2D" parent="." unique_id=1738488973] +position = Vector2(492, 35) +script = ExtResource("2_kxkvm") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy30" unique_id=756582115] +shape = SubResource("RectangleShape2D_kv2i2") +debug_color = Color(0.4298056, 0.599785, 0.1415984, 0.41960785)