Implement core bidding loop (minus loss state and destroy painting)
This commit is contained in:
parent
ed2516a478
commit
a96ec6cc92
8 changed files with 136 additions and 48 deletions
|
|
@ -14,14 +14,15 @@ signal ask_accepted
|
|||
#meant to make the audience more inclined to bid as day progresses
|
||||
@export var audience_time_pressure := 1.4
|
||||
|
||||
@export var min_audience_think_time := 0.5
|
||||
@export var max_audience_think_time := 2.0
|
||||
|
||||
@export var bid_threshold := 3.0
|
||||
@export var think_chance := 0.5
|
||||
@export var think_min_time := 1.0
|
||||
@export var think_max_time := 5.0
|
||||
|
||||
# Whether or not the audience has submitted a bid, and the next call
|
||||
# needs to be higher than the last
|
||||
var bid_pending = false
|
||||
var current_ask: int
|
||||
|
||||
func _ready() -> void:
|
||||
desk.numpad.ask_proposed.connect(_handle_ask_proposed)
|
||||
|
|
@ -29,22 +30,23 @@ func _ready() -> void:
|
|||
|
||||
func raise_paddle():
|
||||
#need to add in logic to animate paddle being raised
|
||||
bid_pending = true
|
||||
pass
|
||||
game_manager.state = game_manager.bidding_state.BID
|
||||
print("Audience accepts the bid at $" + str(current_ask))
|
||||
game_manager.current_bid = desk.numpad.proposed_ask
|
||||
ask_accepted.emit()
|
||||
|
||||
|
||||
func _handle_bid_delay_timeout():
|
||||
if randf_range(1.2, 5.3) >= bid_threshold:
|
||||
raise_paddle()
|
||||
game_manager.current_bid = desk.numpad.proposed_ask
|
||||
ask_accepted.emit()
|
||||
|
||||
timer.stop()
|
||||
|
||||
func _handle_ask_proposed():
|
||||
if bid_pending:
|
||||
bid_pending = false
|
||||
func _handle_ask_proposed(amount):
|
||||
current_ask = amount
|
||||
|
||||
if randf() <= think_chance:
|
||||
timer.stop()
|
||||
var ask_duration: float = randf_range(1.0, 5.0)
|
||||
var ask_duration: float = randf_range(min_audience_think_time, max_audience_think_time)
|
||||
timer.wait_time = ask_duration
|
||||
timer.start()
|
||||
|
|
|
|||
1
desk.gd
1
desk.gd
|
|
@ -4,6 +4,7 @@ class_name Desk extends Control
|
|||
@export var game_manager: GameManager
|
||||
@export var turn_manager: TurnManager
|
||||
@export var audience_manager: AudienceManager
|
||||
@export var gavel: Gavel
|
||||
|
||||
func _ready() -> void:
|
||||
numpad.turn_manager = turn_manager
|
||||
|
|
|
|||
|
|
@ -33,13 +33,14 @@
|
|||
[ext_resource type="AudioStream" uid="uid://bvto7ghmy8j0o" path="res://assets/gavel/audio/invalid-bet.wav" id="31_v5y5a"]
|
||||
[ext_resource type="AudioStream" uid="uid://b7qyt2h17kjea" path="res://assets/gavel/audio/ask-bet.wav" id="32_dnpqj"]
|
||||
|
||||
[node name="Desk" type="Control" node_paths=PackedStringArray("numpad")]
|
||||
[node name="Desk" type="Control" node_paths=PackedStringArray("numpad", "gavel")]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 1280.0
|
||||
offset_bottom = 720.0
|
||||
script = ExtResource("1_yugeg")
|
||||
numpad = NodePath("Numpad")
|
||||
gavel = NodePath("Gavel")
|
||||
|
||||
[node name="Gavel" type="Node2D" parent="." node_paths=PackedStringArray("audio_player")]
|
||||
position = Vector2(971, 563)
|
||||
|
|
|
|||
|
|
@ -1,30 +1,54 @@
|
|||
class_name GameManager extends Node2D
|
||||
|
||||
@export var audience_manager: AudienceManager
|
||||
@export var desk: Desk
|
||||
|
||||
var paintings_sold = 0
|
||||
var paintings_total = 0
|
||||
@export var paintings_total = 7
|
||||
|
||||
var paintings: Array = Array()
|
||||
var current_painting = 0
|
||||
|
||||
# tracker variables for bid markers, proposing bids happens between numpad and audience
|
||||
var current_bid = 0
|
||||
var starting_price = 0
|
||||
var final_bid = 0
|
||||
@export var current_bid_display: RichTextLabel
|
||||
|
||||
var target_sales: int = 0
|
||||
var total_sales: int = 0
|
||||
@export var sales_magnitude = 100000
|
||||
@export var single_painting_magnitude = 1000
|
||||
@export var initial_value_reduction: float = 0.6
|
||||
|
||||
# state tracker for a given painting's auction
|
||||
var bidding_open: bool = false
|
||||
signal bidding_start
|
||||
enum bidding_state {CLOSED, READY, ASKING, BID}
|
||||
var state: int = bidding_state.CLOSED
|
||||
signal new_painting_displayed
|
||||
|
||||
func _ready() -> void:
|
||||
paintings_total = randi_range(7,10)
|
||||
target_sales = (paintings_total * 100000)/randf_range(1.25,2) # need to workshop the target sales generation process for more interesting numbers
|
||||
audience_manager.ask_accepted.connect(_handle_ask_accepted)
|
||||
desk.gavel.gavel_hit.connect(_handle_gavel_hit)
|
||||
|
||||
#var e = 0
|
||||
#for painting in paintings:
|
||||
#if e <= paintings_total:
|
||||
#paintings.append()
|
||||
#paintings_total = randi_range(7,10)
|
||||
target_sales = randi_range(2,5) * sales_magnitude
|
||||
|
||||
var new_painting = 0
|
||||
var new_painting_value: int
|
||||
|
||||
while new_painting < paintings_total:
|
||||
new_painting_value = (target_sales/randf_range(paintings_total - 2, paintings_total + 2))
|
||||
new_painting_value = snappedi(new_painting_value, single_painting_magnitude)
|
||||
print(str(new_painting_value))
|
||||
paintings.append(new_painting_value)
|
||||
new_painting += 1
|
||||
|
||||
print(paintings)
|
||||
print("You have " + str(paintings_total) + " paintings. Sell them for at least $" + str(target_sales) + " or face the consequences!")
|
||||
print("Hit the gavel and input a starting bid to begin!")
|
||||
|
||||
next_painting(0)
|
||||
#build out the initialization process, which should:
|
||||
# -- generate paintings and assign values
|
||||
# -- start the turn timer/auction timer
|
||||
|
|
@ -32,25 +56,39 @@ func _ready() -> void:
|
|||
# -- have tts announcement of starting bid and start of auction
|
||||
|
||||
|
||||
print("You have " + str(paintings_total) + " paintings. Sell them for at least $" + str(target_sales) + " or face the consequences!")
|
||||
pass
|
||||
|
||||
func _on_gavel_gavel_hit():
|
||||
bidding_open = not bidding_open
|
||||
if bidding_open == true:
|
||||
current_bid = target_sales/(paintings_total + 2)
|
||||
print("The new painting will start selling at $" + str(current_bid))
|
||||
|
||||
func _handle_gavel_hit():
|
||||
if state == bidding_state.CLOSED:
|
||||
state = bidding_state.READY
|
||||
print(str(state))
|
||||
elif state == bidding_state.ASKING:
|
||||
if current_bid != 0:
|
||||
state = bidding_state.CLOSED
|
||||
sell_painting()
|
||||
print("Congrats on selling your painting for $" + str(current_bid) + "! You have made $" + str(total_sales) + " so far.")
|
||||
current_painting += 1
|
||||
next_painting((current_painting))
|
||||
print("The next painting is valued at $" + str(starting_price) + " (should be $" + str(paintings[current_painting]) + ")")
|
||||
(print(str(state)))
|
||||
else:
|
||||
total_sales = total_sales + current_bid
|
||||
paintings_sold += 1
|
||||
print("Congrats on selling your painting for $" + str(current_bid) + "! You have made $" + str(total_sales) + " so far.")
|
||||
pass
|
||||
|
||||
func destroy_painting():
|
||||
pass
|
||||
|
||||
func next_painting():
|
||||
pass
|
||||
func sell_painting():
|
||||
total_sales = total_sales + current_bid
|
||||
|
||||
func next_painting(a: int):
|
||||
starting_price = paintings[a]
|
||||
current_bid = 0
|
||||
|
||||
# will need to add animation/image swap
|
||||
new_painting_displayed.emit()
|
||||
|
||||
func _handle_ask_accepted():
|
||||
current_bid_display.text = str(current_bid)
|
||||
# OTHER THINGS TO ADD:
|
||||
# UI elements for score
|
||||
# Bark manager
|
||||
|
|
|
|||
2
gavel.gd
2
gavel.gd
|
|
@ -1,4 +1,4 @@
|
|||
extends Node2D
|
||||
class_name Gavel extends Node2D
|
||||
|
||||
signal gavel_hit
|
||||
|
||||
|
|
|
|||
28
main.tscn
28
main.tscn
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://dt4nq0nkmjiit"]
|
||||
[gd_scene load_steps=9 format=3 uid="uid://dt4nq0nkmjiit"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b5tcsve1oo5ht" path="res://game_manager.gd" id="1_ig7tw"]
|
||||
[ext_resource type="Texture2D" uid="uid://cvqsf1nlfqwpr" path="res://assets/background/background.png" id="1_lquwl"]
|
||||
|
|
@ -8,12 +8,30 @@
|
|||
[ext_resource type="PackedScene" uid="uid://c1acpop6amvcl" path="res://audience_manager.tscn" id="6_272bh"]
|
||||
[ext_resource type="PackedScene" uid="uid://b8key4hjaldui" path="res://turn_manager.tscn" id="7_272bh"]
|
||||
|
||||
[sub_resource type="Theme" id="Theme_272bh"]
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
||||
|
||||
[node name="Background" type="Sprite2D" parent="."]
|
||||
position = Vector2(640, 360)
|
||||
texture = ExtResource("1_lquwl")
|
||||
|
||||
[node name="UI" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 1280.0
|
||||
offset_bottom = 720.0
|
||||
|
||||
[node name="RichTextLabel" type="RichTextLabel" parent="UI"]
|
||||
layout_mode = 0
|
||||
offset_left = 480.0
|
||||
offset_top = 434.0
|
||||
offset_right = 796.0
|
||||
offset_bottom = 457.0
|
||||
theme = SubResource("Theme_272bh")
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="Chairs" type="Node2D" parent="."]
|
||||
|
||||
[node name="ChairsBack" type="Sprite2D" parent="Chairs"]
|
||||
|
|
@ -24,8 +42,14 @@ texture = ExtResource("2_7mycd")
|
|||
position = Vector2(640, 360)
|
||||
texture = ExtResource("3_272bh")
|
||||
|
||||
[node name="GameManager" type="Node2D" parent="."]
|
||||
[node name="GameManager" type="Node2D" parent="." node_paths=PackedStringArray("audience_manager", "desk", "current_bid_display")]
|
||||
script = ExtResource("1_ig7tw")
|
||||
audience_manager = NodePath("../AudienceManager")
|
||||
desk = NodePath("../Desk")
|
||||
current_bid_display = NodePath("../UI/RichTextLabel")
|
||||
|
||||
[node name="Timer" type="Timer" parent="GameManager"]
|
||||
wait_time = 300.0
|
||||
|
||||
[node name="Desk" parent="." node_paths=PackedStringArray("game_manager", "turn_manager", "audience_manager") instance=ExtResource("2_0xm2m")]
|
||||
game_manager = NodePath("../GameManager")
|
||||
|
|
|
|||
36
numpad.gd
36
numpad.gd
|
|
@ -2,7 +2,7 @@ class_name Numpad extends Node2D
|
|||
|
||||
var numpad_buffer = Array()
|
||||
var proposed_ask: int
|
||||
signal ask_proposed
|
||||
signal ask_proposed(amount)
|
||||
|
||||
#var turn_manager: TurnManager
|
||||
var audience_manager: AudienceManager
|
||||
|
|
@ -25,17 +25,39 @@ func keypad_entry(entry: int):
|
|||
numpad_buffer.append(str(entry))
|
||||
|
||||
func keypad_backspace():
|
||||
numpad_buffer.remove_at(-1)
|
||||
if numpad_buffer.size() > 0:
|
||||
numpad_buffer.remove_at(-1)
|
||||
|
||||
func keypad_submit():
|
||||
var keypad_output: String = "".join(numpad_buffer)
|
||||
proposed_ask = int(keypad_output) * 1000
|
||||
|
||||
if proposed_ask > game_manager.current_bid and audience_manager.bid_pending or proposed_ask == game_manager.current_bid:
|
||||
success_audio_player.play()
|
||||
ask_proposed.emit()
|
||||
else:
|
||||
error_audio_player.play()
|
||||
match game_manager.state:
|
||||
game_manager.bidding_state.READY:
|
||||
if proposed_ask == game_manager.starting_price:
|
||||
game_manager.state = game_manager.bidding_state.ASKING
|
||||
success_audio_player.play()
|
||||
ask_proposed.emit(proposed_ask)
|
||||
print("asking for $" + str(proposed_ask))
|
||||
else:
|
||||
error_audio_player.play()
|
||||
game_manager.bidding_state.ASKING:
|
||||
if proposed_ask == game_manager.starting_price or proposed_ask == game_manager.current_bid or proposed_ask == audience_manager.current_ask and proposed_ask != 0:
|
||||
success_audio_player.play()
|
||||
ask_proposed.emit(proposed_ask)
|
||||
print("starting the bidding at $" + str(proposed_ask))
|
||||
else:
|
||||
error_audio_player.play()
|
||||
game_manager.bidding_state.BID:
|
||||
if proposed_ask > game_manager.current_bid:
|
||||
game_manager.state = game_manager.bidding_state.ASKING
|
||||
success_audio_player.play()
|
||||
ask_proposed.emit(proposed_ask)
|
||||
print("asking for $" + str(proposed_ask))
|
||||
else:
|
||||
error_audio_player.play()
|
||||
_:
|
||||
error_audio_player.play()
|
||||
|
||||
reminder_timer.start(-1)
|
||||
numpad_buffer.clear()
|
||||
|
|
|
|||
|
|
@ -23,16 +23,16 @@ func _ready() -> void:
|
|||
func turn_timer_animation():
|
||||
pass
|
||||
|
||||
func _speak_ask_proposed():
|
||||
func _speak_ask_proposed(amount):
|
||||
var speech_variance = randf()
|
||||
if speech_variance < 0.45:
|
||||
DisplayServer.tts_speak(str(desk.numpad.proposed_ask), voice_id, tts_volume, tts_pitch, tts_number_speed)
|
||||
DisplayServer.tts_speak(str(amount), voice_id, tts_volume, tts_pitch, tts_number_speed)
|
||||
elif speech_variance > 0.45 and speech_variance < 0.65:
|
||||
DisplayServer.tts_speak("Do I hear" + str(desk.numpad.proposed_ask), voice_id, tts_volume, tts_pitch, tts_sentence_speed)
|
||||
DisplayServer.tts_speak("Do I hear" + str(amount), voice_id, tts_volume, tts_pitch, tts_sentence_speed)
|
||||
elif speech_variance > 0.65 and speech_variance < 0.8:
|
||||
DisplayServer.tts_speak(str(desk.numpad.proposed_ask) + ", anybody?", voice_id, tts_volume, tts_pitch, tts_sentence_speed)
|
||||
DisplayServer.tts_speak(str(amount) + ", anybody?", voice_id, tts_volume, tts_pitch, tts_sentence_speed)
|
||||
else:
|
||||
DisplayServer.tts_speak("Can I get a" + str(desk.numpad.proposed_ask), voice_id, tts_volume, tts_pitch, tts_sentence_speed)
|
||||
DisplayServer.tts_speak("Can I get a" + str(amount), voice_id, tts_volume, tts_pitch, tts_sentence_speed)
|
||||
|
||||
func _handle_ask_accepted():
|
||||
timer.start()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue