From 2f87a280a26c1edf7de7bbf76a868f4651109807 Mon Sep 17 00:00:00 2001 From: Jonathan-Cheng-RPI Date: Mon, 1 Dec 2025 17:13:42 -0500 Subject: [PATCH] Board Scene: Chip spawning and basic error checking --- .DS_Store | Bin 0 -> 6148 bytes assets/.DS_Store | Bin 0 -> 6148 bytes assets/sprites/RedChip.png | Bin 0 -> 636 bytes assets/sprites/RedChip.png.import | 40 ++++++++++++ assets/sprites/YellowChip.png | Bin 0 -> 668 bytes assets/sprites/YellowChip.png.import | 40 ++++++++++++ connect4-moderator-observer.csproj | 8 +++ connect4-moderator-observer.sln | 19 ++++++ project.godot | 11 +++- scenes/board_screen.tscn | 26 ++++++++ scenes/button_small.tscn | 14 +++-- scenes/create_join_room.tscn | 15 +++-- scenes/game.tscn | 7 ++- scenes/red_chip.tscn | 14 +++++ scenes/yellow_chip.tscn | 14 +++++ scripts/BoardScreen.cs | 91 +++++++++++++++++++++++++++ scripts/BoardScreen.cs.uid | 1 + 17 files changed, 283 insertions(+), 17 deletions(-) create mode 100644 .DS_Store create mode 100644 assets/.DS_Store create mode 100644 assets/sprites/RedChip.png create mode 100644 assets/sprites/RedChip.png.import create mode 100644 assets/sprites/YellowChip.png create mode 100644 assets/sprites/YellowChip.png.import create mode 100644 connect4-moderator-observer.csproj create mode 100644 connect4-moderator-observer.sln create mode 100644 scenes/board_screen.tscn create mode 100644 scenes/red_chip.tscn create mode 100644 scenes/yellow_chip.tscn create mode 100644 scripts/BoardScreen.cs create mode 100644 scripts/BoardScreen.cs.uid diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b13897a96982ea86ad81a4b578b2c31d3c93c89b GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8O({YSiXIod7K}Z#6fYsx7cim+m70*C!I&*gY7V84tG-Blfmlt3 z&OnTu$$H(h4vtUGE@#i_OD5kmj~pmhvS+Y{cTgH7z50tRmDwZM>zq24kQg8ahyh|? z3mGtnfz{u_+Noq>fEf6h0o)%1G(^{6rBQ7i(BbtN{T)OU(D5ySC=9v=D~;d*;W`yi zr*iYe;5r@b!o;}-D~&pxakVncV^*#oFI=q-cA>%Ps z{ALP`hyh~YpE1BYQ-A6~QRZy@Rvwn34j6aBS*@q{Q`A}a}8D+ UaTc_zbU?ZYC_<(^b literal 0 HcmV?d00001 diff --git a/assets/.DS_Store b/assets/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9c31f2e71e28b31e4c8c052b5e11fd8749a33bc7 GIT binary patch literal 6148 zcmeHK%}T>S5T0$TO({YTiXIod7K}Z#6fdFH7cim+mD-S^!I&*cY7eE5tGb*Jgv`VVUE=i_{q4aVs;jV_dm zgHj&{m(gTCYVDq?Bp*k~B-IH~IKhyct0)Q8e4u7YnCV>KIGl#l7`65ni%zdCJH76* zEf@Wc+m>Cozg#w)y~CrE^U-7cl&BZOq(IWO>{u+}6_qbVJ^N`AtK=R%WmXx@$P6$8 z%m6d6VGP)Vz-ew+-CQm+zzqD%0PPPF8=+^hFsQchzW%lomaUg+cV7 z2$PCvQiXkD2$PO>Y2!SLg+Y@JLa&VT*pH_i%m6d+&lnK3p+6j8QTA;8Rvw+T65Aa%5{fHGK|y`x5`Y8RM-H^p_$BEW Y=UFTa(kx`x>4@~ literal 0 HcmV?d00001 diff --git a/assets/sprites/RedChip.png b/assets/sprites/RedChip.png new file mode 100644 index 0000000000000000000000000000000000000000..fcb24f4ec5a5e68a085a440aff9ef387a1a4f671 GIT binary patch literal 636 zcmV-?0)zdDP)u#&P<);6RhD&%VGd#i&4KPA%E$!?{X>&`8>l?aK`@NW^)o66v zg}mEiWXyrtX=zvAb^CO1q$?i;vl^Jfz7M>!Czzg>_U*k$t@&&0)`8-P`V=R|b!A_D ze$nZ)5&6)7ySKOGkuxtXFAC!1fymSOrC=QP!%6HlX~4|rXo8Qq-@uU9gE@U_Rsfgt z@G`A>o#Xhw3Nu1XjUguN0X2Pfa39q4U731xg48Q=G)zrshSsCc_rMCQcCyr?0jci& zwZ4B7nh8PNl)lyM_4PPS%EvY00q#JYK!wx})C4ib#qo)pZtr&Cjx(Ra%I9a_V1K_f zJ00PdoM5^Tf()+@kAgXzv8hQ}T3c1HHo z6r=&C*eRKVLUAt7{Aff@%7Yk6m>)Uh#6xehdrN5`m@|if`? zi)$Wgu-f^!a$w*T=wEtkL}UszC^@}oO$G)vkwv~)@Lno}#Kwx6LiSXFW}GyT*MNNa zt_?*f=f)Lkpl6DI00030|FwQ5od5s;21!IgR09BNEQa77eI7Uf0000 + + net8.0 + net9.0 + true + connect4moderatorobserver + + \ No newline at end of file diff --git a/connect4-moderator-observer.sln b/connect4-moderator-observer.sln new file mode 100644 index 0000000..7623db8 --- /dev/null +++ b/connect4-moderator-observer.sln @@ -0,0 +1,19 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "connect4-moderator-observer", "connect4-moderator-observer.csproj", "{686613AA-A1E3-40F7-8924-9B4FF0746A6F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + ExportDebug|Any CPU = ExportDebug|Any CPU + ExportRelease|Any CPU = ExportRelease|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {686613AA-A1E3-40F7-8924-9B4FF0746A6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {686613AA-A1E3-40F7-8924-9B4FF0746A6F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {686613AA-A1E3-40F7-8924-9B4FF0746A6F}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU + {686613AA-A1E3-40F7-8924-9B4FF0746A6F}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU + {686613AA-A1E3-40F7-8924-9B4FF0746A6F}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU + {686613AA-A1E3-40F7-8924-9B4FF0746A6F}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU + EndGlobalSection +EndGlobal diff --git a/project.godot b/project.godot index e745b7c..2e4428e 100644 --- a/project.godot +++ b/project.godot @@ -11,5 +11,14 @@ config_version=5 [application] config/name="connect4-moderator-observer" -config/features=PackedStringArray("4.5", "Forward Plus") +run/main_scene="uid://cr8fi0e4r88s8" +config/features=PackedStringArray("4.5", "C#", "Forward Plus") config/icon="res://icon.svg" + +[dotnet] + +project/assembly_name="connect4-moderator-observer" + +[rendering] + +textures/canvas_textures/default_texture_filter=0 diff --git a/scenes/board_screen.tscn b/scenes/board_screen.tscn new file mode 100644 index 0000000..58470c6 --- /dev/null +++ b/scenes/board_screen.tscn @@ -0,0 +1,26 @@ +[gd_scene load_steps=4 format=3 uid="uid://m542qwlp7hl7"] + +[ext_resource type="Script" uid="uid://dg5jt0o0r0v3r" path="res://scripts/BoardScreen.cs" id="1_b3w8x"] +[ext_resource type="PackedScene" uid="uid://d1wr0v5ht8vqb" path="res://scenes/button_small.tscn" id="1_tbc1w"] + +[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_b3w8x"] + +[node name="BoardScreen" type="Node2D"] +script = ExtResource("1_b3w8x") + +[node name="StaticBody2D" type="StaticBody2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] +shape = SubResource("WorldBoundaryShape2D_b3w8x") + +[node name="SpwnRed" parent="." instance=ExtResource("1_tbc1w")] +offset_left = 512.0 +offset_top = -324.0 +offset_right = 576.0 +offset_bottom = -292.0 + +[node name="SpwnYlw" parent="." instance=ExtResource("1_tbc1w")] +offset_left = 512.0 +offset_top = -292.0 +offset_right = 576.0 +offset_bottom = -260.0 diff --git a/scenes/button_small.tscn b/scenes/button_small.tscn index ef6d90d..e8e1ebd 100644 --- a/scenes/button_small.tscn +++ b/scenes/button_small.tscn @@ -17,22 +17,24 @@ atlas = ExtResource("2_q2stu") region = Rect2(8, 0, 32, 16) [node name="ButtonSmall" type="TextureButton"] -offset_top = -16.0 +offset_left = -32.0 +offset_top = -32.0 offset_right = 32.0 texture_normal = SubResource("AtlasTexture_6ptbq") texture_pressed = SubResource("AtlasTexture_06p6p") texture_hover = SubResource("AtlasTexture_q2stu") +stretch_mode = 4 script = ExtResource("2_06p6p") [node name="Label" type="Label" parent="."] layout_mode = 0 -offset_left = 1.0 -offset_top = 5.0 -offset_right = 31.0 -offset_bottom = 13.0 +offset_left = 2.0 +offset_top = 9.0 +offset_right = 62.0 +offset_bottom = 25.0 theme_override_colors/font_color = Color(2.7723312e-05, 0.60865843, 0.9772685, 1) theme_override_fonts/font = ExtResource("3_dxjfy") -theme_override_font_sizes/font_size = 8 +theme_override_font_sizes/font_size = 16 text = "TEMP" horizontal_alignment = 1 diff --git a/scenes/create_join_room.tscn b/scenes/create_join_room.tscn index 26899e4..912287a 100644 --- a/scenes/create_join_room.tscn +++ b/scenes/create_join_room.tscn @@ -4,16 +4,15 @@ [ext_resource type="Script" uid="uid://b1ogflafdte71" path="res://scripts/create_join_room.gd" id="1_k6yuv"] [node name="CreateJoinRoom" type="Node2D"] +position = Vector2(0, 42) script = ExtResource("1_k6yuv") [node name="JoinGameButton" parent="." instance=ExtResource("1_4km6l")] -offset_left = -16.0 -offset_top = 12.0 -offset_right = 16.0 -offset_bottom = 28.0 +offset_top = 17.0 +offset_bottom = 49.0 +metadata/_edit_use_anchors_ = true [node name="CreateGameButton" parent="." instance=ExtResource("1_4km6l")] -offset_left = -16.0 -offset_top = 40.0 -offset_right = 16.0 -offset_bottom = 56.0 +offset_top = 85.0 +offset_bottom = 117.0 +metadata/_edit_use_anchors_ = true diff --git a/scenes/game.tscn b/scenes/game.tscn index db00a15..5e243ed 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,12 +1,15 @@ -[gd_scene load_steps=2 format=3 uid="uid://cr8fi0e4r88s8"] +[gd_scene load_steps=3 format=3 uid="uid://cr8fi0e4r88s8"] [ext_resource type="PackedScene" uid="uid://cct663hb47yka" path="res://scenes/create_join_room.tscn" id="1_uwrxv"] +[ext_resource type="PackedScene" uid="uid://m542qwlp7hl7" path="res://scenes/board_screen.tscn" id="2_yqjtg"] [node name="Game" type="Node2D"] [node name="GameManager" type="Node" parent="."] [node name="Camera2D" type="Camera2D" parent="."] -zoom = Vector2(5, 5) [node name="CreateJoinRoom" parent="." instance=ExtResource("1_uwrxv")] +visible = false + +[node name="BoardScreen" parent="." instance=ExtResource("2_yqjtg")] diff --git a/scenes/red_chip.tscn b/scenes/red_chip.tscn new file mode 100644 index 0000000..65ad0de --- /dev/null +++ b/scenes/red_chip.tscn @@ -0,0 +1,14 @@ +[gd_scene load_steps=3 format=3 uid="uid://b4tujjdhmk4h"] + +[ext_resource type="Texture2D" uid="uid://ckmfi0cjgxgyk" path="res://assets/sprites/RedChip.png" id="1_qsflu"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_tfypd"] +radius = 12.0415945 + +[node name="RedChip" type="RigidBody2D"] + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = ExtResource("1_qsflu") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_tfypd") diff --git a/scenes/yellow_chip.tscn b/scenes/yellow_chip.tscn new file mode 100644 index 0000000..16554c0 --- /dev/null +++ b/scenes/yellow_chip.tscn @@ -0,0 +1,14 @@ +[gd_scene load_steps=3 format=3 uid="uid://lruk652t0xe5"] + +[ext_resource type="Texture2D" uid="uid://qy30emdgrk7o" path="res://assets/sprites/YellowChip.png" id="1_eu0sq"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_epi6l"] +radius = 12.0 + +[node name="YellowChip" type="RigidBody2D"] + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = ExtResource("1_eu0sq") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_epi6l") diff --git a/scripts/BoardScreen.cs b/scripts/BoardScreen.cs new file mode 100644 index 0000000..7e9f46d --- /dev/null +++ b/scripts/BoardScreen.cs @@ -0,0 +1,91 @@ +using Godot; +using System; +using System.Collections; +using System.Collections.Generic; + +public partial class BoardScreen : Node2D { + private const string RED_CHIP_PATH = "res://scenes/red_chip.tscn"; + private const string YELLOW_CHIP_PATH = "res://scenes/yellow_chip.tscn"; + private const int CHIP_SIZE = 24; + private const int CHIP_PADDING = 2; + private const int INIT_OFFSET = -(CHIP_SIZE + CHIP_PADDING) * 7 / 2; + + private TextureButton spwnRed; + private TextureButton spwnYlw; + private PackedScene redChip; + private PackedScene ylwChip; + + private RigidBody2D[,] chips = new RigidBody2D[6, 7]; // 6 rows 7 cols | 0, 0 is top left + + // Called when the node enters the scene tree for the first time. + public override void _Ready() { + spwnRed = GetNode("SpwnRed"); + spwnYlw = GetNode("SpwnYlw"); + + spwnRed.GetNode