added win/lose text and fixed several bugs

This commit is contained in:
2025-03-22 20:05:25 -04:00
parent 571197baa7
commit bd014b7e1d
10 changed files with 108 additions and 33 deletions

View File

@@ -3,6 +3,25 @@ extends Node
var cooldown:int = 0
static var SCREAM_ARRAY:Array = [0,1]
func _explode():
%SCREAM.stream = load("res://assets/sounds/scream_%s.wav" % SCREAM_ARRAY.pick_random())
%SCREAM.play()
%RULE_ENFORCEMENT.explode()
%QUESTION.visible = false
%ANSWER.visible = false
cooldown = 180
if GLOBALVARS.selected_player == 0:
%WINLOSE.visible = true
%WINLOSE.self_modulate = Color(1,0,0)
%WINLOSE.text = ":("
elif GLOBALVARS.players_remaining == [0]:
%WINLOSE.visible = true
%WINLOSE.self_modulate = Color(0,1,0)
%WINLOSE.text = "You Win! :)"
else:
cooldown = 60
func _determine_seconds_left() -> float:
var difficulty_calc:float = 20-float(GLOBALVARS.difficulty)
return difficulty_calc if difficulty_calc >= 3.0 else 3.0
@@ -16,14 +35,13 @@ func _on_answer_text_submitted(_new_text: String) -> void:
GLOBALVARS.difficulty+=.5
GLOBALVARS.seconds_left = _determine_seconds_left()
_generate_question()
else:
%SCREAM.stream = load("res://assets/sounds/scream_%s.wav" % SCREAM_ARRAY.pick_random())
%SCREAM.play()
%RULE_ENFORCEMENT.explode()
cooldown = 60
GLOBALVARS.seconds_left = _determine_seconds_left()
GLOBALVARS.rotation_paused = true
GLOBALVARS.players_remaining.erase(GLOBALVARS.selected_player)
get_node("players/player_%s" % GLOBALVARS.selected_player).queue_free()
_explode()
%ANSWER.text = ""
@@ -33,8 +51,8 @@ func _generate_question() -> void:
# 2 - multiply
# 3 - divide
var x:int = randi_range(1,100)
var y:int = randi_range(1,100)
var x:int = randi_range(1,10)
var y:int = randi_range(1,10)
var rand_int:int = randi_range(0,3)
if rand_int == 0:
@@ -44,22 +62,38 @@ func _generate_question() -> void:
GLOBALVARS.current_solution = x-y
GLOBALVARS.current_operand = "-"
elif rand_int == 2:
x = randi_range(0,15) # simplify multiplication
y = randi_range(0,15)
x = randi_range(0,10) # simplify multiplication
y = randi_range(0,10)
GLOBALVARS.current_solution = x*y
GLOBALVARS.current_operand = "*"
elif rand_int == 3:
var fail:int = 0
var solution:int
GLOBALVARS.current_operand = "/"
while x%y != 0: # keep going til the remainder is 0
x = randi_range(0,100)
y = randi_range(1,100)
while x%y != 0 and fail < 10000: # keep going til the remainder is 0
x = randi_range(1,10)
y = randi_range(1,10)
@warning_ignore('integer_division')
GLOBALVARS.current_solution = int(x/y)
solution = floor(x/y)
fail+=1
GLOBALVARS.current_solution = solution
if fail >= 10000: # fallback to addition if no division problem can be found in 10000 loops
GLOBALVARS.current_operand = "+"
GLOBALVARS.current_solution = x+y
%QUESTION.text = "%s %s %s = " % [x,GLOBALVARS.current_operand,y]
%QUESTION.visible = true
%ANSWER.visible = true
func _ready() -> void:
%QUESTION.visible = true
%ANSWER.visible = true
%WINLOSE.visible = false
%WINLOSE.text = ""
GLOBALVARS.seconds_left = _determine_seconds_left()
_generate_question()
@@ -73,13 +107,12 @@ func _physics_process(_delta: float) -> void:
%ANSWER.editable = false
if GLOBALVARS.seconds_left <= 0:
%RULE_ENFORCEMENT.explode()
cooldown = 60
GLOBALVARS.seconds_left = _determine_seconds_left()
GLOBALVARS.rotation_paused = true
if GLOBALVARS.selected_player in GLOBALVARS.players_remaining:
GLOBALVARS.players_remaining.erase(GLOBALVARS.selected_player)
get_node("players/player_%s" % GLOBALVARS.selected_player).queue_free()
_explode()
if cooldown <= 0 and GLOBALVARS.rotation_paused:
if len(GLOBALVARS.players_remaining) > 1 and 0 in GLOBALVARS.players_remaining:
@@ -89,9 +122,6 @@ func _physics_process(_delta: float) -> void:
_generate_question()
%RULE_ENFORCEMENT.reset_rule_enforcement_device()
GLOBALVARS.rotation_paused = false
elif 0 in GLOBALVARS.players_remaining:
get_tree().change_scene_to_file("res://main_scenes/menu.tscn")
else:
get_tree().change_scene_to_file("res://main_scenes/menu.tscn")