85 lines
1.9 KiB
GDScript
85 lines
1.9 KiB
GDScript
extends Node2D
|
|
|
|
var cameraLimitTop
|
|
var rng = RandomNumberGenerator.new()
|
|
|
|
var riding = false
|
|
|
|
var cow
|
|
|
|
var velocity = 0
|
|
var bounceVelocity = -110
|
|
|
|
var gravity = 80
|
|
|
|
var boingSoundPlayer:AudioStreamPlayer2D
|
|
var boingSounds = []
|
|
|
|
var lastBoingIndex = -1
|
|
|
|
func _ready():
|
|
cow = GameVariables.player
|
|
cow.moved.connect(move_request)
|
|
initialize_boing_sounds()
|
|
|
|
func initialize_boing_sounds():
|
|
boingSoundPlayer = $BoingSounds
|
|
boingSounds.append(load("res://Sounds/SFX/Boings/boing1.mp3"))
|
|
boingSounds.append(load("res://Sounds/SFX/Boings/boing2.mp3"))
|
|
boingSounds.append(load("res://Sounds/SFX/Boings/boing3.mp3"))
|
|
boingSounds.append(load("res://Sounds/SFX/Boings/boing4.mp3"))
|
|
boingSounds.append(load("res://Sounds/SFX/Boings/boing5.mp3"))
|
|
|
|
func play_boing():
|
|
var newIndex = rng.randi_range(0, boingSounds.size() - 1)
|
|
|
|
if newIndex == lastBoingIndex:
|
|
newIndex = rng.randi_range(0, boingSounds.size() - 1)
|
|
|
|
boingSoundPlayer.stream = boingSounds[newIndex]
|
|
boingSoundPlayer.play()
|
|
lastBoingIndex = newIndex
|
|
|
|
func _process(delta):
|
|
if riding:
|
|
cow.global_position = global_position + Vector2(0, 0.02)
|
|
cow.movementTarget = cow.global_position
|
|
|
|
velocity += gravity * 1/2 * delta
|
|
cow.get_node("Visuals").position.y += velocity * delta
|
|
velocity += gravity * 1/2 * delta
|
|
|
|
if cow.get_node("Visuals").position.y > 0:
|
|
bounce()
|
|
|
|
func move_request():
|
|
if riding:
|
|
get_off()
|
|
|
|
func bounce():
|
|
cow.get_node("Visuals").position.y = 0
|
|
velocity = bounceVelocity
|
|
|
|
LevelManager.add_XP("trampolining", 2)
|
|
play_boing()
|
|
|
|
func get_off():
|
|
riding = false
|
|
cow.reset_visuals_pos()
|
|
|
|
velocity = 0
|
|
GameVariables.camera.limit_top = cameraLimitTop
|
|
|
|
cow.global_position = global_position + Vector2(0, 110)
|
|
GameVariables.player.change_state("Idle")
|
|
|
|
func ride():
|
|
cameraLimitTop = GameVariables.camera.limit_top
|
|
GameVariables.camera.limit_top = -10000
|
|
|
|
cow.clear_swimming_areas()
|
|
cow.get_node("Visuals").position.y = 0
|
|
velocity = bounceVelocity
|
|
|
|
riding = true
|