diff --git a/godot/main_scenes/game.tscn b/godot/main_scenes/game.tscn index 3901a40..6759b84 100644 --- a/godot/main_scenes/game.tscn +++ b/godot/main_scenes/game.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=12 format=3 uid="uid://bqokbcqplgrgp"] +[gd_scene load_steps=13 format=3 uid="uid://bqokbcqplgrgp"] [ext_resource type="Script" uid="uid://clwubcfa7jndm" path="res://scripts/gamemaster.gd" id="1_sp4xh"] [ext_resource type="PackedScene" uid="uid://bovc5oog85hic" path="res://assets/models/room/room.glb" id="1_wwb56"] [ext_resource type="Script" uid="uid://doxajvf15fv27" path="res://scripts/camera.gd" id="2_joe7c"] +[ext_resource type="Script" uid="uid://dutkdqg1nwysf" path="res://scripts/ai.gd" id="3_6h35g"] [ext_resource type="PackedScene" uid="uid://bw8hdj4fbkpbs" path="res://assets/models/players/player_0.glb" id="3_ofkbr"] [ext_resource type="PackedScene" uid="uid://b4gm46vd64nt2" path="res://assets/models/players/player_1.glb" id="4_is35i"] [ext_resource type="PackedScene" uid="uid://cvvi0laaw1yf" path="res://assets/models/players/player_2.glb" id="5_8vhnl"] @@ -46,6 +47,7 @@ light_energy = 2.385 omni_range = 11.934 [node name="players" type="Node3D" parent="."] +script = ExtResource("3_6h35g") [node name="player_0" parent="players" instance=ExtResource("3_ofkbr")] transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0, 0, -4) diff --git a/godot/scripts/ai.gd b/godot/scripts/ai.gd index 61510e1..38b29e0 100644 --- a/godot/scripts/ai.gd +++ b/godot/scripts/ai.gd @@ -1 +1,46 @@ +''' +Attempts to simulate human-esc responses. + +green - good at subtraction +red - good at multiplication +blue - good at division +''' + extends Node + +var currently_executing:bool = false +var faster_operand:String = "" +var wait_time:int +var is_correct:bool + +var clock:int + +func _physics_process(_delta: float) -> void: + if GLOBALVARS.selected_player != 0: + if not currently_executing: + clock = 0 + if GLOBALVARS.selected_player == 1: + faster_operand = "-" + elif GLOBALVARS.selected_player == 2: + faster_operand = "*" + elif GLOBALVARS.selected_player == 3: + faster_operand = "/" + + if GLOBALVARS.current_operand == faster_operand: + wait_time = randi_range(50,120) + is_correct = true if randf() > 0.05 else false + else: + wait_time = randi_range(60,350) + is_correct = true if randf() > 0.1 else false + currently_executing = true + + elif clock > wait_time: + if %ANSWER.text == "": + %ANSWER.text = str(GLOBALVARS.current_solution) if is_correct else str(GLOBALVARS.current_solution+randi_range(-10,10)) + elif clock > wait_time + 30: + %ANSWER.emit_signal("text_submitted",%ANSWER.text) + currently_executing = false + else: + clock+=1 + else: + clock+=1 diff --git a/godot/scripts/gamemaster.gd b/godot/scripts/gamemaster.gd index 7a5909b..ba7a312 100644 --- a/godot/scripts/gamemaster.gd +++ b/godot/scripts/gamemaster.gd @@ -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: diff --git a/godot/scripts/globalvars.gd b/godot/scripts/globalvars.gd index d236914..c0c6110 100644 --- a/godot/scripts/globalvars.gd +++ b/godot/scripts/globalvars.gd @@ -6,10 +6,12 @@ var difficulty:int = 1 var rotation_paused:bool = false var players_remaining:Array = [0,1,2,3] var current_solution:int +var current_operand:String = "" func reset_variables() -> void: selected_player = 0 seconds_left = 20.0 difficulty = 1 rotation_paused = false + current_operand = "" players_remaining = [0,1,2,3]