You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CupcakeRevolution/Scripts/game_world.gd

242 lines
5.8 KiB
GDScript

extends Node2D
signal condensedCupcake1()
signal condensedCupcake2()
signal condensedCupcake3()
#Cupcake Values
var ccVanNum: int = 0
var ccVanValue: int = 1
var ccChocNum: int = 0
var ccChocValue: int = 1
var ccStrawNum: int = 0
var ccStrawValue: int = 1
var ccRVelNum: int = 0
var ccCRVelValue: int = 1
var ccCinNum: int = 0
var ccCinValue: int = 1
var ccNightmareNum: int = 0
var ccNightmareValue: int = 1
#Cupcake Upgrade Prices
var ccVanPrice: int = 10
var ccVanPrice2: int = 15
var ccVanPrice3: int = 15
var ccVanPrice4: int = 250
var ccChocPrice: int = 10
var ccChocPrice2: int
var ccChocPrice3: int
var ccChocPrice4: int
var ccChocPrice5: int
var ccChocPrice6: int
var ccStrawPrice: int
var ccStrawPrice2: int
var ccStrawPrice3: int
var ccStrawPrice4: int
var ccStrawPrice5: int
var ccStrawPrice6: int
#Preloaded scenes and scripts
var upgradeUI = preload("res://Scenes/UI/upgrades.tscn")
var location = preload("res://Scenes/Locations/yard.tscn")
var horse_scene = preload("res://Scenes/horse.tscn")
var horse = preload("res://Scripts/horse.gd")
var ccVanilla = preload("res://Scenes/Cupcakes/cupcake.tscn")
var ccChocolate = preload("res://Scenes/Cupcakes/chocCupcake.tscn")
var ccStrawberry = preload("res://Scenes/Cupcakes/strawCupcake.tscn")
var ccRedVelvet
var ccCinnamon
var ccNightmare
var ccRock
var ccRuby
var ccSapphire
var ccEmerald
var ccDiamond
var ccChaos
#Instantiations
var ccVan = ccVanilla.instantiate()
var ccChoc = ccChocolate.instantiate()
var ccStraw = ccStrawberry.instantiate()
var ccRVel
var ccNight
var ccRoc
var ccRub
var ccSap
var ccEme
var ccDia
var ccCha
#Cupcake Locks
var ccChocLocked = true
var ccStrawLocked = true
var ccRVelLocked = true
var ccCinLocked = true
var ccNightLocked = true
var ccRocLocked = true
var ccRubLocked = true
var ccSapLocked = true
var ccEmeLocked = true
var ccDiaLocked = true
var ccChaLocked = true
#Spawnrates
var ccVanSpawnRate = 60
var ccChocSpawnRate = 3
var ccStrawSpawnRate = 3
var ccRVelSpawnRate = 3
var ccNightSpawnRate = 3
var ccRocSpawnRate = 3
var ccRubSpawnRate = 3
var ccSapSpawnRate = 3
var ccEmeSpawnRate = 3
var ccDiaSpawnRate = 3
var ccChaSpawnRate = 3
#Other
@onready var timer = get_node("Cupcake Spawn Timer")
var horseAttached = true
var horse_instance
var mouse_position = Vector2.ZERO
var ccCount = 0
var ccMaxOnScreen = 2000
#General
func _ready():
var spawn
horse_instance = horse_scene.instantiate()
spawn = location.instantiate()
$Location.add_child(spawn)
add_child(horse_instance)
func _process(delta):
if horseAttached == true:
mouse_position = get_global_mouse_position()
horse_instance.position = mouse_position
handleInput()
func handleInput():
if Input.is_action_pressed("horseAttach"):
if horseAttached == true:
horseAttached = false
else:
horseAttached = true
func collectCupcakes():
$InGameUI/Num/GridContainer/ccVanNum.text = str(ccVanNum)
$InGameUI/Num/GridContainer/ccChocNum.text = str(ccChocNum)
$InGameUI/Num/GridContainer/ccStrawNum.text = str(ccStrawNum)
func _on_timeout():
spawnVanCupcakes()
if ccChocLocked == false:
spawnChocCupcakes()
if ccStrawLocked == false:
spawnStrawCupcakes()
collectCupcakes()
timer.start
#Spawn
func spawnVanCupcakes():
var randX
var randY
randomize()
if ccCount <= ccMaxOnScreen:
for i in range(ccVanSpawnRate):
randX = randi_range(10, 1910)
randY = randi_range(10, 1070)
ccVan.position = Vector2(randX, randY)
$Cupcakes.add_child(ccVan.duplicate())
ccCount = ccCount + ccVanSpawnRate
func spawnChocCupcakes():
var randX
var randY
randomize()
if ccCount <= ccMaxOnScreen:
for i in range(ccChocSpawnRate):
randX = randi_range(10, 1910)
randY = randi_range(10, 1070)
ccChoc.position = Vector2(randX, randY)
$Cupcakes.add_child(ccChoc.duplicate())
ccCount = ccCount + ccChocSpawnRate
func spawnStrawCupcakes():
var randX
var randY
randomize()
if ccCount <= ccMaxOnScreen:
for i in range(ccStrawSpawnRate):
randX = randi_range(10, 1910)
randY = randi_range(10, 1070)
ccStraw.position = Vector2(randX, randY)
$Cupcakes.add_child(ccStraw.duplicate())
ccCount = ccCount + ccStrawSpawnRate
#Upgrades
func _on_upgrades_one_more_cupcake():
if ccVanNum >= ccVanPrice:
ccVanSpawnRate += 1
ccVanNum -= ccVanPrice
ccVanPrice = ccVanPrice * 1.3
$Upgrades/Control/VanScroll/VanGrid/VanUp1/Price.text = str(ccVanPrice)
collectCupcakes()
func _on_upgrades_faster_cupcake():
if ccVanNum >= ccVanPrice2:
ccVanNum -= ccVanPrice2
ccVanPrice2 = ccVanPrice2 * 1.3
timer.wait_time = timer.wait_time - (timer.wait_time * 0.01)
$Upgrades/Control/VanScroll/VanGrid/VanUp2/Price.text = str(ccVanPrice2)
collectCupcakes()
func _on_upgrades_condensed_cupcake_1():
if ccVanNum >= ccVanPrice3:
ccVanNum -= ccVanPrice3
ccVanPrice3 = ccVanPrice3 * 1.3
ccVanValue += 1
$Upgrades/Control/VanScroll/VanGrid/VanUp3/Price.text = str(ccVanPrice3)
collectCupcakes()
#Unlock
func _on_upgrades_unlock_choc():
if ccVanNum >= ccVanPrice4:
ccVanNum -= ccVanPrice4
ccChocLocked = false
$"InGameUI/Main/HBoxContainer/Choc".visible = true
$"InGameUI/Num/GridContainer/chocIcon".visible = true
$"InGameUI/Num/GridContainer/ccChocNum".visible = true
$"Upgrades/Control/VanScroll/VanGrid/VanUp4/Buy".visible = false
func _on_upgrades_unlock_straw():
if ccChocNum >= ccChocPrice4:
ccChocNum -= ccChocPrice4
ccStrawLocked = false
$"InGameUI/Main/HBoxContainer/Straw".visible = true
$"InGameUI/Num/GridContainer/strawIcon".visible = true
$"InGameUI/Num/GridContainer/ccStrawNum".visible = true
$"Upgrades/Control/ChocScroll/ChocGrid/ChocUp4/Buy".visible = false
#Collect
func _on_van_cupcake_cc_van_collected():
ccVanNum += ccVanValue
ccCount -= 1
collectCupcakes()
func _on_choc_cupcake_cc_choc_collected():
ccChocNum += ccChocValue
ccCount -= 1
collectCupcakes()
func _on_straw_cupcake_cc_straw_collected():
ccStrawNum += ccStrawValue
ccCount -= 1
collectCupcakes()