screen_shake: trembler l'écran quand:
- on tremble depuis longtemps - onse paye un mur en dashant (ou le plafond)
This commit is contained in:
29
princesse.gd
29
princesse.gd
@@ -21,7 +21,7 @@ var gravity: int = ProjectSettings.get("physics/2d/default_gravity")
|
||||
@onready var ground_far_detect := $ground_far_detect as RayCast2D
|
||||
@onready var ground_far_detect2 := $ground_far_detect2 as RayCast2D
|
||||
@onready var animation := $AnimatedSprite2D as AnimatedSprite2D
|
||||
@onready var camera := $Camera2D as Camera2D
|
||||
@onready var camera := $Camera2D as ShakingCamera
|
||||
@onready var death_animation := $"Death player" as AnimationPlayer
|
||||
|
||||
@onready var nuage_prout := $"GPUParticles2D" as GPUParticles2D
|
||||
@@ -108,6 +108,8 @@ var coyote_grab = []
|
||||
|
||||
# variable d'état relative à la gravité
|
||||
var falling_step : int = -1 # Où en est la princess dans son acceleration de chute ?
|
||||
var character_falling: bool = false
|
||||
var airtime: int = 0
|
||||
|
||||
# Variables d'état relative à l'accroche au mur
|
||||
var pressing_wall_left = false # Princesse est elle en contact avec un mur à gauche?
|
||||
@@ -120,6 +122,8 @@ var dashing : bool = false
|
||||
var dash_step : int = -1
|
||||
var dash_direction_x : int = 1
|
||||
var dash_direction_y : int = 1
|
||||
var dashing_x_stuck : bool = false
|
||||
var dashing_y_stuck : bool = false
|
||||
|
||||
# Variables d'état relative au crouch
|
||||
var crouch : bool = false
|
||||
@@ -151,6 +155,7 @@ func copy_from(other : Princess):
|
||||
dash_direction_x = other.dash_direction_x
|
||||
dash_direction_y = other.dash_direction_y
|
||||
near_cliff = other.near_cliff
|
||||
character_falling = other.character_falling
|
||||
|
||||
################################################################################
|
||||
#
|
||||
@@ -282,6 +287,11 @@ func fall() -> float:
|
||||
var intertia = 0
|
||||
if velocity.y < 0:
|
||||
intertia = max(velocity.y, -FALLING_SPEED)
|
||||
if is_on_floor():
|
||||
airtime = 0
|
||||
else:
|
||||
if falling_step > 0:
|
||||
airtime +=1
|
||||
if is_on_floor_only():
|
||||
if get_floor_normal()[0] < 0: # pente à gauche
|
||||
if direction >= 0:# on va à droite, désactive la gravité
|
||||
@@ -306,6 +316,7 @@ func fall() -> float:
|
||||
|
||||
func stop_fall() -> void:
|
||||
falling_step = -1
|
||||
airtime = 0
|
||||
|
||||
func jump() -> float:
|
||||
# fait sauter princesse
|
||||
@@ -590,6 +601,22 @@ func compute_state() -> void:
|
||||
(wall_detect_right3.is_colliding())
|
||||
)
|
||||
pressing_wall = pressing_wall_left or pressing_wall_right
|
||||
if character_falling:
|
||||
if is_on_floor():
|
||||
if airtime/100 > 0.10:
|
||||
camera.add_trauma(min(airtime/100, 0.30))
|
||||
Input.start_joy_vibration(0, 0, 1, min(airtime/100, 0.30))
|
||||
|
||||
dashing_y_stuck = dashing and is_zero_approx(velocity.y) and (is_on_ceiling() or is_on_floor())
|
||||
dashing_x_stuck = dashing and is_zero_approx(velocity.x) and grab_wall
|
||||
if dashing_x_stuck:
|
||||
camera.add_trauma_x(0.05)
|
||||
if dashing_y_stuck:
|
||||
camera.add_trauma_y(0.05)
|
||||
if dashing_x_stuck or dashing_y_stuck:
|
||||
Input.stop_joy_vibration(0)
|
||||
Input.start_joy_vibration(0, 0, 0.5, 0.05)
|
||||
character_falling = !is_on_floor()
|
||||
|
||||
func get_new_animation() -> String:
|
||||
# Renvoie la bonne annimation en fonction de l'état de la princesse
|
||||
|
||||
Reference in New Issue
Block a user