connecting time and pill level changes to player info label

This commit is contained in:
incredibleLeitman 2020-01-28 22:43:35 +01:00
parent 74812a2a10
commit 1c23fc9b2f
5 changed files with 93 additions and 27 deletions

View File

@ -154,6 +154,7 @@ func _set_behavior ():
# EDIT: too early at work is not an angry reason :p # EDIT: too early at work is not an angry reason :p
elif _playerRef.IsInFactory and daytime > Daytime.SLEEP_TIME: # at work after out of WORK_TIME elif _playerRef.IsInFactory and daytime > Daytime.SLEEP_TIME: # at work after out of WORK_TIME
reason = "player in factory out of worktime" reason = "player in factory out of worktime"
Logger.info("daytime: " + String(daytime) + " SLEEP_TIME: " + String(Daytime.SLEEP_TIME))
elif _countCmds > MAX_CMDS: # after MAX_CMDS repeats of the same command elif _countCmds > MAX_CMDS: # after MAX_CMDS repeats of the same command
reason = "player is seemingly not coorperativ" reason = "player is seemingly not coorperativ"

View File

@ -106,12 +106,21 @@ func _ready():
area.connect("area_exited", self, "_on_area_exited") area.connect("area_exited", self, "_on_area_exited")
Daytime.connect("respawn", self, "_on_respawn") Daytime.connect("respawn", self, "_on_respawn")
Daytime.connect("go_home", self, "_on_go_home")
Daytime.connect("go_to_work", self, "_on_go_to_work")
Pills.connect("low_pill_level", self, "_on_pill_level_low")
Pills.connect("very_low_pill_level", self, "_on_pill_level_very_low")
if IsOutside: if IsOutside:
var player = get_node("AudioStreamPlayer3D") var player = get_node("AudioStreamPlayer3D")
player.stream = load("res://Resources/Audio/cock.wav") player.stream = load("res://Resources/Audio/cock.wav")
player.play() player.play()
# only message Player at the beginning
if Daytime.get_time() < 10:
showMessage("Press 'F' to eat your food", 4)
func showMessage (text, duration): func showMessage (text, duration):
_labelMessage.text = text _labelMessage.text = text
@ -234,6 +243,7 @@ func _input(event):
# Prevent player from doing a purzelbaum # Prevent player from doing a purzelbaum
_camera.rotation_degrees.x = clamp(_camera.rotation_degrees.x, -70, 70) _camera.rotation_degrees.x = clamp(_camera.rotation_degrees.x, -70, 70)
func _on_area_entered (area: Area): func _on_area_entered (area: Area):
if area.is_in_group("Forbidden"): if area.is_in_group("Forbidden"):
Logger.info("entering forbidden area!") Logger.info("entering forbidden area!")
@ -246,27 +256,24 @@ func _on_area_entered (area: Area):
_work_areas += 1 _work_areas += 1
elif area.is_in_group("FactoryEntry"): elif area.is_in_group("FactoryEntry"):
Logger.info("entering factory") Logger.info("entering factory")
IsInFactory = true #IsInFactory = true
IsOutside = false #IsOutside = false
get_tree().change_scene("res://Level/InFactory.tscn") get_tree().change_scene("res://Level/InFactory.tscn")
elif area.is_in_group("TunnelEntry"): elif area.is_in_group("TunnelEntry"):
Logger.info("entering factory") Logger.info("entering factory")
IsInFactory = false #IsInFactory = false
IsOutside = false #IsOutside = false
# TODO: move not change_scene!
get_tree().change_scene("res://Level/Tunnel.tscn") get_tree().change_scene("res://Level/Tunnel.tscn")
# TODO: other entries # TODO: other entries
elif area.is_in_group("OutsideEntry"): elif area.is_in_group("OutsideEntry"):
Logger.info("leaving factory") Logger.info("leaving factory")
IsInFactory = false #IsInFactory = false
IsOutside = true #IsOutside = true
# TODO: move not change_scene! get_tree().change_scene("res://Level/OutsideWorldReverse.tscn")
get_tree().change_scene("res://Level/OutsideWorld.tscn")
elif area.is_in_group("LabyrinthEntry"): elif area.is_in_group("LabyrinthEntry"):
Logger.info("entering labyrinth") Logger.info("entering labyrinth")
IsInFactory = false #IsInFactory = false
IsInLabyrinth = true #IsInLabyrinth = true
# TODO: move not change_scene!
get_tree().change_scene("res://Level/Labyrinth.tscn") get_tree().change_scene("res://Level/Labyrinth.tscn")
@ -307,3 +314,23 @@ func _on_respawn ():
get_tree().change_scene("res://Level/OutsideWorld.tscn") get_tree().change_scene("res://Level/OutsideWorld.tscn")
_inventory.show() # enable hud again _inventory.show() # enable hud again
func _on_go_home ():
if IsInFactory:
showMessage("Jobs done! Time to go home", 4)
func _on_go_to_work ():
if IsOutside:
showMessage("Time to go to work", 4)
func _on_pill_level_low ():
Logger.info("player received low pill")
showMessage("Don't starve! Press 'F' to eat your food!", 4)
func _on_pill_level_very_low ():
Logger.info("player received very low pill")
showMessage("REALLY! You should eat your food!", 4)

View File

@ -36,17 +36,31 @@ visible = false
modulate = Color( 0, 0, 0, 1 ) modulate = Color( 0, 0, 0, 1 )
self_modulate = Color( 0, 0, 0, 1 ) self_modulate = Color( 0, 0, 0, 1 )
anchor_left = 0.5 anchor_left = 0.5
anchor_top = 1.0 anchor_top = 0.5
anchor_right = 0.5 anchor_right = 0.5
anchor_bottom = 1.0 anchor_bottom = 0.5
margin_left = -153.0 margin_left = -460.0
margin_top = -106.0 margin_top = 162.0
margin_right = 153.0 margin_right = 460.0
margin_bottom = -82.0 margin_bottom = 186.0
custom_fonts/font = ExtResource( 2 ) custom_fonts/font = ExtResource( 2 )
text = "you don't havve the right key" text = "this is a very long text. just needed to be able to center it at the beginning of the game"
align = 1 align = 1
[node name="labelHealth" type="Label" parent="."]
modulate = Color( 0, 0, 0, 1 )
self_modulate = Color( 0, 0, 0, 1 )
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -790.869
margin_top = -402.863
margin_right = -640.869
margin_bottom = -378.863
custom_fonts/font = ExtResource( 2 )
text = "Health"
[node name="InventoryContainer" type="GridContainer" parent="."] [node name="InventoryContainer" type="GridContainer" parent="."]
anchor_left = 1.0 anchor_left = 1.0
anchor_top = 0.5 anchor_top = 0.5

View File

@ -1,15 +1,18 @@
extends Node extends Node
#const _max: int = 1440 # 24 hour + 60 mins const _max: int = 1440 # 24 hour + 60 mins
const _max: int = 1440
const WORK_TIME = _max * 0.3 const WORK_TIME = _max * 0.3
const SLEEP_TIME = _max * 0.6 const SLEEP_TIME = _max * 0.6
const TIGGER_TIME = _max * 0.2
var _time: float setget _set_time, get_time var _time: float = 0 setget _set_time, get_time
var increase_per_second: float = 5.0 var _prev_time: float = _time
var increase_per_second: float = 25.0
signal respawn signal respawn
signal go_to_work
signal go_home
func _set_time (new_time: float): func _set_time (new_time: float):
@ -26,7 +29,16 @@ func get_max () -> int:
func _process (delta: float) -> void: func _process (delta: float) -> void:
# continually increases daytime # continually increases daytime
_set_time(_time + increase_per_second * delta) _time = _time + increase_per_second * delta
if _time >= _max: if _time >= _max:
_time = 0 _time = 0
emit_signal("respawn") emit_signal("respawn")
if _prev_time < WORK_TIME - TIGGER_TIME and _time > WORK_TIME - TIGGER_TIME:
Logger.info("time to go to work @" + String(_time))
emit_signal("go_to_work")
if _prev_time < SLEEP_TIME and _time > SLEEP_TIME:
Logger.info("time to go home @" + String(_time))
emit_signal("go_home")
_prev_time = _time

View File

@ -1,12 +1,16 @@
extends Node extends Node
var _level: float setget _set_level, get_level
var _min: float = 0.0 var _min: float = 0.0
var _max: float = 6.0 var _max: float = 6.0
var _level: float = _max setget _set_level, get_level
var _prev_level: float = _max
var _decrease_per_second: float = 0.2 var _decrease_per_second: float = 0.2
var _pill_add_amount: float = 2.0 var _pill_add_amount: float = 2.0
signal low_pill_level
signal very_low_pill_level
enum LEVELS { enum LEVELS {
SOBRE = 0, SOBRE = 0,
VERY_LOW = 1, VERY_LOW = 1,
@ -50,7 +54,15 @@ func _ready() -> void:
func _process(delta: float) -> void: func _process(delta: float) -> void:
# Gradually decrease the level by the decrease per second # Gradually decrease the level by the decrease per second
_set_level(_level - _decrease_per_second * delta) _level = _level - _decrease_per_second * delta
if _prev_level > LEVELS.VERY_LOW and _level < LEVELS.VERY_LOW:
Logger.info("very low pill level")
emit_signal("very_low_pill_level")
elif _prev_level > LEVELS.MEDIUM and _level < LEVELS.MEDIUM:
Logger.info("low pill level")
emit_signal("low_pill_level")
_prev_level = _level
func take_pill(): func take_pill():