Board Scene: Chip spawning and basic error checking

This commit is contained in:
Jonathan-Cheng-RPI
2025-12-01 17:13:42 -05:00
Unverified
parent 13bf28712e
commit 2f87a280a2
17 changed files with 283 additions and 17 deletions
Vendored
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 636 B

+40
View File
@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ckmfi0cjgxgyk"
path="res://.godot/imported/RedChip.png-87cfb9e74b846c07f18c0c7fe300f504.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/sprites/RedChip.png"
dest_files=["res://.godot/imported/RedChip.png-87cfb9e74b846c07f18c0c7fe300f504.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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
Binary file not shown.

After

Width:  |  Height:  |  Size: 668 B

+40
View File
@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://qy30emdgrk7o"
path="res://.godot/imported/YellowChip.png-a8245744c0582bab34b9b96583a57ec0.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/sprites/YellowChip.png"
dest_files=["res://.godot/imported/YellowChip.png-a8245744c0582bab34b9b96583a57ec0.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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
+8
View File
@@ -0,0 +1,8 @@
<Project Sdk="Godot.NET.Sdk/4.5.1">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net9.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<RootNamespace>connect4moderatorobserver</RootNamespace>
</PropertyGroup>
</Project>
+19
View File
@@ -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
+10 -1
View File
@@ -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
+26
View File
@@ -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
+8 -6
View File
@@ -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
+7 -8
View File
@@ -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
+5 -2
View File
@@ -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")]
+14
View File
@@ -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")
+14
View File
@@ -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")
+91
View File
@@ -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<TextureButton>("SpwnRed");
spwnYlw = GetNode<TextureButton>("SpwnYlw");
spwnRed.GetNode<Label>("Label").Text = "Red";
spwnYlw.GetNode<Label>("Label").Text = "Ylw";
spwnRed.Pressed += () => spawnRed(0);
spwnYlw.Pressed += () => spawnYellow(0);
redChip = GD.Load<PackedScene>(RED_CHIP_PATH);
ylwChip = GD.Load<PackedScene>(YELLOW_CHIP_PATH);
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta) {
}
/*
* Determines if the column can have a new chip placed
* Will return -1 if invalid
* or
* Will return row of board in which chip can be placed
*/
public int canPlaceOnCol(int col) {
if(col < 0 || col > 6) // Col out of range
return -1;
return getNextAvailRow(col);
}
public int getNextAvailRow(int col) {
for(int i = chips.GetLength(0) - 1; i >= 0; i--) { // Start at bottom
if(chips[i, col] == null)
return i;
}
return -1;
}
private void spawnRed(int col) {
int row = canPlaceOnCol(col);
if(row == -1) {
GD.Print("Invalid Placement!");
return;
}
GD.Print("Spawn Red!");
RigidBody2D newNode = redChip.Instantiate<RigidBody2D>();
newNode.Position = new Vector2(INIT_OFFSET + (CHIP_SIZE + CHIP_PADDING) * col, -(CHIP_SIZE + CHIP_PADDING) * 7);
AddChild(newNode);
chips[row, col] = newNode;
}
private void spawnYellow(int col) {
int row = canPlaceOnCol(col);
if(row == -1) {
GD.Print("Invalid Placement!");
return;
}
GD.Print("Spawn Yellow!");
RigidBody2D newNode = ylwChip.Instantiate<RigidBody2D>();
newNode.Position = new Vector2(INIT_OFFSET + (CHIP_SIZE + CHIP_PADDING) * col, -(CHIP_SIZE + CHIP_PADDING) * 7);
AddChild(newNode);
chips[row, col] = newNode;
}
}
+1
View File
@@ -0,0 +1 @@
uid://dg5jt0o0r0v3r