From 85ee3e7a073e57fcc2bab53b8dcee5d859066ebc Mon Sep 17 00:00:00 2001 From: tiffanyfrias10 <58270660+tiffanyfrias10@users.noreply.github.com> Date: Tue, 23 Nov 2021 11:27:33 -0600 Subject: [PATCH] Coin + Countdown Timer Added a coin for player to pick up and a countdown timer --- Countdown.gd | 27 +++++++++++++++++++++++ Sprites/coin.png | Bin 0 -> 252 bytes Sprites/coin.png.import | 34 +++++++++++++++++++++++++++++ World.gd | 17 +++++++++++++++ World.tscn | 47 +++++++++++++++++++++++++++++++++++++++- coin.gd | 10 +++++++++ coin.tscn | 20 +++++++++++++++++ 7 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 Countdown.gd create mode 100644 Sprites/coin.png create mode 100644 Sprites/coin.png.import create mode 100644 coin.gd create mode 100644 coin.tscn diff --git a/Countdown.gd b/Countdown.gd new file mode 100644 index 0000000..3a2c8d7 --- /dev/null +++ b/Countdown.gd @@ -0,0 +1,27 @@ +extends Control + +export (int) var minutes =0 +export (int) var seconds = 0 +var dsec = 0 + +func _physics_process(delta: float) -> void: + if seconds > 0 and dsec <= 0: + seconds -=1 + dsec = 10 + if minutes > 0 and seconds <= 0: + minutes -= 1 + seconds = 60 + + if seconds >= 10: + $sec.set_text(str(seconds)) + else: + $sec.set_text("0"+str(seconds)) + + if dsec >=10: + $dsec.set_text(str(dsec)) + else: + $dsec.set_text("0" + str(dsec)) + +func _on_Timer_timeout() -> void: + dsec-=1 + pass # Replace with function body. diff --git a/Sprites/coin.png b/Sprites/coin.png new file mode 100644 index 0000000000000000000000000000000000000000..3d586c200121d9e7369f76a81241ed8ab9b86a42 GIT binary patch literal 252 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|wtBiahFJI~ zrz{XKcyvksX#OYp$ago78y9S?{Qv#W{39=zo+V2#Tt0DDtug7_^?3aQedRCP}8xLU&jVm?xM% zw{mafow=u6az>k^(H&lfpHtU3uw<&3Nlg?Mz1G6g_55v;@CG%Nl(P}RN*Xf{m8=t7 z;b6!TYaGVx&~zemZb01OnKL;uTTTY&FfhznIZ5!Hd=(GS0}P(7elF{r5}FtQeHmTm literal 0 HcmV?d00001 diff --git a/Sprites/coin.png.import b/Sprites/coin.png.import new file mode 100644 index 0000000..3aad392 --- /dev/null +++ b/Sprites/coin.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/coin.png-b7fabe76c61e67396a7c0402e221b540.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/coin.png" +dest_files=[ "res://.import/coin.png-b7fabe76c61e67396a7c0402e221b540.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=false +svg/scale=1.0 diff --git a/World.gd b/World.gd index faaf7c8..3690891 100644 --- a/World.gd +++ b/World.gd @@ -1,5 +1,22 @@ extends Node2D +onready var coin = preload("res://coin.tscn") +onready var coin_container = get_node("YSort/coin_container") + +var screensize +var score = 0 + func _ready() -> void: $YSort/Player.position = get_viewport_rect().size / 2 + randomize() + screensize = get_viewport_rect().size + set_process(true) + spawn_coins(5) return + +func spawn_coins(num): + for i in range(num): + var g = coin.instance() + coin_container.add_child(g) + #g.set_pos(Vector2(rand_range(0, screensize.x-40), rand_range(0, screensize.y-40))) + g.position = Vector2(rand_range(0, screensize.x-40), rand_range(0, screensize.y-40)) diff --git a/World.tscn b/World.tscn index 53b4636..f626f4a 100644 --- a/World.tscn +++ b/World.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=2] +[gd_scene load_steps=13 format=2] [ext_resource path="res://Player.tscn" type="PackedScene" id=1] [ext_resource path="res://World.gd" type="Script" id=2] @@ -7,6 +7,7 @@ [ext_resource path="res://Sprites/forestTreeBig.png" type="Texture" id=5] [ext_resource path="res://snowmen_enemy_blue.tscn" type="PackedScene" id=6] [ext_resource path="res://snowmen_enemy_blue.gd" type="Script" id=7] +[ext_resource path="res://Countdown.gd" type="Script" id=8] [sub_resource type="CapsuleShape2D" id=1] radius = 9.0515 @@ -163,3 +164,47 @@ position = Vector2( -49.6063, 34.526 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="YSort/wall3"] position = Vector2( 0, -4.25 ) shape = SubResource( 4 ) + +[node name="coin_container" type="Control" parent="YSort"] +margin_right = 40.0 +margin_bottom = 40.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Countdown" type="Control" parent="."] +margin_right = 40.0 +margin_bottom = 40.0 +script = ExtResource( 8 ) +__meta__ = { +"_edit_use_anchors_": false +} +minutes = 3 + +[node name="sec" type="RichTextLabel" parent="Countdown"] +modulate = Color( 0.25098, 0.0431373, 0.411765, 1 ) +self_modulate = Color( 0.25098, 0.0431373, 0.411765, 1 ) +margin_left = 139.114 +margin_top = 5.0 +margin_right = 169.114 +margin_bottom = 26.0 +text = "00" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="dsec" type="RichTextLabel" parent="Countdown"] +modulate = Color( 0.25098, 0.0431373, 0.411765, 1 ) +self_modulate = Color( 0.25098, 0.0431373, 0.411765, 1 ) +margin_left = 158.512 +margin_top = 4.7622 +margin_right = 198.512 +margin_bottom = 44.7622 +text = "0" + +[node name="Timer" type="Timer" parent="Countdown"] +process_mode = 0 +wait_time = 0.1 +autostart = true + +[connection signal="timeout" from="Countdown/Timer" to="Countdown" method="_on_Timer_timeout"] diff --git a/coin.gd b/coin.gd new file mode 100644 index 0000000..6d6ab09 --- /dev/null +++ b/coin.gd @@ -0,0 +1,10 @@ +extends Area2D + +func _ready() -> void: + pass # Replace with function body. + + + +func _on_Node2D_body_entered(body: Node) -> void: + if body.get_name() == "Player": + queue_free() # Replace with function body. diff --git a/coin.tscn b/coin.tscn new file mode 100644 index 0000000..dced35c --- /dev/null +++ b/coin.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://Sprites/coin.png" type="Texture" id=1] +[ext_resource path="res://coin.gd" type="Script" id=2] + +[sub_resource type="CircleShape2D" id=1] +radius = 6.38067 + +[node name="Node2D" type="Area2D"] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +position = Vector2( 28.3217, 41.6257 ) +texture = ExtResource( 1 ) + +[node name="Collision" type="CollisionShape2D" parent="."] +position = Vector2( 28.4389, 40.6703 ) +shape = SubResource( 1 ) + +[connection signal="body_entered" from="." to="." method="_on_Node2D_body_entered"]