From 6fcf653c978d2146db2b6f5dc3f0e481dbbe1f59 Mon Sep 17 00:00:00 2001 From: Fries Date: Sat, 4 May 2024 17:22:01 -0700 Subject: [PATCH] Implement some sprites and start on game logic scripts. --- Scenes/bird.tscn | 12 +++++---- Scenes/flappy_bird.tscn | 12 ++++++--- Scenes/pipe.tscn | 17 +++++++++++++ Scenes/pipes.tscn | 31 +++++++++++++--------- Scripts/Pipes/movement.gd | 18 +++++++++++++ Scripts/Pipes/pipe_offset_generator.gd | 8 ++++++ Scripts/game_manager.gd | 24 +++++++++++++++++ Sprites/pipe-green.png | Bin 0 -> 2527 bytes Sprites/pipe-green.png.import | 34 +++++++++++++++++++++++++ Sprites/yellowbird-midflap.png | Bin 0 -> 425 bytes Sprites/yellowbird-midflap.png.import | 34 +++++++++++++++++++++++++ 11 files changed, 169 insertions(+), 21 deletions(-) create mode 100644 Scenes/pipe.tscn create mode 100644 Scripts/Pipes/movement.gd create mode 100644 Scripts/Pipes/pipe_offset_generator.gd create mode 100644 Scripts/game_manager.gd create mode 100644 Sprites/pipe-green.png create mode 100644 Sprites/pipe-green.png.import create mode 100644 Sprites/yellowbird-midflap.png create mode 100644 Sprites/yellowbird-midflap.png.import diff --git a/Scenes/bird.tscn b/Scenes/bird.tscn index cb7fb18..113bce0 100644 --- a/Scenes/bird.tscn +++ b/Scenes/bird.tscn @@ -1,16 +1,18 @@ [gd_scene load_steps=4 format=3 uid="uid://cij4p7ni0rujg"] [ext_resource type="Script" path="res://Scripts/Bird/movement.gd" id="1_4imb2"] -[ext_resource type="Texture2D" uid="uid://cfotdween4etw" path="res://icon.svg" id="1_rcshh"] +[ext_resource type="Texture2D" uid="uid://bi1187py7cioc" path="res://Sprites/yellowbird-midflap.png" id="2_iq7mf"] -[sub_resource type="RectangleShape2D" id="RectangleShape2D_5ukl2"] -size = Vector2(102, 128) +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_g0iqt"] +radius = 12.0 +height = 24.0 [node name="Bird" type="CharacterBody2D"] script = ExtResource("1_4imb2") [node name="Sprite2D" type="Sprite2D" parent="."] -texture = ExtResource("1_rcshh") +texture_filter = 1 +texture = ExtResource("2_iq7mf") [node name="CollisionShape2D" type="CollisionShape2D" parent="."] -shape = SubResource("RectangleShape2D_5ukl2") +shape = SubResource("CapsuleShape2D_g0iqt") diff --git a/Scenes/flappy_bird.tscn b/Scenes/flappy_bird.tscn index 02776c7..9d5c4e1 100644 --- a/Scenes/flappy_bird.tscn +++ b/Scenes/flappy_bird.tscn @@ -1,13 +1,17 @@ -[gd_scene load_steps=3 format=3 uid="uid://c0tpkr1ghv33o"] +[gd_scene load_steps=4 format=3 uid="uid://c0tpkr1ghv33o"] [ext_resource type="PackedScene" uid="uid://cij4p7ni0rujg" path="res://Scenes/bird.tscn" id="1_f1cub"] +[ext_resource type="Script" path="res://Scripts/game_manager.gd" id="1_vfafo"] [ext_resource type="PackedScene" uid="uid://k6su505fjc6g" path="res://Scenes/pipes.tscn" id="2_ypsty"] [node name="FlappyBird" type="Node2D"] +[node name="GameManager" type="Node" parent="."] +script = ExtResource("1_vfafo") +Pipes = ExtResource("2_ypsty") + [node name="Bird" parent="." instance=ExtResource("1_f1cub")] +unique_name_in_owner = true +scale = Vector2(2, 2) [node name="Camera2D" type="Camera2D" parent="."] - -[node name="Pipes" parent="." instance=ExtResource("2_ypsty")] -position = Vector2(376, 0) diff --git a/Scenes/pipe.tscn b/Scenes/pipe.tscn new file mode 100644 index 0000000..b25b342 --- /dev/null +++ b/Scenes/pipe.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=3 format=3 uid="uid://b6apltgrsllm7"] + +[ext_resource type="Texture2D" uid="uid://btfaucx6uga8a" path="res://Sprites/pipe-green.png" id="1_7wb7t"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_rkgml"] +size = Vector2(47, 318) + +[node name="Pipe" type="Area2D"] +position = Vector2(0, -555) + +[node name="Icon" type="Sprite2D" parent="."] +texture_filter = 1 +texture = ExtResource("1_7wb7t") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(-0.5, 1) +shape = SubResource("RectangleShape2D_rkgml") diff --git a/Scenes/pipes.tscn b/Scenes/pipes.tscn index 25dbca0..cb14ca1 100644 --- a/Scenes/pipes.tscn +++ b/Scenes/pipes.tscn @@ -1,19 +1,26 @@ -[gd_scene load_steps=2 format=3 uid="uid://k6su505fjc6g"] +[gd_scene load_steps=4 format=3 uid="uid://k6su505fjc6g"] -[ext_resource type="Texture2D" uid="uid://cfotdween4etw" path="res://icon.svg" id="1_xgxmx"] +[ext_resource type="Script" path="res://Scripts/Pipes/movement.gd" id="1_1x6r3"] +[ext_resource type="PackedScene" uid="uid://b6apltgrsllm7" path="res://Scenes/pipe.tscn" id="2_5fcp1"] +[ext_resource type="Script" path="res://Scripts/Pipes/pipe_offset_generator.gd" id="3_yr1uv"] [node name="Pipes" type="Node2D"] +script = ExtResource("1_1x6r3") +move_speed = 250 -[node name="Pipe" type="AnimatableBody2D" parent="."] -position = Vector2(0, -515) -scale = Vector2(0.5, 5.65) +[node name="Pipe" parent="." instance=ExtResource("2_5fcp1")] +position = Vector2(-1, -406) +rotation = -3.14159 +scale = Vector2(2, 2) -[node name="Icon" type="Sprite2D" parent="Pipe"] -texture = ExtResource("1_xgxmx") +[node name="Pipe2" parent="." instance=ExtResource("2_5fcp1")] +position = Vector2(0, 391) +scale = Vector2(2, 2) -[node name="Pipe2" type="AnimatableBody2D" parent="."] -position = Vector2(0, 384) -scale = Vector2(0.5, 5.65) +[node name="PipeOffsetsGenerator" type="Node" parent="." node_paths=PackedStringArray("Pipe1", "Pipe2")] +script = ExtResource("3_yr1uv") +Pipe1 = NodePath("../Pipe") +Pipe2 = NodePath("../Pipe2") -[node name="Icon" type="Sprite2D" parent="Pipe2"] -texture = ExtResource("1_xgxmx") +[connection signal="body_entered" from="Pipe" to="." method="_on_pipe_body_entered"] +[connection signal="body_entered" from="Pipe2" to="." method="_on_pipe_body_entered"] diff --git a/Scripts/Pipes/movement.gd b/Scripts/Pipes/movement.gd new file mode 100644 index 0000000..1c0b79c --- /dev/null +++ b/Scripts/Pipes/movement.gd @@ -0,0 +1,18 @@ +extends Node2D + +@export var move_speed: int +signal pipe_collision + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + global_translate(Vector2.LEFT * move_speed * delta) + pass + + +func _on_pipe_body_entered(_body): + pipe_collision.emit() diff --git a/Scripts/Pipes/pipe_offset_generator.gd b/Scripts/Pipes/pipe_offset_generator.gd new file mode 100644 index 0000000..c6442b6 --- /dev/null +++ b/Scripts/Pipes/pipe_offset_generator.gd @@ -0,0 +1,8 @@ +extends Node + +@export var Pipe1 : Node2D +@export var Pipe2 : Node2D + +func _ready(): + print("pipe") + diff --git a/Scripts/game_manager.gd b/Scripts/game_manager.gd new file mode 100644 index 0000000..e72658f --- /dev/null +++ b/Scripts/game_manager.gd @@ -0,0 +1,24 @@ +extends Node + +var score : int + +@onready var Bird = %Bird +@export var Pipes : PackedScene +const START_POSITION : int = 500 + +# Called when the node enters the scene tree for the first time. +func _ready(): + var instance : Node2D = Pipes.instantiate() + instance.connect("pipe_collision", _on_pipes_pipe_collision) + instance.position.x = START_POSITION + add_child(instance) + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + +func increment_score(): + score += 1 + +func _on_pipes_pipe_collision(): + print("hello") diff --git a/Sprites/pipe-green.png b/Sprites/pipe-green.png new file mode 100644 index 0000000000000000000000000000000000000000..4664401037bdb50a709674c0a23862fa3aa294a4 GIT binary patch literal 2527 zcmZ`)dpy(YAOB*GMLLKYAqhV%YL=WVb;!mj46EF8w>ipfF?Y@85{o%=IVJaEDwkZF za z9fAYu#^16N$nDmDlZKNBkx0H{fq`sN`Hay2ikofQB?Y63uf0s!pnfw%www-EsF z#T@`pxd3oDF!M%-8EBM?yMo8;?d{>unYT^`ch7|nEX9njB}{K8efpj{y^}Puo-iPY zX&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X?&I7fwx?)l$=R zZt37NbV?@ZUI!f=Eo7a-j!Pzg{;l3$f!EGD zW<^Hz`e52x$#ieP*2wUnzH+x_&+z>8*@bB?^mXN@?RIhX>b`s~oKzE;&)_qEIA5To~k)_UG zg(BNua0kqB#&bx>6YUN5RJ)|Oa-iOjj=i-wzpjwT8#7jIbYN_Ykc<}r7_T{j~Jn*qbMU_s_drxf##oOAm92yYtWPwdU-0o;} z_4gEk%~SJg)wW2;qU;i{{g%#uC#^BBUk-(NdHix{5M6yl>H^mVHa=v%_t=U~OeZdf z6VqMyjbzQ(EXyugwpKzU{xmw(ELVL}q*;z6>3Ll=Op}oKqx@vs&*SfdQ?Wv?E${=? zBw-v#-X0_$lvjuk2mlhHXQ+!fqpPQf*E@$oAW?dTClLlH1cDDY0k@DU)Otn z{rdG|yYcmBXZ~0)JZRAQ|NsAjlBe20X~vQuzhDN3XE)M7oFs2|7ml`jQ>%a+&H|6f zVg?3oVGw3ym^DWND9B#o>Fdh=n3;!xN%;9M)g3^gOivfb5Q)pJ7ccT2P~cz*2-_hV zaZog3q4tiZ*WX=k-CFeW?_KXB9ZGT)DW}32LR~d)aPO9UxKJfwxlGFf6@%Z?=Pl^{ zvG%BD+$I544c4p8tvx5#F1#mwQfZCt4!*T6202kV(`MNHKjQ6|w8gBn>)PVeKuc9i zTq8@t-i!lHI literal 0 HcmV?d00001 diff --git a/Sprites/yellowbird-midflap.png.import b/Sprites/yellowbird-midflap.png.import new file mode 100644 index 0000000..c4246f1 --- /dev/null +++ b/Sprites/yellowbird-midflap.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bi1187py7cioc" +path="res://.godot/imported/yellowbird-midflap.png-0e81172432ac4ec18941c9075e4e9fcc.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/yellowbird-midflap.png" +dest_files=["res://.godot/imported/yellowbird-midflap.png-0e81172432ac4ec18941c9075e4e9fcc.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1