Simple player entity
parent
69b66e0511
commit
3525ef2ecd
|
@ -0,0 +1,203 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="67.73333mm"
|
||||
height="67.73333mm"
|
||||
viewBox="0 0 67.73333 67.73333"
|
||||
version="1.1"
|
||||
id="svg1420"
|
||||
inkscape:version="0.92.5 (2060ec1f9f, 2020-04-08)"
|
||||
sodipodi:docname="pirate.svg">
|
||||
<defs
|
||||
id="defs1414" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="1.979899"
|
||||
inkscape:cx="193.12383"
|
||||
inkscape:cy="128.13748"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:window-width="1916"
|
||||
inkscape:window-height="1041"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="37"
|
||||
inkscape:window-maximized="0"
|
||||
fit-margin-top="0"
|
||||
fit-margin-left="0"
|
||||
fit-margin-right="0"
|
||||
fit-margin-bottom="0"
|
||||
showguides="false" />
|
||||
<metadata
|
||||
id="metadata1417">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(-22.735567,-21.843752)">
|
||||
<rect
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:1.16499996;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect2086"
|
||||
width="67.73333"
|
||||
height="67.73333"
|
||||
x="22.735567"
|
||||
y="21.843752" />
|
||||
<ellipse
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:0.97067016;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="path1965"
|
||||
cx="58.817451"
|
||||
cy="69.21006"
|
||||
rx="12.306589"
|
||||
ry="13.607285" />
|
||||
<ellipse
|
||||
style="fill:#ffccaa;fill-opacity:1;stroke:#000000;stroke-width:0.97067016;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="path1967"
|
||||
cx="58.517292"
|
||||
cy="43.996555"
|
||||
rx="12.806856"
|
||||
ry="13.807391" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.64763337;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="M 45.064956,44.376975 70.573747,37.843264"
|
||||
id="path1971"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:#1a1a1a;fill-rule:evenodd;stroke:#000000;stroke-width:0.57276243;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 51.618464,41.275314 0.383478,2.521691 1.51754,1.03021 2.8015,-0.100052 c 1.76379,-0.867768 1.776356,-2.027407 2.001071,-3.151687 z"
|
||||
id="path1975"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cccccc" />
|
||||
<path
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:0.64763337;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 66.571604,49.474492 c -10e-7,0.870314 -5.010624,3.777022 -8.229406,3.777022 -3.218781,0 -8.129351,-3.156842 -8.129352,-4.027156 -10e-7,-0.870314 4.91057,0.875469 8.129352,0.875469 3.218782,0 8.229406,-1.495649 8.229406,-0.625335 z"
|
||||
id="path1982"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="sssss" />
|
||||
<ellipse
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:0.64763337;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="path1985"
|
||||
cx="64.220352"
|
||||
cy="42.645832"
|
||||
rx="2.501339"
|
||||
ry="1.4507767" />
|
||||
<ellipse
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:0.64763337;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="path1987"
|
||||
cx="64.320404"
|
||||
cy="42.370686"
|
||||
rx="0.95050877"
|
||||
ry="0.92549545" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.87224609;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 58.317186,44.346745 c -0.48074,1.110566 -2.780721,3.873885 0.100053,3.501876"
|
||||
id="path1991"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<g
|
||||
id="g2020"
|
||||
transform="matrix(0.7487091,0,0,0.7487091,22.011525,15.311364)">
|
||||
<rect
|
||||
y="60.764866"
|
||||
x="34.11235"
|
||||
height="4.7613068"
|
||||
width="29.098907"
|
||||
id="rect1993"
|
||||
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:1.16499996;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<rect
|
||||
y="70.426895"
|
||||
x="31.608257"
|
||||
height="5.3861618"
|
||||
width="33.261906"
|
||||
id="rect1993-3"
|
||||
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:1.16499996;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<rect
|
||||
inkscape:transform-center-y="-1.7953869"
|
||||
inkscape:transform-center-x="4.2522321"
|
||||
y="80.801094"
|
||||
x="34.773071"
|
||||
height="3.9466267"
|
||||
width="27.487846"
|
||||
id="rect1993-6"
|
||||
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:1.16499996;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
</g>
|
||||
<path
|
||||
style="fill:#ff0000;fill-rule:evenodd;stroke:#000000;stroke-width:1.24660063;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 42.10851,46.397844 11.91124,-6.273146 17.704613,-3.131888 -1.152956,-4.88569 -3.659617,-4.307194 -6.593533,-2.41333 -6.560565,1.23882 -6.046183,2.763322 -4.202251,12.206536 -5.602999,-3.001607 -1.400748,5.803105 5.002677,4.602464 z"
|
||||
id="path1969"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="ccccccccccccc" />
|
||||
<ellipse
|
||||
style="fill:#ffff00;fill-opacity:1;stroke:#241c1c;stroke-width:0.59499997;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.28632483"
|
||||
id="path891"
|
||||
cx="71.115189"
|
||||
cy="57.663963"
|
||||
rx="4.9444861"
|
||||
ry="7.4835467" />
|
||||
<ellipse
|
||||
style="fill:#ffff00;fill-opacity:1;stroke:#241c1c;stroke-width:0.59499997;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.28632483"
|
||||
id="path893"
|
||||
cx="70.914734"
|
||||
cy="46.973183"
|
||||
rx="3.4076865"
|
||||
ry="4.4099469" />
|
||||
<path
|
||||
style="fill:#ffff00;fill-opacity:1;stroke:#241c1c;stroke-width:0.59499997;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.28632483"
|
||||
d="m 76.576478,56.227926 c 0.974202,3.635771 0.665907,6.877365 -0.688596,7.240302 -1.354503,0.362937 -3.24229,-2.290218 -4.216492,-5.925988 -0.974202,-3.635771 -0.665907,-6.877365 0.688596,-7.240302 1.354503,-0.362937 3.24229,2.290218 4.216492,5.925988 z"
|
||||
id="path895"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="sssss" />
|
||||
<path
|
||||
style="fill:#ffff00;fill-rule:evenodd;stroke:#c0be08;stroke-width:0.59500003;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 67.774315,45.866354 c 0,0 -2.666291,1.274117 -3.073598,2.53906 -0.268239,0.833048 0.668174,2.539061 0.668174,2.539061 l 1.202713,-1.469983 2.004521,-0.400904 z"
|
||||
id="path897"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cscccc" />
|
||||
<path
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:0.59499997;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.28632483"
|
||||
id="path899"
|
||||
sodipodi:type="arc"
|
||||
sodipodi:cx="-70.017845"
|
||||
sodipodi:cy="-46.00531"
|
||||
sodipodi:rx="1.0151163"
|
||||
sodipodi:ry="1.603617"
|
||||
sodipodi:start="0"
|
||||
sodipodi:end="6.2530804"
|
||||
d="m -69.002729,-46.00531 a 1.0151163,1.603617 0 0 1 -1.007476,1.603571 1.0151163,1.603617 0 0 1 -1.022641,-1.579434 1.0151163,1.603617 0 0 1 0.992083,-1.627345 1.0151163,1.603617 0 0 1 1.037574,1.554938 l -1.014656,0.04827 z"
|
||||
transform="scale(-1)" />
|
||||
<path
|
||||
style="fill:#ffffff;fill-opacity:0.28627451;stroke:#000000;stroke-width:0.59499997;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="path901"
|
||||
sodipodi:type="arc"
|
||||
sodipodi:cx="69.808182"
|
||||
sodipodi:cy="46.459103"
|
||||
sodipodi:rx="0.20966499"
|
||||
sodipodi:ry="0.45379427"
|
||||
sodipodi:start="0"
|
||||
sodipodi:end="6.2530784"
|
||||
d="m 70.017847,46.459103 a 0.20966499,0.45379427 0 0 1 -0.208087,0.453781 0.20966499,0.45379427 0 0 1 -0.211219,-0.44695 0.20966499,0.45379427 0 0 1 0.204907,-0.46051 0.20966499,0.45379427 0 0 1 0.214304,0.440018 l -0.20957,0.01366 z" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 9.6 KiB |
|
@ -0,0 +1,35 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/pirate.svg-3b2dea93c8f9ecaa3dd364c5dc991522.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Assets/pirate.svg"
|
||||
dest_files=[ "res://.import/pirate.svg-3b2dea93c8f9ecaa3dd364c5dc991522.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
|
||||
process/normal_map_invert_y=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
|
@ -7,10 +7,22 @@ export var collision_size = Vector2(1, 1)
|
|||
|
||||
onready var collision_shape = $Area2D
|
||||
|
||||
var is_mouseover = false
|
||||
|
||||
# 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:
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseButton and event.pressed and is_mouseover:
|
||||
emit_signal ("clicked")
|
||||
get_tree().get_root().set_input_as_handled()
|
||||
|
||||
|
||||
func _on_Area2D_mouse_entered():
|
||||
is_mouseover = true
|
||||
|
||||
|
||||
func _on_Area2D_mouse_exited():
|
||||
is_mouseover = false
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Components/ClickableComponent.gd" type="Script" id=1]
|
||||
|
||||
[sub_resource type="CircleShape2D" id=1]
|
||||
radius = 31.4006
|
||||
|
||||
[node name="Clickable" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[connection signal="mouse_entered" from="Area2D" to="." method="_on_Area2D_mouse_entered"]
|
||||
[connection signal="mouse_exited" from="Area2D" to="." method="_on_Area2D_mouse_exited"]
|
|
@ -1,12 +1,16 @@
|
|||
extends Node2D
|
||||
|
||||
var SpringDamper = preload("res://Utils/SpringDamper.gd")
|
||||
|
||||
export var target = Vector2 (0, 0)
|
||||
export var pos = Vector2 (0, 0)
|
||||
export var vel = Vector2 (0, 0)
|
||||
export var max_speed = 50
|
||||
export var spring_k = 10
|
||||
export var spring_b = 0.5
|
||||
|
||||
onready var spring_damper = SpringDamper.new(4, .99, 0.5)
|
||||
|
||||
var velocity = Vector2(0, 0)
|
||||
|
||||
const pos_error_eps = 0.01
|
||||
|
@ -20,8 +24,9 @@ func _ready():
|
|||
# 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
|
||||
var spring_res = spring_damper.calc(pos, vel, target, delta)
|
||||
|
||||
pos = spring_res[0]
|
||||
vel = spring_res[1]
|
||||
|
||||
emit_signal("position_updated", pos)
|
||||
|
|
|
@ -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 on_world_location_clicked(position):
|
||||
assert(movable_component)
|
||||
|
||||
movable_component.target = position
|
|
@ -0,0 +1,25 @@
|
|||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://Entities/PlayerEntity.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Components/TintedSpriteComponent.gd" type="Script" id=2]
|
||||
[ext_resource path="res://Components/ColorComponent.gd" type="Script" id=3]
|
||||
[ext_resource path="res://Components/ClickableComponent.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://Components/MovableComponent.gd" type="Script" id=5]
|
||||
[ext_resource path="res://Assets/pirate.svg" type="Texture" id=6]
|
||||
|
||||
[node name="PlayerEntity" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Components" type="Node2D" parent="."]
|
||||
|
||||
[node name="Movable" type="Node2D" parent="Components"]
|
||||
script = ExtResource( 5 )
|
||||
|
||||
[node name="Clickable" parent="Components" instance=ExtResource( 4 )]
|
||||
|
||||
[node name="TintedSprite" type="Sprite" parent="Components"]
|
||||
texture = ExtResource( 6 )
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Color" type="Node" parent="Components"]
|
||||
script = ExtResource( 3 )
|
|
@ -1,9 +1,9 @@
|
|||
extends Node
|
||||
extends Node2D
|
||||
|
||||
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 movable_component = $Components/Movable
|
||||
|
||||
onready var is_active = false
|
||||
|
||||
|
@ -12,15 +12,12 @@ 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,
|
|
@ -1,26 +1,17 @@
|
|||
[gd_scene load_steps=7 format=2]
|
||||
[gd_scene load_steps=6 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://Entities/SimpleEntity.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://Components/ClickableComponent.tscn" type="PackedScene" 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="Clickable" parent="Components" instance=ExtResource( 4 )]
|
||||
|
||||
[node name="TintedSprite" type="Sprite" parent="Components"]
|
||||
texture = ExtResource( 5 )
|
||||
|
@ -29,5 +20,3 @@ 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"]
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
[gd_scene load_steps=8 format=2]
|
||||
[gd_scene load_steps=7 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://Components/ClickableComponent.tscn" type="PackedScene" 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 )
|
||||
|
||||
|
@ -18,13 +15,7 @@ script = ExtResource( 2 )
|
|||
[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="Clickable" parent="Components" instance=ExtResource( 4 )]
|
||||
|
||||
[node name="TintedSprite" type="Sprite" parent="Components"]
|
||||
texture = ExtResource( 5 )
|
||||
|
@ -32,5 +23,3 @@ 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"]
|
||||
|
|
15
Game.gd
15
Game.gd
|
@ -3,17 +3,14 @@ extends Node2D
|
|||
|
||||
onready var SimpleEntity = preload("res://Entities/SimpleEntity.tscn")
|
||||
onready var WanderingEntity = preload("res://Entities/WanderingEntity.tscn")
|
||||
onready var player = $PlayerEntity
|
||||
onready var entities = $Entities
|
||||
|
||||
signal world_location_clicked
|
||||
|
||||
# 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
|
||||
self.connect("world_location_clicked", player, "on_world_location_clicked")
|
||||
|
||||
func _on_AddEntityButton_pressed():
|
||||
var entity_instance = SimpleEntity.instance()
|
||||
|
@ -27,3 +24,9 @@ func _on_AddWanderingEntity_pressed():
|
|||
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]))
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event is InputEventMouseButton and event.pressed:
|
||||
#get_tree().get_root().set_input_as_handled()
|
||||
emit_signal("world_location_clicked", event.position)
|
||||
pass
|
||||
|
|
10
Game.tscn
10
Game.tscn
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Entities/SimpleEntity.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://Entities/PlayerEntity.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://Game.gd" type="Script" id=6]
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
|
@ -34,15 +35,18 @@ __meta__ = {
|
|||
[node name="SimpleEntity" parent="Entities" instance=ExtResource( 1 )]
|
||||
position = Vector2( 360, 118 )
|
||||
|
||||
[node name="Color" parent="Entities/SimpleEntity/Components" index="3"]
|
||||
[node name="Color" parent="Entities/SimpleEntity/Components" index="2"]
|
||||
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"]
|
||||
[node name="Color" parent="Entities/SimpleEntity2/Components" index="2"]
|
||||
color = Color( 0, 0.0156863, 1, 1 )
|
||||
|
||||
[node name="PlayerEntity" parent="." instance=ExtResource( 2 )]
|
||||
position = Vector2( 263, 225 )
|
||||
|
||||
[connection signal="pressed" from="Control/AddEntityButton" to="." method="_on_AddEntityButton_pressed"]
|
||||
[connection signal="pressed" from="Control/AddWanderingEntity" to="." method="_on_AddWanderingEntity_pressed"]
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
# Based on: allenchou.net/2015/04/game-math-precise-control-over-numeric-springing/
|
||||
|
||||
extends Object
|
||||
|
||||
class_name SpringDamper
|
||||
|
||||
var omega
|
||||
var zeta
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
func _init(osc_freq:float = 1.0, osc_red:float = 0.1, osc_red_h:float = 1.0):
|
||||
assert (osc_red > 0.001 and osc_red < 0.999)
|
||||
omega = osc_freq * 2 * PI
|
||||
zeta = log(1.0 - osc_red) / (-omega * osc_red_h)
|
||||
print ("omega: ", omega, " zeta: ", zeta)
|
||||
|
||||
func calc(x, v, xt, h:float):
|
||||
var f = 1.0 + 2.0 * h * zeta * omega
|
||||
var oo = omega * omega
|
||||
var hoo = oo * h
|
||||
var hhoo = hoo * h
|
||||
var det_inv = 1.0 / (f + hhoo)
|
||||
var det_x = f * x + h * v + hhoo * xt
|
||||
var det_v = v + hoo * (xt - x)
|
||||
return [det_x * det_inv, det_v * det_inv]
|
|
@ -19,6 +19,11 @@ _global_script_classes=[ {
|
|||
"language": "GDScript",
|
||||
"path": "res://Components/ColorComponent.gd"
|
||||
}, {
|
||||
"base": "Object",
|
||||
"class": "SpringDamper",
|
||||
"language": "GDScript",
|
||||
"path": "res://Utils/SpringDamper.gd"
|
||||
}, {
|
||||
"base": "Sprite",
|
||||
"class": "TintedSpriteComponent",
|
||||
"language": "GDScript",
|
||||
|
@ -27,6 +32,7 @@ _global_script_classes=[ {
|
|||
_global_script_class_icons={
|
||||
"ClickableComponent": "",
|
||||
"ColorComponent": "",
|
||||
"SpringDamper": "",
|
||||
"TintedSpriteComponent": ""
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue