Skip to content

Commit

Permalink
ball: use _integrate_forces() to scale
Browse files Browse the repository at this point in the history
  • Loading branch information
dulvui committed Jan 28, 2024
1 parent bbc5705 commit 5126996
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 45 deletions.
30 changes: 23 additions & 7 deletions game/src/actors/bin/Bin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@

# SPDX-License-Identifier: AGPL-3.0-or-later

extends StaticBody
extends RigidBody

signal win

#func _ready():
# $AnimationPlayer.play("Size")

const scale_min:float = 1.01
const scale_max:float = 1.08
const scale_factor:float = 0.001

var scale_up:bool = true

func _integrate_forces(state:PhysicsDirectBodyState) -> void:
if state.transform.basis.x.x < scale_max and scale_up:
state.transform.basis.x.x += scale_factor
state.transform.basis.y.y += scale_factor
state.transform.basis.z.z += scale_factor
elif state.transform.basis.x.x > scale_min:
scale_up = false
state.transform.basis.x.x -= scale_factor
state.transform.basis.y.y -= scale_factor
state.transform.basis.z.z -= scale_factor
else:
scale_up = true


func _on_BallDetector_body_entered(body) -> void:
if body.is_in_group("ball"):
$Timer.start()
Expand All @@ -21,9 +38,8 @@ func _on_Timer_timeout() -> void:
func fade_in() -> void:
# to match arrow animation
if Global.current_level > 1:
$AnimationPlayer.play("FadeIn")
yield($AnimationPlayer,"animation_finished")
$AnimationPlayer.play("Size")
# TODO use integrate forces
pass

func hide() -> void:
visible = false
Expand Down
43 changes: 5 additions & 38 deletions game/src/actors/bin/Bin.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=2]
[gd_scene load_steps=17 format=2]

[ext_resource path="res://src/actors/bin/Bin.gd" type="Script" id=1]
[ext_resource path="res://materials/bin-material.tres" type="Material" id=2]
Expand Down Expand Up @@ -40,40 +40,12 @@ metallic_specular = 0.0

[sub_resource type="BoxShape" id=13]

[sub_resource type="Animation" id=14]
length = 0.2
tracks/0/type = "value"
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.2 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Vector3( 0.01, 0.01, 0.01 ), Vector3( 1, 1, 1 ) ]
}

[sub_resource type="Animation" id=15]
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.5, 1 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ Vector3( 1.05, 1.05, 1.05 ), Vector3( 0.95, 0.95, 0.95 ), Vector3( 1.05, 1.05, 1.05 ) ]
}

[node name="Bin" type="StaticBody" groups=["objects"]]
[node name="Bin" type="RigidBody" groups=["objects"]]
pause_mode = 2
transform = Transform( 1.05, 0, 0, 0, 1.05, 0, 0, 0, 1.05, 0, 0, 0 )
mode = 3
physics_material_override = SubResource( 1 )
custom_integrator = true
can_sleep = false
script = ExtResource( 1 )

[node name="MeshInstance" type="MeshInstance" parent="."]
Expand Down Expand Up @@ -168,10 +140,5 @@ shape = SubResource( 13 )
wait_time = 0.01
one_shot = true

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/FadeIn = SubResource( 14 )
anims/Size = SubResource( 15 )

[connection signal="body_entered" from="BallDetector" to="." method="_on_BallDetector_body_entered"]
[connection signal="body_exited" from="BallDetector" to="." method="_on_BallDetector_body_exited"]
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]

0 comments on commit 5126996

Please sign in to comment.