core game logic done
This commit is contained in:
@@ -3,24 +3,22 @@ extends Node
|
||||
var cooldown:int = 0
|
||||
|
||||
func _determine_seconds_left() -> float:
|
||||
var difficulty_calc:float = 20/float(GLOBALVARS.difficulty)
|
||||
var difficulty_calc:float = 20-float(GLOBALVARS.difficulty)
|
||||
return difficulty_calc if difficulty_calc >= 3.0 else 3.0
|
||||
|
||||
func _on_answer_text_submitted(_new_text: String) -> void:
|
||||
if GLOBALVARS.selected_player == 0:
|
||||
if GLOBALVARS.current_solution == (%ANSWER.text).to_int():
|
||||
GLOBALVARS.selected_player = (GLOBALVARS.selected_player+1)%4
|
||||
GLOBALVARS.difficulty+=1
|
||||
_determine_seconds_left()
|
||||
_generate_question()
|
||||
%ANSWER.text = ""
|
||||
else:
|
||||
%RULE_ENFORCEMENT.explode()
|
||||
cooldown = 120
|
||||
GLOBALVARS.rotation_paused = true
|
||||
GLOBALVARS.players_remaining.erase(0)
|
||||
get_node("players/player_0").queue_free()
|
||||
|
||||
if GLOBALVARS.current_solution == (%ANSWER.text).to_int():
|
||||
GLOBALVARS.selected_player = (GLOBALVARS.selected_player+1)%4
|
||||
GLOBALVARS.difficulty+=1
|
||||
GLOBALVARS.seconds_left = _determine_seconds_left()
|
||||
_generate_question()
|
||||
%ANSWER.text = ""
|
||||
else:
|
||||
%RULE_ENFORCEMENT.explode()
|
||||
cooldown = 60
|
||||
GLOBALVARS.rotation_paused = true
|
||||
GLOBALVARS.players_remaining.erase(GLOBALVARS.selected_player)
|
||||
get_node("players/player_%s" % GLOBALVARS.selected_player).queue_free()
|
||||
|
||||
func _generate_question() -> void:
|
||||
# 0 - add
|
||||
@@ -31,21 +29,20 @@ func _generate_question() -> void:
|
||||
var x:int = randi_range(1,100)
|
||||
var y:int = randi_range(1,100)
|
||||
var rand_int:int = randi_range(0,3)
|
||||
var operand:String
|
||||
|
||||
if rand_int == 0:
|
||||
GLOBALVARS.current_solution = x+y
|
||||
operand = "+"
|
||||
GLOBALVARS.current_operand = "+"
|
||||
elif rand_int == 1:
|
||||
GLOBALVARS.current_solution = x-y
|
||||
operand = "-"
|
||||
GLOBALVARS.current_operand = "-"
|
||||
elif rand_int == 2:
|
||||
x = randi_range(0,10) # simplify multiplication
|
||||
y = randi_range(0,10)
|
||||
GLOBALVARS.current_solution = x*y
|
||||
operand = "*"
|
||||
GLOBALVARS.current_operand = "*"
|
||||
elif rand_int == 3:
|
||||
operand = "/"
|
||||
GLOBALVARS.current_operand = "/"
|
||||
while x%y != 0: # keep going til the remainder is 0
|
||||
x = randi_range(0,100)
|
||||
y = randi_range(1,100)
|
||||
@@ -53,10 +50,10 @@ func _generate_question() -> void:
|
||||
@warning_ignore('integer_division')
|
||||
GLOBALVARS.current_solution = x/y
|
||||
|
||||
%QUESTION.text = "%s %s %s = " % [x,operand,y]
|
||||
%QUESTION.text = "%s %s %s = " % [x,GLOBALVARS.current_operand,y]
|
||||
|
||||
func _ready() -> void:
|
||||
_determine_seconds_left()
|
||||
GLOBALVARS.seconds_left = _determine_seconds_left()
|
||||
_generate_question()
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
|
Reference in New Issue
Block a user