Coin + Countdown Timer

Added a coin for player to pick up and a countdown timer
This commit is contained in:
tiffanyfrias10
2021-11-23 11:27:33 -06:00
parent d4302081be
commit 85ee3e7a07
7 changed files with 154 additions and 1 deletions

27
Countdown.gd Normal file
View File

@@ -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.

BIN
Sprites/coin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

34
Sprites/coin.png.import Normal file
View File

@@ -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

View File

@@ -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))

View File

@@ -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"]

10
coin.gd Normal file
View File

@@ -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.

20
coin.tscn Normal file
View File

@@ -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"]