Skip to content

Commit

Permalink
Add signals demo and starter project
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanLovato committed Apr 6, 2021
1 parent 0963bb5 commit 89046b7
Show file tree
Hide file tree
Showing 43 changed files with 1,083 additions and 0 deletions.
20 changes: 20 additions & 0 deletions starter-projects/using-signals/CustomSignal.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://CustomSignal/Player.tscn" type="PackedScene" id=1]
[ext_resource path="res://CustomSignal/Enemy.tscn" type="PackedScene" id=2]
[ext_resource path="res://CustomSignal/LifeBar.tscn" type="PackedScene" id=3]
[ext_resource path="res://CustomSignal/lifebar_foreground.png" type="Texture" id=4]

[node name="CustomSignal" type="Node2D"]

[node name="Enemy" parent="." instance=ExtResource( 2 )]
position = Vector2( 570.022, 302.383 )

[node name="Player" parent="." instance=ExtResource( 1 )]
position = Vector2( 225, 310 )

[node name="LifeBar" parent="." instance=ExtResource( 3 )]
max_value = 10.0
value = 10.0
texture_over = null
texture_progress = ExtResource( 4 )
19 changes: 19 additions & 0 deletions starter-projects/using-signals/CustomSignal/Enemy.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
extends Area2D

var angle_increase_speed = PI
var radius = Vector2(300.0, 150.0)

var angle = 0.0

onready var start_position = position
onready var previous_position = start_position


func _process(delta):
angle = wrapf(angle + angle_increase_speed * delta, 0.0, 2 * PI)

var direction = Vector2(cos(angle), sin(2*angle))

previous_position = position
position = start_position + direction * radius
rotation = (position - previous_position).angle()
17 changes: 17 additions & 0 deletions starter-projects/using-signals/CustomSignal/Enemy.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://CustomSignal/topdown-enemy.svg" type="Texture" id=1]
[ext_resource path="res://CustomSignal/Enemy.gd" type="Script" id=2]

[sub_resource type="CircleShape2D" id=1]
radius = 27.4179

[node name="Enemy" type="Area2D"]
position = Vector2( 643.022, 309.383 )
script = ExtResource( 2 )

[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )

[node name="CollisionPolygon2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )
1 change: 1 addition & 0 deletions starter-projects/using-signals/CustomSignal/LifeBar.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extends TextureProgress
27 changes: 27 additions & 0 deletions starter-projects/using-signals/CustomSignal/LifeBar.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://CustomSignal/lifebar_foreground.png" type="Texture" id=1]
[ext_resource path="res://CustomSignal/lifebar_background.png" type="Texture" id=2]
[ext_resource path="res://CustomSignal/LifeBar.gd" type="Script" id=3]

[node name="LifeBar" type="TextureProgress"]
margin_left = 43.0
margin_top = 51.0
margin_right = 235.0
margin_bottom = 91.0
texture_under = ExtResource( 2 )
texture_over = ExtResource( 1 )
script = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Label" type="Label" parent="."]
margin_left = 8.3943
margin_top = -19.315
margin_right = 95.3943
margin_bottom = -5.315
text = "Player health:"
__meta__ = {
"_edit_use_anchors_": false
}
15 changes: 15 additions & 0 deletions starter-projects/using-signals/CustomSignal/Player.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extends Area2D

var health = 10


func take_damage(amount):
health -= amount
if health < 0:
health = 0

get_node("AnimationPlayer").play("take_damage")


func _on_area_entered(area):
take_damage(2)
55 changes: 55 additions & 0 deletions starter-projects/using-signals/CustomSignal/Player.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[gd_scene load_steps=6 format=2]

[ext_resource path="res://CustomSignal/topdown-player.svg" type="Texture" id=1]
[ext_resource path="res://CustomSignal/Player.gd" type="Script" id=2]

[sub_resource type="CircleShape2D" id=1]
radius = 26.0512

[sub_resource type="Animation" id=3]
resource_name = "setup"
length = 0.001
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ) ]
}

[sub_resource type="Animation" id=2]
resource_name = "take_damage"
length = 0.4
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ), Color( 0.952941, 0.32549, 0.32549, 1 ), Color( 1, 1, 1, 1 ), Color( 0.952941, 0.32549, 0.32549, 1 ), Color( 1, 1, 1, 1 ) ]
}

[node name="Player" type="Area2D"]
script = ExtResource( 2 )

[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "setup"
anims/setup = SubResource( 3 )
anims/take_damage = SubResource( 2 )

[connection signal="area_entered" from="." to="." method="_on_area_entered"]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/lifebar_background.png-96b0303205556105005ced94d441b1ab.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://CustomSignal/lifebar_background.png"
dest_files=[ "res://.import/lifebar_background.png-96b0303205556105005ced94d441b1ab.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=true
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/lifebar_foreground.png-4d9a03410adce54378306a5b29e6e35a.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://CustomSignal/lifebar_foreground.png"
dest_files=[ "res://.import/lifebar_foreground.png-4d9a03410adce54378306a5b29e6e35a.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=true
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
66 changes: 66 additions & 0 deletions starter-projects/using-signals/CustomSignal/topdown-enemy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/topdown-enemy.svg-8388bfbd8771e40eb43b052764eceb0f.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://CustomSignal/topdown-enemy.svg"
dest_files=[ "res://.import/topdown-enemy.svg-8388bfbd8771e40eb43b052764eceb0f.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=true
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
66 changes: 66 additions & 0 deletions starter-projects/using-signals/CustomSignal/topdown-player.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 89046b7

Please sign in to comment.