first work
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dmsd30hc2ob1w"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_bdxrg"]
|
||||
size = Vector2(40, 40)
|
||||
|
||||
[node name="Ball" type="RigidBody2D"]
|
||||
gravity_scale = 1.66533e-16
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(20, 20)
|
||||
shape = SubResource("RectangleShape2D_bdxrg")
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
|
||||
const SPEED = 300.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity.y += gravity * delta
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
var direction = Input.get_axis("ui_left", "ui_right")
|
||||
if direction:
|
||||
velocity.x = direction * SPEED
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
move_and_slide()
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://ce4mnfokb6pkn"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ehve4"]
|
||||
size = Vector2(40, 144)
|
||||
|
||||
[node name="Racket" type="CharacterBody2D"]
|
||||
up_direction = Vector2(2.94434e-12, 1)
|
||||
|
||||
[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)
|
||||
+1
-1
@@ -11,7 +11,7 @@ config_version=5
|
||||
[application]
|
||||
|
||||
config/name="pong"
|
||||
run/main_scene="res://Playground.tscn"
|
||||
run/main_scene="res://scenes/playground/Playground.tscn"
|
||||
config/features=PackedStringArray("4.2", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -1,7 +1,11 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://catrpx1vuhvou"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://catrpx1vuhvou"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://ce4mnfokb6pkn" path="res://Racket.tscn" id="1_ywul3"]
|
||||
[ext_resource type="Script" path="res://Racket.gd" id="2_wrt7t"]
|
||||
[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)
|
||||
@@ -10,11 +14,15 @@ size = Vector2(100, 600)
|
||||
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, 8)
|
||||
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="."]
|
||||
|
||||
@@ -30,17 +38,19 @@ shape = SubResource("RectangleShape2D_u7af8")
|
||||
|
||||
[node name="RacketLeft" parent="." instance=ExtResource("1_ywul3")]
|
||||
position = Vector2(128, 224)
|
||||
script = ExtResource("2_wrt7t")
|
||||
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)
|
||||
script = ExtResource("2_wrt7t")
|
||||
metadata/UP_KEY = "right_up"
|
||||
metadata/DOWN_KEY = "right_down"
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
[node name="Score" type="Label" parent="."]
|
||||
offset_left = 544.0
|
||||
offset_top = 32.0
|
||||
offset_right = 673.0
|
||||
@@ -49,3 +59,8 @@ 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"]
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
@@ -1,16 +1,14 @@
|
||||
extends CharacterBody2D
|
||||
extends RigidBody2D
|
||||
|
||||
|
||||
const SPEED = 300.0
|
||||
|
||||
func _ready():
|
||||
contact_monitor = true
|
||||
|
||||
func _physics_process(delta):
|
||||
|
||||
|
||||
if Input.is_action_pressed(get_meta("UP_KEY")):
|
||||
velocity.y = move_toward(velocity.y, -1, SPEED)
|
||||
move_and_collide(Vector2.UP * SPEED * delta)
|
||||
|
||||
if Input.is_action_pressed(get_meta("DOWN_KEY")):
|
||||
velocity.y = move_toward(velocity.y, 1, SPEED)
|
||||
move_and_collide(Vector2.DOWN * SPEED * delta)
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user