Skip to content

Commit

Permalink
Add collision box to trains (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
mineiwik authored Sep 30, 2023
2 parents 4b3645e + 306aa14 commit 92b6be7
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 48 deletions.
2 changes: 2 additions & 0 deletions prefabs/TrainEngine.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ brake_application_speed = 5.0

[node name="TextureRect" parent="Body/Node2D2" index="0"]
texture = ExtResource("3_unrkn")

[connection signal="area_entered" from="Area2D" to="." method="_on_area_2d_area_entered"]
33 changes: 33 additions & 0 deletions prefabs/TrainStation.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[gd_scene load_steps=6 format=3 uid="uid://ctghq2lknpslx"]

[ext_resource type="Script" path="res://scripts/TrainStation.gd" id="1_c6ixw"]
[ext_resource type="PackedScene" uid="uid://d1xy67euifbh6" path="res://prefabs/Track.tscn" id="1_pb151"]
[ext_resource type="Texture2D" uid="uid://bb544qs74gbdt" path="res://assets/station.png" id="2_ysqsg"]

[sub_resource type="Curve2D" id="Curve2D_7h8le"]
resource_local_to_scene = true
_data = {
"points": PackedVector2Array(0, 0, 0, 0, 2.08165e-12, 2.08165e-12, 0, 0, 0, 0, 300, 0)
}
point_count = 2

[sub_resource type="RectangleShape2D" id="RectangleShape2D_fhstt"]
size = Vector2(300, 85)

[node name="TrainStation" type="Node2D"]
script = ExtResource("1_c6ixw")

[node name="Track" parent="." instance=ExtResource("1_pb151")]
curve = SubResource("Curve2D_7h8le")

[node name="Station" type="Sprite2D" parent="."]
z_index = 100
position = Vector2(150, 45)
scale = Vector2(1.15, 1.15)
texture = ExtResource("2_ysqsg")

[node name="Area2D" type="Area2D" parent="." groups=["train_station"]]

[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2(150, 0)
shape = SubResource("RectangleShape2D_fhstt")
12 changes: 11 additions & 1 deletion prefabs/TrainVehicle.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[gd_scene load_steps=4 format=3 uid="uid://dpgkkb4iqrw5b"]
[gd_scene load_steps=5 format=3 uid="uid://dpgkkb4iqrw5b"]

[ext_resource type="PackedScene" uid="uid://dt8qvg4eqnc71" path="res://prefabs/TrainWheel.tscn" id="1"]
[ext_resource type="Script" path="res://scripts/TrainVehicle.gd" id="2"]
[ext_resource type="Texture2D" uid="uid://bwresqdpylkai" path="res://assets/train_car.png" id="3_0sagh"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_cdjcq"]
size = Vector2(88, 20)

[node name="TrainVehicle" type="Node2D"]
script = ExtResource("2")

Expand Down Expand Up @@ -42,3 +45,10 @@ offset_top = -12.0
offset_right = 70.0
offset_bottom = 12.0
texture = ExtResource("3_0sagh")

[node name="Area2D" type="Area2D" parent="."]
monitorable = false

[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2(29, 0)
shape = SubResource("RectangleShape2D_cdjcq")
Loading

0 comments on commit 92b6be7

Please sign in to comment.