Skip to content

Commit b0cffa6

Browse files
committed
make scene
1 parent 706b743 commit b0cffa6

4 files changed

Lines changed: 36 additions & 5 deletions

File tree

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1-
[gd_scene load_steps=4 format=2]
1+
[gd_scene load_steps=5 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]
6+
[ext_resource path="res://scenes/Paddle.tscn" type="PackedScene" id=4]
67

78
[node name="Game" type="Node2D"]
89
script = ExtResource( 1 )
910

1011
[node name="Ball" parent="." instance=ExtResource( 2 )]
11-
position = Vector2( 448, 266 )
12+
position = Vector2( 462, 218 )
1213

1314
[node name="TopWall" parent="." instance=ExtResource( 3 )]
1415
position = Vector2( 464, 156 )
1516
_color = Color( 0.941176, 0.0784314, 0.0784314, 1 )
1617

1718
[node name="BottomWall" parent="." instance=ExtResource( 3 )]
18-
position = Vector2( 462, 447 )
19+
position = Vector2( 469, 291 )
1920
_color = Color( 0.0431373, 0.909804, 0.2, 1 )
2021

22+
[node name="P1Paddle" parent="." instance=ExtResource( 4 )]
23+
position = Vector2( 353, 225 )
24+
25+
[node name="P2Paddle" parent="." instance=ExtResource( 4 )]
26+
position = Vector2( 578, 218 )
27+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[gd_scene load_steps=3 format=2]
2+
3+
[ext_resource path="res://scripts/paddle.gd" type="Script" id=1]
4+
5+
[sub_resource type="RectangleShape2D" id=1]
6+
extents = Vector2( 10, 54.8 )
7+
8+
[node name="Paddle" type="Area2D"]
9+
script = ExtResource( 1 )
10+
11+
[node name="Shape" type="CollisionShape2D" parent="."]
12+
shape = SubResource( 1 )
13+
14+
[connection signal="area_entered" from="." to="." method="_on_Paddle_area_entered"]

TddAndPong/Episode3/scripts/game.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ extends Node2D
22

33
func _ready():
44
$Ball.set_speed(300)
5-
$Ball.set_direction(Vector2(0, 1))
5+
$Ball.set_direction(Vector2(1, 1))
66

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
extends Area2D
2+
13
func bounce(ball):
24
var new_y = rand_range(-.5, .5)
35
var new_x = ball.get_direction().x * -1
4-
ball.set_direction(Vector2(new_x, new_y))
6+
ball.set_direction(Vector2(new_x, new_y))
7+
8+
func _draw():
9+
var e = $Shape.shape.extents
10+
draw_rect(Rect2(e.x * -1, e.y * -1, e.x * 2, e.y * 2), Color(1, 1, 1))#_color)
11+
12+
13+
func _on_Paddle_area_entered(area):
14+
bounce(area)

0 commit comments

Comments
 (0)