File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,15 +15,15 @@ class Ball(classes.Area2D):
1515 def __init__ (self ):
1616 super ().__init__ ()
1717 self ._speed = self .DEFAULT_SPEED
18- self .direction = Vector2 .LEFT
18+ self .direction = Vector2 .LEFT ()
1919 self ._initial_pos = Vector2 ()
2020
2121 def _ready (self ):
2222 self ._initial_pos = self .position
2323
2424 def _process (self , delta : float ) -> None :
2525 self ._speed += delta * 2
26- self .position += self ._speed * delta * self . direction
26+ self .position += self .direction * ( self . _speed * delta )
2727
2828 def reset (self ) -> None :
2929 self .direction = Vector2 .LEFT
Original file line number Diff line number Diff line change @@ -13,6 +13,13 @@ class Paddle(classes.Area2D):
1313 _down : GDString
1414 _screen_size_y : float
1515
16+ def __init__ (self ):
17+ super ().__init__ ()
18+ self ._ball_dir = 1
19+ self ._up = GDString ()
20+ self ._down = GDString ()
21+ self ._screen_size_y = 0
22+
1623 def _ready (self ) -> None :
1724 self ._screen_size_y = self .get_viewport_rect ().size .y
1825 n = self .name .to_lower ()
@@ -25,9 +32,9 @@ def _ready(self) -> None:
2532
2633 def _process (self , delta : float ) -> None :
2734 # Move up and down based on input.
28- self . input = Input .get_action_strength (self ._down ) - Input .get_action_strength (self ._up )
35+ input_dir = Input .get_action_strength (self ._down ) - Input .get_action_strength (self ._up )
2936 self .position .y = utils .clamp (
30- self .position .y + input * self .MOVE_SPEED * delta , 16 , self ._screen_size_y - 16
37+ self .position .y + input_dir * self .MOVE_SPEED * delta , 16 , self ._screen_size_y - 16
3138 )
3239
3340 def _on_area_entered (self , area : classes .Area2D ) -> None :
Original file line number Diff line number Diff line change 1- [gd_scene load_steps =12 format =3 uid ="uid://1edquvuh4xlu" ]
1+ [gd_scene load_steps =11 format =3 uid ="uid://1edquvuh4xlu" ]
22
33[ext_resource type ="Script" uid ="uid://bbiup6xhh6s17" path ="res://logic/paddle.gd" id ="1" ]
44[ext_resource type ="Texture2D" uid ="uid://ybn78qkuq21d" path ="res://paddle.png" id ="2" ]
5- [ext_resource type ="Script" uid ="uid://c2ofwebuaqwtq" path ="res://logic/ball.gd" id ="4" ]
65[ext_resource type ="Texture2D" uid ="uid://bcir5xteju0j5" path ="res://ball.png" id ="5" ]
76[ext_resource type ="Texture2D" uid ="uid://7rr8ipvil66w" path ="res://separator.png" id ="6" ]
87[ext_resource type ="Script" uid ="uid://d0ctwatj03r3b" path ="res://logic/wall.gd" id ="7" ]
@@ -49,9 +48,8 @@ texture = ExtResource("2")
4948[node name ="Collision" type ="CollisionShape2D" parent ="Right" ]
5049shape = SubResource ("1" )
5150
52- [node name ="Ball" type ="Area2D " parent ="." ]
51+ [node name ="Ball" type ="Ball " parent ="." ]
5352position = Vector2 (320.5 , 191.124 )
54- script = ExtResource ("4" )
5553
5654[node name ="Sprite2D" type ="Sprite2D" parent ="Ball" ]
5755texture = ExtResource ("5" )
You can’t perform that action at this time.
0 commit comments