mirror of
https://github.com/creyD/ludum_dare_46.git
synced 2026-06-13 14:02:23 +02:00
Added walk sounds for the player
This commit is contained in:
@@ -5,18 +5,25 @@ This is an example player controller script created by Paul
|
||||
"""
|
||||
var velocity := Vector2.ZERO
|
||||
var rollvector := Vector2.ZERO
|
||||
|
||||
# This is how you export variables with ranges to the editor window
|
||||
export(int, 0, 500) var ROLL_SPEED := 150
|
||||
export(int, 0, 500) var FRICTION := 200 # Speed at which the player deaccelarates
|
||||
export(int, 0, 500) var ACCELERATION := 450
|
||||
# Reference for the current player
|
||||
|
||||
# Reference for the current player
|
||||
onready var player_stats := $Stats
|
||||
onready var debug_label := $DebugLabel
|
||||
onready var animation_player := $AnimationPlayer
|
||||
onready var animation_tree := $AnimationTree
|
||||
onready var animation_state = animation_tree.get("parameters/playback")
|
||||
|
||||
# Variables for sound selection
|
||||
onready var walk_sounds = $Sounds/Walk
|
||||
var _rng = RandomNumberGenerator.new()
|
||||
var is_playing_sound = false
|
||||
|
||||
|
||||
enum moveState{
|
||||
MOVE,
|
||||
ROLL,
|
||||
@@ -81,8 +88,9 @@ func movement_move(delta):
|
||||
animation_tree.set("parameters/hit/blend_position", input_vector)
|
||||
animation_tree.set("parameters/roll/blend_position", input_vector)
|
||||
animation_tree.set("parameters/run/blend_position", input_vector)
|
||||
animation_state.travel("run")
|
||||
animation_state.travel("run")
|
||||
velocity = velocity.move_toward(player_stats.speed * input_vector, ACCELERATION * delta)
|
||||
_play_random_sound(walk_sounds)
|
||||
if Input.is_action_just_pressed("roll"):
|
||||
movementState = moveState.ROLL
|
||||
elif Input.is_action_just_pressed("attack"):
|
||||
@@ -120,3 +128,20 @@ func _on_Hitbox_area_entered(area):
|
||||
currency += area.currency_value
|
||||
player_stats.health = player_stats.health+area.health_value
|
||||
player_stats.speed -= area.slowdown_value
|
||||
|
||||
|
||||
func _walk_sound_finished():
|
||||
is_playing_sound = false
|
||||
|
||||
|
||||
func _play_random_sound(path = walk_sounds):
|
||||
if not is_playing_sound:
|
||||
var sound = path.get_children()[_rng.randi_range(0, path.get_child_count() - 1)]
|
||||
sound.play()
|
||||
is_playing_sound = true
|
||||
|
||||
|
||||
# Overrides ready method for this entire script, checks for the finished method of each possible sound
|
||||
func _ready():
|
||||
for child in walk_sounds.get_children():
|
||||
child.connect("finished", self, "_walk_sound_finished")
|
||||
|
||||
Reference in New Issue
Block a user