134 lines
5.5 KiB
GDScript
134 lines
5.5 KiB
GDScript
class_name Character extends Node3D
|
|
|
|
@onready var shotAnimations = $Shots/shotAnimations
|
|
@onready var gunAnimations = $gun/gunAnimations
|
|
@onready var gunPosition1 = $GunPositions/GunPosition1
|
|
@onready var gunPosition2 = $GunPositions/GunPosition2
|
|
@onready var gunPosition3 = $GunPositions/GunPosition3
|
|
@onready var gunPosition4 = $GunPositions/GunPosition4
|
|
@onready var shotGlas1 = $Shots/ShotGlas1
|
|
@onready var shotGlas2 = $Shots/ShotGlas2
|
|
@onready var shotGlas3 = $Shots/ShotGlas3
|
|
@onready var gameNameLabel = $gameNameLabel
|
|
|
|
@onready var gun = $gun
|
|
|
|
@onready var headPosition = $HeadPosition
|
|
|
|
@onready var shots = $Shots
|
|
|
|
@onready var shootAudio = $GunPositions/GunPosition1/shootAudio
|
|
@onready var triggerAudio = $gun/triggerAudio
|
|
|
|
signal shootGunFinished
|
|
signal addGunToPoolFinished
|
|
signal aimGunFinished
|
|
signal shotDrinkingFinished
|
|
|
|
func shootGun(hit: bool):
|
|
var currentRotationDegrees = gun.rotation_degrees
|
|
var currentPosition = gun.position
|
|
var tween1 = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_OUT)
|
|
var tween2 = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_OUT)
|
|
triggerAudio.play()
|
|
if hit:
|
|
shootAudio.play()
|
|
gunAnimations.play("shoot")
|
|
tween1.finished.connect(emitShootGunFinished.bind())
|
|
tween2.tween_property(gun, "position", gun.position+Vector3(0,0,-0.2), 0.2)
|
|
tween1.tween_property(gun, "rotation_degrees", gun.rotation_degrees+Vector3(-10,0,0), 0.2)
|
|
tween2.tween_property(gun, "position", currentPosition, 1).set_trans(Tween.TRANS_QUART)
|
|
tween1.tween_property(gun, "rotation_degrees", currentRotationDegrees, 1).set_trans(Tween.TRANS_QUART)
|
|
else:
|
|
tween2.finished.connect(emitShootGunFinished.bind())
|
|
tween2.tween_property(gun, "position", gun.position+Vector3(-0.01,-0.01,-0.01), 0.2).set_trans(Tween.TRANS_BOUNCE)
|
|
#tween1.tween_property(gun, "rotation_degrees", gun.rotation_degrees+Vector3(10,0,0), 0.2).set_trans(Tween.TRANS_BOUNCE)
|
|
tween2.tween_property(gun, "position", currentPosition, 1).set_trans(Tween.TRANS_QUART)
|
|
#tween1.tween_property(gun, "rotation_degrees", currentRotationDegrees, 1).set_trans(Tween.TRANS_QUART)
|
|
|
|
func emitShootGunFinished():
|
|
shootGunFinished.emit()
|
|
|
|
|
|
func addGunToPool():
|
|
var tween1 = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_IN)
|
|
var tween2 = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_IN)
|
|
tween1.finished.connect(emitAddGunToPoolFinished.bind())
|
|
tween2.tween_property(gun, "position", gunPosition3.position, 0.6)
|
|
tween1.tween_property(gun, "rotation_degrees", gunPosition3.rotation_degrees, 0.6)
|
|
tween2.tween_property(gun, "position", gunPosition3.position, 1)
|
|
tween1.tween_property(gun, "rotation_degrees", gunPosition3.rotation_degrees, 1)
|
|
tween2.tween_property(gun, "position", gunPosition1.position, 0.6)
|
|
tween1.tween_property(gun, "rotation_degrees", gunPosition1.rotation_degrees, 0.6)
|
|
|
|
func emitAddGunToPoolFinished():
|
|
addGunToPoolFinished.emit()
|
|
|
|
func aimGun():
|
|
var tween1 = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_IN)
|
|
var tween2 = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_IN)
|
|
tween1.finished.connect(emitAimGunFinished.bind())
|
|
tween2.tween_property(gun, "position", gunPosition1.position, 0.6)
|
|
tween1.tween_property(gun, "rotation_degrees", gunPosition1.rotation_degrees, 0.6)
|
|
|
|
func setAim(_player: Player):
|
|
gunPosition1.look_at(Vector3(_player.character.getHeadPosition().x,_player.character.getHeadPosition().y,_player.character.getHeadPosition().z), Vector3.UP, true)
|
|
|
|
func resetAim():
|
|
gunPosition1.rotation = Vector3(0,0,0)
|
|
|
|
func emitAimGunFinished():
|
|
aimGunFinished.emit()
|
|
|
|
func loadGun():
|
|
var tween1 = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_IN)
|
|
var tween2 = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_IN)
|
|
tween2.tween_property(gun, "position", gunPosition4.position, 0.6)
|
|
tween1.tween_property(gun, "rotation_degrees", gunPosition4.rotation_degrees, 0.6)
|
|
|
|
|
|
|
|
#func aimGunAtPlayer(_player: Player):
|
|
#gunPosition1.look_at(Vector3(_player.character.getHeadPosition().x,_player.character.getHeadPosition().y,_player.character.getHeadPosition().z), Vector3.UP, true)
|
|
#moveGunTo(gunPosition1)
|
|
|
|
#func aimGunAtSelf():
|
|
#moveGunTo(gunPosition2)
|
|
|
|
#func addGunToPool():
|
|
#moveGunTo(gunPosition3)
|
|
|
|
#func removeGunToPool():
|
|
#moveGunTo(gunPosition1)
|
|
|
|
func moveGunTo(toPosition: Marker3D):
|
|
var tween1 = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_IN)
|
|
var tween2 = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_IN)
|
|
tween2.tween_property(gun, "position", toPosition.position, 0.6)
|
|
tween1.tween_property(gun, "rotation_degrees", toPosition.rotation_degrees, 0.6)
|
|
|
|
#print("Finish")
|
|
|
|
#func aimGun(_player: Player):
|
|
#var lookAt: Vector3 = gun.global_position
|
|
#lookAt = _player.character.getHeadPosition()
|
|
#gun.look_at(lookAt, Vector3.UP, true)
|
|
|
|
func drinkShot():
|
|
await get_tree().create_timer(1.0).timeout
|
|
if shotGlas1 != null:
|
|
shotAnimations.play("drinkShot1")
|
|
elif shotGlas2 != null:
|
|
shotAnimations.play("drinkShot2")
|
|
elif shotGlas3 != null:
|
|
shotAnimations.play("drinkShot3")
|
|
|
|
func getHeadPosition() -> Vector3:
|
|
return headPosition.global_position
|
|
|
|
func _on_shot_animations_current_animation_changed(name: String) -> void:
|
|
shotDrinkingFinished.emit()
|
|
|
|
|
|
func setGameName(_name: String):
|
|
gameNameLabel.text = _name
|