create the player

master
Sascha 2025-01-16 12:43:50 +07:00
parent 7f563a5bdd
commit f29437aeec
6 changed files with 88 additions and 0 deletions

@ -0,0 +1,3 @@
{
"godotTools.editorPath.godot4": "/home/sascha/Godot/Godot_v4.4-dev7_linux.x86_64"
}

@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://cjxteipqurqy5"]
[ext_resource type="PackedScene" uid="uid://cm7lrhjnutqxx" path="res://player.tscn" id="1_80nbo"]
[node name="Game" type="Node2D"]
[node name="Player1" parent="." instance=ExtResource("1_80nbo")]
position = Vector2(20, 68)
[node name="Player2" parent="." instance=ExtResource("1_80nbo")]
position = Vector2(1124, 578)
player_number = 2

@ -0,0 +1,21 @@
extends CharacterBody2D
@export var player_number: int = 1
const SPEED := 300
var direction: int
func _physics_process(delta: float) -> void:
position.y += direction * SPEED * delta
func _input(event: InputEvent) -> void:
direction = 0
if player_number == 1:
if event.is_action_pressed("player1up"):
direction = -1
elif event.is_action_pressed("player1down"):
direction = +1
elif player_number == 2:
if event.is_action_pressed("player2up"):
direction = -1
elif event.is_action_pressed("player2down"):
direction = +1

@ -0,0 +1 @@
uid://0884gjf31t4j

@ -0,0 +1,27 @@
[gd_scene load_steps=6 format=3 uid="uid://cm7lrhjnutqxx"]
[ext_resource type="Script" uid="uid://0884gjf31t4j" path="res://player.gd" id="1_4flbx"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_e2o6t"]
size = Vector2(10, 100)
[sub_resource type="QuadMesh" id="QuadMesh_feb5d"]
[sub_resource type="Gradient" id="Gradient_fc0e3"]
colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 1)
[sub_resource type="GradientTexture1D" id="GradientTexture1D_7jktm"]
gradient = SubResource("Gradient_fc0e3")
[node name="Player" type="CharacterBody2D"]
motion_mode = 1
script = ExtResource("1_4flbx")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_e2o6t")
[node name="MeshInstance2D" type="MeshInstance2D" parent="."]
position = Vector2(0.5, 0)
scale = Vector2(11, 100)
mesh = SubResource("QuadMesh_feb5d")
texture = SubResource("GradientTexture1D_7jktm")

@ -11,5 +11,29 @@ config_version=5
[application]
config/name="Pong_GDScript"
run/main_scene="uid://cjxteipqurqy5"
config/features=PackedStringArray("4.4", "Forward Plus")
config/icon="res://icon.svg"
[input]
player1up={
"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)
]
}
player1down={
"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)
]
}
player2up={
"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":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
player2down={
"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":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}