diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f28239b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +root = true + +[*] +charset = utf-8 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0af181c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Godot 4+ specific ignores +.godot/ +/android/ diff --git a/Paddle.gd b/Paddle.gd new file mode 100644 index 0000000..055ee0c --- /dev/null +++ b/Paddle.gd @@ -0,0 +1,18 @@ +extends CharacterBody2D + +const SPEED: float = 350.0 + +@export var player_id: int + +func _input(event: InputEvent) -> void: + if event.is_action_pressed('up-%d' % player_id): + velocity = Vector2(0, -SPEED) + if event.is_action_pressed( 'down-%d' % player_id): + velocity = Vector2(0, SPEED) + if event.is_action_released('up-%d' % player_id) or \ + event.is_action_released('down-%d' % player_id): + velocity = Vector2.ZERO + +func _physics_process(delta: float) -> void: + + move_and_slide() diff --git a/Paddle.gd.uid b/Paddle.gd.uid new file mode 100644 index 0000000..42c78d9 --- /dev/null +++ b/Paddle.gd.uid @@ -0,0 +1 @@ +uid://d0dti6pba80ci diff --git a/ball.gd b/ball.gd new file mode 100644 index 0000000..1f04ad1 --- /dev/null +++ b/ball.gd @@ -0,0 +1,23 @@ +extends CharacterBody2D + +const SPEED : float = 300.0 + +func _ready() -> void: + initialize() + +func _physics_process(delta: float) -> void: + move_and_slide() + +func initialize(): + var extra_offset = 0.0 if randf() < 0.5 else PI + var angle = \ + extra_offset + randf_range(-PI/3.0, PI/3.0) + velocity = Vector2(cos(angle), sin(angle)).normalized() + position = get_viewport_rect().size / 2.0 + + +func _on_screen_exited() -> void: + # update score + # reinit after 1 second + await get_tree().create_timer (1.0).timeout + initialize() diff --git a/ball.gd.uid b/ball.gd.uid new file mode 100644 index 0000000..6e0766f --- /dev/null +++ b/ball.gd.uid @@ -0,0 +1 @@ +uid://wrequpaalk7f diff --git a/game.tscn b/game.tscn new file mode 100644 index 0000000..54d9afe --- /dev/null +++ b/game.tscn @@ -0,0 +1,82 @@ +[gd_scene load_steps=5 format=3 uid="uid://ct7v3x7imstlk"] + +[ext_resource type="PackedScene" uid="uid://dd0cxfceqwxca" path="res://prefabs/paddle.tscn" id="1_80nbo"] +[ext_resource type="Script" uid="uid://wrequpaalk7f" path="res://ball.gd" id="2_e2o6t"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_mwb40"] +size = Vector2(1200, 20) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_feb5d"] + +[node name="Root" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Background" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = 2.0 +offset_bottom = 2.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0.184063, 0.191379, 0.203873, 1) + +[node name="MiddleLine" type="ColorRect" parent="."] +custom_minimum_size = Vector2(4, 0) +layout_mode = 1 +anchors_preset = 13 +anchor_left = 0.5 +anchor_right = 0.5 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0.938114, 0.940897, 0.945648, 1) + +[node name="TopWall" type="StaticBody2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="TopWall"] +position = Vector2(571, 0) +shape = SubResource("RectangleShape2D_mwb40") + +[node name="Polygon2D" type="Polygon2D" parent="TopWall"] +polygon = PackedVector2Array(-30, -10, -30, 10, 1172, 10, 1172, -10) + +[node name="BottomWall" type="StaticBody2D" parent="."] +position = Vector2(0, 649) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="BottomWall"] +position = Vector2(571, 0) +shape = SubResource("RectangleShape2D_mwb40") + +[node name="Polygon2D" type="Polygon2D" parent="BottomWall"] +polygon = PackedVector2Array(-30, -10, -30, 10, 1172, 10, 1172, -10) + +[node name="Paddle-0" parent="." instance=ExtResource("1_80nbo")] +position = Vector2(40, 273) + +[node name="Paddle-1" parent="." instance=ExtResource("1_80nbo")] +position = Vector2(1078, 273) +player_id = 1 + +[node name="Ball" type="CharacterBody2D" parent="."] +position = Vector2(134, 72) +motion_mode = 1 +script = ExtResource("2_e2o6t") + +[node name="Polygon2D" type="Polygon2D" parent="Ball"] +polygon = PackedVector2Array(100, 75, 120, 75, 120, 95, 100, 95) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Ball"] +position = Vector2(110, 85) +shape = SubResource("RectangleShape2D_feb5d") + +[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="Ball"] +position = Vector2(110, 85) + +[connection signal="screen_exited" from="Ball/VisibleOnScreenNotifier2D" to="Ball" method="_on_screen_exited"] diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..9d8b7fa --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..107361c --- /dev/null +++ b/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ba4whcm6uncvu" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/prefabs/paddle.tscn b/prefabs/paddle.tscn new file mode 100644 index 0000000..923cb05 --- /dev/null +++ b/prefabs/paddle.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=3 format=3 uid="uid://dd0cxfceqwxca"] + +[ext_resource type="Script" uid="uid://d0dti6pba80ci" path="res://Paddle.gd" id="1_q73f6"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_e2o6t"] +size = Vector2(33, 105) + +[node name="Paddle" type="CharacterBody2D"] +motion_mode = 1 +script = ExtResource("1_q73f6") + +[node name="Polygon2D" type="Polygon2D" parent="."] +position = Vector2(8, 60) +polygon = PackedVector2Array(-8, -60, 25, -60, 25, 45, -8, 45) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(16.5, 52.5) +shape = SubResource("RectangleShape2D_e2o6t") diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..908a2a2 --- /dev/null +++ b/project.godot @@ -0,0 +1,39 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="2025-08-23 Learning" +run/main_scene="uid://ct7v3x7imstlk" +config/features=PackedStringArray("4.4", "Forward Plus") +config/icon="res://icon.svg" + +[input] + +up-0={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null) +] +} +down-0={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null) +] +} +up-1={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":73,"key_label":0,"unicode":105,"location":0,"echo":false,"script":null) +] +} +down-1={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":75,"key_label":0,"unicode":107,"location":0,"echo":false,"script":null) +] +}