Snowball! (; Detail physics layer, Snowballs trigger detail and collide on solid/player/box!

This commit is contained in:
Harmony Honey 2023-03-05 16:31:57 -05:00
parent 3c2a231a4a
commit aac7723d57
14 changed files with 54 additions and 40 deletions

View file

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

View file

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

View file

@ -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": [ ],

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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