Allows the player to swim form 10 seconds !

main
Ervan Lefevre 2 years ago
parent 4919dc92de
commit df61097d27
  1. 9
      nodes/npc/npc.gd
  2. 37
      nodes/player/player.gd
  3. 4
      scenes/poc.tscn
  4. 7
      scripts/gameplay/rising_level.gd

@ -6,6 +6,7 @@ const SPEED = 100
const MINIMUM_STATE_DURATION = 3
const STATES = ['panic', 'dead']
const QUEUE_FREE_DELAY = 30
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var direction = 0
@ -19,9 +20,10 @@ func panic_state(delta):
if is_on_wall():
direction *= -1
var state_duration_in_seconds = ceili($fsm.state_duration)
var should_update = (
$fsm.state_duration >= MINIMUM_STATE_DURATION
&& ceil($fsm.state_duration) % 2 == (randi() %2)
&& state_duration_in_seconds % 2 == (randi() %2)
)
if should_update:
@ -36,7 +38,7 @@ func on_enter_dead_state():
$shape.queue_free()
func dead_state(_delta):
velocity = Vector2(0, -rising_speed * (randf_range(0.9,1)))
velocity = Vector2(0, -rising_speed)
move_and_slide()
@ -44,5 +46,8 @@ func die(level_speed):
$fsm.set_next_state('dead')
rising_speed = level_speed
if $fsm.state_duration > QUEUE_FREE_DELAY:
queue_free()
func pick_new_direction():
direction = [1,-1][randi_range(0,1)] * SPEED

@ -4,6 +4,7 @@ class_name Player
const SPEED = 100.0
const JUMP_VELOCITY = 200.0
const APNEA_DURATION = 10
const STATES= [
"climb",
@ -11,7 +12,8 @@ const STATES= [
"idle",
"jump",
"spawn",
"walk"
"walk",
"swim"
]
var use_gravity = {
@ -20,7 +22,8 @@ var use_gravity = {
"idle": true,
"jump": true,
"spawn": true,
"walk": true
"walk": true,
"swim": true
}
var can_grab_obstacles = {
@ -29,7 +32,8 @@ var can_grab_obstacles = {
"idle": true,
"jump": false,
"spawn": false,
"walk": true
"walk": true,
"swim": true
}
@ -37,7 +41,8 @@ var can_grab_obstacles = {
@onready var sprite = get_node('oriented_container/sprite')
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var WORLD_GRAVITY = ProjectSettings.get_setting("physics/2d/default_gravity")
var gravity = WORLD_GRAVITY
var grabbed_obstacle = null
@ -184,6 +189,30 @@ func handle_sprite_orientation():
$oriented_container.rotation = 0 if (velocity.x > 0) else PI
sprite.flip_v = velocity.x < 0
func on_enter_swim_state():
gravity = WORLD_GRAVITY / 2
func swim_state(_delta):
var direction_x = Input.get_axis("player_left", "player_right")
var direction_y = Input.get_axis("player_up", "player_down")
velocity = Vector2(direction_x, direction_y).normalized() * SPEED
var progress_to_black = 1 - clamp($fsm.state_duration / APNEA_DURATION, 0, 1)
sprite.modulate = Color(progress_to_black, progress_to_black, progress_to_black )
if $fsm.state_duration >= APNEA_DURATION:
die()
func on_exit_swim_state():
gravity = WORLD_GRAVITY
sprite.modulate = Color(1,1,1)
func swim():
$fsm.set_next_state("swim")
func unswim():
$fsm.set_next_state("idle")
func die():
$fsm.set_next_state("die")

File diff suppressed because one or more lines are too long

@ -5,6 +5,7 @@ class_name RisingLevel
func _ready():
body_entered.connect(_body_entered)
body_exited.connect(_body_exited)
func _physics_process(delta):
$shape.position.y -= RISING_SPEED * delta
@ -13,7 +14,11 @@ func _physics_process(delta):
func _body_entered(body):
if body.is_in_group("player"):
body.die()
body.swim()
if body.is_in_group("npc"):
body.die(RISING_SPEED)
func _body_exited(body):
if body.is_in_group("player"):
body.unswim()

Loading…
Cancel
Save