diff --git a/game/Player.gd b/game/Player.gd new file mode 100644 index 0000000..ee1d144 --- /dev/null +++ b/game/Player.gd @@ -0,0 +1,32 @@ +extends HBoxContainer + +class_name Player + +@onready var label: Label = $VBoxContainer/Label +@onready var medal: TextureRect = $TextureRect/Medal +@onready var dice1: DiceUi = $VBoxContainer/HBoxContainer/dice1 +@onready var dice2: DiceUi = $VBoxContainer/HBoxContainer/dice2 +@onready var dice3: DiceUi = $VBoxContainer/HBoxContainer/dice3 + +@export var player_name: String : + set(value): + player_name = value + visible = player_name != "" + label.text = player_name + +@export var show_medal: bool = false : + set(value): + show_medal = value + medal.visible = show_medal + +@export var score: int = 0 : + set(value): + score = value + dice1.value = score / 100 + dice2.value = (score % 100) / 10 + dice3.value = score % 10 + +func _ready(): + player_name = player_name + show_medal = show_medal + score = score \ No newline at end of file diff --git a/game/dice-ui.gd b/game/dice-ui.gd index f3d99bc..8b38b6a 100644 --- a/game/dice-ui.gd +++ b/game/dice-ui.gd @@ -1,4 +1,5 @@ extends Control +class_name DiceUi @export var value := 1 : set(_value): @@ -30,20 +31,20 @@ func _ready() -> void: stylebox.corner_radius_top_right = radius func _draw() -> void: - var dim = min(size.x, size.y) + var dim: float = min(size.x, size.y) draw_style_box(stylebox, Rect2(Vector2(), size)) - var point_size = dim / 10 - var center = Vector2(dim / 2, dim / 2) - var topleft = Vector2(dim / 4, dim / 4) - var topright = topleft + Vector2(dim / 2, 0) - var bottomleft = topleft + Vector2(0, dim / 2) - var bottomright = topleft + Vector2(dim / 2, dim / 2) - var centerleft = topleft + Vector2(0, dim / 4) - var centerright = topleft + Vector2(dim / 2, dim / 4) - var centertop = topleft + Vector2(dim / 4, 0) - var centerbottom = topleft + Vector2(dim / 4, dim / 2) + var point_size := dim / 10 + var center := Vector2(dim / 2, dim / 2) + var topleft := Vector2(dim / 4, dim / 4) + var topright := topleft + Vector2(dim / 2, 0) + var bottomleft := topleft + Vector2(0, dim / 2) + var bottomright := topleft + Vector2(dim / 2, dim / 2) + var centerleft := topleft + Vector2(0, dim / 4) + var centerright := topleft + Vector2(dim / 2, dim / 4) + var centertop := topleft + Vector2(dim / 4, 0) + var centerbottom := topleft + Vector2(dim / 4, dim / 2) if value % 2 == 1: draw_circle(center, point_size, color) diff --git a/game/main.gd b/game/main.gd index 794603c..cab9b38 100644 --- a/game/main.gd +++ b/game/main.gd @@ -28,10 +28,12 @@ enum MasterState { var state: GameState = GameState.START var master_state: MasterState = MasterState.LOGO +var current_player = 0 var camera_transition := 0. var camera_speed := 1.5 var first_throw := true var physics_timer := Timer.new() +var target_score = 100 func _ready() -> void: ui.connect("roll_pressed", throw_dice) @@ -40,6 +42,7 @@ func _ready() -> void: menu_scene.connect("start_game", switch_to_player_select) player_select.connect("start_game", switch_to_game) player_select.connect("back_to_menu", switch_to_menu) + ui.connect("back_to_menu", switch_to_menu) switch_to_menu() func master_state_sync() -> void: @@ -50,6 +53,7 @@ func master_state_sync() -> void: player_select.visible = MasterState.PLAYER_SELECT == master_state if master_state != MasterState.GAME: physics_timer_timeout() + ui.update_medal() func switch_to_player_select() -> void: master_state = MasterState.PLAYER_SELECT @@ -57,6 +61,18 @@ func switch_to_player_select() -> void: func switch_to_game() -> void: master_state = MasterState.GAME + # for i in ui.players.size(): + # ui.players[i].player_name = "" + for i in player_select.player_names.size(): + var player_name: String = player_select.player_names[i] + # if not player_name: continue + ui.players[i].player_name = player_name + ui.players[i].score = 0 + ui.players[i].show_medal = false + for i in player_select.player_names.size(): + if player_select.player_names[i]: + current_player = i + break master_state_sync() func switch_to_menu() -> void: @@ -68,6 +84,26 @@ func physics_timer_timeout() -> void: dice2.sleeping = true pass +func next_player() -> void: + current_player = (current_player + 1) % ui.players.size() + if not ui.players[current_player].player_name: + var found = false + for i in player_select.player_names: + if i: + found = true + break + if not found: + print("Trying to run next_player with no players! Semi-crashing to main menu.") + switch_to_menu() + return + next_player() + +func check_score() -> void: + for i in ui.players: + if i.score >= target_score: + print("Player", i.player_name, "won with", i.score, "points!") + break + func _physics_process(delta: float) -> void: camera_transition += delta * camera_speed camera_transition = min(camera_transition, 1.) @@ -87,6 +123,15 @@ func _physics_process(delta: float) -> void: camera_transition = 0. first_throw = false physics_timer.stop() + var d1 = dice1.get_value() + var d2 = dice2.get_value() + if d1 != 1 and d2 != 1: + ui.players[current_player].score += d1 + d2 + elif d1 == 1 and d2 == 1: + ui.players[current_player].score = 0 + ui.update_medal() + check_score() + next_player() ui.set_current_throw_value([dice1.get_value(), dice2.get_value()]) diff --git a/game/ui.gd b/game/ui.gd index 054d95e..8b2a233 100644 --- a/game/ui.gd +++ b/game/ui.gd @@ -10,4 +10,29 @@ func _on_roll_button_pressed() -> void: func set_current_throw_value(value: Array[int]) -> void: dice1.value = value[0] - dice2.value = value[1] \ No newline at end of file + dice2.value = value[1] + +@onready var player1 = $VBoxContainer/Player +@onready var player2 = $VBoxContainer/Player2 +@onready var player3 = $VBoxContainer/Player3 +@onready var player4 = $VBoxContainer/Player4 +@onready var player5 = $VBoxContainer/Player5 + +var players: Array[Player] = [] + +func _ready() -> void: + players = [player1, player2, player3, player4, player5] + +func update_medal() -> void: + var max_score = 0 + for player in players: + if player.score > max_score: + max_score = player.score + for player in players: + player.show_medal = player.score == max_score and max_score > 0 + +signal back_to_menu +func _on_texture_rect_gui_input(event: InputEvent) -> void: + if event is InputEventMouse: + if event.is_pressed(): + back_to_menu.emit() \ No newline at end of file diff --git a/game/ui.tscn b/game/ui.tscn index 9841777..f8ca4bb 100644 --- a/game/ui.tscn +++ b/game/ui.tscn @@ -1,7 +1,11 @@ -[gd_scene load_steps=5 format=3 uid="uid://c8jkqtbqtg7ub"] +[gd_scene load_steps=9 format=3 uid="uid://c8jkqtbqtg7ub"] [ext_resource type="Script" path="res://game/ui.gd" id="1_qipxr"] [ext_resource type="Script" path="res://game/dice-ui.gd" id="2_g0ok8"] +[ext_resource type="Script" path="res://game/Player.gd" id="3_qtea6"] +[ext_resource type="Texture2D" uid="uid://c25g6oj4fnw0h" path="res://icons/singleplayer.png" id="3_xwlig"] +[ext_resource type="Texture2D" uid="uid://olq6rc614eq1" path="res://icons/medal2.png" id="4_gisdl"] +[ext_resource type="Texture2D" uid="uid://dgwgb7g0gca8m" path="res://icons/exit.png" id="6_ephx3"] [sub_resource type="InputEventKey" id="InputEventKey_6n7ot"] device = -1 @@ -61,4 +65,230 @@ offset_bottom = -8.0 grow_vertical = 0 script = ExtResource("2_g0ok8") +[node name="VBoxContainer" type="VBoxContainer" parent="."] +layout_mode = 1 +offset_right = 185.0 +offset_bottom = 500.0 +theme_override_constants/separation = 0 + +[node name="Player" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 +script = ExtResource("3_qtea6") + +[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Player"] +self_modulate = Color(0.329412, 0.690196, 1, 1) +layout_mode = 2 +texture = ExtResource("3_xwlig") + +[node name="Medal" type="TextureRect" parent="VBoxContainer/Player/TextureRect"] +layout_mode = 0 +offset_left = 36.0 +offset_top = 41.0 +offset_right = 101.0 +offset_bottom = 106.0 +texture = ExtResource("4_gisdl") +expand_mode = 1 + +[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/Player"] +layout_mode = 2 +alignment = 1 + +[node name="Label" type="Label" parent="VBoxContainer/Player/VBoxContainer"] +layout_mode = 2 +text = "Player 1" + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/Player/VBoxContainer"] +layout_mode = 2 +alignment = 2 + +[node name="dice1" type="Control" parent="VBoxContainer/Player/VBoxContainer/HBoxContainer"] +layout_mode = 2 +script = ExtResource("2_g0ok8") + +[node name="dice2" type="Control" parent="VBoxContainer/Player/VBoxContainer/HBoxContainer"] +layout_mode = 2 +script = ExtResource("2_g0ok8") + +[node name="dice3" type="Control" parent="VBoxContainer/Player/VBoxContainer/HBoxContainer"] +layout_mode = 2 +script = ExtResource("2_g0ok8") + +[node name="Player2" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 +script = ExtResource("3_qtea6") + +[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Player2"] +self_modulate = Color(0.780392, 0.529412, 0.992157, 1) +layout_mode = 2 +texture = ExtResource("3_xwlig") + +[node name="Medal" type="TextureRect" parent="VBoxContainer/Player2/TextureRect"] +offset_left = 36.0 +offset_top = 41.0 +offset_right = 101.0 +offset_bottom = 106.0 +texture = ExtResource("4_gisdl") +expand_mode = 1 + +[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/Player2"] +layout_mode = 2 +alignment = 1 + +[node name="Label" type="Label" parent="VBoxContainer/Player2/VBoxContainer"] +layout_mode = 2 +text = "Player 1" + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/Player2/VBoxContainer"] +layout_mode = 2 +alignment = 2 + +[node name="dice1" type="Control" parent="VBoxContainer/Player2/VBoxContainer/HBoxContainer"] +layout_mode = 2 +script = ExtResource("2_g0ok8") + +[node name="dice2" type="Control" parent="VBoxContainer/Player2/VBoxContainer/HBoxContainer"] +layout_mode = 2 +script = ExtResource("2_g0ok8") + +[node name="dice3" type="Control" parent="VBoxContainer/Player2/VBoxContainer/HBoxContainer"] +layout_mode = 2 +script = ExtResource("2_g0ok8") + +[node name="Player3" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 +script = ExtResource("3_qtea6") + +[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Player3"] +self_modulate = Color(1, 0.47451, 0.501961, 1) +layout_mode = 2 +texture = ExtResource("3_xwlig") + +[node name="Medal" type="TextureRect" parent="VBoxContainer/Player3/TextureRect"] +offset_left = 36.0 +offset_top = 41.0 +offset_right = 101.0 +offset_bottom = 106.0 +texture = ExtResource("4_gisdl") +expand_mode = 1 + +[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/Player3"] +layout_mode = 2 +alignment = 1 + +[node name="Label" type="Label" parent="VBoxContainer/Player3/VBoxContainer"] +layout_mode = 2 +text = "Player 1" + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/Player3/VBoxContainer"] +layout_mode = 2 +alignment = 2 + +[node name="dice1" type="Control" parent="VBoxContainer/Player3/VBoxContainer/HBoxContainer"] +layout_mode = 2 +script = ExtResource("2_g0ok8") + +[node name="dice2" type="Control" parent="VBoxContainer/Player3/VBoxContainer/HBoxContainer"] +layout_mode = 2 +script = ExtResource("2_g0ok8") + +[node name="dice3" type="Control" parent="VBoxContainer/Player3/VBoxContainer/HBoxContainer"] +layout_mode = 2 +script = ExtResource("2_g0ok8") + +[node name="Player4" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 +script = ExtResource("3_qtea6") + +[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Player4"] +self_modulate = Color(0.996078, 0.509804, 0, 1) +layout_mode = 2 +texture = ExtResource("3_xwlig") + +[node name="Medal" type="TextureRect" parent="VBoxContainer/Player4/TextureRect"] +offset_left = 36.0 +offset_top = 41.0 +offset_right = 101.0 +offset_bottom = 106.0 +texture = ExtResource("4_gisdl") +expand_mode = 1 + +[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/Player4"] +layout_mode = 2 +alignment = 1 + +[node name="Label" type="Label" parent="VBoxContainer/Player4/VBoxContainer"] +layout_mode = 2 +text = "Player 1" + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/Player4/VBoxContainer"] +layout_mode = 2 +alignment = 2 + +[node name="dice1" type="Control" parent="VBoxContainer/Player4/VBoxContainer/HBoxContainer"] +layout_mode = 2 +script = ExtResource("2_g0ok8") + +[node name="dice2" type="Control" parent="VBoxContainer/Player4/VBoxContainer/HBoxContainer"] +layout_mode = 2 +script = ExtResource("2_g0ok8") + +[node name="dice3" type="Control" parent="VBoxContainer/Player4/VBoxContainer/HBoxContainer"] +layout_mode = 2 +script = ExtResource("2_g0ok8") + +[node name="Player5" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 +script = ExtResource("3_qtea6") + +[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Player5"] +self_modulate = Color(0, 0.780392, 0.556863, 1) +layout_mode = 2 +texture = ExtResource("3_xwlig") + +[node name="Medal" type="TextureRect" parent="VBoxContainer/Player5/TextureRect"] +offset_left = 36.0 +offset_top = 41.0 +offset_right = 101.0 +offset_bottom = 106.0 +texture = ExtResource("4_gisdl") +expand_mode = 1 + +[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/Player5"] +layout_mode = 2 +alignment = 1 + +[node name="Label" type="Label" parent="VBoxContainer/Player5/VBoxContainer"] +layout_mode = 2 +text = "Player 1" + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/Player5/VBoxContainer"] +layout_mode = 2 +alignment = 2 + +[node name="dice1" type="Control" parent="VBoxContainer/Player5/VBoxContainer/HBoxContainer"] +layout_mode = 2 +script = ExtResource("2_g0ok8") + +[node name="dice2" type="Control" parent="VBoxContainer/Player5/VBoxContainer/HBoxContainer"] +layout_mode = 2 +script = ExtResource("2_g0ok8") + +[node name="dice3" type="Control" parent="VBoxContainer/Player5/VBoxContainer/HBoxContainer"] +layout_mode = 2 +script = ExtResource("2_g0ok8") + +[node name="TextureRect" type="TextureRect" parent="."] +layout_mode = 1 +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -79.0 +offset_top = 18.0 +offset_right = -16.0 +offset_bottom = 81.0 +grow_horizontal = 0 +texture = ExtResource("6_ephx3") +expand_mode = 1 + [connection signal="pressed" from="roll button" to="." method="_on_roll_button_pressed"] +[connection signal="gui_input" from="TextureRect" to="." method="_on_texture_rect_gui_input"] diff --git a/icons/medal2.png b/icons/medal2.png new file mode 100644 index 0000000..cb60876 Binary files /dev/null and b/icons/medal2.png differ diff --git a/icons/medal2.png.import b/icons/medal2.png.import new file mode 100644 index 0000000..a157c5e --- /dev/null +++ b/icons/medal2.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://olq6rc614eq1" +path="res://.godot/imported/medal2.png-c75ade619c385a2ea0cb42d44a8184fc.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icons/medal2.png" +dest_files=["res://.godot/imported/medal2.png-c75ade619c385a2ea0cb42d44a8184fc.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/menu/menu_bg.gd b/menu/menu_bg.gd index cd7eb75..a6e1ff7 100644 --- a/menu/menu_bg.gd +++ b/menu/menu_bg.gd @@ -1,7 +1,5 @@ extends Node3D -# var select_scene = preload("res://player_select/player_select.tscn") - @onready var menu_ui = $MenuUi signal start_game @@ -14,5 +12,4 @@ func _ready() -> void: menu_ui.visible = ui_visible func _on_menu_ui_start_pressed() -> void: - # get_tree().change_scene_to_packed(select_scene) start_game.emit() \ No newline at end of file diff --git a/player_select/player_select.tscn b/player_select/player_select.tscn index 50982c0..21a3c74 100644 --- a/player_select/player_select.tscn +++ b/player_select/player_select.tscn @@ -163,10 +163,8 @@ anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -20.0 -offset_top = -20.0 -offset_right = 20.0 -offset_bottom = 20.0 +offset_right = 40.0 +offset_bottom = 40.0 grow_horizontal = 2 grow_vertical = 2 texture = ExtResource("2_de6io") @@ -188,11 +186,15 @@ grow_vertical = 0 text = "Name 2+ players to continue" [node name="TextureRect" type="TextureRect" parent="."] -layout_mode = 0 -offset_left = 21.0 -offset_top = 20.0 -offset_right = 84.0 -offset_bottom = 83.0 +layout_mode = 1 +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -79.0 +offset_top = 18.0 +offset_right = -16.0 +offset_bottom = 81.0 +grow_horizontal = 0 texture = ExtResource("4_4xfaw") expand_mode = 1