pongodot

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

commit ddcf3997b761926e1b083a9717fa7db43c71e129
parent ac12d83be524afdb368ac84ce86cbc7ebd5ed54f
Author: Christopher Ray Langford <chris@hellocld.com>
Date:   Mon, 11 Nov 2019 06:36:57 -0500

Better paddle limiting, animated sprites on collisions

Diffstat:
MBall.gd | 1+
MBall.tscn | 23++++++++++++++++++++++-
MGame.tscn | 20+-------------------
MPaddle.gd | 10++++++++--
MPaddle.tscn | 22+++++++++++++++++++++-
ASprites/System6-Slice-Sheet.png | 0
ASprites/System6-Slice-Sheet.png.import | 34++++++++++++++++++++++++++++++++++
ASprites/System6-Slice1.png | 0
ASprites/System6-Slice1.png.import | 34++++++++++++++++++++++++++++++++++
ASprites/System6-Slice2.png | 0
ASprites/System6-Slice2.png.import | 34++++++++++++++++++++++++++++++++++
11 files changed, 155 insertions(+), 23 deletions(-)

diff --git a/Ball.gd b/Ball.gd @@ -13,6 +13,7 @@ func _physics_process(delta): var collision = move_and_collide(_dir * _speed * delta) if collision: print(collision.collider.name) + $AnimationPlayer.play("Boop") _dir = _dir.bounce(collision.normal) if position.x >= get_viewport().size.x - _radius or position.x < _radius: _dir.x *= -1 diff --git a/Ball.tscn b/Ball.tscn @@ -1,10 +1,28 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://Ball.gd" type="Script" id=1] [ext_resource path="res://Sprites/System6-Slice.png" type="Texture" id=2] +[ext_resource path="res://Sprites/System6-Slice2.png" type="Texture" id=3] +[ext_resource path="res://Sprites/System6-Slice1.png" type="Texture" id=4] [sub_resource type="CircleShape2D" id=1] +[sub_resource type="Animation" id=2] +resource_name = "Boop" +length = 0.2 +tracks/0/type = "value" +tracks/0/path = NodePath("NinePatchRect:texture") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 0.2 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 1, +"values": [ ExtResource( 3 ), ExtResource( 4 ) ] +} + [node name="Ball" type="KinematicBody2D"] script = ExtResource( 1 ) @@ -23,3 +41,6 @@ axis_stretch_vertical = 2 [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource( 1 ) + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +anims/Boop = SubResource( 2 ) diff --git a/Game.tscn b/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://Game.gd" type="Script" id=1] [ext_resource path="res://Sprites/bg-01.png" type="Texture" id=2] @@ -6,9 +6,6 @@ [ext_resource path="res://Paddle.tscn" type="PackedScene" id=4] [ext_resource path="res://Goal.tscn" type="PackedScene" id=5] -[sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 256, 2 ) - [node name="Game" type="Node2D"] script = ExtResource( 1 ) game_score = 3 @@ -37,20 +34,5 @@ _player = "p2" [node name="Goal 2" parent="." instance=ExtResource( 5 )] position = Vector2( 8, 171 ) - -[node name="PaddleBounds" type="StaticBody2D" parent="."] -editor/display_folded = true - -[node name="CollisionShape2D" type="CollisionShape2D" parent="PaddleBounds"] -position = Vector2( 256, -2 ) -shape = SubResource( 1 ) - -[node name="PaddleBounds2" type="StaticBody2D" parent="."] -editor/display_folded = true -position = Vector2( 0, 346 ) - -[node name="CollisionShape2D" type="CollisionShape2D" parent="PaddleBounds2"] -position = Vector2( 256, -2 ) -shape = SubResource( 1 ) [connection signal="body_entered" from="Goal 1" to="." method="_on_Goal_1_body_entered"] [connection signal="body_entered" from="Goal 2" to="." method="_on_Goal_2_body_entered"] diff --git a/Paddle.gd b/Paddle.gd @@ -5,8 +5,11 @@ export var _speed = 32 export (String, "p1", "p2") var _player = "p1" var vec = Vector2(0, 0) +var _height = 0 func _ready(): + var shape = $CollisionShape2D.shape as RectangleShape2D + _height = shape.extents.y print(_player + " ready!") func _physics_process(delta): @@ -16,4 +19,7 @@ func _physics_process(delta): vec.y = -1 if Input.is_action_pressed(_player + "_down"): vec.y = 1 - move_and_collide(vec * _speed * delta)- \ No newline at end of file + var collision = move_and_collide(vec * _speed * delta) + if collision: + $AnimationPlayer.play("Boop") + position.y = clamp(position.y, _height, get_viewport_rect().size.y - _height)+ \ No newline at end of file diff --git a/Paddle.tscn b/Paddle.tscn @@ -1,11 +1,28 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://Paddle.gd" type="Script" id=1] [ext_resource path="res://Sprites/System6-Slice.png" type="Texture" id=2] +[ext_resource path="res://Sprites/System6-Slice2.png" type="Texture" id=3] [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 10, 60 ) +[sub_resource type="Animation" id=2] +resource_name = "Boop" +length = 0.2 +tracks/0/type = "value" +tracks/0/path = NodePath("NinePatchRect:texture") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 0.2 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 1, +"values": [ ExtResource( 3 ), ExtResource( 2 ) ] +} + [node name="Paddle" type="KinematicBody2D"] script = ExtResource( 1 ) @@ -24,3 +41,6 @@ axis_stretch_vertical = 2 [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource( 1 ) + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +anims/Boop = SubResource( 2 ) diff --git a/Sprites/System6-Slice-Sheet.png b/Sprites/System6-Slice-Sheet.png Binary files differ. diff --git a/Sprites/System6-Slice-Sheet.png.import b/Sprites/System6-Slice-Sheet.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/System6-Slice-Sheet.png-2d6d6173f744fa1291f8c02255405e21.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/System6-Slice-Sheet.png" +dest_files=[ "res://.import/System6-Slice-Sheet.png-2d6d6173f744fa1291f8c02255405e21.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/Sprites/System6-Slice1.png b/Sprites/System6-Slice1.png Binary files differ. diff --git a/Sprites/System6-Slice1.png.import b/Sprites/System6-Slice1.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/System6-Slice1.png-100d7d9bdd110e6985de0400c98e6231.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/System6-Slice1.png" +dest_files=[ "res://.import/System6-Slice1.png-100d7d9bdd110e6985de0400c98e6231.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/Sprites/System6-Slice2.png b/Sprites/System6-Slice2.png Binary files differ. diff --git a/Sprites/System6-Slice2.png.import b/Sprites/System6-Slice2.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/System6-Slice2.png-42767e6eb5fe998178bf01135d7099a1.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/System6-Slice2.png" +dest_files=[ "res://.import/System6-Slice2.png-42767e6eb5fe998178bf01135d7099a1.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0