first work

This commit is contained in:
2024-03-07 22:17:10 +01:00
parent af7ecc10e3
commit f83f6989b4
10 changed files with 146 additions and 72 deletions
+47
View File
@@ -0,0 +1,47 @@
extends Node2D
var Ball = preload("res://scenes/playground/ball/Ball.tscn")
var left_point = 0
var right_point = 0
func start():
var ball = Ball.instantiate()
add_child(ball)
func set_score():
get_node("Score").text = "{right} - {left}".format({
"left": left_point,
"right": right_point
})
func new_round(ball):
remove_child(ball)
set_score()
start()
func _ready():
start()
func _process(delta):
pass
func _on_goal_area_left_body_entered(body):
if body.name == "Ball":
left_point += 1
new_round(body)
func _on_goal_area_right_body_entered(body):
if body.name == "Ball":
right_point += 1
new_round(body)
func _on_racket_left_body_entered(body):
if body.name == "Ball":
body.linear_velocity = body.linear_velocity * -1
func _on_racket_right_body_entered(body):
if body.name == "Ball":
body.linear_velocity = body.linear_velocity * -1
+66
View File
@@ -0,0 +1,66 @@
[gd_scene load_steps=6 format=3 uid="uid://catrpx1vuhvou"]
[ext_resource type="Script" path="res://scenes/playground/Playground.gd" id="1_86x6h"]
[ext_resource type="PackedScene" uid="uid://ce4mnfokb6pkn" path="res://scenes/playground/racket/Racket.tscn" id="1_ywul3"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_v2vae"]
friction = 0.0
bounce = 1.0
[sub_resource type="RectangleShape2D" id="RectangleShape2D_u7af8"]
size = Vector2(100, 600)
[sub_resource type="LabelSettings" id="LabelSettings_ildlg"]
font_size = 64
[node name="Playground" type="Node2D"]
script = ExtResource("1_86x6h")
[node name="Wall" type="StaticBody2D" parent="."]
disable_mode = 1
physics_material_override = SubResource("PhysicsMaterial_v2vae")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Wall"]
polygon = PackedVector2Array(0, 8, 0, 600, 1200, 600, 1200, 8, 0, 0, 0, 8, 1192, 16, 1192, 16, 1192, 592, 8, 592, 8, 16)
one_way_collision_margin = 0.0
[node name="GoalAreaLeft" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="GoalAreaLeft"]
position = Vector2(50, 300)
shape = SubResource("RectangleShape2D_u7af8")
[node name="GoalAreaRight" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="GoalAreaRight"]
position = Vector2(1150, 300)
shape = SubResource("RectangleShape2D_u7af8")
[node name="RacketLeft" parent="." instance=ExtResource("1_ywul3")]
position = Vector2(128, 224)
collision_layer = 255
collision_mask = 255
max_contacts_reported = 1000
contact_monitor = true
metadata/UP_KEY = "left_up"
metadata/DOWN_KEY = "left_down"
[node name="RacketRight" parent="." instance=ExtResource("1_ywul3")]
position = Vector2(1032, 224)
metadata/UP_KEY = "right_up"
metadata/DOWN_KEY = "right_down"
[node name="Score" type="Label" parent="."]
offset_left = 544.0
offset_top = 32.0
offset_right = 673.0
offset_bottom = 120.0
text = "0 - 0"
label_settings = SubResource("LabelSettings_ildlg")
horizontal_alignment = 1
vertical_alignment = 1
[connection signal="body_entered" from="GoalAreaLeft" to="." method="_on_goal_area_left_body_entered"]
[connection signal="body_entered" from="GoalAreaRight" to="." method="_on_goal_area_right_body_entered"]
[connection signal="body_entered" from="RacketLeft" to="." method="_on_racket_left_body_entered"]
[connection signal="body_entered" from="RacketRight" to="." method="_on_racket_right_body_entered"]
+21
View File
@@ -0,0 +1,21 @@
extends RigidBody2D
const SPEED = 300.00
func _ready():
randomize()
global_position = Vector2(640, 360)
var x_direction = pow(-1, randi() % 2)
var y_direction = pow(-1, randi() % 2)
await get_tree().create_timer(1.0).timeout
linear_velocity = Vector2(x_direction, y_direction) * SPEED
func _process(delta):
pass
+27
View File
@@ -0,0 +1,27 @@
[gd_scene load_steps=4 format=3 uid="uid://dmsd30hc2ob1w"]
[ext_resource type="Script" path="res://scenes/playground/ball/Ball.gd" id="1_vsr7q"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_h7mi1"]
friction = 0.0
[sub_resource type="RectangleShape2D" id="RectangleShape2D_bdxrg"]
size = Vector2(32, 32)
[node name="Ball" type="RigidBody2D"]
mass = 0.01
physics_material_override = SubResource("PhysicsMaterial_h7mi1")
gravity_scale = 1.66533e-16
can_sleep = false
lock_rotation = true
freeze_mode = 1
linear_damp_mode = 1
script = ExtResource("1_vsr7q")
[node name="ColorRect" type="ColorRect" parent="."]
offset_right = 40.0
offset_bottom = 40.0
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(20, 20)
shape = SubResource("RectangleShape2D_bdxrg")
+14
View File
@@ -0,0 +1,14 @@
extends RigidBody2D
const SPEED = 300.0
func _ready():
contact_monitor = true
func _physics_process(delta):
if Input.is_action_pressed(get_meta("UP_KEY")):
move_and_collide(Vector2.UP * SPEED * delta)
if Input.is_action_pressed(get_meta("DOWN_KEY")):
move_and_collide(Vector2.DOWN * SPEED * delta)
+25
View File
@@ -0,0 +1,25 @@
[gd_scene load_steps=4 format=3 uid="uid://ce4mnfokb6pkn"]
[ext_resource type="Script" path="res://scenes/playground/racket/Racket.gd" id="1_gclos"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_lq6ot"]
friction = 0.0
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ehve4"]
size = Vector2(40, 144)
[node name="Racket" type="RigidBody2D"]
physics_material_override = SubResource("PhysicsMaterial_lq6ot")
gravity_scale = 1.66533e-16
can_sleep = false
lock_rotation = true
script = ExtResource("1_gclos")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(20, 72)
shape = SubResource("RectangleShape2D_ehve4")
[node name="ColorRect" type="ColorRect" parent="."]
offset_right = 40.0
offset_bottom = 144.0
color = Color(0.0117647, 0.0117647, 0.0117647, 1)