Globalized variables, team member consistency

This commit is contained in:
2024-06-03 13:23:41 -04:00
parent 394beabb7c
commit 341bf010d4
8 changed files with 224 additions and 78 deletions

View File

@@ -1,3 +1,14 @@
extends Node extends Node
var selected_texture : AtlasTexture = null var selected_texture : AtlasTexture = null
var teamScreenVisible : bool = false
var teamSelectionVisible : bool = false
var globalScore : int = 0
var globalClickAdd : int = 1
var globalScorePerSec : int = 1
var globalScoreMultiplier: int = 1
var teamScreenPath: String = "/root/Root/UI/AspectRatioContainer"
var teamSelectionPath: String = "/root/Root/UI/TeamSelection"

View File

@@ -5,6 +5,7 @@ signal texture_selected(texture : AtlasTexture)
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
# Iterate over all children of the GridContainer # Iterate over all children of the GridContainer
for button in get_children(): for button in get_children():
# Check if the child is a TextureButton # Check if the child is a TextureButton
@@ -12,14 +13,23 @@ func _ready():
# Connect the pressed signal of the TextureButton to the handler function # Connect the pressed signal of the TextureButton to the handler function
button.connect("pressed", Callable(self, "_on_TextureButton_pressed").bind(button)) button.connect("pressed", Callable(self, "_on_TextureButton_pressed").bind(button))
# Handler function for the pressed signal # Handler function for the pressed signal
func _on_TextureButton_pressed(button): func _on_TextureButton_pressed(button):
# Print the name of the button # Print the name of the button
print("Button pressed: ", button.name) #print("Button pressed: ", button.name)
#Texture Variable #Texture Variable
var texture : AtlasTexture = button.texture_normal var texture : AtlasTexture = button.texture_normal
#Sets the selected texture on the team screen
Global.selected_texture = texture Global.selected_texture = texture
get_tree().change_scene_to_file("res://User Interface/UserInterface.tscn")
#For returning to the Team Selection Screen after selecting member
#Sets the global variable for the team selection screen to true so when you move back it's already open
Global.teamScreenVisible = true
Global.teamSelectionVisible = false

18
User Interface/Hank.gd Normal file
View File

@@ -0,0 +1,18 @@
extends TextureButton
@export var memberClickAdd: int = 0
@export var memberPerSec: int = 0
# Called when the node enters the scene tree for the first time.
func _ready():
# Connect the pressed signal to the _on_Button_pressed function
self.connect("pressed", Callable(self, "_on_Button_pressed"))
func _on_Button_pressed():
Global.globalClickAdd += memberClickAdd
Global.globalScorePerSec += memberPerSec
pass

View File

@@ -1,7 +1,5 @@
extends Control extends Control
#https://www.youtube.com/watch?v=V79YabQZC1s
#13:03
var score = 0 var score = 0
var clickAdd = 1 var clickAdd = 1
@@ -61,23 +59,45 @@ func _ready():
$ClickUpgrades.get_popup().connect("id_pressed",clickUpgrade) $ClickUpgrades.get_popup().connect("id_pressed",clickUpgrade)
$PassiveUpgrades.get_popup().connect("id_pressed",passiveUpgrade) $PassiveUpgrades.get_popup().connect("id_pressed",passiveUpgrade)
$Timer.connect("timeout", _on_Timer_timeout) $Timer.connect("timeout", _on_Timer_timeout)
#$TeamButton.pressed.connect(self.openTeamWindow)
#Code for the Click Me Button (deprecated)
#$Click.pressed.connect(self._on_button_pressed)
#Prints all input events, only for debugging #Prints all input events, only for debugging
#func _input(event): #func _input(event):
#print(event.as_text()) #print(event.as_text())
func _on_Timer_timeout(): func _on_Timer_timeout():
score += scorePerSec * scoreMultiplier Global.globalScore += Global.globalScorePerSec * Global.globalScoreMultiplier
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
#Displays normal numbers until commas are needed #Displays normal numbers until commas are needed
if score > 999: if Global.globalScore > 999:
$Score.text = str(scoreFormat(score)) $Score.text = str(scoreFormat(score))
else: else:
$Score.text = str(score) #Changes the score number $Score.text = str(Global.globalScore) #Changes the score number
$ClickAdd.text = str(Global.globalClickAdd)
$PerSec.text = str(Global.globalScorePerSec)
#Pulls the global score data to keep it up to date
#score = Global.globalScore
#Global.globalClickAdd = Global.globalClickAdd
#scorePerSec = Global.globalScorePerSec
#scoreMultiplier = Global.globalScoreMultiplier
#Stores the score stats in a global variable to be called in other scenes
#Global.globalScore = score
#Global.globalClickAdd = Global.globalClickAdd
#Global.globalScorePerSec = scorePerSec
#Global.globalScoreMultiplier = scoreMultiplier
#Get the current status of any screens needed
var teamScreen = get_node(Global.teamScreenPath)
teamScreen.visible = Global.teamScreenVisible
var teamSelection = get_node(Global.teamSelectionPath)
teamSelection.visible = Global.teamSelectionVisible
#This checks any input that comes in #This checks any input that comes in
func _input(event): func _input(event):
@@ -87,14 +107,11 @@ func _input(event):
#_on_button_pressed() #_on_button_pressed()
#Formats the score string so commas are inserted #Formats the score string so commas are inserted
func scoreFormat(score): func scoreFormat(score):
# Convert value to string. # Convert value to string.
var str_value: String = str(score) var str_value: String = str(Global.globalScore)
# Loop backward starting at the last 3 digits, # Loop backward starting at the last 3 digits,
# add comma then, repeat every 3rd step. # add comma then, repeat every 3rd step.
for i in range(str_value.length()-3, 0, -3): for i in range(str_value.length()-3, 0, -3):
@@ -103,155 +120,155 @@ func scoreFormat(score):
return score return score
func leftClick(): func leftClick():
score += clickAdd * scoreMultiplier Global.globalScore += Global.globalClickAdd * Global.globalScoreMultiplier
func clickUpgrade(id): func clickUpgrade(id):
match id: match id:
0: 0:
if score >= clickUpgradeReq1: if Global.globalScore >= clickUpgradeReq1:
print ("Score sufficient") print ("Score sufficient")
score -=clickUpgradeReq1 Global.globalScore -=clickUpgradeReq1
$ClickUpgrades.get_popup().set_item_disabled(id, true) $ClickUpgrades.get_popup().set_item_disabled(id, true)
clickAdd += clickUpgradeAmt1 Global.globalClickAdd += clickUpgradeAmt1
else: else:
print("not enough score") print("not enough score")
1: 1:
if score >= clickUpgradeReq10: if Global.globalScore >= clickUpgradeReq10:
print ("Score sufficient") print ("Score sufficient")
score -=clickUpgradeReq10 Global.globalScore -=clickUpgradeReq10
$ClickUpgrades.get_popup().set_item_disabled(id, true) $ClickUpgrades.get_popup().set_item_disabled(id, true)
clickAdd += clickUpgradeAmt10 Global.globalClickAdd += clickUpgradeAmt10
else: else:
print("not enough score") print("not enough score")
2: 2:
if score >= clickUpgradeReq20: if Global.globalScore >= clickUpgradeReq20:
print ("Score sufficient") print ("Score sufficient")
score -=clickUpgradeReq20 Global.globalScore -=clickUpgradeReq20
$ClickUpgrades.get_popup().set_item_disabled(id, true) $ClickUpgrades.get_popup().set_item_disabled(id, true)
clickAdd += clickUpgradeAmt20 Global.globalClickAdd += clickUpgradeAmt20
else: else:
print("not enough score") print("not enough score")
3: 3:
if score >= clickUpgradeReq40: if Global.globalScore >= clickUpgradeReq40:
print ("Score sufficient") print ("Score sufficient")
score -=clickUpgradeReq40 Global.globalScore -=clickUpgradeReq40
$ClickUpgrades.get_popup().set_item_disabled(id, true) $ClickUpgrades.get_popup().set_item_disabled(id, true)
clickAdd += clickUpgradeAmt40 Global.globalClickAdd += clickUpgradeAmt40
else: else:
print("not enough score") print("not enough score")
4: 4:
if score >= clickUpgradeReq60: if Global.globalScore >= clickUpgradeReq60:
print ("Score sufficient") print ("Score sufficient")
score -=clickUpgradeReq60 Global.globalScore -=clickUpgradeReq60
$ClickUpgrades.get_popup().set_item_disabled(id, true) $ClickUpgrades.get_popup().set_item_disabled(id, true)
clickAdd += clickUpgradeAmt60 Global.globalClickAdd += clickUpgradeAmt60
else: else:
print("not enough score") print("not enough score")
5: 5:
if score >= clickUpgradeReq80: if Global.globalScore >= clickUpgradeReq80:
print ("Score sufficient") print ("Score sufficient")
score -=clickUpgradeReq80 Global.globalScore -=clickUpgradeReq80
$ClickUpgrades.get_popup().set_item_disabled(id, true) $ClickUpgrades.get_popup().set_item_disabled(id, true)
clickAdd += clickUpgradeAmt80 Global.globalClickAdd += clickUpgradeAmt80
else: else:
print("not enough score") print("not enough score")
6: 6:
if score >= clickUpgradeReq100: if Global.globalScore >= clickUpgradeReq100:
print ("Score sufficient") print ("Score sufficient")
score -=clickUpgradeReq100 Global.globalScore -=clickUpgradeReq100
$ClickUpgrades.get_popup().set_item_disabled(id, true) $ClickUpgrades.get_popup().set_item_disabled(id, true)
clickAdd += clickUpgradeAmt100 Global.globalClickAdd += clickUpgradeAmt100
else: else:
print("not enough score") print("not enough score")
7: 7:
if score >= clickUpgradeReq200: if Global.globalScore >= clickUpgradeReq200:
print ("Score sufficient") print ("Score sufficient")
score -=clickUpgradeReq200 Global.globalScore -=clickUpgradeReq200
$ClickUpgrades.get_popup().set_item_disabled(id, true) $ClickUpgrades.get_popup().set_item_disabled(id, true)
clickAdd += clickUpgradeAmt200 Global.globalClickAdd += clickUpgradeAmt200
else: else:
print("not enough score") print("not enough score")
8: 8:
if score >= clickUpgradeReq400: if Global.globalScore >= clickUpgradeReq400:
print ("Score sufficient") print ("Score sufficient")
score -=clickUpgradeReq400 Global.globalScore -=clickUpgradeReq400
$ClickUpgrades.get_popup().set_item_disabled(id, true) $ClickUpgrades.get_popup().set_item_disabled(id, true)
clickAdd += clickUpgradeAmt400 Global.globalClickAdd += clickUpgradeAmt400
else: else:
print("not enough score") print("not enough score")
func passiveUpgrade(id): func passiveUpgrade(id):
match id: match id:
0: 0:
if score >= passiveUpgradeReq2: if Global.globalScore >= passiveUpgradeReq2:
print ("Score sufficient") print ("Score sufficient")
score -=passiveUpgradeReq2 Global.globalScore -=passiveUpgradeReq2
$PassiveUpgrades.get_popup().set_item_disabled(id, true) $PassiveUpgrades.get_popup().set_item_disabled(id, true)
scorePerSec = passiveUpgradeAmt2 Global.globalScorePerSec = passiveUpgradeAmt2
else: else:
print("not enough score") print("not enough score")
1: 1:
if score >= passiveUpgradeReq10: if Global.globalScore >= passiveUpgradeReq10:
print ("Score sufficient") print ("Score sufficient")
score -=passiveUpgradeReq10 Global.globalScore -=passiveUpgradeReq10
$PassiveUpgrades.get_popup().set_item_disabled(id, true) $PassiveUpgrades.get_popup().set_item_disabled(id, true)
scorePerSec = passiveUpgradeAmt10 Global.globalScorePerSec = passiveUpgradeAmt10
else: else:
print("not enough score") print("not enough score")
2: 2:
if score >= passiveUpgradeReq20: if Global.globalScore >= passiveUpgradeReq20:
print ("Score sufficient") print ("Score sufficient")
score -=passiveUpgradeReq20 Global.globalScore -=passiveUpgradeReq20
$PassiveUpgrades.get_popup().set_item_disabled(id, true) $PassiveUpgrades.get_popup().set_item_disabled(id, true)
scorePerSec = passiveUpgradeAmt20 Global.globalScorePerSec = passiveUpgradeAmt20
else: else:
print("not enough score") print("not enough score")
3: 3:
if score >= passiveUpgradeReq50: if Global.globalScore >= passiveUpgradeReq50:
print ("Score sufficient") print ("Score sufficient")
score -=passiveUpgradeReq50 Global.globalScore -=passiveUpgradeReq50
$PassiveUpgrades.get_popup().set_item_disabled(id, true) $PassiveUpgrades.get_popup().set_item_disabled(id, true)
scorePerSec = passiveUpgradeAmt50 Global.globalScorePerSec = passiveUpgradeAmt50
else: else:
print("not enough score") print("not enough score")
4: 4:
if score >= passiveUpgradeReq100: if Global.globalScore >= passiveUpgradeReq100:
print ("Score sufficient") print ("Score sufficient")
score -=passiveUpgradeReq100 Global.globalScore -=passiveUpgradeReq100
$PassiveUpgrades.get_popup().set_item_disabled(id, true) $PassiveUpgrades.get_popup().set_item_disabled(id, true)
scorePerSec = passiveUpgradeAmt100 Global.globalScorePerSec = passiveUpgradeAmt100
else: else:
print("not enough score") print("not enough score")
5: 5:
if score >= passiveUpgradeReq200: if Global.globalScore >= passiveUpgradeReq200:
print ("Score sufficient") print ("Score sufficient")
score -=passiveUpgradeReq200 Global.globalScore -=passiveUpgradeReq200
$PassiveUpgrades.get_popup().set_item_disabled(id, true) $PassiveUpgrades.get_popup().set_item_disabled(id, true)
scorePerSec = passiveUpgradeAmt200 Global.globalScorePerSec = passiveUpgradeAmt200
else: else:
print("not enough score") print("not enough score")
6: 6:
if score >= passiveUpgradeReq500: if Global.globalScore >= passiveUpgradeReq500:
print ("Score sufficient") print ("Score sufficient")
score -=passiveUpgradeReq500 Global.globalScore -=passiveUpgradeReq500
$PassiveUpgrades.get_popup().set_item_disabled(id, true) $PassiveUpgrades.get_popup().set_item_disabled(id, true)
scorePerSec = passiveUpgradeAmt500 Global.globalScorePerSec = passiveUpgradeAmt500
else: else:
print("not enough score") print("not enough score")
7: 7:
if score >= passiveUpgradeReq1000: if Global.globalScore >= passiveUpgradeReq1000:
print ("Score sufficient") print ("Score sufficient")
score -=passiveUpgradeReq1000 Global.globalScore -=passiveUpgradeReq1000
$PassiveUpgrades.get_popup().set_item_disabled(id, true) $PassiveUpgrades.get_popup().set_item_disabled(id, true)
scorePerSec = passiveUpgradeAmt1000 Global.globalScorePerSec = passiveUpgradeAmt1000
else: else:
print("not enough score") print("not enough score")
8: 8:
if score >= passiveUpgradeReq10000: if Global.globalScore >= passiveUpgradeReq10000:
print ("Score sufficient") print ("Score sufficient")
score -=passiveUpgradeReq10000 Global.globalScore -=passiveUpgradeReq10000
$PassiveUpgrades.get_popup().set_item_disabled(id, true) $PassiveUpgrades.get_popup().set_item_disabled(id, true)
scorePerSec = passiveUpgradeAmt10000 Global.globalScorePerSec = passiveUpgradeAmt10000
else: else:
print("not enough score") print("not enough score")

View File

@@ -1,18 +1,27 @@
extends TextureButton extends TextureButton
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
# Connect the pressed signal to the _on_Button_pressed function # Connect the pressed signal to the _on_Button_pressed function
self.connect("pressed", Callable(self, "_on_Button_pressed")) self.connect("pressed", Callable(self, "_on_Button_pressed"))
#Checks if the texture needs to be set
func _process(delta):
#Checks if the texture needs to be set
if Global.selected_texture: if Global.selected_texture:
self.texture_normal = Global.selected_texture self.texture_normal = Global.selected_texture
# Function to handle the button press # Function to handle the button press
func _on_Button_pressed(): func _on_Button_pressed():
# Change the current scene
get_tree().change_scene_to_file("res://team.tscn")
Global.teamScreenVisible = false
Global.teamSelectionVisible = true
#Function to set texture of the button #Function to set texture of the button

View File

@@ -1,5 +1,18 @@
extends Button extends Button
# Called when the node enters the scene tree for the first time.
func _ready():
self.connect("pressed", Callable(self, "_on_Button_pressed"))
# Function to handle the button press
func _on_Button_pressed():
if Global.teamScreenVisible == false:
Global.teamSelectionVisible = false
Global.teamScreenVisible = true
else:
Global.teamScreenVisible = false

View File

@@ -1,10 +1,32 @@
[gd_scene load_steps=6 format=3 uid="uid://xh0p6v5ir05f"] [gd_scene load_steps=14 format=3 uid="uid://xh0p6v5ir05f"]
[ext_resource type="Script" path="res://Root.gd" id="1_dtx5s"] [ext_resource type="Script" path="res://Root.gd" id="1_dtx5s"]
[ext_resource type="Script" path="res://User Interface/TeamButton.gd" id="3_g0muc"] [ext_resource type="Script" path="res://User Interface/TeamButton.gd" id="3_g0muc"]
[ext_resource type="Script" path="res://User Interface/Header.gd" id="3_q5rri"] [ext_resource type="Script" path="res://User Interface/Header.gd" id="3_q5rri"]
[ext_resource type="Script" path="res://User Interface/Member1.gd" id="4_4xump"] [ext_resource type="Script" path="res://User Interface/Member1.gd" id="4_4xump"]
[ext_resource type="Texture2D" uid="uid://bfdqkquqtf6ir" path="res://Images/plus-icon-vector-illustration.jpg" id="4_gxo13"] [ext_resource type="Texture2D" uid="uid://bfdqkquqtf6ir" path="res://Images/plus-icon-vector-illustration.jpg" id="4_gxo13"]
[ext_resource type="Script" path="res://TeamSelection.gd" id="6_1cnw8"]
[ext_resource type="Texture2D" uid="uid://b1kl4huy0vnin" path="res://Member/#1 - Transparent Icons.png" id="7_s2y5l"]
[ext_resource type="Script" path="res://User Interface/Hank.gd" id="8_kx4m8"]
[sub_resource type="AtlasTexture" id="AtlasTexture_74gmg"]
atlas = ExtResource("7_s2y5l")
region = Rect2(128, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_xmmtg"]
atlas = ExtResource("7_s2y5l")
region = Rect2(96, 320, 32, 32)
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_pioex"]
load_path = "res://.godot/imported/#1 - Transparent Icons.png-075c51137bc59a17da3b30778a360723.ctex"
[sub_resource type="AtlasTexture" id="AtlasTexture_l5qwh"]
atlas = SubResource("CompressedTexture2D_pioex")
region = Rect2(32, 416, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_t1ab2"]
atlas = SubResource("CompressedTexture2D_pioex")
region = Rect2(288, 416, 32, 32)
[node name="Root" type="Control"] [node name="Root" type="Control"]
layout_mode = 3 layout_mode = 3
@@ -94,7 +116,25 @@ flat = true
alignment = 0 alignment = 0
script = ExtResource("3_g0muc") script = ExtResource("3_g0muc")
[node name="ClickAddLabel" type="Label" parent="UI/CanvasLayer/Header"]
layout_mode = 2
text = "ClickAdd:"
[node name="ClickAdd" type="Label" parent="UI/CanvasLayer/Header"]
layout_mode = 2
text = "0"
[node name="PerSecLabel" type="Label" parent="UI/CanvasLayer/Header"]
layout_mode = 2
text = "PerSec:
"
[node name="PerSec" type="Label" parent="UI/CanvasLayer/Header"]
layout_mode = 2
text = "0"
[node name="AspectRatioContainer" type="AspectRatioContainer" parent="UI"] [node name="AspectRatioContainer" type="AspectRatioContainer" parent="UI"]
visible = false
layout_mode = 0 layout_mode = 0
offset_left = -2.60654 offset_left = -2.60654
offset_top = 271.396 offset_top = 271.396
@@ -150,3 +190,31 @@ text = "Click Here"
visible = false visible = false
layout_mode = 2 layout_mode = 2
text = "testtestsetsetsetsetsetsetset" text = "testtestsetsetsetsetsetsetset"
[node name="TeamSelection" type="GridContainer" parent="UI"]
visible = false
offset_left = 3.0
offset_top = 40.0
offset_right = 1923.0
offset_bottom = 1120.0
columns = 10
script = ExtResource("6_1cnw8")
[node name="Hank" type="TextureButton" parent="UI/TeamSelection"]
layout_mode = 2
texture_normal = SubResource("AtlasTexture_74gmg")
script = ExtResource("8_kx4m8")
memberClickAdd = 5
memberPerSec = 25
[node name="Rory" type="TextureButton" parent="UI/TeamSelection"]
layout_mode = 2
texture_normal = SubResource("AtlasTexture_xmmtg")
[node name="TextureButton3" type="TextureButton" parent="UI/TeamSelection"]
layout_mode = 2
texture_normal = SubResource("AtlasTexture_l5qwh")
[node name="TextureButton4" type="TextureButton" parent="UI/TeamSelection"]
layout_mode = 2
texture_normal = SubResource("AtlasTexture_t1ab2")

View File

@@ -11,15 +11,15 @@ region = Rect2(128, 0, 32, 32)
atlas = ExtResource("1_o7i06") atlas = ExtResource("1_o7i06")
region = Rect2(96, 320, 32, 32) region = Rect2(96, 320, 32, 32)
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_pioex"] [sub_resource type="CompressedTexture2D" id="CompressedTexture2D_yxbb2"]
load_path = "res://.godot/imported/#1 - Transparent Icons.png-075c51137bc59a17da3b30778a360723.ctex" load_path = "res://.godot/imported/#1 - Transparent Icons.png-075c51137bc59a17da3b30778a360723.ctex"
[sub_resource type="AtlasTexture" id="AtlasTexture_d8eoy"] [sub_resource type="AtlasTexture" id="AtlasTexture_d8eoy"]
atlas = SubResource("CompressedTexture2D_pioex") atlas = SubResource("CompressedTexture2D_yxbb2")
region = Rect2(32, 416, 32, 32) region = Rect2(32, 416, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_ng453"] [sub_resource type="AtlasTexture" id="AtlasTexture_ng453"]
atlas = SubResource("CompressedTexture2D_pioex") atlas = SubResource("CompressedTexture2D_yxbb2")
region = Rect2(288, 416, 32, 32) region = Rect2(288, 416, 32, 32)
[node name="Root" type="Control"] [node name="Root" type="Control"]