One time income and pay expense signals

Test income and expense with varies variables.
This commit is contained in:
Anthony Foxclaw 2020-04-13 01:49:07 -04:00
parent 63bde9f37f
commit d13622dd1b
5 changed files with 40 additions and 19 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=16 format=2] [gd_scene load_steps=18 format=2]
[ext_resource path="res://src/room.gd" type="Script" id=1] [ext_resource path="res://src/room.gd" type="Script" id=1]
[ext_resource path="res://assets/Office/office_t0_1_3.png" type="Texture" id=2] [ext_resource path="res://assets/Office/office_t0_1_3.png" type="Texture" id=2]
@ -14,15 +14,17 @@
[ext_resource path="res://assets/Office/office_t1_2_2.png" type="Texture" id=12] [ext_resource path="res://assets/Office/office_t1_2_2.png" type="Texture" id=12]
[ext_resource path="res://assets/Office/office_t1_2_0.png" type="Texture" id=13] [ext_resource path="res://assets/Office/office_t1_2_0.png" type="Texture" id=13]
[ext_resource path="res://assets/Office/office_t1_2_5.png" type="Texture" id=14] [ext_resource path="res://assets/Office/office_t1_2_5.png" type="Texture" id=14]
[ext_resource path="res://assets/Office/office_t0_0_1.png" type="Texture" id=15]
[ext_resource path="res://assets/Office/office_t1_0_1.png" type="Texture" id=16]
[sub_resource type="SpriteFrames" id=1] [sub_resource type="SpriteFrames" id=1]
animations = [ { animations = [ {
"frames": [ ExtResource( 13 ), ExtResource( 10 ), ExtResource( 12 ), ExtResource( 3 ), ExtResource( 11 ), ExtResource( 14 ) ], "frames": [ ExtResource( 16 ), ExtResource( 13 ), ExtResource( 10 ), ExtResource( 12 ), ExtResource( 3 ), ExtResource( 11 ), ExtResource( 14 ) ],
"loop": true, "loop": true,
"name": "v2", "name": "v2",
"speed": 2.0 "speed": 2.0
}, { }, {
"frames": [ ExtResource( 9 ), ExtResource( 8 ), ExtResource( 7 ), ExtResource( 2 ), ExtResource( 5 ), ExtResource( 4 ), ExtResource( 6 ) ], "frames": [ ExtResource( 15 ), ExtResource( 9 ), ExtResource( 8 ), ExtResource( 7 ), ExtResource( 2 ), ExtResource( 5 ), ExtResource( 4 ), ExtResource( 6 ) ],
"loop": true, "loop": true,
"name": "v1", "name": "v1",
"speed": 2.0 "speed": 2.0
@ -30,14 +32,9 @@ animations = [ {
[node name="Office" type="Node2D"] [node name="Office" type="Node2D"]
script = ExtResource( 1 ) script = ExtResource( 1 )
room_cost = 1000
room_income = 500
room_expense = 350
room_capacity = 1
is_rentable = true
[node name="AnimatedSprite" type="AnimatedSprite" parent="."] [node name="RoomAnime" type="AnimatedSprite" parent="."]
frames = SubResource( 1 ) frames = SubResource( 1 )
animation = "v1" animation = "v1"
frame = 5 frame = 2
playing = true playing = true

View file

@ -11,3 +11,5 @@ var news: String
enum GameSpeed { SLOW, MEDIUM, FAST } enum GameSpeed { SLOW, MEDIUM, FAST }
signal quarter_income signal quarter_income
signal one_time_income
signal pay_expense

View file

@ -9,16 +9,20 @@ export var room_income: int
export var room_expense: int export var room_expense: int
export var room_capacity: int export var room_capacity: int
export var is_rentable: bool export var is_rentable: bool
export(IncomeFrequency) var income_frequency = IncomeFrequency.QUARTERLY export(IncomeFrequency) var income_frequency = IncomeFrequency.QUARTERLY
export(ChooseSprite) var choose_sprite = ChooseSprite.VERSION_1 export(ChooseSprite) var choose_sprite = ChooseSprite.VERSION_1
var is_vacant: bool var is_paid: bool = false
var num_of_tenants: int var is_vacant: bool = true
var is_full: bool var is_full: bool = false
var num_of_tenants: int = 0
func _ready(): func _ready():
GameData.connect("quarter_income", self, "_get_quarter_income") GameData.connect("quarter_income", self, "_get_quarter_income")
GameData.connect("one_time_income", self, "_get_one_time_income")
GameData.connect("pay_expense", self, "_get_expense")
# Once placed in-world, it'll substract from your budget # Once placed in-world, it'll substract from your budget
if GameData.budget >= room_cost: if GameData.budget >= room_cost:
@ -26,17 +30,25 @@ func _ready():
func _process(delta): func _process(delta):
match choose_sprite:
ChooseSprite.VERSION_1:
$AnimatedSprite.play("v1")
ChooseSprite.VERSION_2:
$AnimatedSprite.play("v2")
# If the office is no longer vacant, start rent timer # If the office is no longer vacant, start rent timer
if is_rentable == true: if is_rentable == true:
if num_of_tenants >= room_capacity: if num_of_tenants >= room_capacity:
is_vacant = false is_vacant = false
num_of_tenants += 1 num_of_tenants += 1
match choose_sprite:
ChooseSprite.VERSION_1:
$RoomAnime.play("v1")
ChooseSprite.VERSION_2:
$RoomAnime.play("v2")
func _get_expense():
GameData.budget -= room_expense
func _get_one_time_income():
if is_paid == false:
GameData.budget += room_income
is_paid = true
func _get_quarter_income(): func _get_quarter_income():
GameData.budget += room_income GameData.budget += room_income

View file

@ -5,6 +5,8 @@ func _on_Quarters_timeout():
if GameData.prev_quarter == 4: if GameData.prev_quarter == 4:
GameData.quarter = 1 GameData.quarter = 1
GameData.year += 1 GameData.year += 1
GameData.emit_signal("one_time_income")
GameData.emit_signal("pay_expense")
else: else:
GameData.emit_signal("quarter_income") GameData.emit_signal("quarter_income")
GameData.quarter += 1 GameData.quarter += 1

View file

@ -13,9 +13,17 @@ autostart = true
[node name="Office" parent="." instance=ExtResource( 3 )] [node name="Office" parent="." instance=ExtResource( 3 )]
position = Vector2( 481.153, 260.554 ) position = Vector2( 481.153, 260.554 )
room_income = 700
room_expense = 200
room_capacity = 1
is_rentable = true
[node name="Office2" parent="." instance=ExtResource( 3 )] [node name="Office2" parent="." instance=ExtResource( 3 )]
position = Vector2( 271.221, 296.175 ) position = Vector2( 271.221, 296.175 )
room_income = 600
room_expense = 300
room_capacity = 1
is_rentable = true
choose_sprite = 1 choose_sprite = 1
[node name="GUI" parent="." instance=ExtResource( 2 )] [node name="GUI" parent="." instance=ExtResource( 2 )]