Merge branch 'main' into audio

This commit is contained in:
Marvin Dalheimer 2024-01-28 15:33:01 +01:00
commit 9831759095
Signed by: Rinma
GPG Key ID: 44CAD3A9F1679D8D
10 changed files with 160 additions and 165 deletions

View File

@ -12,109 +12,132 @@ var ducking_texture: Texture2D = load("res://sprites/tim_ducking.svg")
var last_joke: Joke var last_joke: Joke
var blabla_sounds = [ var blabla_sounds = [
preload("res://audio/tim_blabla_1.wav"), preload("res://audio/tim_blabla_1.wav"),
preload("res://audio/tim_blabla_2.wav"), preload("res://audio/tim_blabla_2.wav"),
preload("res://audio/tim_blabla_3.wav"), preload("res://audio/tim_blabla_3.wav"),
preload("res://audio/tim_blabla_4.wav") preload("res://audio/tim_blabla_4.wav")
] ]
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
Signals.hit_tim.connect(ouch) Signals.hit_tim.connect(ouch)
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
if $AnimationPlayer.is_playing(): if $AnimationPlayer.is_playing():
return return
if Input.is_action_pressed("move_right"): if Input.is_action_pressed("move_right"):
tim_sprite.flip_h = true tim_sprite.flip_h = true
global_position += Vector2.RIGHT * delta * move_speed global_position += Vector2.RIGHT * delta * move_speed
if global_position.x > boundary.get_most_right_position(): if global_position.x > boundary.get_most_right_position():
global_position = Vector2(boundary.get_most_right_position(), global_position.y) global_position = Vector2(boundary.get_most_right_position(), global_position.y)
if Input.is_action_pressed("move_left"):
tim_sprite.flip_h = false
global_position += Vector2.LEFT * delta * move_speed
if global_position.x < boundary.get_most_left_position():
global_position = Vector2(boundary.get_most_left_position(), global_position.y)
if Input.is_action_pressed("move_left"):
tim_sprite.flip_h = false
global_position += Vector2.LEFT * delta * move_speed
if global_position.x < boundary.get_most_left_position():
global_position = Vector2(boundary.get_most_left_position(), global_position.y)
func _disable_buttons(): func _disable_buttons():
$"Joke Buttons".hide() $"Joke Buttons".hide()
$"Joke Buttons".process_mode = Node.PROCESS_MODE_DISABLED $"Joke Buttons".process_mode = Node.PROCESS_MODE_DISABLED
func _enable_buttons(): func _enable_buttons():
$"Joke Buttons".show() $"Joke Buttons".show()
$"Joke Buttons".process_mode = Node.PROCESS_MODE_INHERIT $"Joke Buttons".process_mode = Node.PROCESS_MODE_INHERIT
func _on_joke_button_button_pressed(joke: Joke): func _on_joke_button_button_pressed(joke: Joke):
last_joke = joke last_joke = joke
stamina -= joke.required_stamina stamina -= joke.required_stamina
_disable_buttons() _disable_buttons()
_start_joke_for_audience() _start_joke_for_audience()
$AnimationPlayer.play("talking") $AnimationPlayer.play("talking")
$Speaker.stream = blabla_sounds[randi() % blabla_sounds.size()] $Speaker.stream = blabla_sounds[randi() % blabla_sounds.size()]
$Speaker.play() $Speaker.play()
func _get_targeted_audience_members(target_all: bool): func _get_targeted_audience_members(target_all: bool):
if target_all: if target_all:
return _get_all_targeted_audience_members() return _get_all_targeted_audience_members()
return _get_targeted_audience_members_in_target_area() return _get_targeted_audience_members_in_target_area()
func _get_all_targeted_audience_members() -> Array[AudienceMember]: func _get_all_targeted_audience_members() -> Array[AudienceMember]:
var crowd = get_node("/root/IngameScene/Crowd") var crowd = get_node("/root/IngameScene/Crowd")
return crowd.audience return crowd.audience
func _get_targeted_audience_members_in_target_area() -> Array[AudienceMember]: func _get_targeted_audience_members_in_target_area() -> Array[AudienceMember]:
var arr: Array[AudienceMember] var arr: Array[AudienceMember]
for body in transmitter_area.get_overlapping_bodies(): for body in transmitter_area.get_overlapping_bodies():
var person = body.find_parent("Person") var person = body.find_parent("Person")
if not (person is AudienceMember): if not (person is AudienceMember):
continue continue
arr.append(person) arr.append(person)
return arr return arr
func _start_joke_for_audience(): func _start_joke_for_audience():
for person in _get_targeted_audience_members(true): for person in _get_targeted_audience_members(true):
person.on_joke_start() person.on_joke_start()
func _tell_joke_for_audience(joke: Joke, target_all: bool): func _tell_joke_for_audience(joke: Joke, target_all: bool):
for person in _get_targeted_audience_members(target_all): for person in _get_targeted_audience_members(target_all):
person.on_hear_joke(joke) person.on_hear_joke(joke)
func _finish_joke_for_audience(): func _finish_joke_for_audience():
for person in _get_targeted_audience_members(true): for person in _get_targeted_audience_members(true):
person.on_joke_finish() person.on_joke_finish()
func _on_stamina_empty(): func _on_stamina_empty():
get_node("../DisplayGUI").visible = false get_node("../DisplayGUI").visible = false
var fade = get_node("/root/IngameScene/UI/FadeOverlay") var fade = get_node("/root/IngameScene/UI/FadeOverlay")
fade.modulate.a = fade.minimum_opacity fade.modulate.a = fade.minimum_opacity
fade.visible = true fade.visible = true
get_node("/root/IngameScene/UI/Curtain").visible = true get_node("/root/IngameScene/UI/Curtain").visible = true
get_viewport().set_input_as_handled() get_viewport().set_input_as_handled()
get_tree().paused = true get_tree().paused = true
var score_overlay = get_node("/root/IngameScene/UI/ScoreOverlay")
score_overlay.get_node("VBoxContainer3/FinalScore").text = str(
int(get_node("/root/IngameScene/Crowd").overall_mood)
)
score_overlay.grab_button_focus()
score_overlay.visible = true
pass
var score_overlay = get_node("/root/IngameScene/UI/ScoreOverlay")
score_overlay.get_node("VBoxContainer3/FinalScore").text = str(int(get_node("/root/IngameScene/Crowd").overall_mood))
score_overlay.grab_button_focus()
score_overlay.visible = true
pass
func ouch(): func ouch():
$Sprite2D.texture = ducking_texture $Sprite2D.texture = ducking_texture
_start_joke_for_audience() var bottle_joke = Joke.get_bottle_joke()
await get_tree().create_timer(1).timeout _start_joke_for_audience()
$Sprite2D.texture = default_texture stamina -= bottle_joke.required_stamina
_tell_joke_for_audience(Joke.get_bottle_joke(), true)
_finish_joke_for_audience() await get_tree().create_timer(1).timeout
$Sprite2D.texture = default_texture
_tell_joke_for_audience(bottle_joke, true)
_finish_joke_for_audience()
if stamina <= 0:
_on_stamina_empty()
func _on_animation_player_animation_finished(anim_name): func _on_animation_player_animation_finished(anim_name):
_tell_joke_for_audience(last_joke, false) _tell_joke_for_audience(last_joke, false)
_finish_joke_for_audience() _finish_joke_for_audience()
if stamina <= 0: if stamina <= 0:
_on_stamina_empty() _on_stamina_empty()
else: else:
_enable_buttons() _enable_buttons()

View File

@ -1,6 +1,16 @@
class_name AudienceProfile class_name AudienceProfile
extends Node2D extends Node2D
const HAPPY_THRESHOLD: float = 2
const ANGRY_THRESHOLD: float = -1
const LASHOUT_THRESHOLD: float = -5
const HAPPINESS_DECAY: float = .01
const LASHOUT_DECAY: float = .01
const GOOD_REACTION: float = 1
const NEUTRAL_REACTION: float = .1
const BAD_REACTION: float = -1.2
const BOTTLE_REACTION: float = 3
class ProfileData: class ProfileData:
var happy_threshold: float var happy_threshold: float
@ -39,23 +49,12 @@ var joke_mood_mapping: Dictionary
static func get_profile_data(index) -> ProfileData: static func get_profile_data(index) -> ProfileData:
var profiles = [ var profiles = [
ProfileData.new(3, -3, -10, 0.1, 0.1, {0: 1, 1: -0.25, 2: 0, 3: 2}), ProfileData.new(HAPPY_THRESHOLD, ANGRY_THRESHOLD, LASHOUT_THRESHOLD, HAPPINESS_DECAY, LASHOUT_DECAY, {0: GOOD_REACTION, 1: BAD_REACTION, 2: NEUTRAL_REACTION, 3: BOTTLE_REACTION}),
ProfileData.new(3, -3, -10, 0.1, 0.1, {0: 0, 1: 1, 2: -0.25, 3: 2}), ProfileData.new(HAPPY_THRESHOLD, ANGRY_THRESHOLD, LASHOUT_THRESHOLD, HAPPINESS_DECAY, LASHOUT_DECAY, {0: NEUTRAL_REACTION, 1: GOOD_REACTION, 2: BAD_REACTION, 3: BOTTLE_REACTION}),
ProfileData.new(3, -3, -10, 0.1, 0.1, {0: -0.25, 1: 0, 2: 1, 3: 2}), ProfileData.new(HAPPY_THRESHOLD, ANGRY_THRESHOLD, LASHOUT_THRESHOLD, HAPPINESS_DECAY, LASHOUT_DECAY, {0: BAD_REACTION, 1: NEUTRAL_REACTION, 2: GOOD_REACTION, 3: BOTTLE_REACTION}),
] ]
return profiles[index] return profiles[index]
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
pass
func load_data(data: ProfileData): func load_data(data: ProfileData):
happy_threshold = data.happy_threshold happy_threshold = data.happy_threshold
angry_threshold = data.angry_threshold angry_threshold = data.angry_threshold

View File

@ -2,7 +2,7 @@
[ext_resource type="Script" path="res://scenes/crowd/crowd.gd" id="1_y7wyj"] [ext_resource type="Script" path="res://scenes/crowd/crowd.gd" id="1_y7wyj"]
[ext_resource type="Texture2D" uid="uid://b6p145ne8x013" path="res://sprites/room/table.svg" id="2_bax5s"] [ext_resource type="Texture2D" uid="uid://b6p145ne8x013" path="res://sprites/room/table.svg" id="2_bax5s"]
[ext_resource type="PackedScene" path="res://sprites/room/chair.tscn" id="3_y4hpm"] [ext_resource type="PackedScene" uid="uid://bbehbuw5lvfkr" path="res://sprites/room/chair.tscn" id="3_y4hpm"]
[node name="Crowd" type="Node2D"] [node name="Crowd" type="Node2D"]
position = Vector2(240, 232) position = Vector2(240, 232)

View File

@ -112,11 +112,10 @@ func _process(delta):
if laughter_left >= 0: if laughter_left >= 0:
laughter_left -= delta laughter_left -= delta
if not is_listening and mood > profile.happy_threshold * .5: if not is_listening and mood > profile.happy_threshold * .9:
mood -= profile.happiness_decay * delta mood -= profile.happiness_decay * delta
elif not is_listening and mood < profile.lashout_threshold * .9: elif not is_listening and mood < profile.lashout_threshold * .9:
mood += profile.lashout_decay * delta mood += profile.lashout_decay * delta
if mood < profile.lashout_threshold: if mood < profile.lashout_threshold:
throw_bottle() throw_bottle()
@ -132,11 +131,13 @@ func _input(event):
update_mood(-1.) update_mood(-1.)
func update_mood(change: float): func update_mood(change: float):
if mood > profile.happy_threshold and change > 0 and laughter_left <= 0: if laughter_left <= 0 and change > 0 and (mood + change) > profile.happy_threshold :
laughter_left = laughter_duration laughter_left = laughter_duration
# bob head # bob head
var tween = get_tree().create_tween().bind_node(self).set_loops(laughter_bobs) var tween = get_tree().create_tween().bind_node(self).set_loops(laughter_bobs)
var bob_duration = laughter_duration / laughter_bobs / 2 var bob_duration = laughter_duration / laughter_bobs / 2
tween.tween_property(face, "position", Vector2.UP * 20, bob_duration).set_delay(randf_range(0, bob_duration))
tween.tween_property(face, "position", Vector2.ZERO, bob_duration)
$Speaker.stream = get_random_laugh() $Speaker.stream = get_random_laugh()
$Speaker.play() $Speaker.play()
@ -179,17 +180,17 @@ func on_joke_start():
is_listening = true is_listening = true
func on_hear_joke(joke: Joke): func on_hear_joke(joke: Joke):
var mood_change = profile.joke_mood_mapping.get(joke.type, 0) * joke.effectiveness var mood_change = profile.joke_mood_mapping.get(joke.type, 0) * joke.effectiveness
if joke.type == last_joke_heard: if joke.type == last_joke_heard and mood_change > 0:
mood_change = min(0, mood_change) mood_change *= .5
update_mood(mood_change) update_mood(mood_change)
last_joke_heard = joke.type last_joke_heard = joke.type
func on_joke_finish(): func on_joke_finish():
is_listening = false is_listening = false
func throw_bottle(): func throw_bottle():
mood += 2.0 mood = profile.lashout_threshold * 0.99
$Speaker.stream = get_random_buh() $Speaker.stream = get_random_buh()
$Speaker.play() $Speaker.play()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 792 B

View File

@ -1,34 +0,0 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c37ydueny6n1f"
path="res://.godot/imported/table.png-4bc92ae90425ddea852f77e75ef69549.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://scenes/crowd/table.png"
dest_files=["res://.godot/imported/table.png-4bc92ae90425ddea852f77e75ef69549.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@ -10,6 +10,12 @@ var is_hidding: bool
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
tim_global_position = get_node("/root/IngameScene/Stage/Tim/ThrowPoint").global_position tim_global_position = get_node("/root/IngameScene/Stage/Tim/ThrowPoint").global_position
tim_global_position += _random_inside_unit_circle() * 23
rotation_degrees += randf() * 360
func _random_inside_unit_circle() -> Vector2:
var theta : float = randf() * 2 * PI
return Vector2(cos(theta), sin(theta)) * sqrt(randf())
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://c5f5v1wtottyp"] [gd_scene load_steps=4 format=3 uid="uid://c5f5v1wtottyp"]
[ext_resource type="Script" path="res://scenes/objects/bottle.gd" id="1_87ktq"] [ext_resource type="Script" path="res://scenes/objects/bottle.gd" id="1_87ktq"]
[ext_resource type="Texture2D" uid="uid://cow4dd0hlxrgr" path="res://sprites/room/bottle.svg" id="1_uea7l"] [ext_resource type="Texture2D" uid="uid://bavsg3hu7pccy" path="res://sprites/room/bottle.svg" id="1_uea7l"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_p8qcj"] [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_p8qcj"]
radius = 22.4893 radius = 22.4893

View File

@ -19,7 +19,7 @@ var required_stamina: int
var effectiveness: float var effectiveness: float
static func get_bottle_joke(): static func get_bottle_joke():
return Joke.new(JokeType.Bottle, 0, 1) return Joke.new(JokeType.Bottle, 15, 1)
static func get_random_joke(type): static func get_random_joke(type):
var stamina = STAMINA_CATEGORIES[randi_range(0, STAMINA_CATEGORIES.size() - 1)] var stamina = STAMINA_CATEGORIES[randi_range(0, STAMINA_CATEGORIES.size() - 1)]

File diff suppressed because one or more lines are too long