pongodot

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

commit 41a815d80d2f95d3d8dbda88d10875570826a610
parent c536f53c1e00ef7e58517c48575692f5f8ae4308
Author: Christopher Ray Langford <chris@hellocld.com>
Date:   Mon,  4 Nov 2019 15:41:31 -0500

Ball and paddle both use KinematicBody2D, ball bounces off paddle

Diffstat:
MBall.gd | 15++++++---------
MBall.tscn | 5+----
MPaddle.tscn | 2+-
Mproject.godot | 1+
4 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/Ball.gd b/Ball.gd @@ -1,17 +1,14 @@ -extends Area2D +extends KinematicBody2D export var _speed = 10 var _dir = Vector2(1, 1) -func _process(delta): - position += _dir * _speed * delta +func _physics_process(delta): + var collision = move_and_collide(_dir * _speed * delta) + if collision: + print(collision.normal) + _dir = _dir.bounce(collision.normal) if position.x >= get_viewport().size.x or position.x < 0: _dir.x *= -1 if position.y >= get_viewport().size.y or position.y < 0: _dir.y *= -1 - - - - -func _on_Ball_area_entered(area): - print("Area entered!") diff --git a/Ball.tscn b/Ball.tscn @@ -6,14 +6,11 @@ [sub_resource type="CircleShape2D" id=1] radius = 16.0 -[node name="Ball" type="Area2D"] -editor/display_folded = true +[node name="Ball" type="KinematicBody2D"] script = ExtResource( 1 ) -_speed = 32 [node name="Sprite" type="Sprite" parent="."] texture = ExtResource( 2 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource( 1 ) -[connection signal="area_entered" from="." to="." method="_on_Ball_area_entered"] diff --git a/Paddle.tscn b/Paddle.tscn @@ -5,7 +5,7 @@ [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 16, 64 ) -[node name="Paddle" type="Area2D"] +[node name="Paddle" type="KinematicBody2D"] [node name="Sprite" type="Sprite" parent="."] texture = ExtResource( 1 ) diff --git a/project.godot b/project.godot @@ -16,6 +16,7 @@ _global_script_class_icons={ [application] config/name="pongodot" +run/main_scene="res://Game.tscn" config/icon="res://icon.png" [display]