Initial commit
commit
69b66e0511
|
@ -0,0 +1,3 @@
|
||||||
|
.import/*
|
||||||
|
.mono/*
|
||||||
|
*.swp
|
|
@ -0,0 +1,16 @@
|
||||||
|
class_name ClickableComponent
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
signal clicked()
|
||||||
|
|
||||||
|
export var collision_size = Vector2(1, 1)
|
||||||
|
|
||||||
|
onready var collision_shape = $Area2D
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
collision_shape.scale = collision_size
|
||||||
|
|
||||||
|
func _on_Area2D_input_event(viewport, event, shape_idx):
|
||||||
|
if event is InputEventMouseButton and event.pressed:
|
||||||
|
emit_signal ("clicked")
|
|
@ -0,0 +1,14 @@
|
||||||
|
class_name ColorComponent
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
export var color = Color(1, 0, 1)
|
||||||
|
|
||||||
|
signal color_changed(color)
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
set_color(color)
|
||||||
|
|
||||||
|
func set_color(c : Color):
|
||||||
|
color = c
|
||||||
|
emit_signal("color_changed", color)
|
|
@ -0,0 +1,27 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
|
||||||
|
export var target = Vector2 (0, 0)
|
||||||
|
export var pos = Vector2 (0, 0)
|
||||||
|
export var max_speed = 50
|
||||||
|
export var spring_k = 10
|
||||||
|
export var spring_b = 0.5
|
||||||
|
|
||||||
|
var velocity = Vector2(0, 0)
|
||||||
|
|
||||||
|
const pos_error_eps = 0.01
|
||||||
|
|
||||||
|
signal position_updated
|
||||||
|
|
||||||
|
# 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):
|
||||||
|
if (target - pos).length_squared() > pos_error_eps * pos_error_eps:
|
||||||
|
var acceleration = spring_k * (target - pos) - spring_b * velocity
|
||||||
|
velocity = velocity + acceleration * delta
|
||||||
|
pos = pos + velocity * delta
|
||||||
|
|
||||||
|
emit_signal("position_updated", pos)
|
|
@ -0,0 +1,18 @@
|
||||||
|
class_name TintedSpriteComponent
|
||||||
|
extends Sprite
|
||||||
|
|
||||||
|
export var tint_color = Color (1, 1, 1)
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _process(delta):
|
||||||
|
if Engine.editor_hint:
|
||||||
|
modulate = tint_color
|
||||||
|
|
||||||
|
func set_color_tint(color: Color):
|
||||||
|
tint_color = color
|
||||||
|
modulate = tint_color
|
||||||
|
update()
|
|
@ -0,0 +1,33 @@
|
||||||
|
[gd_scene load_steps=7 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Components/TintedSpriteComponent.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://PlayerNode.gd" type="Script" id=2]
|
||||||
|
[ext_resource path="res://Components/ColorComponent.gd" type="Script" id=3]
|
||||||
|
[ext_resource path="res://Components/ClickableComponent.gd" type="Script" id=4]
|
||||||
|
[ext_resource path="res://icon.png" type="Texture" id=5]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id=1]
|
||||||
|
radius = 31.4006
|
||||||
|
|
||||||
|
[node name="SimpleEntity" type="Node2D"]
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
|
[node name="Components" type="Node2D" parent="."]
|
||||||
|
|
||||||
|
[node name="Clickable" type="Node2D" parent="Components"]
|
||||||
|
script = ExtResource( 4 )
|
||||||
|
|
||||||
|
[node name="Area2D" type="Area2D" parent="Components/Clickable"]
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Components/Clickable/Area2D"]
|
||||||
|
shape = SubResource( 1 )
|
||||||
|
|
||||||
|
[node name="TintedSprite" type="Sprite" parent="Components"]
|
||||||
|
texture = ExtResource( 5 )
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
|
[node name="Color" type="Node" parent="Components"]
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
color = Color( 1, 1, 1, 1 )
|
||||||
|
|
||||||
|
[connection signal="input_event" from="Components/Clickable/Area2D" to="Components/Clickable" method="_on_Area2D_input_event"]
|
|
@ -0,0 +1,44 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
onready var color_component = $Components/Color
|
||||||
|
onready var tinted_sprite_component = $Components/TintedSprite
|
||||||
|
onready var clickable_component = $Components/Clickable
|
||||||
|
onready var movable_component = $Components/Movable
|
||||||
|
|
||||||
|
onready var is_active = false
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
if color_component and tinted_sprite_component:
|
||||||
|
print ("Connecting signals")
|
||||||
|
color_component.connect("color_changed", tinted_sprite_component, "set_color_tint")
|
||||||
|
|
||||||
|
if clickable_component:
|
||||||
|
clickable_component.connect("clicked", self, "_on_entity_clicked")
|
||||||
|
|
||||||
|
if movable_component:
|
||||||
|
movable_component.connect("position_updated", self, "_on_position_updated")
|
||||||
|
movable_component.target = self.transform.origin
|
||||||
|
movable_component.pos = self.transform.origin
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
if is_active and color_component:
|
||||||
|
var color = Color(
|
||||||
|
(sin(float(OS.get_system_time_msecs()) / 1000.0) + 1.0) / 2.0,
|
||||||
|
(sin(float(OS.get_system_time_msecs()) / 300.0) + 1.0) / 2.0,
|
||||||
|
(sin(float(OS.get_system_time_msecs()) / 100.0) + 1.0) / 2.0
|
||||||
|
)
|
||||||
|
color_component.set_color(color)
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _on_entity_clicked():
|
||||||
|
is_active = not is_active
|
||||||
|
|
||||||
|
func _on_position_updated(new_position):
|
||||||
|
transform.origin = new_position
|
||||||
|
update()
|
||||||
|
|
||||||
|
func set_target(new_target):
|
||||||
|
assert(movable_component)
|
||||||
|
|
||||||
|
movable_component.target = new_target
|
|
@ -0,0 +1,36 @@
|
||||||
|
[gd_scene load_steps=8 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Components/TintedSpriteComponent.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://Entities/WanderingEntity.gd" type="Script" id=2]
|
||||||
|
[ext_resource path="res://Components/ColorComponent.gd" type="Script" id=3]
|
||||||
|
[ext_resource path="res://Components/ClickableComponent.gd" type="Script" id=4]
|
||||||
|
[ext_resource path="res://icon.png" type="Texture" id=5]
|
||||||
|
[ext_resource path="res://Components/MovableComponent.gd" type="Script" id=6]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id=1]
|
||||||
|
radius = 31.4006
|
||||||
|
|
||||||
|
[node name="WanderingEntity" type="Node2D"]
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
|
[node name="Components" type="Node2D" parent="."]
|
||||||
|
|
||||||
|
[node name="Movable" type="Node2D" parent="Components"]
|
||||||
|
script = ExtResource( 6 )
|
||||||
|
|
||||||
|
[node name="Clickable" type="Node2D" parent="Components"]
|
||||||
|
script = ExtResource( 4 )
|
||||||
|
|
||||||
|
[node name="Area2D" type="Area2D" parent="Components/Clickable"]
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Components/Clickable/Area2D"]
|
||||||
|
shape = SubResource( 1 )
|
||||||
|
|
||||||
|
[node name="TintedSprite" type="Sprite" parent="Components"]
|
||||||
|
texture = ExtResource( 5 )
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
|
[node name="Color" type="Node" parent="Components"]
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
|
[connection signal="input_event" from="Components/Clickable/Area2D" to="Components/Clickable" method="_on_Area2D_input_event"]
|
|
@ -0,0 +1,29 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
|
||||||
|
onready var SimpleEntity = preload("res://Entities/SimpleEntity.tscn")
|
||||||
|
onready var WanderingEntity = preload("res://Entities/WanderingEntity.tscn")
|
||||||
|
onready var entities = $Entities
|
||||||
|
|
||||||
|
|
||||||
|
# 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):
|
||||||
|
# pass
|
||||||
|
|
||||||
|
func _on_AddEntityButton_pressed():
|
||||||
|
var entity_instance = SimpleEntity.instance()
|
||||||
|
var viewport_rect = get_viewport_rect()
|
||||||
|
entity_instance.transform.origin = Vector2(randf() * viewport_rect.size[0], randf() * viewport_rect.size[1])
|
||||||
|
entities.add_child(entity_instance)
|
||||||
|
|
||||||
|
func _on_AddWanderingEntity_pressed():
|
||||||
|
var entity_instance = WanderingEntity.instance()
|
||||||
|
var viewport_rect = get_viewport_rect()
|
||||||
|
entity_instance.transform.origin = Vector2(randf() * viewport_rect.size[0], randf() * viewport_rect.size[1])
|
||||||
|
entities.add_child(entity_instance)
|
||||||
|
entity_instance.set_target(Vector2(randf() * viewport_rect.size[0], randf() * viewport_rect.size[1]))
|
|
@ -0,0 +1,50 @@
|
||||||
|
[gd_scene load_steps=3 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Entities/SimpleEntity.tscn" type="PackedScene" id=1]
|
||||||
|
[ext_resource path="res://Game.gd" type="Script" id=6]
|
||||||
|
|
||||||
|
[node name="Game" type="Node2D"]
|
||||||
|
script = ExtResource( 6 )
|
||||||
|
|
||||||
|
[node name="Control" type="HBoxContainer" parent="."]
|
||||||
|
margin_left = 30.0
|
||||||
|
margin_top = 30.0
|
||||||
|
margin_right = 40.0
|
||||||
|
margin_bottom = 40.0
|
||||||
|
|
||||||
|
[node name="AddEntityButton" type="Button" parent="Control"]
|
||||||
|
margin_right = 77.0
|
||||||
|
margin_bottom = 20.0
|
||||||
|
text = "Add Entity"
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="AddWanderingEntity" type="Button" parent="Control"]
|
||||||
|
margin_left = 81.0
|
||||||
|
margin_right = 190.0
|
||||||
|
margin_bottom = 20.0
|
||||||
|
text = "Add Wandering"
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Entities" type="Node2D" parent="."]
|
||||||
|
|
||||||
|
[node name="SimpleEntity" parent="Entities" instance=ExtResource( 1 )]
|
||||||
|
position = Vector2( 360, 118 )
|
||||||
|
|
||||||
|
[node name="Color" parent="Entities/SimpleEntity/Components" index="3"]
|
||||||
|
color = Color( 0.298039, 0.745098, 0.368627, 1 )
|
||||||
|
|
||||||
|
[node name="SimpleEntity2" parent="Entities" instance=ExtResource( 1 )]
|
||||||
|
position = Vector2( 157, 306 )
|
||||||
|
|
||||||
|
[node name="Color" parent="Entities/SimpleEntity2/Components" index="3"]
|
||||||
|
color = Color( 0, 0.0156863, 1, 1 )
|
||||||
|
|
||||||
|
[connection signal="pressed" from="Control/AddEntityButton" to="." method="_on_AddEntityButton_pressed"]
|
||||||
|
[connection signal="pressed" from="Control/AddWanderingEntity" to="." method="_on_AddWanderingEntity_pressed"]
|
||||||
|
|
||||||
|
[editable path="Entities/SimpleEntity"]
|
||||||
|
[editable path="Entities/SimpleEntity2"]
|
|
@ -0,0 +1,34 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
onready var color_component = $Components/Color
|
||||||
|
onready var tinted_sprite_component = $Components/TintedSprite
|
||||||
|
onready var clickable_component = $Components/Clickable
|
||||||
|
onready var undef_component = $ebvlerb
|
||||||
|
|
||||||
|
onready var is_active = false
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
if color_component and tinted_sprite_component:
|
||||||
|
print ("Connecting signals")
|
||||||
|
color_component.connect("color_changed", tinted_sprite_component, "set_color_tint")
|
||||||
|
tinted_sprite_component.set_color_tint(color_component.color)
|
||||||
|
|
||||||
|
if clickable_component:
|
||||||
|
clickable_component.connect("clicked", self, "_on_entity_clicked")
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
if Engine.editor_hint:
|
||||||
|
tinted_sprite_component.tint_color = color_component.color
|
||||||
|
|
||||||
|
if is_active and color_component:
|
||||||
|
var color = Color(
|
||||||
|
(sin(float(OS.get_system_time_msecs()) / 1000.0) + 1.0) / 2.0,
|
||||||
|
(sin(float(OS.get_system_time_msecs()) / 300.0) + 1.0) / 2.0,
|
||||||
|
(sin(float(OS.get_system_time_msecs()) / 100.0) + 1.0) / 2.0
|
||||||
|
)
|
||||||
|
color_component.set_color(color)
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _on_entity_clicked():
|
||||||
|
is_active = not is_active
|
|
@ -0,0 +1,16 @@
|
||||||
|
extends Sprite
|
||||||
|
|
||||||
|
|
||||||
|
# Declare member variables here. Examples:
|
||||||
|
# var a = 2
|
||||||
|
# var b = "text"
|
||||||
|
|
||||||
|
|
||||||
|
# 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):
|
||||||
|
# pass
|
|
@ -0,0 +1,7 @@
|
||||||
|
[gd_resource type="Environment" load_steps=2 format=2]
|
||||||
|
|
||||||
|
[sub_resource type="ProceduralSky" id=1]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
background_mode = 2
|
||||||
|
background_sky = SubResource( 1 )
|
|
@ -0,0 +1,37 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path.s3tc="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.s3tc.stex"
|
||||||
|
path.etc2="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.etc2.stex"
|
||||||
|
metadata={
|
||||||
|
"imported_formats": [ "s3tc", "etc2" ],
|
||||||
|
"vram_texture": true
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://icon.png"
|
||||||
|
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.s3tc.stex", "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.etc2.stex" ]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=2
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_mode=0
|
||||||
|
compress/bptc_ldr=0
|
||||||
|
compress/normal_map=0
|
||||||
|
flags/repeat=true
|
||||||
|
flags/filter=true
|
||||||
|
flags/mipmaps=true
|
||||||
|
flags/anisotropic=false
|
||||||
|
flags/srgb=2
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/HDR_as_SRGB=false
|
||||||
|
process/invert_color=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
stream=false
|
||||||
|
size_limit=0
|
||||||
|
detect_3d=false
|
||||||
|
svg/scale=1.0
|
|
@ -0,0 +1,45 @@
|
||||||
|
; Engine configuration file.
|
||||||
|
; It's best edited using the editor UI and not directly,
|
||||||
|
; since the parameters that go here are not all obvious.
|
||||||
|
;
|
||||||
|
; Format:
|
||||||
|
; [section] ; section goes between []
|
||||||
|
; param=value ; assign values to parameters
|
||||||
|
|
||||||
|
config_version=4
|
||||||
|
|
||||||
|
_global_script_classes=[ {
|
||||||
|
"base": "Node",
|
||||||
|
"class": "ClickableComponent",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://Components/ClickableComponent.gd"
|
||||||
|
}, {
|
||||||
|
"base": "Node",
|
||||||
|
"class": "ColorComponent",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://Components/ColorComponent.gd"
|
||||||
|
}, {
|
||||||
|
"base": "Sprite",
|
||||||
|
"class": "TintedSpriteComponent",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://Components/TintedSpriteComponent.gd"
|
||||||
|
} ]
|
||||||
|
_global_script_class_icons={
|
||||||
|
"ClickableComponent": "",
|
||||||
|
"ColorComponent": "",
|
||||||
|
"TintedSpriteComponent": ""
|
||||||
|
}
|
||||||
|
|
||||||
|
[application]
|
||||||
|
|
||||||
|
config/name="GodotComponentTest"
|
||||||
|
run/main_scene="res://Game.tscn"
|
||||||
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
|
[physics]
|
||||||
|
|
||||||
|
common/enable_pause_aware_picking=true
|
||||||
|
|
||||||
|
[rendering]
|
||||||
|
|
||||||
|
environment/default_environment="res://default_env.tres"
|
Loading…
Reference in New Issue