pongodot

Tinkering with Godot, remaking pong
git clone git://git.hellocld.com/pongodot
Log | Files | Refs

commit c3780b6a6fd2809f894758ee7e35d3d43eed817b
parent 3081e3b383196d0f6111eeb074571329020095e7
Author: Christopher Ray Langford <chris@hellocld.com>
Date:   Tue,  5 Nov 2019 19:59:51 -0500

Paddles are now multiplayer friendly, with new input managers

Diffstat:
MGame.tscn | 13++++---------
MPaddle.gd | 13+++++++++----
Mproject.godot | 27+++++++++++++++++++++++++++
3 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/Game.tscn b/Game.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://Game.gd" type="Script" id=1] [ext_resource path="res://Ball.tscn" type="PackedScene" id=2] [ext_resource path="res://Paddle.tscn" type="PackedScene" id=3] -[ext_resource path="res://Goal.tscn" type="PackedScene" id=4] [node name="Node2D" type="Node2D"] script = ExtResource( 1 ) @@ -13,14 +12,10 @@ position = Vector2( 320, 240 ) _speed = 128 [node name="Paddle 1" parent="." instance=ExtResource( 3 )] -position = Vector2( 40, 240 ) +position = Vector2( 39.7101, 255.408 ) _speed = 64 [node name="Paddle 2" parent="." instance=ExtResource( 3 )] -position = Vector2( 600, 240 ) +position = Vector2( 597.457, 255.408 ) _speed = 64 - -[node name="Goal 2" parent="." instance=ExtResource( 4 )] - -[node name="Goal 1" parent="." instance=ExtResource( 4 )] -position = Vector2( 12, 240 ) +_player = "p2" diff --git a/Paddle.gd b/Paddle.gd @@ -2,13 +2,18 @@ extends KinematicBody2D export var _speed = 32 -enum player {P1, P2} -export (player) var _player +export (String, "p1", "p2") var _player = "p1" + +var vec = Vector2(0, 0) + +func _ready(): + print(_player + " ready!") func _physics_process(delta): var vec = Vector2(0, 0); - if Input.is_action_pressed("ui_up"): + + if Input.is_action_pressed(_player + "_up"): vec.y = -1 - if Input.is_action_pressed("ui_down"): + if Input.is_action_pressed(_player + "_down"): vec.y = 1 move_and_collide(vec * _speed * delta) \ No newline at end of file diff --git a/project.godot b/project.godot @@ -26,6 +26,33 @@ window/size/height=480 window/stretch/mode="viewport" window/stretch/aspect="keep" +[input] + +p1_up={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null) + ] +} +p1_down={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null) + ] +} +p2_up={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":1,"axis":1,"axis_value":-1.0,"script":null) + ] +} +p2_down={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":1,"axis":1,"axis_value":1.0,"script":null) + ] +} + [rendering] quality/driver/driver_name="GLES2"