code-game-jam-drop-plafond-.../scripts/player_control.gd

120 lines
3.1 KiB
GDScript3
Raw Normal View History

2025-01-24 09:53:10 +01:00
extends CharacterBody2D
2025-01-25 02:33:26 +01:00
@export var interface : Control
2025-01-24 11:38:05 +01:00
const move_speed = 400
2025-01-24 12:07:11 +01:00
const acceleration = 0.25
const max_boost_speed = 800
var previous_direction = Vector2.ZERO
var boost_speed = 0
2025-01-24 18:45:09 +01:00
2025-01-24 14:27:04 +01:00
var flute = null
2025-01-24 18:45:09 +01:00
var tambour = null
var lyre = null
2025-01-24 18:45:09 +01:00
var flute_timer = 0.0
var tambour_timer = 0.0
var lyre_timer = 0.0
2025-01-24 18:45:09 +01:00
var flute_cooldown = 0.5
var tambour_cooldown = 3.0
var lyre_cooldown = 1
2025-01-25 05:54:27 +01:00
var instrument_list = [
"",
""
]
2025-01-24 14:27:04 +01:00
2025-01-25 01:44:33 +01:00
var vie = 10
2025-01-25 05:54:27 +01:00
signal instrument_switch
2025-01-24 14:27:04 +01:00
func _ready() -> void:
2025-01-24 15:56:39 +01:00
flute = load("res://scripts/Instrument/Flute.gd").new()
flute.set_scene_parent(get_tree().get_root())
2025-01-24 18:45:09 +01:00
tambour = load("res://scripts/Instrument/Tambour.gd").new()
tambour.set_scene_parent(get_tree().get_root())
lyre = load("res://scripts/Instrument/Lyre.gd").new()
lyre.set_scene_parent(get_tree().get_root())
2025-01-25 02:33:26 +01:00
2025-01-24 09:53:10 +01:00
func _physics_process(delta: float) -> void:
move_and_slide()
2025-01-25 05:54:27 +01:00
func play_music(delta : float):
2025-01-24 21:16:37 +01:00
var direction_balle = Vector2.ZERO
var angle = 0
var angle_lyre = 0
2025-01-24 21:16:37 +01:00
if Input.is_action_pressed("JOUER_MUSIQUE_HAUT"):
direction_balle = Vector2(0, -1)
angle = 180
angle_lyre = 270
2025-01-24 21:16:37 +01:00
elif Input.is_action_pressed("JOUER_MUSIQUE_BAS"):
direction_balle = Vector2(0, 1)
angle_lyre = 90
2025-01-24 21:16:37 +01:00
elif Input.is_action_pressed("JOUER_MUSIQUE_DROITE"):
direction_balle = Vector2(1, 0)
angle = 270
2025-01-24 21:16:37 +01:00
elif Input.is_action_pressed("JOUER_MUSIQUE_GAUCHE"):
direction_balle = Vector2(-1, 0)
angle = 90
angle_lyre = 180
2025-01-25 05:54:27 +01:00
if flute_timer > 0:
flute_timer -= delta
if tambour_timer > 0:
tambour_timer -= delta
if lyre_timer > 0:
lyre_timer -= delta
2025-01-25 05:54:27 +01:00
if instrument_list.has("flute") and flute_timer <= 0.0 and direction_balle != Vector2.ZERO:
flute.jouer_melodie(position, direction_balle, angle)
flute_timer = flute_cooldown
2025-01-25 05:54:27 +01:00
if instrument_list.has("tambour") and tambour_timer <= 0.0 and direction_balle != Vector2.ZERO:
tambour.jouer_melodie(position)
tambour_timer = tambour_cooldown
2025-01-25 05:54:27 +01:00
if instrument_list.has("lyre") and lyre_timer <= 0.0 and direction_balle != Vector2.ZERO :
lyre.jouer_melodie(position, direction_balle, angle_lyre)
lyre_timer = lyre_cooldown
2025-01-25 05:54:27 +01:00
func _process(delta: float) -> void:
var direction : Vector2 = Vector2.ZERO
direction.x = Input.get_action_raw_strength("BOUGER_DROITE") - Input.get_action_raw_strength("BOUGER_GAUCHE")
direction.y = Input.get_action_raw_strength("BOUGER_BAS") - Input.get_action_raw_strength("BOUGER_HAUT")
if direction != Vector2.ZERO:
if direction == previous_direction:
if direction.x != 0 and direction.y != 0:
boost_speed = min(boost_speed + acceleration / 16, (max_boost_speed - move_speed) / 8)
else:
boost_speed = min(boost_speed + acceleration, max_boost_speed - move_speed)
else:
boost_speed = 0
previous_direction = direction
velocity = direction * (move_speed + boost_speed)
else:
velocity = Vector2.ZERO
play_music(delta)
2025-01-25 05:54:27 +01:00
func pick_up(instrument : String) :
if len(instrument_list) < 2 :
instrument_list.append(instrument)
else :
instrument_list[0] = instrument_list[1]
instrument_list[1] = instrument
instrument_switch.emit()
2025-01-25 01:44:33 +01:00
func take_damage(dmg : int) :
vie -= dmg
2025-01-25 02:33:26 +01:00
interface.set_life(vie)