File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- [gd_scene load_steps =5 format =2 ]
1+ [gd_scene load_steps =6 format =2 ]
22
33[ext_resource path ="res://scripts/game.gd" type ="Script" id =1 ]
44[ext_resource path ="res://scenes/Ball.tscn" type ="PackedScene" id =2 ]
55[ext_resource path ="res://scenes/Wall.tscn" type ="PackedScene" id =3 ]
66[ext_resource path ="res://scenes/Paddle.tscn" type ="PackedScene" id =4 ]
7+ [ext_resource path ="res://scenes/KillBox.tscn" type ="PackedScene" id =5 ]
78
89[node name ="Game" type ="Node2D" ]
910script = ExtResource ( 1 )
@@ -25,3 +26,11 @@ position = Vector2( 353, 225 )
2526[node name ="P2Paddle" parent ="." instance =ExtResource ( 4 )]
2627position = Vector2 ( 578 , 218 )
2728
29+ [node name ="P1KillBox" parent ="." instance =ExtResource ( 5 )]
30+ position = Vector2 ( 285 , 289.5 )
31+
32+ [node name ="P2KillBox" parent ="." instance =ExtResource ( 5 )]
33+ position = Vector2 ( 667.5 , 289.5 )
34+
35+ [connection signal ="kill_ball" from ="P1KillBox" to ="." method ="_on_P1KillBox_kill_ball" ]
36+ [connection signal ="kill_ball" from ="P2KillBox" to ="." method ="_on_P2KillBox_kill_ball" ]
Original file line number Diff line number Diff line change 1+ [gd_scene load_steps =3 format =2 ]
2+
3+ [ext_resource path ="res://scripts/killbox.gd" type ="Script" id =1 ]
4+
5+ [sub_resource type ="RectangleShape2D" id =1 ]
6+ extents = Vector2 ( 10 , 371 )
7+
8+ [node name ="KillBox" type ="Area2D" ]
9+ script = ExtResource ( 1 )
10+
11+ [node name ="CollisionShape2D" type ="CollisionShape2D" parent ="." ]
12+ shape = SubResource ( 1 )
13+
14+ [connection signal ="area_entered" from ="." to ="." method ="_on_KillBox_area_entered" ]
Original file line number Diff line number Diff line change 11extends Node2D
22
3+ var _ball_start_pos = null
4+
35func _ready ():
46 $ Ball .set_speed (300 )
57 $ Ball .set_direction (Vector2 (1 , 1 ))
8+ _ball_start_pos = $ Ball .get_position ()
69
710 $ P1Paddle .set_speed (300 )
811 $ P2Paddle .set_speed (300 )
@@ -16,3 +19,14 @@ func _process(delta):
1619 $ P2Paddle .move_up (delta )
1720 if Input .is_action_pressed ("p2_down" ):
1821 $ P2Paddle .move_down (delta )
22+
23+
24+ func _on_P2KillBox_kill_ball ():
25+ $ Ball .set_position (_ball_start_pos )
26+
27+
28+ func _on_P1KillBox_kill_ball ():
29+ $ Ball .set_position (_ball_start_pos )
30+
31+ func get_ball ():
32+ return $ Ball
Original file line number Diff line number Diff line change 1+ extends Area2D
2+
3+ signal kill_ball
4+
5+ func _on_KillBox_area_entered (area ):
6+ emit_signal ('kill_ball' )
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ script = ExtResource( 1 )
1414__meta__ = {
1515"_editor_icon" : ExtResource ( 2 )
1616}
17- _select_script = "test_wall_and_paddle "
17+ _select_script = "test_game "
1818_run_on_load = true
1919_should_maximize = true
2020_yield_between_tests = false
Original file line number Diff line number Diff line change 1+ extends 'res://addons/gut/test.gd'
2+
3+ var Game = load ('res://scenes/Game.tscn' )
4+
5+ var _game = null
6+
7+ func before_each ():
8+ _game = Game .instance ()
9+ add_child (_game )
10+
11+ func after_each ():
12+ remove_child (_game )
13+
14+ func test_can_make_game ():
15+ assert_not_null (Game .instance ())
16+
17+ func test_when_p1_killbox_emits_kill_ball_then_ball_is_recentered ():
18+ var ball = _game .get_ball ()
19+ var orig_pos = ball .get_position ()
20+ var kb = _game .get_node ("P1KillBox" )
21+
22+ ball .set_position (Vector2 (1 , 1 ))
23+ kb .emit_signal ('kill_ball' )
24+ assert_eq (ball .get_position (), orig_pos )
25+
26+ func test_when_p2_killbox_emits_kill_ball_then_ball_is_recentered ():
27+ var ball = _game .get_ball ()
28+ var orig_pos = ball .get_position ()
29+ var kb = _game .get_node ("P2KillBox" )
30+
31+ ball .set_position (Vector2 (1 , 1 ))
32+ kb .emit_signal ('kill_ball' )
33+ assert_eq (ball .get_position (), orig_pos )
You can’t perform that action at this time.
0 commit comments