From a58c87cfeb12721bdadb0c7e20e2735ea1f2ebde Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 28 Jan 2024 19:07:40 +0100 Subject: [PATCH] operation --- scenes/game/ads/Ads_operation.tscn | 38 ++++++++++++++++++++++++++- scripts/ads/ads_operation.gd | 42 ++++++++++++++++++++++++++++-- 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/scenes/game/ads/Ads_operation.tscn b/scenes/game/ads/Ads_operation.tscn index 49fab4b..2b5a325 100644 --- a/scenes/game/ads/Ads_operation.tscn +++ b/scenes/game/ads/Ads_operation.tscn @@ -1,7 +1,43 @@ -[gd_scene load_steps=3 format=3 uid="uid://c3qlt4pa4qbji"] +[gd_scene load_steps=4 format=3 uid="uid://c3qlt4pa4qbji"] [ext_resource type="PackedScene" uid="uid://n06gkookqeml" path="res://scenes/game/windows/Ads.tscn" id="1_2b68r"] [ext_resource type="Script" path="res://scripts/ads/ads_operation.gd" id="2_jop1v"] +[ext_resource type="Texture2D" uid="uid://goinpjd4qxgd" path="res://ressources/assets/Operation/Operation.png" id="3_nc0f5"] [node name="Windows" instance=ExtResource("1_2b68r")] script = ExtResource("2_jop1v") + +[node name="Operation" type="Sprite2D" parent="." index="2"] +position = Vector2(250.5, 224) +scale = Vector2(0.400833, 0.35) +texture = ExtResource("3_nc0f5") + +[node name="Question" type="Label" parent="." index="3"] +layout_mode = 0 +offset_left = 82.0 +offset_top = 144.0 +offset_right = 385.0 +offset_bottom = 249.0 +theme_override_colors/font_color = Color(0.905882, 0.639216, 0.858824, 1) +theme_override_font_sizes/font_size = 76 +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Button1" type="Button" parent="." index="4"] +layout_mode = 0 +offset_left = 103.0 +offset_top = 229.0 +offset_right = 235.0 +offset_bottom = 325.0 +theme_override_font_sizes/font_size = 31 + +[node name="Button2" type="Button" parent="." index="5"] +layout_mode = 0 +offset_left = 237.0 +offset_top = 230.0 +offset_right = 381.0 +offset_bottom = 326.0 +theme_override_font_sizes/font_size = 31 + +[connection signal="pressed" from="Button1" to="." method="_on_button_1_pressed"] +[connection signal="pressed" from="Button2" to="." method="_on_button_2_pressed"] diff --git a/scripts/ads/ads_operation.gd b/scripts/ads/ads_operation.gd index 4e92afc..b482ae0 100644 --- a/scripts/ads/ads_operation.gd +++ b/scripts/ads/ads_operation.gd @@ -1,9 +1,47 @@ extends "res://scripts/ads/ads_default.gd" -# TODO +@onready var question := $Question +@onready var responseA := $Button1 +@onready var responseB := $Button2 + +enum OP { + ADD, + SUB, + MUL, +} + +var reponse func _ready(): - pass + var a := randi_range(0, 9) + var b := randi_range(0, 9) + + var operation = OP.values().pick_random() + var operator := "" + + match operation: + OP.ADD: + reponse = a + b + operator = "+" + OP.SUB: + reponse = a - b + operator = "-" + OP.MUL: + reponse = a * b + operator = "*" + + question.text = str(str(a), " ", operator, " " , str(b)) + + var buttons := [responseA, responseB] + buttons.shuffle() + buttons[0].text = str(reponse) + buttons[1].text = str(randi_range(-10, 30)) func exit_condition(): return condition + +func _on_button_1_pressed(): + condition = int(responseA.text) == reponse + +func _on_button_2_pressed(): + condition = int(responseB.text) == reponse