boardscreen code front end

This commit is contained in:
Multiplyster
2025-12-03 19:13:23 -05:00
Unverified
parent 50dc7bdc1e
commit ab4ebaea42
11 changed files with 221 additions and 53 deletions

View File

@@ -1,6 +1,6 @@
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}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "connect4-moderator-observer", "connect4-moderator-observer.csproj", "{88C189D2-5C9A-411D-8713-291AC0841D8C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -9,11 +9,11 @@ Global
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
{88C189D2-5C9A-411D-8713-291AC0841D8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88C189D2-5C9A-411D-8713-291AC0841D8C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88C189D2-5C9A-411D-8713-291AC0841D8C}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU
{88C189D2-5C9A-411D-8713-291AC0841D8C}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU
{88C189D2-5C9A-411D-8713-291AC0841D8C}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU
{88C189D2-5C9A-411D-8713-291AC0841D8C}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -11,7 +11,7 @@ config_version=5
[application]
config/name="connect4-moderator-observer"
run/main_scene="uid://dcx5nvs0pa7me"
run/main_scene="uid://cr8fi0e4r88s8"
config/features=PackedStringArray("4.5", "C#", "Forward Plus")
config/icon="res://icon.svg"
@@ -26,3 +26,4 @@ project/assembly_name="connect4-moderator-observer"
[rendering]
textures/canvas_textures/default_texture_filter=0
renderer/rendering_method="gl_compatibility"

View File

@@ -1,10 +1,25 @@
[gd_scene load_steps=4 format=3 uid="uid://m542qwlp7hl7"]
[gd_scene load_steps=10 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"]
[ext_resource type="Texture2D" uid="uid://dlx02qat7j6lf" path="res://assets/sprites/AssetTileset.png" id="3_1tlhv"]
[ext_resource type="FontFile" uid="uid://c3jmev24lo6ci" path="res://assets/fonts/PixelOperator8.ttf" id="3_rjcmr"]
[ext_resource type="Texture2D" uid="uid://ckmfi0cjgxgyk" path="res://assets/sprites/RedChip.png" id="4_1hrcj"]
[ext_resource type="Texture2D" uid="uid://qy30emdgrk7o" path="res://assets/sprites/YellowChip.png" id="5_i2o8i"]
[ext_resource type="Texture2D" uid="uid://8un28mol7qow" path="res://assets/sprites/BoardTileMap.png" id="6_i2o8i"]
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_b3w8x"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_glh1q"]
texture = ExtResource("6_i2o8i")
texture_region_size = Vector2i(26, 26)
0:0/0 = 0
1:0/0 = 0
2:0/0 = 0
3:0/0 = 0
[sub_resource type="TileSet" id="TileSet_u1oi2"]
sources/0 = SubResource("TileSetAtlasSource_glh1q")
[node name="BoardScreen" type="Node2D"]
script = ExtResource("1_b3w8x")
@@ -13,14 +28,98 @@ script = ExtResource("1_b3w8x")
[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="Player1Card" type="Node2D" parent="."]
[node name="SpwnYlw" parent="." instance=ExtResource("1_tbc1w")]
offset_left = 512.0
[node name="Left" type="Sprite2D" parent="Player1Card"]
position = Vector2(-556, -300)
scale = Vector2(2, 2)
texture = ExtResource("3_1tlhv")
region_enabled = true
region_rect = Rect2(60, 4, 20, 24)
[node name="Center" type="Sprite2D" parent="Player1Card"]
position = Vector2(-482, -300)
scale = Vector2(6.75, 2)
texture = ExtResource("3_1tlhv")
region_enabled = true
region_rect = Rect2(80, 4, 16, 24)
[node name="Right" type="Sprite2D" parent="Player1Card"]
position = Vector2(-420, -300)
scale = Vector2(2, 2)
texture = ExtResource("3_1tlhv")
region_enabled = true
region_rect = Rect2(96, 4, 8, 24)
[node name="RedChip" type="Sprite2D" parent="Player1Card/Right"]
position = Vector2(-7, 6)
scale = Vector2(0.25, 0.25)
texture = ExtResource("4_1hrcj")
[node name="Name" type="Label" parent="Player1Card"]
offset_left = -530.0
offset_top = -312.0
offset_right = -428.0
offset_bottom = -296.0
theme_override_fonts/font = ExtResource("3_rjcmr")
text = "Player 1"
[node name="Status" type="Label" parent="Player1Card"]
offset_left = -529.0
offset_top = -292.0
offset_right = 576.0
offset_bottom = -260.0
offset_right = -427.0
offset_bottom = -284.0
theme_override_colors/font_color = Color(1, 0, 0, 1)
theme_override_fonts/font = ExtResource("3_rjcmr")
theme_override_font_sizes/font_size = 8
text = "NOT READY"
[node name="Player2Card" type="Node2D" parent="."]
[node name="Left" type="Sprite2D" parent="Player2Card"]
position = Vector2(-556, -228)
scale = Vector2(2, 2)
texture = ExtResource("3_1tlhv")
region_enabled = true
region_rect = Rect2(60, 4, 20, 24)
[node name="Center" type="Sprite2D" parent="Player2Card"]
position = Vector2(-482.5, -228)
scale = Vector2(6.6875, 2)
texture = ExtResource("3_1tlhv")
region_enabled = true
region_rect = Rect2(80, 4, 16, 24)
[node name="Right" type="Sprite2D" parent="Player2Card"]
position = Vector2(-421, -228)
scale = Vector2(2, 2)
texture = ExtResource("3_1tlhv")
region_enabled = true
region_rect = Rect2(96, 4, 8, 24)
[node name="YellowChip" type="Sprite2D" parent="Player2Card/Right"]
position = Vector2(-7, 6)
scale = Vector2(0.25, 0.25)
texture = ExtResource("5_i2o8i")
[node name="Label" type="Label" parent="Player2Card"]
offset_left = -531.0
offset_top = -240.0
offset_right = -429.0
offset_bottom = -224.0
theme_override_fonts/font = ExtResource("3_rjcmr")
text = "Player 2"
[node name="Status" type="Label" parent="Player2Card"]
offset_left = -530.0
offset_top = -220.0
offset_right = -428.0
offset_bottom = -212.0
theme_override_colors/font_color = Color(1, 0, 0, 1)
theme_override_fonts/font = ExtResource("3_rjcmr")
theme_override_font_sizes/font_size = 8
text = "NOT READY"
[node name="TileMap" type="TileMap" parent="."]
tile_set = SubResource("TileSet_u1oi2")
format = 2

View File

@@ -1,7 +1,7 @@
[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"]
[ext_resource type="PackedScene" uid="uid://cct663hb47yka" path="res://scenes/create_join_room.tscn" id="1_yqjtg"]
[ext_resource type="PackedScene" uid="uid://m542qwlp7hl7" path="res://scenes/board_screen.tscn" id="2_lnu2h"]
[node name="Game" type="Node2D"]
@@ -9,7 +9,7 @@
[node name="Camera2D" type="Camera2D" parent="."]
[node name="CreateJoinRoom" parent="." instance=ExtResource("1_uwrxv")]
[node name="CreateJoinRoom" parent="." instance=ExtResource("1_yqjtg")]
visible = false
[node name="BoardScreen" parent="." instance=ExtResource("2_yqjtg")]
[node name="BoardScreen" parent="." instance=ExtResource("2_lnu2h")]

View File

@@ -1,11 +1,13 @@
[gd_scene load_steps=3 format=3 uid="uid://b4tujjdhmk4h"]
[gd_scene load_steps=4 format=3 uid="uid://b4tujjdhmk4h"]
[ext_resource type="Texture2D" uid="uid://ckmfi0cjgxgyk" path="res://assets/sprites/RedChip.png" id="1_qsflu"]
[ext_resource type="Script" uid="uid://dd5nu6037qsr0" path="res://scripts/red_chip.gd" id="1_tfypd"]
[sub_resource type="CircleShape2D" id="CircleShape2D_tfypd"]
radius = 12.0415945
radius = 14.0
[node name="RedChip" type="RigidBody2D"]
script = ExtResource("1_tfypd")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1_qsflu")

View File

@@ -1,11 +1,13 @@
[gd_scene load_steps=3 format=3 uid="uid://lruk652t0xe5"]
[gd_scene load_steps=4 format=3 uid="uid://lruk652t0xe5"]
[ext_resource type="Script" uid="uid://ddg7dv686sbrb" path="res://scripts/yellow_chip.gd" id="1_epi6l"]
[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
radius = 14.0
[node name="YellowChip" type="RigidBody2D"]
script = ExtResource("1_epi6l")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1_eu0sq")

View File

@@ -1,41 +1,58 @@
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 const int X_OFF = -(CHIP_SIZE + CHIP_PADDING) * 7 / 2;
private const int Y_OFF = 300;
private TextureButton spwnRed;
private TextureButton spwnYlw;
private PackedScene redChip;
private PackedScene ylwChip;
private Node2D player1Card;
private Node2D player2Card;
private PlayerData p1;
private PlayerData p2;
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);
// Node initialization
player1Card = GetNode<Node2D>("Player1Card");
player2Card = GetNode<Node2D>("Player2Card");
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) {
}
if(p1 != null) {
Label username = player1Card.GetNode<Label>("Name");
username.Text = p1.username;
if(p1.isReady) {
Label status = player1Card.GetNode<Label>("Status");
status.Text = "Ready!";
status.AddThemeColorOverride("font_color", Colors.LimeGreen);
}
}
if(p2 != null) {
Label username = player2Card.GetNode<Label>("Name");
username.Text = p2.username;
if(p2.isReady) {
Label status = player2Card.GetNode<Label>("Status");
status.Text = "Ready!";
status.AddThemeColorOverride("font_color", Colors.LimeGreen);
}
}
}
/*
* Determines if the column can have a new chip placed
@@ -48,16 +65,16 @@ public partial class BoardScreen : Node2D {
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)
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);
@@ -66,13 +83,12 @@ public partial class BoardScreen : Node2D {
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);
newNode.Position = new Vector2(X_OFF + (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);
@@ -81,11 +97,33 @@ public partial class BoardScreen : Node2D {
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);
newNode.Position = new Vector2(X_OFF + (CHIP_SIZE + CHIP_PADDING) * col, -(CHIP_SIZE + CHIP_PADDING) * 7);
AddChild(newNode);
chips[row, col] = newNode;
}
private void setPlayerCardScale(float x, Node2D playerCard) {
Sprite2D cardCenter = playerCard.GetNode<Sprite2D>("Center");
Sprite2D cardRight = playerCard.GetNode<Sprite2D>("Right");
float offX = 16 * x / 2 - 16;
cardCenter.Scale = new Vector2(x, 2);
cardCenter.Position += new Vector2(offX, 0);
cardRight.Position += new Vector2(offX * 2, 0);
}
}
enum Direction
{
UP,
UP_RIGHT,
RIGHT,
DOWN_RIGHT,
DOWN,
DOWN_LEFT,
LEFT,
UP_LEFT
}

12
scripts/red_chip.gd Normal file
View File

@@ -0,0 +1,12 @@
extends RigidBody2D
var color_ = "red";
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass

1
scripts/red_chip.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://dd5nu6037qsr0

12
scripts/yellow_chip.gd Normal file
View File

@@ -0,0 +1,12 @@
extends RigidBody2D
var color_ = "yellow";
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass

View File

@@ -0,0 +1 @@
uid://ddg7dv686sbrb