From 3226da488fb2f5350090f77d78832134d424f610 Mon Sep 17 00:00:00 2001 From: Ileyan Al Jaaf <3003916@stud.hs-mannheim.de> Date: Thu, 28 Mar 2024 00:16:22 +0100 Subject: [PATCH] =?UTF-8?q?W=C3=BCrfel=20funktioniert=20jetzt=20mit=20Anim?= =?UTF-8?q?ation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.gd | 47 +++++++++++++++++++++++++++++++++++- game.tscn | 66 +++++++++++++++++++++++++++++++++------------------ project.godot | 5 ++++ 3 files changed, 94 insertions(+), 24 deletions(-) diff --git a/game.gd b/game.gd index 75e4c3f..33dcff1 100644 --- a/game.gd +++ b/game.gd @@ -3,10 +3,18 @@ extends Node2D var current_player: int = 0 var player_states := ["Circle", "Cross"] var won := "" +var tile_size : Vector2 = Vector2(32, 32) # Annahme: 32x32 Pixel pro Tile +var tileset_texture : Texture = preload("res://assets/sprites.png") + @onready var board := $Board as Board @onready var nextPlayer := $GUI/NextPlayer as Sprite2D @onready var wonPlayer := $GUI/WonPlayer as Sprite2D +@onready var diceButton := $GUI/DiceButton as Button +@onready var diceSprite = $GUI/DiceSprite as Sprite2D + + + # Called when the node enters the scene tree for the first time. func _ready(): @@ -19,6 +27,8 @@ func _ready(): board.active = true + + # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta): if won == "": @@ -64,7 +74,42 @@ func _check_win() -> String: return state return "" +#Generiert die Zufallszahl von 1-6 +func _roll_dice(): + var zahl = randi() % 6 + 1 + _update_dice_sprite(zahl) + print(zahl) #Debug ausgabe, später löschen lol + return zahl - +#Funktion um Knop und Methode zu verbinden +func _on_dice_button_pressed(): + _roll_dice() + +#Sucht sich für die entsprechende Augenzahl +#die X und Y-Koordinaten in der Tilemap +func _update_dice_sprite(result :int): + diceSprite.region_rect.position.x = _get_dice_pos_x(result) + diceSprite.region_rect.position.y = _get_dice_pos_y(result) +#X-Koordinaten der Augenzahlen in der Tilemap +func _get_dice_pos_x(result: int) -> int: + match result: + 1: return 8 + 2: return 108 + 3: return 208 + 4: return 308 + 5: return 108 + 6: return 208 + return 8 +#Y-Koordinaten in der Tilemap +func _get_dice_pos_y(result: int) -> int: + match result: + 1: return 308 + 2: return 308 + 3: return 308 + 4: return 308 + 5: return 410 + 6: return 410 + return 308 + diff --git a/game.tscn b/game.tscn index 39a0227..a70d1d8 100644 --- a/game.tscn +++ b/game.tscn @@ -8,61 +8,81 @@ script = ExtResource("1_g1ie7") [node name="Nummerierung links" parent="." instance=ExtResource("1_ym80r")] -position = Vector2(420, 222) +position = Vector2(419, 240) layer_0/tile_data = PackedInt32Array(65533, 1, 3, 131069, 65537, 3, 196605, 131073, 3, 262141, 196609, 3, 327677, 65537, 4, 393213, 131073, 4, 65534, 1, 3, -2, 1, 3, -1, 65537, 3, -65536, 131073, 3, -65535, 196609, 3, -65534, 65537, 4, -65533, 131073, 4) [node name="Board" parent="." instance=ExtResource("1_ym80r")] -position = Vector2(420, 222) +position = Vector2(419, 240) layer_0/tile_data = PackedInt32Array(65537, 1, 0, 131073, 1, 0, 131074, 1, 0, 0, 1, 0, 65536, 1, 0, 131072, 1, 0, 1, 1, 0, 2, 1, 0, 65538, 1, 0, 65534, 1, 0, 131070, 1, 0, 131071, 1, 0, 196607, 1, 0, 65535, 1, 0, 196606, 1, 0, 262142, 1, 0, 327678, 1, 0, 393214, 1, 0, 393215, 1, 0, 327680, 1, 0, 327681, 1, 0, 327682, 1, 0, 327683, 1, 0, 262147, 1, 0, 196611, 1, 0, 131075, 1, 0, 65539, 1, 0, 3, 1, 0, 196610, 1, 0, 262146, 1, 0, 262145, 1, 0, 196609, 1, 0, 262144, 1, 0, 196608, 1, 0, 327679, 1, 0, 262143, 1, 0) [node name="GUI" type="Node2D" parent="."] [node name="Title" type="Label" parent="GUI"] -offset_left = 370.0 -offset_top = 44.0 -offset_right = 709.0 -offset_bottom = 116.0 -theme_override_font_sizes/font_size = 32 +offset_left = 560.0 +offset_top = 36.0 +offset_right = 941.0 +offset_bottom = 108.0 +theme_override_font_sizes/font_size = 40 text = "Tic Tac Toe Extreme" [node name="NextPlayer" type="Sprite2D" parent="GUI"] -position = Vector2(1012, 245) -scale = Vector2(0.5, 0.5) +position = Vector2(1178, 246.5) +scale = Vector2(1.3, 1.29) texture = ExtResource("3_0333r") region_enabled = true region_rect = Rect2(0, 100, 100, 100) [node name="NextPlayerLabel" type="Label" parent="GUI"] -offset_left = 924.0 -offset_top = 233.0 -offset_right = 966.0 -offset_bottom = 259.0 +offset_left = 953.0 +offset_top = 206.5 +offset_right = 1083.0 +offset_bottom = 275.5 size_flags_horizontal = 4 +theme_override_font_sizes/font_size = 45 text = "Next:" metadata/_edit_use_anchors_ = true [node name="WonPlayer" type="Sprite2D" parent="GUI"] -position = Vector2(1009, 311) -scale = Vector2(0.5, 0.5) +position = Vector2(1179, 400.5) +scale = Vector2(1.3, 1.3) texture = ExtResource("3_0333r") region_enabled = true region_rect = Rect2(0, 100, 100, 100) [node name="WonPlayerLabel" type="Label" parent="GUI"] -offset_left = 925.0 -offset_top = 300.0 -offset_right = 967.0 -offset_bottom = 326.0 +offset_left = 967.0 +offset_top = 369.5 +offset_right = 1091.0 +offset_bottom = 438.5 size_flags_horizontal = 4 +theme_override_font_sizes/font_size = 45 text = "Won:" metadata/_edit_use_anchors_ = true +[node name="DiceSprite" type="Sprite2D" parent="GUI"] +position = Vector2(1224, 576) +scale = Vector2(1.26596, 1.2191) +texture = ExtResource("3_0333r") +region_enabled = true +region_rect = Rect2(207, 410, 85, 85) + [node name="RestartButton" type="Button" parent="GUI"] -offset_left = 926.0 -offset_top = 366.0 -offset_right = 1029.0 -offset_bottom = 397.0 +offset_left = 896.0 +offset_top = 688.0 +offset_right = 1125.0 +offset_bottom = 808.0 +theme_override_colors/font_color = Color(1, 0, 0, 1) +theme_override_font_sizes/font_size = 30 text = "Restart" metadata/_edit_use_anchors_ = true +[node name="DiceButton" type="Button" parent="GUI"] +offset_left = 896.0 +offset_top = 520.0 +offset_right = 1128.0 +offset_bottom = 640.0 +theme_override_font_sizes/font_size = 30 +text = "Würfeln" + [connection signal="pressed" from="GUI/RestartButton" to="." method="_on_restart_button_pressed"] +[connection signal="pressed" from="GUI/DiceButton" to="." method="_on_dice_button_pressed"] diff --git a/project.godot b/project.godot index c7a99ff..d6d8123 100644 --- a/project.godot +++ b/project.godot @@ -15,6 +15,11 @@ run/main_scene="res://game.tscn" config/features=PackedStringArray("4.2", "GL Compatibility") config/icon="res://icon.svg" +[display] + +window/size/viewport_width=1500 +window/size/viewport_height=1000 + [input] Click={