faire le ménage dans le bouzin

abracadabrac!
This commit is contained in:
Thomas
2025-02-21 18:30:27 +01:00
parent fe463ad396
commit bf4bfb9f5a
19 changed files with 527 additions and 4462 deletions

View File

@@ -0,0 +1,39 @@
[gd_scene load_steps=6 format=3 uid="uid://vclpg4e4ql54"]
[ext_resource type="Script" path="res://caracters/player/player_controler.gd" id="1_oapm5"]
[ext_resource type="AnimationNodeStateMachine" uid="uid://ddr1ltkievtku" path="res://animations/human/human_state_machine.tres" id="3_1y7fn"]
[ext_resource type="PackedScene" uid="uid://bvsendl25xjju" path="res://animations/human/human_animation_player.tscn" id="3_c286j"]
[ext_resource type="PackedScene" uid="uid://cg4dhp7qe68pt" path="res://animations/human/human.tscn" id="4_rsj36"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_a4vmx"]
radius = 5.0
height = 48.0
[node name="CharacterBody2D" type="CharacterBody2D"]
z_index = 100
motion_mode = 1
script = ExtResource("1_oapm5")
[node name="Camera2D" type="Camera2D" parent="."]
zoom = Vector2(0.7, 0.7)
position_smoothing_enabled = true
drag_horizontal_enabled = true
drag_vertical_enabled = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 43)
rotation = 1.5708
shape = SubResource("CapsuleShape2D_a4vmx")
[node name="AnimationTree" type="AnimationTree" parent="."]
tree_root = ExtResource("3_1y7fn")
advance_expression_base_node = NodePath("..")
anim_player = NodePath("../AnimationPlayer")
parameters/grabing/blend_position = Vector2(0, 0)
parameters/idling/blend_position = Vector2(-0.353287, 0.839053)
parameters/walking/blend_position = Vector2(0, 0)
[node name="AnimationPlayer" parent="." instance=ExtResource("3_c286j")]
[node name="Sprite2D" parent="." instance=ExtResource("4_rsj36")]
frame = 1

View File

@@ -0,0 +1,36 @@
class_name PlayerControler
extends CharacterBody2D
@export var speed = 450 # How fast the player will move (pixels/sec).
# intensions of the player turner into a boolean
@export var wants_to_grab = false;
@onready var animation_tree := $AnimationTree
@onready var state_machine := animation_tree.get("parameters/playback") as AnimationNodeStateMachinePlayback
var last_facing_direction = Vector2(0,-1) # facing south
func readInputs():
wants_to_grab = Input.is_action_pressed("grab");
if state_machine.get_current_node() == "grabing":
velocity = Vector2(0,0);
else:
velocity = Input.get_vector("move_left", "move_right", "move_up", "move_down") * speed
func updateFacingDirectionInAnimationTree():
animation_tree.set("parameters/walking/blend_position", last_facing_direction)
animation_tree.set("parameters/idling/blend_position", last_facing_direction)
animation_tree.set("parameters/grabing/blend_position", last_facing_direction)
func _physics_process(delta):
readInputs()
# move the caracter
move_and_slide()
# compute the direction the player wants to look at
if velocity:
last_facing_direction = velocity.normalized()
updateFacingDirectionInAnimationTree()