From c20fd855676052b135e7c99af9800af86ad81060 Mon Sep 17 00:00:00 2001 From: Andrew Tang Date: Mon, 4 Jul 2022 00:13:15 +0800 Subject: [PATCH 1/9] Added D10 and easier die selection --- .../DiceRoller/DiceRoller.tscn | 1 + .../DiceRoller/Die.gd | 23 ++--------- .../DiceRoller/DieManager.gd | 40 +++++++++++++++++-- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/Phase2/Godot ===(Game Code)===/DiceRoller/DiceRoller.tscn b/Phase2/Godot ===(Game Code)===/DiceRoller/DiceRoller.tscn index 73da74a..15b38bb 100644 --- a/Phase2/Godot ===(Game Code)===/DiceRoller/DiceRoller.tscn +++ b/Phase2/Godot ===(Game Code)===/DiceRoller/DiceRoller.tscn @@ -7,6 +7,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 script = ExtResource( 1 ) +desiredDice = [ 20, 7, 10 ] [node name="ColorRect" type="ColorRect" parent="."] anchor_right = 1.0 diff --git a/Phase2/Godot ===(Game Code)===/DiceRoller/Die.gd b/Phase2/Godot ===(Game Code)===/DiceRoller/Die.gd index 2f7be5b..3ddab3d 100644 --- a/Phase2/Godot ===(Game Code)===/DiceRoller/Die.gd +++ b/Phase2/Godot ===(Game Code)===/DiceRoller/Die.gd @@ -4,15 +4,8 @@ extends Button class_name Die -#array of valid number of faces -var dieTypes = [4, 6, 8, 10, 12, 20] - #value of selected die type var numFaces: int - -#bool will be used to check if a valid die type was chosen -var validNumFaces = false - #Class constructor func _init(value): numFaces = value @@ -21,18 +14,8 @@ func _init(value): func rollDie(): randomize() - #check if selected die type exists in dieTypes array - for value in dieTypes: - if value == numFaces: - validNumFaces = true - - #if the selected die type exists, we can roll an integer value based on the number of sides. - if validNumFaces: - var rolledNum - rolledNum = randi() % numFaces + 1 - return rolledNum - else: - print("You do not have a valid number of sides on the die!") - return + var rolledNum + rolledNum = randi() % numFaces + 1 + return rolledNum diff --git a/Phase2/Godot ===(Game Code)===/DiceRoller/DieManager.gd b/Phase2/Godot ===(Game Code)===/DiceRoller/DieManager.gd index 8f34f01..d7bc50d 100644 --- a/Phase2/Godot ===(Game Code)===/DiceRoller/DieManager.gd +++ b/Phase2/Godot ===(Game Code)===/DiceRoller/DieManager.gd @@ -5,6 +5,14 @@ extends Control export var desiredDice = [20, 8] +var validDieTypes = [4, 6, 8, 10, 12, 20] + + +#boolean for if a percentageroll is taking place +#we need a boolean for this because the way a percentage roll is calculated +#with two D10s is different than if one were using other dice +var isPercentageRoll = false + #diceUsed holds the dice objects that are rolled var diceUsed = [] @@ -29,7 +37,15 @@ var degreeOfSuccess #Load the diceInPlay array func _ready(): for elem in desiredDice: - diceInPlay.append(Die.new(elem)) + if elem in validDieTypes: + diceInPlay.append(Die.new(elem)) + + #conditional to check if two D10s are being used + #if so, we know that a percentage roll is taking place + if len(desiredDice) == 2 && desiredDice[0] == 10 && desiredDice[1] == 10: + isPercentageRoll = true + + #This is the function that returns the percentage of a rolled die (rolled val / total sides) #The UML showed that this function only had one parameter, "inputedDie," so I assumed that @@ -37,12 +53,23 @@ func _ready(): #As a result, I would get the total sides by ensuring that the inputedDie corresponds to the die at index 0 #of the diceInPlay array. func returnDiePercentage(inputedDie): + var totalSides = diceInPlay[0].numFaces #ensuring we don't lose the die objects in memory by storing them in another array diceUsed.append(diceInPlay[0]) diceInPlay.remove(0) - + + #Checks if a percentageroll is being done + if isPercentageRoll: + + #This conditional is used to detemrine if the rolled value is + #for the tens or ones digit + if (len(diceUsed) == 1): + return float(inputedDie % 10) / 10.0 + else: + return float(inputedDie % 10) / 100.0 + var result = float(inputedDie) / float(totalSides) return result @@ -102,8 +129,13 @@ func _on_Die_button_down(): #increment denominator denominator += 1 - #result is average of sum of percentages - var result = sumOfPercentages / denominator + var result + if isPercentageRoll: + #Percentage roll result remains the sum of the rolls + result = sumOfPercentages + else: + #result is average of sum of percentages otherwise + result = sumOfPercentages / denominator passedRoll = (result >= neededPercentageToPass) From 4f788de0c7676fec60624f50be6284b4f2e419ac Mon Sep 17 00:00:00 2001 From: Andrew Tang <90939405+TangoDevelopments@users.noreply.github.com> Date: Sun, 3 Jul 2022 13:05:05 -0400 Subject: [PATCH 2/9] Delete .DS_Store --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 14c586a0622dbe3a9b2181333e67d7620ae6d6cf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK&uiN-6n;vx#-Fvi(U&77>ZgIB5~piO7R8R(v$S5stGiNyU0< zK%vLjr;vJknL3WMrEKT;8yVoatI=E9qh0FJ-2AB+5ndKM(9IuOU=gj-0i94p1r4ZW z=K41G@}AuGVy<|0Uv4}p&f-judljE$X)$UxuSI30`e?Q0)x0(DC_GV^sr)Pa9P{ZAQ?Wx`dI#L3Q%ZiJj)$I~5_Fw71{?#9frl_)cP?-3Aw@3N zG2j^ZFBstcK|&b=i={!mb)eB#0ALkvEwK5gk!z&Iz+!0-5r{CQKvOF06+@VE_@&JY zES3gMISG6D5cbK!-cW>oI>wheokU>JwT=PDz#;=Hrd#Lpzjycjf3e8*90QJle~JN7 z?S|bBKFOY~OCQH)t%QDovT$B$@U{eoK8lgcNAWsT3;dD|U|_K{2oJ>l2xuBy;~4m( G4EzN6Re%`) From c00b24c60ac3cc9a39a93b79cf3352241b1c9186 Mon Sep 17 00:00:00 2001 From: Andrew Tang <90939405+TangoDevelopments@users.noreply.github.com> Date: Sun, 3 Jul 2022 13:05:16 -0400 Subject: [PATCH 3/9] Delete .DS_Store --- Phase2/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Phase2/.DS_Store diff --git a/Phase2/.DS_Store b/Phase2/.DS_Store deleted file mode 100644 index 0dc27f25717df5318ec5857580266ab74e20efce..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK(TWo>6us$IciOtp2N(Jx1bk5_+ODg(h)}y#S|EM4~&6+C+6C^5Bf+Dw3ZV*R!u! z$(Arr=srRUD5D`|d&x>`SKt(I3jAvd@V8r`9=_WgUig01AWT$WiorXzgqspjSsqb%J^7MP!xm{oc}3EEA-KE#M4aIsqyIpWe1r$Gt4-!jtA2{Pt9-Bs|Fn;q!Pn>DMprsx%McbU4z4I2xkK%l$Zw)TFD%X_RTMZz{ZsSLxRq z)9Kds?WSzEZ_b)>y0g`4%IzDsX0wX7dHMRCC;hj{QK~**jxd3JSlfoh6JQNatz(o8 zk`VLYPESpK=a14vr3c_LzeYZmPhr8|Bg~Xu`esXu{G;|X7@*(WV z!roAX9v%Hl-JC?npi7+sPJu-Q*34_2&;R?szW* Date: Sun, 3 Jul 2022 13:05:28 -0400 Subject: [PATCH 4/9] Delete .DS_Store --- Phase2/Godot ===(Game Code)===/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Phase2/Godot ===(Game Code)===/.DS_Store diff --git a/Phase2/Godot ===(Game Code)===/.DS_Store b/Phase2/Godot ===(Game Code)===/.DS_Store deleted file mode 100644 index b4ddea2283a6b0e266d88e426d3962ff829f1bc1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKL2uJA6n^f?nyy0X0i<1!B5|#t9Rq>5l&%xnVH}nT4uDG1R$D|CM@_N}Rh4>% z|G;11$}i!+aDwmIo|LBDg#$v!ud+YK{+?g*rGAcyNDT5xkEl&V4hmy^2h|4SaV~3C zGd(S!P;;D+qzJz$&DPkq!zy4E_}3KRwYx(@3Tcd0TUx(IksJq+3^2~g;Ty`=U&_$B z!6zuv#Q1y|ztK!eErR?v}F}NXO z9jl1>Dqq~I@LS;JNZ1*C5};3?)}sg(r5vR}ufQtkCHQ!ED^y~=+>xLW&D13RnfK0%Zj_Ke#B2eS=GlDs`YzM*v_Q z-OAAB&jt2z4fYK#HDUxNv@1}%3UkB|+8zC_;q?tJHEMSf=I|j*WMNJyLPf{?uA-CZ zYqYghz$&n+z?Qyj^ZtK$^Z9?($zE9ntOEa)0-`?jh66m3*<05hj`vy@?QP%_xcD)3ho_zl Date: Mon, 11 Jul 2022 01:16:34 +0800 Subject: [PATCH 5/9] Complete DiceRoller Singleton Version Created script: "DiceRoller.gd" to be the only dice script attached to a node and will act as a singleton. A single DieManager object is created in this script. The DieManager's values can be changed and methods can be called through the DiceRoller Script --- .../DiceRoller/DiceRoller.gd | 69 +++++++ .../DiceRoller/DiceRoller.tscn | 11 +- .../DiceRoller/Die.gd | 7 +- .../DiceRoller/DieManager.gd | 172 ++++++++---------- .../DiceRoller/project.godot | 14 +- 5 files changed, 162 insertions(+), 111 deletions(-) create mode 100644 Phase2/Godot ===(Game Code)===/DiceRoller/DiceRoller.gd diff --git a/Phase2/Godot ===(Game Code)===/DiceRoller/DiceRoller.gd b/Phase2/Godot ===(Game Code)===/DiceRoller/DiceRoller.gd new file mode 100644 index 0000000..858415a --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/DiceRoller/DiceRoller.gd @@ -0,0 +1,69 @@ +#This script is for the overarching node that will contain the diemanager singleton +#It should be the only one of the die scripts that is attached onto a node. + +extends Control + +#desired dice types and needed percentage to pass are selected by game/user +#desiredDice takes an int array representing the # sides on the die/dice +#neededPercentageToPass takes a float that +export var desiredDice: Array +export var neededPercentageToPass: float + +#Define dieManager variable +var dieManager + +func _ready(): + #create diemanager object + dieManager = DieManager.new(desiredDice, neededPercentageToPass) + +#function gets the result of the roll(s) and shows it in the UI +func _on_Die_button_down(): + #rollDice function returns an array with the following elements in the following positions: + #rollDice result: [[rolledValues], percentRolled, passResult, neededPercent, degreeOfSuccess, dice] + var result = dieManager.rollDice() + + + #assigning variable names to each of them for better clarity + var rolledValues = result[0] + var percentRolled = result[1] + var passResult = result[2] + var neededPercent = result[3] + var degreeOfSuccess = result[4] + var dice = result[5] + + + #Check if passed or not + if passResult: + $Outcome.text = "Successful Roll!" + else: + $Outcome.text = "Failed Roll!" + + var diceResultText = "Rolled Values:\n" + + #Prints the integer calues of each die rolled in the form: "D(num faces): (value rolled)" + for i in range(dice.size()): + diceResultText += ("D" + str(dice[i]) + ": " + str(rolledValues[i]) + "\n") + + #changing labels on screen + $RolledValues.text = diceResultText + $PercentNeeded.text = "Percent Needed to Pass: " + str(neededPercent * 100) + "%" + $PercentRolled.text = "Percent Rolled: " + str(percentRolled * 100) + "%" + $DegreeOfSuccess.text = "Degree of Success: " + str(degreeOfSuccess * 100) + "%" + + #revealing labels to user + $Outcome.show() + $RolledValues.show() + $PercentNeeded.show() + $PercentRolled.show() + $DegreeOfSuccess.show() + + +#Calls the cleardata method for the diemanager and hides the text on screen +func _on_Reset_button_down(): + $Outcome.hide() + $PercentNeeded.hide() + $PercentRolled.hide() + $DegreeOfSuccess.hide() + $RolledValues.hide() + dieManager.clearData() + dieManager.setDieManager(desiredDice, neededPercentageToPass) diff --git a/Phase2/Godot ===(Game Code)===/DiceRoller/DiceRoller.tscn b/Phase2/Godot ===(Game Code)===/DiceRoller/DiceRoller.tscn index 15b38bb..49188e8 100644 --- a/Phase2/Godot ===(Game Code)===/DiceRoller/DiceRoller.tscn +++ b/Phase2/Godot ===(Game Code)===/DiceRoller/DiceRoller.tscn @@ -1,13 +1,13 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=2 format=2] -[ext_resource path="res://DieManager.gd" type="Script" id=1] -[ext_resource path="res://Die.gd" type="Script" id=2] +[ext_resource path="res://DiceRoller.gd" type="Script" id=1] [node name="DieManager" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 script = ExtResource( 1 ) -desiredDice = [ 20, 7, 10 ] +desiredDice = [ 10, 4, 6, 20 ] +neededPercentageToPass = 0.4 [node name="ColorRect" type="ColorRect" parent="."] anchor_right = 1.0 @@ -24,7 +24,6 @@ margin_top = 2.0 margin_right = 92.0 margin_bottom = 91.0 text = "Roll Die/Dice" -script = ExtResource( 2 ) [node name="RolledValues" type="Label" parent="."] visible = false @@ -95,4 +94,4 @@ margin_bottom = 469.0 text = "Reset" [connection signal="button_down" from="Die" to="." method="_on_Die_button_down"] -[connection signal="pressed" from="Reset" to="." method="_on_Reset_pressed"] +[connection signal="button_down" from="Reset" to="." method="_on_Reset_button_down"] diff --git a/Phase2/Godot ===(Game Code)===/DiceRoller/Die.gd b/Phase2/Godot ===(Game Code)===/DiceRoller/Die.gd index 3ddab3d..e2c7c66 100644 --- a/Phase2/Godot ===(Game Code)===/DiceRoller/Die.gd +++ b/Phase2/Godot ===(Game Code)===/DiceRoller/Die.gd @@ -1,11 +1,11 @@ #Die class - -extends Button +extends Node2D class_name Die #value of selected die type var numFaces: int + #Class constructor func _init(value): numFaces = value @@ -19,3 +19,6 @@ func rollDie(): return rolledNum +#Returns the number of faces on this die +func getNumFaces(): + return numFaces diff --git a/Phase2/Godot ===(Game Code)===/DiceRoller/DieManager.gd b/Phase2/Godot ===(Game Code)===/DiceRoller/DieManager.gd index d7bc50d..4605559 100644 --- a/Phase2/Godot ===(Game Code)===/DiceRoller/DieManager.gd +++ b/Phase2/Godot ===(Game Code)===/DiceRoller/DieManager.gd @@ -1,13 +1,17 @@ #This is the diemanager script that controls the rolling of the die/dice as well as calculates #the end result -extends Control +class_name DieManager -export var desiredDice = [20, 8] +extends Node2D + +#Array of the desired dice values to mod god wants +var desiredDice: Array + +#User can select the percentage needed for a successful roll +var neededPercentageToPass: float var validDieTypes = [4, 6, 8, 10, 12, 20] - - #boolean for if a percentageroll is taking place #we need a boolean for this because the way a percentage roll is calculated #with two D10s is different than if one were using other dice @@ -16,143 +20,109 @@ var isPercentageRoll = false #diceUsed holds the dice objects that are rolled var diceUsed = [] -#diceInPlay holds the die objects as well. -#This and diceUsed are essentially the same arrays (holding the dice objects), but I had to use -#two arrays due to the parameters in returnDiePercentage -var diceInPlay = [] - #rolledValues holds the integer value rolled from each die var rolledValues = [] -#User can select the percentage needed for a successful roll -export var neededPercentageToPass = .2 - #boolean based on whether the overall roll passed or not var passedRoll #float holding the degree of success (rolledVal - neededPercentageToPass) var degreeOfSuccess +#Constructor for diemanager class +func _init(dice, percent): + desiredDice = dice + neededPercentageToPass = percent + loadData() +#set values of diemanager +func setDieManager(dice, percent): + desiredDice = dice + neededPercentageToPass = percent + loadData() + #Load the diceInPlay array -func _ready(): +func loadData(): for elem in desiredDice: if elem in validDieTypes: - diceInPlay.append(Die.new(elem)) + diceUsed.append(Die.new(elem)) #conditional to check if two D10s are being used #if so, we know that a percentage roll is taking place if len(desiredDice) == 2 && desiredDice[0] == 10 && desiredDice[1] == 10: isPercentageRoll = true - - -#This is the function that returns the percentage of a rolled die (rolled val / total sides) -#The UML showed that this function only had one parameter, "inputedDie," so I assumed that -#was the rolled integer value. However, in order to find the percetage we need the total sides as well -#As a result, I would get the total sides by ensuring that the inputedDie corresponds to the die at index 0 -#of the diceInPlay array. +#Resets the data in the script +func clearData(): + isPercentageRoll = false + rolledValues = [] + desiredDice = [] + diceUsed = [] + neededPercentageToPass = 0 + +#Returns the percent value of an individual die +#Stores the rolled value in rolledValues func returnDiePercentage(inputedDie): + #In case this method is being called on no dice + if len(diceUsed) == 0: + push_error("Cannot roll without any dice!") + + var rolledVal = inputedDie.rollDie() - var totalSides = diceInPlay[0].numFaces - - #ensuring we don't lose the die objects in memory by storing them in another array - diceUsed.append(diceInPlay[0]) - diceInPlay.remove(0) + #add rolled integer value to array + rolledValues.append(rolledVal) #Checks if a percentageroll is being done if isPercentageRoll: - #This conditional is used to detemrine if the rolled value is #for the tens or ones digit - if (len(diceUsed) == 1): - return float(inputedDie % 10) / 10.0 - else: - return float(inputedDie % 10) / 100.0 - - var result = float(inputedDie) / float(totalSides) - return result + return float(rolledVal % 10) + return float(rolledVal) / float(inputedDie.numFaces) -#Function to show all of the results on screen -func showOnUI(passResult, percentRolled) -> void: - if passResult: - $Outcome.text = "Successful Roll!" - else: - $Outcome.text = "Failed Roll!" - - var diceResultText = "Rolled Values:\n" - - #Prints the integer calues of each die rolled in the form: "D(num faces): (value rolled)" - for i in range(diceUsed.size()): - diceResultText += ("D" + str(diceUsed[i].numFaces) + ": " + str(rolledValues[i]) + "\n") - - - #NOTE: degree of success is always calculated regardlesss of success/failure. Let me know if this should be changed - degreeOfSuccess = percentRolled - neededPercentageToPass - - #changing labels on screen - $RolledValues.text = diceResultText - $PercentNeeded.text = "Percent Needed to Pass: " + str(neededPercentageToPass * 100) + "%" - $PercentRolled.text = "Percent Rolled: " + str(percentRolled * 100) + "%" - $DegreeOfSuccess.text = "Degree of Success: " + str(degreeOfSuccess * 100) + "%" - - #revealing labels to user - $Outcome.show() - $RolledValues.show() - $PercentNeeded.show() - $PercentRolled.show() - $DegreeOfSuccess.show() +#Rolls all of the dice in diceUsed +#returns the average of all the percentages +func rollDice(): + #In case this method is being called on no dice + if len(diceUsed) == 0: + push_error("Cannot roll without any dice!") - -#function for when "roll" button is clicked -func _on_Die_button_down(): #denominator will equal the total number of dice rolled var denominator = 0 #sum of floats of all rolled die percentages var sumOfPercentages = 0 - #stores the rolled integer value of die in loop - var rolledVal + if isPercentageRoll: + sumOfPercentages += (returnDiePercentage(diceUsed[0]) / 10.0) + (returnDiePercentage(diceUsed[1]) / 100.0) + else: + for die in diceUsed: + sumOfPercentages += returnDiePercentage(die) + denominator += 1 + + var result = [] + + result.append(rolledValues) - #remember that the size of diceInPlay decrements by 1 each time returnDiePercentage is called - while diceInPlay.size() > 0: - rolledVal = diceInPlay[0].rollDie() - - #add rolled integer vaslue to array - rolledValues.append(rolledVal) - - #add percentage to sum - sumOfPercentages += returnDiePercentage(rolledVal) - - #increment denominator - denominator += 1 - - var result if isPercentageRoll: #Percentage roll result remains the sum of the rolls - result = sumOfPercentages + result.append(sumOfPercentages) else: - #result is average of sum of percentages otherwise - result = sumOfPercentages / denominator + if denominator == 0: + result.append(0) + #result is average of sum of percentages otherwise rounded to 2 decimcal places + + result.append(stepify((float(sumOfPercentages) / float(denominator)), 0.0001)) + + passedRoll = (result[1] >= neededPercentageToPass) +#NOTE: degree of success is always calculated regardlesss of success/failure. Let me know if this should be changed + degreeOfSuccess = result[1] - neededPercentageToPass + result.append(passedRoll) + result.append(neededPercentageToPass) + result.append(degreeOfSuccess) + result.append(desiredDice) - passedRoll = (result >= neededPercentageToPass) - - showOnUI(passedRoll, result) + #rollDice result: [[rolledValues], percentRolled, passResult, neededPercent, degreeOfSuccess, dice] return result - -#Reset stored values and text -func _on_Reset_pressed(): - $Outcome.hide() - $PercentNeeded.hide() - $PercentRolled.hide() - $DegreeOfSuccess.hide() - $RolledValues.hide() - #Fill diceInPlay again and empty diceUsed - for die in diceUsed: - diceInPlay.append(die) - diceUsed = [] - rolledValues = [] diff --git a/Phase2/Godot ===(Game Code)===/DiceRoller/project.godot b/Phase2/Godot ===(Game Code)===/DiceRoller/project.godot index cad39e9..b95a96b 100644 --- a/Phase2/Godot ===(Game Code)===/DiceRoller/project.godot +++ b/Phase2/Godot ===(Game Code)===/DiceRoller/project.godot @@ -9,13 +9,19 @@ config_version=4 _global_script_classes=[ { -"base": "Button", +"base": "Node2D", "class": "Die", "language": "GDScript", "path": "res://Die.gd" +}, { +"base": "Node2D", +"class": "DieManager", +"language": "GDScript", +"path": "res://DieManager.gd" } ] _global_script_class_icons={ -"Die": "" +"Die": "", +"DieManager": "" } [application] @@ -24,6 +30,10 @@ config/name="GodotDiceRoller_Andrew" run/main_scene="res://DiceRoller.tscn" config/icon="res://icon.png" +[autoload] + +DiceRoller="*res://DiceRoller.gd" + [physics] common/enable_pause_aware_picking=true From 3fbf2640da1a59e6bc5727b4b2748b72df59fefa Mon Sep 17 00:00:00 2001 From: Andrew Tang Date: Mon, 25 Jul 2022 02:29:27 +0800 Subject: [PATCH 6/9] Test Multiplayer --- .../Andrew_Multiplayer_Test/.import/.gdignore | 1 + ...n.png-487276ed1e3a0c39cad0279d744ee560.md5 | 3 + ....png-487276ed1e3a0c39cad0279d744ee560.stex | Bin 0 -> 1496 bytes .../Andrew_Multiplayer_Test/Network.gd | 35 +++++++++++ .../Andrew_Multiplayer_Test/Network_Setup.gd | 32 ++++++++++ .../Network_Setup.tscn | 58 ++++++++++++++++++ .../Andrew_Multiplayer_Test/Test.tscn | 6 ++ .../Andrew_Multiplayer_Test/default_env.tres | 7 +++ .../Andrew_Multiplayer_Test/icon.png | Bin 0 -> 3305 bytes .../Andrew_Multiplayer_Test/icon.png.import | 35 +++++++++++ .../Andrew_Multiplayer_Test/project.godot | 26 ++++++++ 11 files changed, 203 insertions(+) create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/.gdignore create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Test.tscn create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/default_env.tres create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/icon.png create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/icon.png.import create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/project.godot diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/.gdignore b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/.gdignore new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/.gdignore @@ -0,0 +1 @@ + diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 new file mode 100644 index 0000000..5328bc7 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 @@ -0,0 +1,3 @@ +source_md5="47313fa4c47a9963fddd764e1ec6e4a8" +dest_md5="26ea799ea0a3da9e753b3ebe822e0570" + diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex new file mode 100644 index 0000000000000000000000000000000000000000..71f69131f1bad5ac84f9f5fb77b8014d6f855868 GIT binary patch literal 1496 zcmV;}1t8#jQIRc$f~c)tQiw!~w%QUQ6exqX5cknk z0+d35DiDbTDuoE4>Lo>6B7>ey@m$S@5kjOuv{fWhh-@ho&(;2WkwS$K6`&Ldl|Us> zi4+J0k-+z7D#fx5bCy(4v8-W?7^7rF3d=UlIm}g3kr8v2*TVsYG0L(HsaUol6{$#J zzu%jyB(dI3x&O7SY0hEJfqi2jQf;@JF@lOwkr88**UM&PLd-R!kcy0;loU$Knm#_B zpssT<`uctM`T6EPm%A7K9*tSP|39fzMMT%Jh>GrWxv%zI|5WGxr!+(rs;IWI7+u$| ztA8kAM1hddg9IT6zY$?4T#831gq|cT869IJntT)|=01mwu*fe$Smy`ebi^HL+s-xg7chk284pq%~oy)o1W?`nc*zBC=zRt+_#M70<6PFG z6}tee5v>KVd&MI&-P+`h3e5&K^|-6M0EkEyjlf*9+`s@4^=sduefxeS9)KHW zxry#hT9*zlA+*bJIQpy4c0ZhsA-z^ z>#WBV&J`yU4D>m2?bqM)mFeH8@`b;@t{w3iXa*Wm8VHI_5p)5%2vTB$fYL+A6hukG z$!S`fHfaJP8lFT>jWhoL$`1ibnR*S{w;v;KO#Alr>y=RgAjwy$tV9ApAt(LXJMHJB z5CB9fl}q_biX|eNFsP!BlcI21)QL~UK@*6GVkMnytRt$6Bte>2l|jNPUTK0P)Fok~ z<8pRY5;Z~3$-3c)Ct*B>>n8U^6H%qzayG_@T0>t#DTYp>PAI07fWEaTdcB-^=q5<& z*tTB18j2DbF@k^@@+ev1QMg zL5#haz6F3%uU@HhjobH`e9qrvh%#pS={PAR-X0k%SWDWbr)+o y|M)fYRW9dto5g$WGgZ~$_?(~f&V283@;^HqstN$fY}?!b literal 0 HcmV?d00001 diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd new file mode 100644 index 0000000..1fbc43d --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd @@ -0,0 +1,35 @@ +extends Node + +const DEFAULT_PORT = 28960 +const MAX_CLIENTS = 6 + +var server = null +var client = null + +var ip_address = "" + +func _ready() -> void: + ip_address = IP.get_local_addresses()[3] + + for ip in IP.get_local_addresses(): + if ip.begins_with("192.168."): + ip_address = ip + + get_tree().connect("connected_to_server", self, "_connected_to_server") + get_tree().connect("server_disconnected", self, "_server_disconnected") + +func _create_server() -> void: + server = NetworkedMultiplayerENet.new() + server.create_server(DEFAULT_PORT, MAX_CLIENTS) + get_tree().set_network_peer(server) + +func _join_server() -> void: + client = NetworkedMultiplayerENet.new() + client.create_client(ip_address, DEFAULT_PORT) + get_tree().set_network_peer(client) + +func _connected_to_server() -> void: + print("Successfully connected to the server") + +func _server_disconnected() -> void: + print("Disconnected from the server") diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd new file mode 100644 index 0000000..426b3d1 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd @@ -0,0 +1,32 @@ +extends Control + + +onready var multiplayer_config_ui = $Multiplayer_Configure +onready var server_ip_address = $Multiplayer_Configure/Server_IP_Address +onready var device_ip_address = $CanvasLayer/Device_IP_Address + + + +# Called when the node enters the scene tree for the first time. +func _ready(): + get_tree().connect("network_peer_connected", self, "_player_connected") + get_tree().connect("network_peer_disconnected", self, "_player_disconnected") + get_tree().connect("connected_to_server", self, "_connected_to_server") + + device_ip_address.text = Network.ip_address + +func _player_connected(id) -> void: + print("Player " + str(id) + "connected") + +func _player_disconnected(id) -> void: + print("Player " + str(id) + "disconnected") + +func _on_Create_Server_pressed(): + multiplayer.config_ui.hide() + Network._create_server() + +func _on_Join_Server_pressed(): + if server_ip_address.text != "": + multiplayer_config_ui.hide() + Network.ip_address = server_ip_address.text + Network._join_server() diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn new file mode 100644 index 0000000..49caf72 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn @@ -0,0 +1,58 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Network_Setup.gd" type="Script" id=1] + +[node name="Network_Setup" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 1 ) + +[node name="Multiplayer_Configure" type="Control" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="Create_Server" type="Button" parent="Multiplayer_Configure"] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -125.0 +margin_top = 21.0 +margin_right = 125.0 +margin_bottom = 121.0 +text = "Create Server" + +[node name="Join_Server" type="Button" parent="Multiplayer_Configure"] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -125.0 +margin_top = -129.0 +margin_right = 125.0 +margin_bottom = -29.0 +text = "Join Server" + +[node name="Server_IP_Address" type="LineEdit" parent="Multiplayer_Configure"] +margin_left = 389.0 +margin_top = 82.0 +margin_right = 639.0 +margin_bottom = 132.0 +text = "Enter IP Address" +align = 1 + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="Device_IP_Address" type="Label" parent="CanvasLayer"] +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = -1.0 +margin_top = -76.0 +margin_right = -1.0 +margin_bottom = -26.0 +align = 1 +valign = 1 + +[connection signal="pressed" from="Multiplayer_Configure/Create_Server" to="." method="_on_Create_Server_pressed"] +[connection signal="pressed" from="Multiplayer_Configure/Join_Server" to="." method="_on_Join_Server_pressed"] diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Test.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Test.tscn new file mode 100644 index 0000000..45a4ba7 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Test.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Network.gd" type="Script" id=1] + +[node name="Node" type="Node"] +script = ExtResource( 1 ) diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/default_env.tres b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/default_env.tres new file mode 100644 index 0000000..20207a4 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/default_env.tres @@ -0,0 +1,7 @@ +[gd_resource type="Environment" load_steps=2 format=2] + +[sub_resource type="ProceduralSky" id=1] + +[resource] +background_mode = 2 +background_sky = SubResource( 1 ) diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/icon.png b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..c98fbb601c83c81ec8c22b1dba7d1d57c62b323c GIT binary patch literal 3305 zcmVNc=P)Px>qe(&U$es`gSqKCHF-lq>v1vga#%UF>TTrLR zW%{UNJKZi|Pj@Rc9GyPBD1CamMMf6SL~V^ag9~Vzut^L^0!Tv0LK0FTdnJ`x->EF(MZIP5kY*1-@^egP~7mH>({qi7{6 zQF;bN-XMq~+RzA8lI9AtJuz@PY*+{SP-Gbd@mZ(r*eE&`XO5!C>w#-pcmS28K^qzY zfTGCjor*I@ltgKb03nh#Fh$KpDL=o}gj-g4v6{}ZR1*mvXv?|gEA&Yr#r;Zw*d zUabIx8iHf+WoIO_c11Ba&!34XihSMF&C#YFDjU0)mmbXz3ex!D&t9UYp>;&R%(O(_ z*z^;&A84SWzKiQpqsdQ+Vs?rFS(f?R;c8xg_ft;Roec_~1KsVww}wzq5D}*5x6k|& zf~2A3@L4|ix|Q=L>rnmKE;B3UB=OMQxAK$Ce;LvDp?hwn-{Rn}Uo~U4IXTs4V%MQY zCWULcZFU0R%gbU;_Ef(A#76r1%|YWis0t`9$R{cyjFnsV(POrI)SGQi-l{mu{e?5R zepcp?AQ54D3g_mswd@RLn{z~;^Cl}>%j@}TWixL+audY``MmSV{-E(3R0Ws^U9%mk zmAond;N8k*{(f!}e^~d(i1Hq@jdv@XN2MLAl}3yaECf{nz5N3KMCjDCFzB_7)gkjj z>2Z={^e74l7u>P4oo1{Kc~sgFI`xP#f`uR}z_p~qLwws5)h)eLxAX=?+fB2_6kG)a zeE3U}YSi;Qc}gq*;kw|Tu5Oy{F)l`0;$$RA6)@d^I9>n9N^W1g0D!WJYJT&d@6p`W zfmWmD=^x$2@|)+=&@n(wn<-#M#zIY-iH42=UU>XI3i7l0^?#ILwb@CU63f5b_jeS| zn+d@CpB>^?Ti*1WuHSaRniWO-^Xl8!b+D0stAl$BQjr8G`KX-vGpCc0lEAKmjl6lN z5r?ddL)6hBi2|!`NM+@MRO*^qsi>~y`%4$%P+-S_M#8ibt8Pf;m7O23?cF^-X$52l zEV@3AM^`Q9vy(=)?W+gi)8lPCP&k!)Z(Bsa#m@S7j#1gzJx&pQ!yzlYvA==iExkN@ zTMnz!68Wg=9Ius~p?A=A>P(5$@#w1MG`6<$`Il8=(j0RI#KlIj>!qL4)MMjk|8*3* zbL8w!iwnbSb<*17eb=8TBt(Uv*Qz*e>>p9CRtapnJD-#&4Xd8ojIpD~Yk&6&7;_U` z|L{sgNzJAYPkIOsaN5{^*@Xva?HTkC9>DHY*!1B^L`lv1hgXhC$EO1BSh9fYXU*VG zpVwjRvs^m2ml?)B3xE2&j_YU5;Ep8=e75zefN3cSw04`>U3D&~3|AIJAJnEseqE*p>uF=1Cv$SfvI z!(+vnRMj+4vb)@8Tb~MW$}-RYemjyN^W@U3pfWj;cyehLk|6W*KkUFMkM3W9AE!Wb zTL-_}Udr6GXl}`!5;P_!3b*7=VQyM9zuR6)b6dxl?fo)@-u`$$Pu#bHB*W+#Gp!_Y z*ZdUbq#B3_QPbElK4*QE)$x+;qpGazKD1C!=jx=^ta=2+!&oRjmg4Jf{ z?T`J78TjoBD9Y&OtwFEhrIq<48uS2IEEbY8C$TVd5`X!kj*`Qd7RI`3elib!C*xb1 z(UIgPMzT12GEcpEly0*vU|ugqP(r~!E}l-JK~G&>9S_|9Aj@uD&azvVQ&RF4YZp!> zJ3hi|zlabu5u>=y+3^vqT{xAJlDCHFJ#hbn)Ya9IXwdWH;_1O)ef$at)k@qrEf%ZQ z%DU&)(a_KUxMpn2t6Mm@e?LVzaUT6LCWo=>;TzfYZ~+;U!#wJXa^g66-~d}*-Gas9 zGQt`f8d&$-daPC}H%^NkiV}?n<5oawj2=M{sHv&JXl(bWFDox6HP$o6KRY=Jl_;PR zMP?^QdD4vyrL3&XqugjTQd3idAPA(!=*P?c_!Z!e`f9aWuk~t4qQew;9IwMq>%w#92+*iNN#Qp zadB}J6)j=I#urf#czO3X!C*Z&LD5rfCLY^S$>ZP6}eFW#%-2L)+t{`cPyqLD6))yK1?m7F>6=?Y&8f)>3zbH1O)cT}QNtB4KL(A@1i zMzF88gDrb&hn~H`?o`-XUeDI@dXfwwboAS>*qvV6UMhkfzO~q$V+s%8loj4P(&9H= ze`sC`uI?L9L4e;YK&2A7XF)0}u1lh+%Z$S*Q{ORwtSHpAyWYpI>bqzU!p`gqlf$*l zO^*g(+T?Hq0n%ebkyIin(R#FM6&9;^6WJU5R)By&tZQ6PV zS^MWhqtcj}7)kON#>?4Gv(K#2=6mv)5;@W->l(1q*>9t&xfesIn$&3j4WxkffXaq0 zwwBkAD2vjoi4E8CK;cwoC3#wO!|}v-XOJ`obIo05{&DMQIRyHAd5@%-0xA%uA0UK2qng>xb(kvMzX)7t^ z);-|T`mgSsHKM$+a{!w|Mt5QLwD>sA+;u-+k%z_ZL?el$#&|kX?ygLfm zxZ^Fo^bOhx)w*6In?vS{Q|uk08cKRK}t+0ukQSCOyP$^HEC+zzX51M#=e-?*xHWMDRcLdIV41daHy{HimwDo z6!_O=*(}MK!YeyJpmgu(cF1tpEv}m;0s8{4z4HlHyMxDncn8zs!g+OXEk`CeEj}9N zq#Ag1$#jyV_5AjYQg*!mS->;`S^;iU)ih9D+eks)H2z`1RHny;F<^CEwk+}d^k^Ph zl);*XQ|ayL;rZWh=fA(G2#AJz1&r&as9I8S@9m3Owftrb5n*)pTluK^9LHOFIo{G2 zG}l$9R*{<+L2hCsOJ~Lt6Q-rRub*8X{*4{)e}>%=_&DxOFeq1LRia4Yyj*Tyynw>F zxkKf(MiaG0*L|V-^Zhtvg-(-|F0&1rU8bqab*n5TT8~C860O$|6Rt%P1=1(EjIQZ% z;Y^PU2VC*~^2!sG?mbBPS0~0yd-+086)+rHjhfk6>CB$t`o%;=kdYF9NwiKkwbIpN z;_FlOuHQHHSZ&@fUuSI-S*t`DjsiIB z{=1M@JKVC$a8z{2;xCPfRb{~T>uo#5rL4L+z9n`rSUt3Tt nAZ`TZm+q1gPVN84&*%Ra7her>#-hHS00000NkvXXu0mjf|6N@O literal 0 HcmV?d00001 diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/icon.png.import b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/icon.png.import new file mode 100644 index 0000000..a4c02e6 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/icon.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.png" +dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/project.godot b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/project.godot new file mode 100644 index 0000000..aa2113f --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/project.godot @@ -0,0 +1,26 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=4 + +[application] + +config/name="Multiplayer Test" +config/icon="res://icon.png" + +[autoload] + +Network="*res://Network.gd" + +[physics] + +common/enable_pause_aware_picking=true + +[rendering] + +environment/default_environment="res://default_env.tres" From db69386b6d2f12adf284b45a3f84111bbfeb2b0b Mon Sep 17 00:00:00 2001 From: Andrew Tang Date: Mon, 1 Aug 2022 02:48:32 +0800 Subject: [PATCH 7/9] Test Lobby Working Server creation works and others are able to join by entering the creator's IP. Shows a list of player names (currently only shows player #) --- .../Andrew_Multiplayer_Test/Global.gd | 9 +++++++ .../Andrew_Multiplayer_Test/Network.gd | 2 +- .../Andrew_Multiplayer_Test/Network_Setup.gd | 23 +++++++++++++++- .../Andrew_Multiplayer_Test/Player.gd | 7 +++++ .../Andrew_Multiplayer_Test/Player.tscn | 26 +++++++++++++++++++ .../Andrew_Multiplayer_Test/Players.tscn | 3 +++ .../Andrew_Multiplayer_Test/Test.tscn | 6 ----- .../Andrew_Multiplayer_Test/project.godot | 3 +++ 8 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Global.gd create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Player.gd create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Player.tscn create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Players.tscn delete mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Test.tscn diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Global.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Global.gd new file mode 100644 index 0000000..6c826ed --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Global.gd @@ -0,0 +1,9 @@ +extends Node + + +func instance_node(node: Object, parent: Object) -> Object: + var node_instance = node.instance() + parent.add_child(node_instance) + return node_instance + + diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd index 1fbc43d..052b427 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd @@ -12,7 +12,7 @@ func _ready() -> void: ip_address = IP.get_local_addresses()[3] for ip in IP.get_local_addresses(): - if ip.begins_with("192.168."): + if ip.begins_with("192.168.") and not ip.ends_with(".1"): ip_address = ip get_tree().connect("connected_to_server", self, "_connected_to_server") diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd index 426b3d1..f1bee1b 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd @@ -1,6 +1,9 @@ extends Control +var playerCounter = 1 +var player = load("res://Player.tscn") + onready var multiplayer_config_ui = $Multiplayer_Configure onready var server_ip_address = $Multiplayer_Configure/Server_IP_Address onready var device_ip_address = $CanvasLayer/Device_IP_Address @@ -17,16 +20,34 @@ func _ready(): func _player_connected(id) -> void: print("Player " + str(id) + "connected") + instance_player(id) func _player_disconnected(id) -> void: print("Player " + str(id) + "disconnected") + + if Players.has_node(str(id)): + Players.get_node(str(id)).queue_free() func _on_Create_Server_pressed(): - multiplayer.config_ui.hide() + multiplayer_config_ui.hide() Network._create_server() + instance_player(get_tree().get_network_unique_id()) func _on_Join_Server_pressed(): if server_ip_address.text != "": multiplayer_config_ui.hide() Network.ip_address = server_ip_address.text Network._join_server() + +func _connected_to_server() -> void: + yield(get_tree().create_timer(0.1), "timeout") + instance_player(get_tree().get_network_unique_id()) + +func instance_player(id) -> void: + var player_instance = Global.instance_node(player, Players) + player_instance.name = str(id) + var player_name = "Player " + str(playerCounter) + player_instance._set_name(player_name) + player_instance._set_name_position(playerCounter) + player_instance.set_network_master(id) + playerCounter += 1 diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Player.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Player.gd new file mode 100644 index 0000000..d47114b --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Player.gd @@ -0,0 +1,7 @@ +extends Control + +func _set_name(name) -> void: + $Name.text = name + +func _set_name_position(counterVal) -> void: + $Name.rect_position.y = -225 + (50 * counterVal) diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Player.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Player.tscn new file mode 100644 index 0000000..ce42f2b --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Player.tscn @@ -0,0 +1,26 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Player.gd" type="Script" id=1] + +[node name="Player" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 1 ) + +[node name="Name" type="Label" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_top = -175.0 +margin_bottom = -175.0 +text = "Name" +align = 1 +valign = 1 + +[node name="Players" type="Label" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_top = -225.0 +margin_bottom = -225.0 +text = "Players:" +align = 1 +valign = 1 diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Players.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Players.tscn new file mode 100644 index 0000000..2683f83 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Players.tscn @@ -0,0 +1,3 @@ +[gd_scene format=2] + +[node name="Players" type="Node"] diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Test.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Test.tscn deleted file mode 100644 index 45a4ba7..0000000 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Test.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=2] - -[ext_resource path="res://Network.gd" type="Script" id=1] - -[node name="Node" type="Node"] -script = ExtResource( 1 ) diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/project.godot b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/project.godot index aa2113f..7546d2a 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/project.godot +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/project.godot @@ -11,11 +11,14 @@ config_version=4 [application] config/name="Multiplayer Test" +run/main_scene="res://Network_Setup.tscn" config/icon="res://icon.png" [autoload] Network="*res://Network.gd" +Global="*res://Global.gd" +Players="*res://Players.tscn" [physics] From c0243c67f2dc4883e9d322fb3d48276b96db56ea Mon Sep 17 00:00:00 2001 From: Andrew Tang Date: Mon, 15 Aug 2022 03:09:55 +0800 Subject: [PATCH 8/9] Updating multiplayer test to have more customization --- .../But_ChangeScene.gd | 18 ++++ .../Andrew_Multiplayer_Test/Network.gd | 6 ++ .../Andrew_Multiplayer_Test/Network_Setup.gd | 98 ++++++++++--------- .../Network_Setup.tscn | 9 +- .../Andrew_Multiplayer_Test/Room_Creation.gd | 59 +++++++++++ .../Room_Creation.tscn | 86 ++++++++++++++++ 6 files changed, 225 insertions(+), 51 deletions(-) create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/But_ChangeScene.gd create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.gd create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.tscn diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/But_ChangeScene.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/But_ChangeScene.gd new file mode 100644 index 0000000..f8a43ac --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/But_ChangeScene.gd @@ -0,0 +1,18 @@ +#BUT_CHANGESCENE: +# Generic template script allowing GUI linking of scenes by button press. + +tool +extends Button + +#Creates param usable in the UI; and the params next to export make it string and file browser +export(String, FILE) var next_scene_path: = "" + +var tempToggle = 0 + +func _on_But_NewGame_button_up(): + get_tree().change_scene(next_scene_path) + + +func _get_configuration_warning() -> String: + return "next_scene_path must be set for this button to work" if next_scene_path == "" else "" + diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd index 052b427..7782a71 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd @@ -7,6 +7,8 @@ var server = null var client = null var ip_address = "" +var room_name = "" +var room_password = "" func _ready() -> void: ip_address = IP.get_local_addresses()[3] @@ -33,3 +35,7 @@ func _connected_to_server() -> void: func _server_disconnected() -> void: print("Disconnected from the server") + +func _set_server_info(name, password) -> void: + room_name = name + room_password = password diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd index f1bee1b..1b2737d 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd @@ -1,53 +1,55 @@ extends Control -var playerCounter = 1 -var player = load("res://Player.tscn") - -onready var multiplayer_config_ui = $Multiplayer_Configure -onready var server_ip_address = $Multiplayer_Configure/Server_IP_Address -onready var device_ip_address = $CanvasLayer/Device_IP_Address +#var playerCounter = 1 +#var player = load("res://Player.tscn") +# +#onready var multiplayer_config_ui = $Multiplayer_Configure +#onready var server_ip_address = $Multiplayer_Configure/Server_IP_Address +#onready var device_ip_address = $CanvasLayer/Device_IP_Address +# +# +# +## Called when the node enters the scene tree for the first time. +#func _ready(): +# get_tree().connect("network_peer_connected", self, "_player_connected") +# get_tree().connect("network_peer_disconnected", self, "_player_disconnected") +# get_tree().connect("connected_to_server", self, "_connected_to_server") +# +# device_ip_address.text = Network.ip_address +# +#func _player_connected(id) -> void: +# print("Player " + str(id) + "connected") +# instance_player(id) +# +#func _player_disconnected(id) -> void: +# print("Player " + str(id) + "disconnected") +# +# if Players.has_node(str(id)): +# Players.get_node(str(id)).queue_free() +# +#func _on_Create_Server_pressed(): +# multiplayer_config_ui.hide() +# Network._create_server() +# instance_player(get_tree().get_network_unique_id()) +# +#func _on_Join_Server_pressed(): +# if server_ip_address.text != "": +# multiplayer_config_ui.hide() +# Network.ip_address = server_ip_address.text +# Network._join_server() +# +#func _connected_to_server() -> void: +# yield(get_tree().create_timer(0.1), "timeout") +# instance_player(get_tree().get_network_unique_id()) +# +#func instance_player(id) -> void: +# var player_instance = Global.instance_node(player, Players) +# player_instance.name = str(id) +# var player_name = "Player " + str(playerCounter) +# player_instance._set_name(player_name) +# player_instance._set_name_position(playerCounter) +# player_instance.set_network_master(id) +# playerCounter += 1 - -# Called when the node enters the scene tree for the first time. -func _ready(): - get_tree().connect("network_peer_connected", self, "_player_connected") - get_tree().connect("network_peer_disconnected", self, "_player_disconnected") - get_tree().connect("connected_to_server", self, "_connected_to_server") - - device_ip_address.text = Network.ip_address - -func _player_connected(id) -> void: - print("Player " + str(id) + "connected") - instance_player(id) - -func _player_disconnected(id) -> void: - print("Player " + str(id) + "disconnected") - - if Players.has_node(str(id)): - Players.get_node(str(id)).queue_free() - -func _on_Create_Server_pressed(): - multiplayer_config_ui.hide() - Network._create_server() - instance_player(get_tree().get_network_unique_id()) - -func _on_Join_Server_pressed(): - if server_ip_address.text != "": - multiplayer_config_ui.hide() - Network.ip_address = server_ip_address.text - Network._join_server() - -func _connected_to_server() -> void: - yield(get_tree().create_timer(0.1), "timeout") - instance_player(get_tree().get_network_unique_id()) - -func instance_player(id) -> void: - var player_instance = Global.instance_node(player, Players) - player_instance.name = str(id) - var player_name = "Player " + str(playerCounter) - player_instance._set_name(player_name) - player_instance._set_name_position(playerCounter) - player_instance.set_network_master(id) - playerCounter += 1 diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn index 49caf72..82e64be 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://Network_Setup.gd" type="Script" id=1] +[ext_resource path="res://But_ChangeScene.gd" type="Script" id=2] [node name="Network_Setup" type="Control"] anchor_right = 1.0 @@ -21,6 +22,8 @@ margin_top = 21.0 margin_right = 125.0 margin_bottom = 121.0 text = "Create Server" +script = ExtResource( 2 ) +next_scene_path = "res://Room_Creation.tscn" [node name="Join_Server" type="Button" parent="Multiplayer_Configure"] anchor_left = 0.5 @@ -32,6 +35,7 @@ margin_top = -129.0 margin_right = 125.0 margin_bottom = -29.0 text = "Join Server" +script = ExtResource( 2 ) [node name="Server_IP_Address" type="LineEdit" parent="Multiplayer_Configure"] margin_left = 389.0 @@ -54,5 +58,4 @@ margin_bottom = -26.0 align = 1 valign = 1 -[connection signal="pressed" from="Multiplayer_Configure/Create_Server" to="." method="_on_Create_Server_pressed"] -[connection signal="pressed" from="Multiplayer_Configure/Join_Server" to="." method="_on_Join_Server_pressed"] +[connection signal="button_up" from="Multiplayer_Configure/Create_Server" to="Multiplayer_Configure/Create_Server" method="_on_But_NewGame_button_up"] diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.gd new file mode 100644 index 0000000..e2ac87e --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.gd @@ -0,0 +1,59 @@ +extends Control + + +var playerCounter = 1 +var player = load("res://Player.tscn") + +onready var multiplayer_config_ui = $Multiplayer_Configure +#onready var server_ip_address = $Multiplayer_Configure/Server_IP_Address +onready var device_ip_address = $CanvasLayer/Device_IP_Address +onready var player_name = $Multiplayer_Configure/Player_Name +onready var room_name = $Multiplayer_Configure/Room_Name +onready var room_password = $Multiplayer_Configure/Room_Password +onready var room_ui = $Room_UI + + + +# Called when the node enters the scene tree for the first time. +func _ready(): + get_tree().connect("network_peer_connected", self, "_player_connected") + get_tree().connect("network_peer_disconnected", self, "_player_disconnected") + get_tree().connect("connected_to_server", self, "_connected_to_server") + + device_ip_address.text = Network.ip_address + +func _player_connected(id) -> void: + print("Player " + str(id) + "connected") + instance_player(id) + +func _player_disconnected(id) -> void: + print("Player " + str(id) + "disconnected") + + if Players.has_node(str(id)): + Players.get_node(str(id)).queue_free() + +func _on_Create_Server_pressed(): + multiplayer_config_ui.hide() + Network._create_server() + instance_player(get_tree().get_network_unique_id()) + Network._set_server_info(room_name.text, room_password.text) + $Room_UI/Room_Name.text = room_name.text + room_ui.show() + +#func _on_Join_Server_pressed(): +# if server_ip_address.text != "": +# multiplayer_config_ui.hide() +# Network.ip_address = server_ip_address.text +# Network._join_server() + +func _connected_to_server() -> void: + yield(get_tree().create_timer(0.1), "timeout") + instance_player(get_tree().get_network_unique_id()) + +func instance_player(id) -> void: + var player_instance = Global.instance_node(player, Players) + player_instance.name = str(id) + player_instance._set_name(player_name.text) + player_instance._set_name_position(playerCounter) + player_instance.set_network_master(id) + playerCounter += 1 diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.tscn new file mode 100644 index 0000000..2543f5f --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.tscn @@ -0,0 +1,86 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Room_Creation.gd" type="Script" id=1] + +[node name="Room_Creation" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 1 ) + +[node name="Back" type="Button" parent="."] +margin_left = 312.0 +margin_top = 419.0 +margin_right = 474.0 +margin_bottom = 493.0 +text = "Back" + +[node name="Multiplayer_Configure" type="Control" parent="."] +margin_right = 40.0 +margin_bottom = 40.0 + +[node name="Create_Server" type="Button" parent="Multiplayer_Configure"] +margin_left = 592.0 +margin_top = 419.0 +margin_right = 754.0 +margin_bottom = 493.0 +text = "Create" + +[node name="Room_Name" type="LineEdit" parent="Multiplayer_Configure"] +margin_left = 452.0 +margin_top = 250.0 +margin_right = 619.0 +margin_bottom = 274.0 +text = "Room Name" +align = 1 + +[node name="Room_Password" type="LineEdit" parent="Multiplayer_Configure"] +margin_left = 452.0 +margin_top = 315.0 +margin_right = 619.0 +margin_bottom = 339.0 +text = "Room Password" +align = 1 + +[node name="Player_Name" type="LineEdit" parent="Multiplayer_Configure"] +margin_left = 451.0 +margin_top = 188.0 +margin_right = 618.0 +margin_bottom = 212.0 +text = "Player Name" +align = 1 + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="Device_IP_Address" type="Label" parent="CanvasLayer"] +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = -1.0 +margin_top = -76.0 +margin_right = -1.0 +margin_bottom = -26.0 +align = 1 +valign = 1 + +[node name="Room_UI" type="Control" parent="."] +visible = false +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="Room_Name" type="Label" parent="Room_UI"] +anchor_left = 0.5 +anchor_right = 0.5 +margin_left = -20.0 +margin_right = 20.0 +margin_bottom = 14.0 + +[node name="Players" type="Label" parent="Room_UI"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_top = -225.0 +margin_bottom = -225.0 +text = "Players:" +align = 1 +valign = 1 + +[connection signal="pressed" from="Multiplayer_Configure/Create_Server" to="." method="_on_Create_Server_pressed"] From ac73e184d3a5a28c3eb0122a7dada6eeca6f12ef Mon Sep 17 00:00:00 2001 From: Andrew Tang Date: Mon, 22 Aug 2022 02:56:29 +0800 Subject: [PATCH 9/9] Adjustments to Multiplayer Test Added a join scene but was unable to get the client-server interaction working properly. Hopefully some of the code can be used as a starting point once we begin working on Dario's UI. --- .../Andrew_Multiplayer_Test/Global.gd | 2 +- .../Andrew_Multiplayer_Test/Network.gd | 12 ++++ .../Andrew_Multiplayer_Test/Network_Setup.gd | 55 ----------------- .../Network_Setup.tscn | 7 ++- .../Andrew_Multiplayer_Test/Room_Creation.gd | 14 ++--- .../Room_Creation.tscn | 11 +++- .../Andrew_Multiplayer_Test/Room_Join.gd | 13 ++++ .../Andrew_Multiplayer_Test/Room_Join.tscn | 60 +++++++++++++++++++ 8 files changed, 102 insertions(+), 72 deletions(-) delete mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Join.gd create mode 100644 Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Join.tscn diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Global.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Global.gd index 6c826ed..e0efd6b 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Global.gd +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Global.gd @@ -1,7 +1,7 @@ extends Node -func instance_node(node: Object, parent: Object) -> Object: +func _instance_node(node: Object, parent: Object) -> Object: var node_instance = node.instance() parent.add_child(node_instance) return node_instance diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd index 7782a71..e3a25a8 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd @@ -5,6 +5,8 @@ const MAX_CLIENTS = 6 var server = null var client = null +var player_counter = 1 +var player = load("res://Player.tscn") var ip_address = "" var room_name = "" @@ -39,3 +41,13 @@ func _server_disconnected() -> void: func _set_server_info(name, password) -> void: room_name = name room_password = password + +func _instance_player(id, name) -> void: + var player_instance = Global._instance_node(player, Players) + player_instance.name = str(id) + player_instance._set_name(name) + #Using player_counter to determine the positioning of the player's name on the screen + #So that they aren't all overlapping + player_instance._set_name_position(player_counter) + player_instance.set_network_master(id) + player_counter += 1 diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd deleted file mode 100644 index 1b2737d..0000000 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd +++ /dev/null @@ -1,55 +0,0 @@ -extends Control - - -#var playerCounter = 1 -#var player = load("res://Player.tscn") -# -#onready var multiplayer_config_ui = $Multiplayer_Configure -#onready var server_ip_address = $Multiplayer_Configure/Server_IP_Address -#onready var device_ip_address = $CanvasLayer/Device_IP_Address -# -# -# -## Called when the node enters the scene tree for the first time. -#func _ready(): -# get_tree().connect("network_peer_connected", self, "_player_connected") -# get_tree().connect("network_peer_disconnected", self, "_player_disconnected") -# get_tree().connect("connected_to_server", self, "_connected_to_server") -# -# device_ip_address.text = Network.ip_address -# -#func _player_connected(id) -> void: -# print("Player " + str(id) + "connected") -# instance_player(id) -# -#func _player_disconnected(id) -> void: -# print("Player " + str(id) + "disconnected") -# -# if Players.has_node(str(id)): -# Players.get_node(str(id)).queue_free() -# -#func _on_Create_Server_pressed(): -# multiplayer_config_ui.hide() -# Network._create_server() -# instance_player(get_tree().get_network_unique_id()) -# -#func _on_Join_Server_pressed(): -# if server_ip_address.text != "": -# multiplayer_config_ui.hide() -# Network.ip_address = server_ip_address.text -# Network._join_server() -# -#func _connected_to_server() -> void: -# yield(get_tree().create_timer(0.1), "timeout") -# instance_player(get_tree().get_network_unique_id()) -# -#func instance_player(id) -> void: -# var player_instance = Global.instance_node(player, Players) -# player_instance.name = str(id) -# var player_name = "Player " + str(playerCounter) -# player_instance._set_name(player_name) -# player_instance._set_name_position(playerCounter) -# player_instance.set_network_master(id) -# playerCounter += 1 - - diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn index 82e64be..b4b93c3 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn @@ -1,12 +1,10 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=2 format=2] -[ext_resource path="res://Network_Setup.gd" type="Script" id=1] [ext_resource path="res://But_ChangeScene.gd" type="Script" id=2] [node name="Network_Setup" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 -script = ExtResource( 1 ) [node name="Multiplayer_Configure" type="Control" parent="."] anchor_right = 1.0 @@ -36,8 +34,10 @@ margin_right = 125.0 margin_bottom = -29.0 text = "Join Server" script = ExtResource( 2 ) +next_scene_path = "res://Room_Join.tscn" [node name="Server_IP_Address" type="LineEdit" parent="Multiplayer_Configure"] +visible = false margin_left = 389.0 margin_top = 82.0 margin_right = 639.0 @@ -59,3 +59,4 @@ align = 1 valign = 1 [connection signal="button_up" from="Multiplayer_Configure/Create_Server" to="Multiplayer_Configure/Create_Server" method="_on_But_NewGame_button_up"] +[connection signal="button_up" from="Multiplayer_Configure/Join_Server" to="Multiplayer_Configure/Join_Server" method="_on_But_NewGame_button_up"] diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.gd index e2ac87e..dc7ba6f 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.gd +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.gd @@ -24,7 +24,7 @@ func _ready(): func _player_connected(id) -> void: print("Player " + str(id) + "connected") - instance_player(id) + Network._instance_player(id, "New Player") func _player_disconnected(id) -> void: print("Player " + str(id) + "disconnected") @@ -35,7 +35,7 @@ func _player_disconnected(id) -> void: func _on_Create_Server_pressed(): multiplayer_config_ui.hide() Network._create_server() - instance_player(get_tree().get_network_unique_id()) + Network._instance_player(get_tree().get_network_unique_id(), player_name.text) Network._set_server_info(room_name.text, room_password.text) $Room_UI/Room_Name.text = room_name.text room_ui.show() @@ -48,12 +48,6 @@ func _on_Create_Server_pressed(): func _connected_to_server() -> void: yield(get_tree().create_timer(0.1), "timeout") - instance_player(get_tree().get_network_unique_id()) + Network._instance_player(get_tree().get_network_unique_id(), player_name.text) + -func instance_player(id) -> void: - var player_instance = Global.instance_node(player, Players) - player_instance.name = str(id) - player_instance._set_name(player_name.text) - player_instance._set_name_position(playerCounter) - player_instance.set_network_master(id) - playerCounter += 1 diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.tscn index 2543f5f..28c5aaf 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.tscn +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://Room_Creation.gd" type="Script" id=1] +[ext_resource path="res://But_ChangeScene.gd" type="Script" id=2] [node name="Room_Creation" type="Control"] anchor_right = 1.0 @@ -13,6 +14,8 @@ margin_top = 419.0 margin_right = 474.0 margin_bottom = 493.0 text = "Back" +script = ExtResource( 2 ) +next_scene_path = "res://Network_Setup.tscn" [node name="Multiplayer_Configure" type="Control" parent="."] margin_right = 40.0 @@ -70,9 +73,10 @@ anchor_bottom = 1.0 [node name="Room_Name" type="Label" parent="Room_UI"] anchor_left = 0.5 anchor_right = 0.5 -margin_left = -20.0 -margin_right = 20.0 +margin_left = -80.5 +margin_right = 80.5 margin_bottom = 14.0 +align = 1 [node name="Players" type="Label" parent="Room_UI"] anchor_right = 1.0 @@ -83,4 +87,5 @@ text = "Players:" align = 1 valign = 1 +[connection signal="button_up" from="Back" to="Back" method="_on_But_NewGame_button_up"] [connection signal="pressed" from="Multiplayer_Configure/Create_Server" to="." method="_on_Create_Server_pressed"] diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Join.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Join.gd new file mode 100644 index 0000000..5202eea --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Join.gd @@ -0,0 +1,13 @@ +extends Control + +onready var multiplayer_config_ui = $Multiplayer_Configure +onready var server_ip_address = $Multiplayer_Configure/Server_IP_Address +onready var room_password = $Multiplayer_Configure/Room_Password +onready var player_name = $Multiplayer_Configure/Player_Name + +func _on_Join_Server_pressed(): + if server_ip_address.text != "": + multiplayer_config_ui.hide() + Network.ip_address = server_ip_address.text + Network._join_server() + Network._instance_player(get_tree().get_network_unique_id(), player_name.text) diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Join.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Join.tscn new file mode 100644 index 0000000..a2ca72a --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Join.tscn @@ -0,0 +1,60 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Room_Join.gd" type="Script" id=1] +[ext_resource path="res://But_ChangeScene.gd" type="Script" id=2] + +[node name="Room_Join" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 1 ) + +[node name="Multiplayer_Configure" type="Control" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="Server_IP_Address" type="LineEdit" parent="Multiplayer_Configure"] +margin_left = 386.0 +margin_top = 236.0 +margin_right = 636.0 +margin_bottom = 286.0 +text = "Enter Room IP" +align = 1 + +[node name="Join_Server" type="Button" parent="Multiplayer_Configure"] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = 21.0 +margin_top = 93.0 +margin_right = 271.0 +margin_bottom = 193.0 +text = "Join Server" + +[node name="Room_Password" type="LineEdit" parent="Multiplayer_Configure"] +margin_left = 388.0 +margin_top = 311.0 +margin_right = 638.0 +margin_bottom = 361.0 +text = "Room Password" +align = 1 + +[node name="Player_Name" type="LineEdit" parent="Multiplayer_Configure"] +margin_left = 387.0 +margin_top = 164.0 +margin_right = 637.0 +margin_bottom = 214.0 +text = "Player Name" +align = 1 + +[node name="Back" type="Button" parent="."] +margin_left = 235.0 +margin_top = 394.0 +margin_right = 485.0 +margin_bottom = 494.0 +text = "Back" +script = ExtResource( 2 ) +next_scene_path = "res://Network_Setup.tscn" + +[connection signal="pressed" from="Multiplayer_Configure/Join_Server" to="." method="_on_Join_Server_pressed"] +[connection signal="button_up" from="Back" to="Back" method="_on_But_NewGame_button_up"]