1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-21 23:54:23 +00:00

I made BetterCharacterBody2D and then forgot to commit

This commit is contained in:
Steffo 2024-04-28 10:52:21 +02:00
parent bad1bec1c4
commit 3362124bc5
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
11 changed files with 107 additions and 68 deletions

View file

@ -1,4 +1,4 @@
extends CharacterBody2D
extends BetterCharacterBody2D
class_name Chupacabra

View file

@ -1,4 +1,4 @@
extends CharacterBody2D
extends BetterCharacterBody2D
class_name Cthulhu
@ -7,7 +7,7 @@ class_name Cthulhu
func _on_move(movement: Vector2):
move_and_collide(movement)
better_move_and_collide(movement)
sprite.handle_move(movement)
func _on_dragged(_cursor: Cursor) -> void:

View file

@ -68,58 +68,6 @@ tracks/3/keys = {
"values": [0.0]
}
[sub_resource type="Animation" id="Animation_qhrn0"]
resource_name = "drag_start"
length = 0.4
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("SpriteFocus/Sprite:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.4),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector2(2, 2), Vector2(2.4, 2.4)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("SpriteFocus/Sprite:left_texture")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [ExtResource("5_6ho60")]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("SpriteFocus/Sprite:right_texture")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [ExtResource("6_behik")]
}
tracks/3/type = "value"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath("SpriteFocus:rotation")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [0.0]
}
[sub_resource type="Animation" id="Animation_iyn5h"]
resource_name = "drag_loop"
length = 2.0
@ -173,6 +121,58 @@ tracks/3/keys = {
"values": [-0.10472, 0.10472]
}
[sub_resource type="Animation" id="Animation_qhrn0"]
resource_name = "drag_start"
length = 0.4
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("SpriteFocus/Sprite:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.4),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector2(2, 2), Vector2(2.4, 2.4)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("SpriteFocus/Sprite:left_texture")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [ExtResource("5_6ho60")]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("SpriteFocus/Sprite:right_texture")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [ExtResource("6_behik")]
}
tracks/3/type = "value"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath("SpriteFocus:rotation")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [0.0]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_clmy5"]
_data = {
"RESET": SubResource("Animation_aspa2"),
@ -207,8 +207,8 @@ unique_name_in_owner = true
libraries = {
"": SubResource("AnimationLibrary_clmy5")
}
next/drag_start = &"drag_loop"
next/drag_loop = &"drag_loop"
next/drag_start = &"drag_loop"
blend_times = [&"drag_start", &"drag_loop", 0.5]
[node name="MovementSampler" parent="." instance=ExtResource("6_truco")]

View file

@ -1,4 +1,4 @@
extends CharacterBody2D
extends BetterCharacterBody2D
class_name Imp
@ -8,7 +8,7 @@ class_name Imp
func _on_move(movement: Vector2):
move_and_collide(movement)
better_move_and_collide(movement)
sprite.handle_move(movement)
func _on_eater_eaten(edible: Edible) -> void:

View file

@ -1,4 +1,4 @@
extends CharacterBody2D
extends BetterCharacterBody2D
class_name Monocle
@ -6,7 +6,7 @@ class_name Monocle
func _on_move(movement: Vector2) -> void:
move_and_collide(movement)
better_move_and_collide(movement)
func _on_dragged(_cursor: Cursor) -> void:
collision_layer = 16

View file

@ -1,4 +1,4 @@
extends CharacterBody2D
extends BetterCharacterBody2D
class_name Sheep
@ -7,7 +7,7 @@ class_name Sheep
func _on_move(movement: Vector2) -> void:
move_and_collide(movement)
better_move_and_collide(movement)
sprite.handle_move(movement)
func _on_dragged(_cursor: Cursor) -> void:

View file

@ -1,4 +1,4 @@
extends CharacterBody2D
extends BetterCharacterBody2D
class_name Skull
@ -6,7 +6,7 @@ class_name Skull
func _on_move(movement: Vector2) -> void:
move_and_collide(movement)
better_move_and_collide(movement)
func _on_dragged(_cursor: Cursor) -> void:
collision_layer = 16

View file

@ -1,4 +1,4 @@
extends CharacterBody2D
extends BetterCharacterBody2D
class_name TopHat
@ -6,7 +6,7 @@ class_name TopHat
func _on_move(movement: Vector2) -> void:
move_and_collide(movement)
better_move_and_collide(movement)
func _on_dragged(_cursor: Cursor) -> void:
collision_layer = 16

View file

@ -1,4 +1,4 @@
extends CharacterBody2D
extends BetterCharacterBody2D
class_name Watcher
@ -8,7 +8,7 @@ class_name Watcher
func _on_move(movement: Vector2):
move_and_collide(movement)
better_move_and_collide(movement)
sprite.handle_move(movement)
func _on_dragged(_cursor: Cursor) -> void:

View file

@ -0,0 +1,35 @@
extends CharacterBody2D
class_name BetterCharacterBody2D
## Emitted the first time [method better_move_and_collide] collides with something in a frame.
signal collided_once(collision: KinematicCollision2D)
## Emitted all times [method better_move_and_collide] collides with something in a frame.
signal collided(collision: KinematicCollision2D)
@export var physics_max_bounces: int = 3
func better_move_and_collide(movement: Vector2):
# How many times the body collided in the current physics step.
var bounces: int = 0
# While the body should still move some space, and it isn't stuck in a perpetual loop of bouncing...
while movement.length() > 0.0 and bounces < physics_max_bounces:
# Try to move!
var collision: KinematicCollision2D = move_and_collide(movement)
# If the body did not collide and performed its full movement, we're done!
if not collision:
break
# Let's try to handle the collision properly
bounces += 1
# Emit the signals
collided.emit(collision)
if bounces == 1:
collided_once.emit(collision)
# Determine the normal of the collision (the direction the body should be pushed back in)
var collision_normal = collision.get_normal()
# Change the velocity adequately
velocity = velocity.bounce(collision_normal)
# Reflect the remaining movement
movement = collision.get_remainder().bounce(collision_normal)

View file

@ -22,6 +22,10 @@ window/size/viewport_height=720
window/size/initial_position_type=3
window/size/resizable=false
[editor]
movie_writer/movie_file="/mnt/work/steffo/ld55/.build/movie/capture.avi"
[filesystem]
import/blender/enabled=false