From aac7723d576d5cd3c1b911be3eeb6a7687255403 Mon Sep 17 00:00:00 2001 From: Harmony Honey Date: Sun, 5 Mar 2023 16:31:57 -0500 Subject: [PATCH] Snowball! (; Detail physics layer, Snowballs trigger detail and collide on solid/player/box! --- project.godot | 6 ++---- src/actor/Player.gd | 25 ++++++++++++++++--------- src/actor/Player.tscn | 2 +- src/actor/Snowball.gd | 20 +++++++++++++++----- src/actor/Snowball.tscn | 5 ++--- src/detail/Candle.tscn | 4 ++-- src/detail/Flower.tscn | 4 ++-- src/detail/FlowerPetals.tscn | 4 ++-- src/detail/Lamppost.tscn | 4 ++-- src/detail/PineTree.tscn | 4 ++-- src/detail/Saguaro.tscn | 4 ++-- src/detail/Snowman.tscn | 4 ++-- src/detail/Tree.tscn | 4 ++-- src/detail/TreeTop.tscn | 4 ++-- 14 files changed, 54 insertions(+), 40 deletions(-) diff --git a/project.godot b/project.godot index 1be8ce3..64f54c0 100644 --- a/project.godot +++ b/project.godot @@ -363,10 +363,8 @@ debug_warp={ 2d_physics/layer_2="player" 2d_physics/layer_3="box" 2d_physics/layer_4="spike" -2d_physics/layer_5="spinner" -2d_physics/layer_6="arrow" -2d_physics/layer_7="portal" -2d_physics/layer_8="exit" +2d_physics/layer_5="detail" +2d_physics/layer_6="snowball" 2d_physics/layer_11="door" 2d_physics/layer_12="goal" diff --git a/src/actor/Player.gd b/src/actor/Player.gd index 89030f9..8bea7a0 100644 --- a/src/actor/Player.gd +++ b/src/actor/Player.gd @@ -130,6 +130,9 @@ export var chat_offset := Vector2(0, -110) setget set_chat_offset onready var arrow := get_node_or_null("Arrow") onready var chat := get_node_or_null("Arrow/Chat") +export var snowball_scene : PackedScene +var snowballs = [] + func _enter_tree(): if Engine.editor_hint: return if get_parent() == Shared: @@ -767,17 +770,21 @@ func release_anim(): anim.play("release") -export var snowball_scene : PackedScene - func throw_snowball(): - var s = snowball_scene.instance() - s.global_position = spr_hand_l.global_position - s.dir = dir - s.velocity = Vector2(500 * dir_x, -50) - var p = get_parent() - p.add_child(s) - s.owner = p + var s = null + for i in snowballs: + if i.is_out: + s = i + break + if !is_instance_valid(s): + s = snowball_scene.instance() + var p = get_parent() + p.add_child(s) + s.owner = p + snowballs.append(s) + + s.throw(spr_hand_l.global_position, Vector2(500 * dir_x, -50), dir) print(name, " throw snowball ", s) func enter_door(): diff --git a/src/actor/Player.tscn b/src/actor/Player.tscn index c5d363d..27a6187 100644 --- a/src/actor/Player.tscn +++ b/src/actor/Player.tscn @@ -640,7 +640,7 @@ tracks/7/loop_wrap = true tracks/7/imported = false tracks/7/enabled = true tracks/7/keys = { -"times": PoolRealArray( 2.7 ), +"times": PoolRealArray( 2.6 ), "transitions": PoolRealArray( 1 ), "values": [ { "args": [ ], diff --git a/src/actor/Snowball.gd b/src/actor/Snowball.gd index daca651..0d168ff 100644 --- a/src/actor/Snowball.gd +++ b/src/actor/Snowball.gd @@ -10,7 +10,7 @@ onready var polygon := $Polygon2D var is_hit := false var is_out := false var lifetime := 0.0 -var life_min := 0.3 +var life_min := 0.1 var hit_easy := EaseMover.new() @@ -42,11 +42,21 @@ func rot(vec : Vector2, _dir := dir) -> Vector2: return vec func area_entered(area): - if lifetime > life_min: - #is_hit = true - print(name, " ", area) + if lifetime > life_min and !area.get_collision_layer_bit(4): + is_hit = true + #print(name, " ", area) func body_entered(body): if lifetime > life_min: is_hit = true - print(name, " ", body) + #print(name, " ", body) + +func throw(from := Vector2.ZERO, vel := Vector2(500, -50), _dir := dir): + global_position = from + velocity = vel + dir = _dir + is_out = false + is_hit = false + hit_easy.clock = 0 + lifetime = 0 + polygon.scale = Vector2.ONE diff --git a/src/actor/Snowball.tscn b/src/actor/Snowball.tscn index c533fea..fe584c2 100644 --- a/src/actor/Snowball.tscn +++ b/src/actor/Snowball.tscn @@ -8,15 +8,14 @@ [node name="Snowball" type="Area2D"] z_index = 10 z_as_relative = false -collision_layer = 7 -collision_mask = 0 +collision_layer = 32 +collision_mask = 7 script = ExtResource( 2 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource( 1 ) [node name="Polygon2D" type="Polygon2D" parent="."] -color = Color( 1, 0, 0, 1 ) polygon = PoolVector2Array( 10, 0, 8.66025, 5, 5, 8.66025, -4.37114e-07, 10, -5, 8.66025, -8.66025, 5, -10, -8.74228e-07, -8.66025, -5, -5, -8.66025, 1.19249e-07, -10, 5, -8.66025, 8.66025, -5 ) script = ExtResource( 1 ) is_baked = false diff --git a/src/detail/Candle.tscn b/src/detail/Candle.tscn index 2f8ef3c..cd9240d 100644 --- a/src/detail/Candle.tscn +++ b/src/detail/Candle.tscn @@ -44,8 +44,8 @@ script = ExtResource( 7 ) [node name="Area2D" type="Area2D" parent="."] visible = false position = Vector2( 0, -35 ) -collision_layer = 0 -collision_mask = 6 +collision_layer = 16 +collision_mask = 38 [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] shape = SubResource( 1 ) diff --git a/src/detail/Flower.tscn b/src/detail/Flower.tscn index 144e876..f31c0b2 100644 --- a/src/detail/Flower.tscn +++ b/src/detail/Flower.tscn @@ -48,8 +48,8 @@ script = ExtResource( 1 ) [node name="Area2D" type="Area2D" parent="."] visible = false position = Vector2( 0, -25 ) -collision_layer = 0 -collision_mask = 6 +collision_layer = 16 +collision_mask = 38 [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] shape = SubResource( 1 ) diff --git a/src/detail/FlowerPetals.tscn b/src/detail/FlowerPetals.tscn index 762db12..2a3cce3 100644 --- a/src/detail/FlowerPetals.tscn +++ b/src/detail/FlowerPetals.tscn @@ -35,8 +35,8 @@ script = ExtResource( 2 ) [node name="Area2D" type="Area2D" parent="."] visible = false -collision_layer = 0 -collision_mask = 6 +collision_layer = 16 +collision_mask = 38 [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] shape = SubResource( 1 ) diff --git a/src/detail/Lamppost.tscn b/src/detail/Lamppost.tscn index d4e7db0..2076293 100644 --- a/src/detail/Lamppost.tscn +++ b/src/detail/Lamppost.tscn @@ -46,8 +46,8 @@ pitch_to = 0.5 [node name="Area2D" type="Area2D" parent="Spring"] visible = false -collision_layer = 0 -collision_mask = 6 +collision_layer = 16 +collision_mask = 38 [node name="CollisionShape2D" type="CollisionShape2D" parent="Spring/Area2D"] position = Vector2( 0, -100 ) diff --git a/src/detail/PineTree.tscn b/src/detail/PineTree.tscn index f045db5..b41acea 100644 --- a/src/detail/PineTree.tscn +++ b/src/detail/PineTree.tscn @@ -28,8 +28,8 @@ offset = Vector2( 0, -430 ) [node name="Area2D" type="Area2D" parent="."] visible = false -collision_layer = 0 -collision_mask = 6 +collision_layer = 16 +collision_mask = 38 [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] position = Vector2( 0, -430 ) diff --git a/src/detail/Saguaro.tscn b/src/detail/Saguaro.tscn index 7032a7c..983c56e 100644 --- a/src/detail/Saguaro.tscn +++ b/src/detail/Saguaro.tscn @@ -32,8 +32,8 @@ texture = ExtResource( 1 ) [node name="Area2D" type="Area2D" parent="."] visible = false -collision_layer = 0 -collision_mask = 6 +collision_layer = 16 +collision_mask = 38 [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] position = Vector2( 0, -350 ) diff --git a/src/detail/Snowman.tscn b/src/detail/Snowman.tscn index 1672417..4899910 100644 --- a/src/detail/Snowman.tscn +++ b/src/detail/Snowman.tscn @@ -22,8 +22,8 @@ position = Vector2( 0, -325 ) texture = ExtResource( 1 ) [node name="Area2D" type="Area2D" parent="."] -collision_layer = 0 -collision_mask = 6 +collision_layer = 16 +collision_mask = 38 [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] visible = false diff --git a/src/detail/Tree.tscn b/src/detail/Tree.tscn index 0b6a178..88a312e 100644 --- a/src/detail/Tree.tscn +++ b/src/detail/Tree.tscn @@ -50,8 +50,8 @@ pitch_to = 0.5 [node name="Area2D" type="Area2D" parent="Spring"] visible = false -collision_layer = 0 -collision_mask = 6 +collision_layer = 16 +collision_mask = 38 [node name="CollisionShape2D" type="CollisionShape2D" parent="Spring/Area2D"] position = Vector2( 0, -50 ) diff --git a/src/detail/TreeTop.tscn b/src/detail/TreeTop.tscn index 3409f87..702b812 100644 --- a/src/detail/TreeTop.tscn +++ b/src/detail/TreeTop.tscn @@ -34,8 +34,8 @@ script = ExtResource( 1 ) [node name="Area2D" type="Area2D" parent="."] visible = false -collision_layer = 0 -collision_mask = 6 +collision_layer = 16 +collision_mask = 38 [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] shape = SubResource( 1 )