diff --git a/Game/Minigames/MatchGame/Dice.gd b/Game/Minigames/MatchGame/Dice.gd new file mode 100644 index 000000000..4742bfca1 --- /dev/null +++ b/Game/Minigames/MatchGame/Dice.gd @@ -0,0 +1,48 @@ +extends ColorRect + +var colour = Color.gray +var radius = 10.0 +var offset = 90.0 +var size = 45 +var number = 0 +var blind = false + +func _ready() -> void: + number = RNG.randi_range(1, 6) + +func _draw(): + match number: + 1: + draw_circle(Vector2(offset + 0, offset + 0), radius, pickColor()) + 2: + draw_circle(Vector2(offset + size, offset - size), radius, pickColor()) + draw_circle(Vector2(offset - size, offset + size), radius, pickColor()) + 3: + draw_circle(Vector2(offset + 0, offset + 0), radius, pickColor()) + draw_circle(Vector2(offset + size, offset - size), radius, pickColor()) + draw_circle(Vector2(offset - size, offset + size), radius, pickColor()) + 4: + draw_circle(Vector2(offset - size, offset - size), radius, pickColor()) + draw_circle(Vector2(offset - size, offset + size), radius, pickColor()) + draw_circle(Vector2(offset + size, offset - size), radius, pickColor()) + draw_circle(Vector2(offset + size, offset + size), radius, pickColor()) + 5: + draw_circle(Vector2(offset + 0, offset + 0), radius, pickColor()) + draw_circle(Vector2(offset - size, offset - size), radius, pickColor()) + draw_circle(Vector2(offset - size, offset + size), radius, pickColor()) + draw_circle(Vector2(offset + size, offset - size), radius, pickColor()) + draw_circle(Vector2(offset + size, offset + size), radius, pickColor()) + 6: + draw_circle(Vector2(offset + size, offset - 0), radius, pickColor()) + draw_circle(Vector2(offset - size, offset + 0), radius, pickColor()) + draw_circle(Vector2(offset - size, offset - size), radius, pickColor()) + draw_circle(Vector2(offset - size, offset + size), radius, pickColor()) + draw_circle(Vector2(offset + size, offset - size), radius, pickColor()) + draw_circle(Vector2(offset + size, offset + size), radius, pickColor()) + _: + draw_circle(Vector2(offset + 0, offset + 0), 0, pickColor()) + +func pickColor(): + if blind && RNG.chance(10): + return color + return colour diff --git a/Game/Minigames/MatchGame/MatchGame.gd b/Game/Minigames/MatchGame/MatchGame.gd new file mode 100644 index 000000000..6409b49d9 --- /dev/null +++ b/Game/Minigames/MatchGame/MatchGame.gd @@ -0,0 +1,102 @@ +extends Control + +var inGame = false +var freeze = false +var timer = 30.0 +var timeLeft = timer +var lastRound = timer +var lastdice = 0 +var dices +var level = 1 +var blind = false + +signal minigameCompleted(finalScore) + +func _ready() -> void: + dices = [$GameScreen/Panel1, $GameScreen/Panel2, $GameScreen/Panel3] + setIngame(false) + doRound() + + +func _process(delta): + if inGame && !freeze: + timeLeft -= delta + setTimeBar(timeLeft / timer) + if timeLeft <= 0: + finish() + if lastRound - timeLeft > 0.6: + lastRound = timeLeft + doRound() + +func doRound(): + if RNG.chance(50): + lastdice += 1 + else: + lastdice -= 1 + if lastdice >= dices.size(): + lastdice = 0 + if lastdice < 0: + lastdice = dices.size() - 1 + if RNG.chance(35 - difficulty()): + updateDice(dices[lastdice], RNG.pick(dices).number) + else: + updateDice(dices[lastdice], dices[lastdice].number) + +func updateDice(dice, number): + while number == dice.number: + number = RNG.randi_range(1, 6) + + dice.blind = blind + dice.number = number + dice.color = Color.black + + +func _on_Click(event): + if event is InputEventMouseButton: + if event.pressed && !freeze: + finish() + +func finish(): + freeze = true + yield(get_tree().create_timer(0.9), "timeout") + freeze = false + emit_signal("minigameCompleted", calcScore()) + +# calculate score from -1.0 to +1.3 +func calcScore(): + var score = 0 + if dices[0].number == dices[1].number && dices[1].number == dices[2].number: + score = 1 + dices[0].number * 2 + elif dices[0].number == dices[1].number || dices[0].number == dices[2].number: + score = dices[0].number + elif dices[1].number == dices[2].number: + score = dices[1].number + else: + score = -(dices[0].number + dices[1].number + dices[2].number)/1.5 + if RNG.chance(50): + score = 0 + return score/10.0 + +# caclc difficulty 1 to 20, rise up with level +func difficulty(): + return min((0.6 + pow(max(1.0, level) / 2.0, 1.2)), 20) + +func _on_Button_pressed(): + timer = 30.0 - difficulty()/2.0 + timeLeft = timer + lastRound = timer + setIngame(true) + +func setIngame(_inGame): + inGame = _inGame + $StartMenu.visible = !_inGame + $GameScreen.visible = _inGame + +func setTimeBar(val): + $GameScreen/ProgressBar.value = clamp(val, 0.0, 1.0) + +func config(_params = {}): + if(_params.has("level")): + level = _params["level"] + if(_params.has("blind")): + blind = _params["blind"] diff --git a/Game/Minigames/MatchGame/MatchGame.tscn b/Game/Minigames/MatchGame/MatchGame.tscn new file mode 100644 index 000000000..bb10acfe3 --- /dev/null +++ b/Game/Minigames/MatchGame/MatchGame.tscn @@ -0,0 +1,141 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://Game/Minigames/MatchGame/MatchGame.gd" type="Script" id=1] +[ext_resource path="res://Game/Minigames/MatchGame/Dice.gd" type="Script" id=4] + +[sub_resource type="StyleBoxFlat" id=7] +bg_color = Color( 0.639216, 0, 0, 1 ) + +[sub_resource type="StyleBoxFlat" id=8] +bg_color = Color( 0, 0, 0, 1 ) +border_width_left = 4 +border_width_top = 4 +border_width_right = 4 +border_width_bottom = 4 +corner_radius_top_left = 4 +corner_radius_top_right = 4 +corner_radius_bottom_right = 4 +corner_radius_bottom_left = 4 +expand_margin_left = 4.0 +expand_margin_right = 4.0 +expand_margin_top = 4.0 +expand_margin_bottom = 4.0 + +[node name="MatchGame" type="Control"] +margin_right = 1280.0 +margin_bottom = 720.0 +rect_min_size = Vector2( 0, 500 ) +script = ExtResource( 1 ) + +[node name="ColorRect" type="ColorRect" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +color = Color( 0.105882, 0.0588235, 0.258824, 1 ) + +[node name="GameScreen" type="Control" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="Panel1" type="ColorRect" parent="GameScreen"] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -320.0 +margin_top = -120.0 +margin_right = -140.0 +margin_bottom = 60.0 +rect_pivot_offset = Vector2( 90, 90 ) +color = Color( 0, 0, 0, 1 ) +script = ExtResource( 4 ) + +[node name="Panel2" type="ColorRect" parent="GameScreen"] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -90.0 +margin_top = -120.0 +margin_right = 90.0 +margin_bottom = 60.0 +rect_pivot_offset = Vector2( 90, 90 ) +color = Color( 0, 0, 0, 1 ) +script = ExtResource( 4 ) + +[node name="Panel3" type="ColorRect" parent="GameScreen"] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = 140.0 +margin_top = -120.0 +margin_right = 320.0 +margin_bottom = 60.0 +rect_pivot_offset = Vector2( 90, 90 ) +color = Color( 0, 0, 0, 1 ) +script = ExtResource( 4 ) + +[node name="ProgressBar" type="ProgressBar" parent="GameScreen"] +anchor_left = 0.35 +anchor_top = 0.5 +anchor_right = 0.65 +anchor_bottom = 0.5 +margin_top = 163.0 +margin_bottom = 193.0 +rect_min_size = Vector2( 0, 30 ) +custom_styles/fg = SubResource( 7 ) +custom_styles/bg = SubResource( 8 ) +max_value = 1.0 +value = 0.37 +percent_visible = false + +[node name="Label" type="Label" parent="GameScreen/ProgressBar"] +anchor_right = 1.0 +anchor_bottom = 1.0 +text = "Time" +align = 1 +valign = 1 + +[node name="StreakLabel" type="Label" parent="GameScreen"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = 10.0 +margin_bottom = -10.0 +valign = 2 + +[node name="ClickStealer" type="Control" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="StartMenu" type="Control" parent="."] +visible = false +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="CenterContainer" type="CenterContainer" parent="StartMenu"] +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="VBoxContainer" type="VBoxContainer" parent="StartMenu/CenterContainer"] +margin_left = 407.0 +margin_top = 326.0 +margin_right = 873.0 +margin_bottom = 394.0 + +[node name="Label" type="Label" parent="StartMenu/CenterContainer/VBoxContainer"] +margin_right = 466.0 +margin_bottom = 14.0 +text = "Click when at least two dices has same number, +bigger number is better, 6 6 6 is the best. +Some dots will not appear if you can't see." +align = 1 + +[node name="Button" type="Button" parent="StartMenu/CenterContainer/VBoxContainer"] +margin_top = 18.0 +margin_right = 466.0 +margin_bottom = 68.0 +rect_min_size = Vector2( 0, 50 ) +text = "Begin" + +[connection signal="gui_input" from="ClickStealer" to="." method="_on_Click"] +[connection signal="pressed" from="StartMenu/CenterContainer/VBoxContainer/Button" to="." method="_on_Button_pressed"]