Added hunger tick damage

This commit is contained in:
akshay 2022-08-16 19:56:48 -04:00
parent 3fb9fce92f
commit c6da4e0aa2
6 changed files with 138 additions and 25 deletions

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=2]
[gd_scene load_steps=22 format=2]
[ext_resource path="res://scenes/player.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/moonbase_whitebox/Moonbase_Whitebox.tscn" type="PackedScene" id=2]
@ -14,15 +14,16 @@
[ext_resource path="res://scenes/dinner_table.tscn" type="PackedScene" id=12]
[ext_resource path="res://scenes/hydroponics_station.tscn" type="PackedScene" id=13]
[ext_resource path="res://scenes/oven.tscn" type="PackedScene" id=14]
[ext_resource path="res://scenes/game_manager.tscn" type="PackedScene" id=15]
[sub_resource type="CylinderShape" id=1]
[sub_resource type="CylinderShape" id=8]
height = 5.22615
radius = 8.72145
[sub_resource type="BoxShape" id=2]
[sub_resource type="BoxShape" id=9]
extents = Vector3( 1.78436, 2.33105, 6.04815 )
[sub_resource type="Animation" id=3]
[sub_resource type="Animation" id=10]
length = 0.001
tracks/0/type = "value"
tracks/0/path = NodePath(".:camera_lerp")
@ -37,7 +38,7 @@ tracks/0/keys = {
"values": [ 0.0 ]
}
[sub_resource type="Animation" id=4]
[sub_resource type="Animation" id=11]
resource_name = "switch_camera"
length = 0.3
tracks/0/type = "value"
@ -53,10 +54,26 @@ tracks/0/keys = {
"values": [ 0.0, 1.0 ]
}
[sub_resource type="ProceduralSky" id=7]
sky_top_color = Color( 0.486275, 0.486275, 0.486275, 1 )
sky_horizon_color = Color( 0.180392, 0.180392, 0.180392, 1 )
ground_bottom_color = Color( 0.545098, 0.545098, 0.545098, 1 )
ground_horizon_color = Color( 0.8, 0.8, 0.8, 1 )
sun_color = Color( 0, 0, 0, 1 )
[sub_resource type="Environment" id=12]
background_mode = 2
background_sky = SubResource( 7 )
ss_reflections_enabled = true
ssao_enabled = true
[node name="dev_akshay" type="Spatial"]
[node name="Moonbase_Whitebox" parent="." instance=ExtResource( 2 )]
[node name="Player" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5.27448 )
[node name="cameras" type="Spatial" parent="."]
script = ExtResource( 10 )
target = NodePath("../Player")
@ -79,7 +96,7 @@ collision_mask = 2
[node name="CollisionShape" type="CollisionShape" parent="cameras/camera_room_center/hitbox"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.52689, 0 )
shape = SubResource( 1 )
shape = SubResource( 8 )
[node name="camera_room_hallway" type="Spatial" parent="cameras"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0726166, 0, 17.4284 )
@ -94,7 +111,7 @@ collision_mask = 2
[node name="CollisionShape" type="CollisionShape" parent="cameras/camera_room_hallway/hitbox"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.52689, -1.44831 )
shape = SubResource( 2 )
shape = SubResource( 9 )
[node name="camera_room0" parent="cameras" instance=ExtResource( 8 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 15.408, 0, 0 )
@ -118,11 +135,72 @@ transform = Transform( -0.661796, 0, -0.749684, 0, 1, 0, 0.749684, 0, -0.661796,
transform = Transform( 0.696427, 0, -0.717628, 0, 1, 0, 0.717628, 0, 0.696427, 10.8827, 0, 10.7342 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="cameras"]
anims/RESET = SubResource( 3 )
anims/switch_camera = SubResource( 4 )
anims/RESET = SubResource( 10 )
anims/switch_camera = SubResource( 11 )
[node name="Player" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5.27448 )
[node name="lights" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 4.14791, 0, 6.48126 )
[node name="Hub1" type="OmniLight" parent="lights"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.11319, 4.20288, -1.73099 )
shadow_enabled = true
omni_range = 10.7698
[node name="Hub2" type="OmniLight" parent="lights"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.059, 4.20288, -11.3228 )
shadow_enabled = true
omni_range = 10.7698
[node name="OmniLight20" type="OmniLight" parent="lights"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 10.9024, 3.329, -6.67066 )
shadow_enabled = true
omni_range = 5.893
omni_attenuation = 2.0
[node name="OmniLight21" type="OmniLight" parent="lights"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 6.06107, 3.329, -17.2136 )
shadow_enabled = true
omni_range = 5.893
omni_attenuation = 2.0
[node name="OmniLight22" type="OmniLight" parent="lights"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.23606, 3.329, -21.2439 )
shadow_enabled = true
omni_range = 5.893
omni_attenuation = 2.0
[node name="OmniLight23" type="OmniLight" parent="lights"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -14.8527, 3.329, -16.8695 )
shadow_enabled = true
omni_range = 5.893
omni_attenuation = 2.0
[node name="OmniLight24" type="OmniLight" parent="lights"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -19.2271, 3.329, -6.05627 )
shadow_enabled = true
omni_range = 5.893
omni_attenuation = 2.0
[node name="OmniLight25" type="OmniLight" parent="lights"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -14.2271, 3.329, 4.94373 )
shadow_enabled = true
omni_range = 5.893
omni_attenuation = 2.0
[node name="OmniLight26" type="OmniLight" parent="lights"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 7.64507, 3.329, 3.88698 )
shadow_enabled = true
omni_range = 5.893
omni_attenuation = 2.0
[node name="OmniLight27" type="OmniLight" parent="lights"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.20031, 3.329, 9.61307 )
shadow_enabled = true
omni_range = 5.893
omni_attenuation = 2.0
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 12 )
[node name="power_station" parent="." instance=ExtResource( 3 )]
transform = Transform( 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 1, 0 )
@ -196,6 +274,8 @@ transform = Transform( 1, 0, 0, 0, 1, 5.82077e-11, 0, 0, 1, 1.96066, -2.56114e-0
[node name="hydroponics_station3" parent="Hydroponics_Room" instance=ExtResource( 13 )]
transform = Transform( 1, 0, 0, 0, 1, 5.82077e-11, 0, 0, 1, -1.9892, -3.0268e-09, -7.67101 )
[node name="game_manager" parent="." instance=ExtResource( 15 )]
[connection signal="player_entered" from="cameras/camera_room_center" to="cameras" method="_on_camera_room_player_entered"]
[connection signal="player_exited" from="cameras/camera_room_center" to="cameras" method="_on_camera_room_player_exited"]
[connection signal="area_entered" from="cameras/camera_room_center/hitbox" to="cameras/camera_room_center" method="_on_hitbox_area_entered"]

6
scenes/game_manager.tscn Normal file
View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://scripts/game_manager.gd" type="Script" id=1]
[node name="game_manager" type="Node"]
script = ExtResource( 1 )

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=13 format=2]
[gd_scene load_steps=14 format=2]
[ext_resource path="res://assets/moonbase_whitebox/Moonbase_Whitebox.tscn" type="PackedScene" id=1]
[ext_resource path="res://scripts/cameras.gd" type="Script" id=2]
@ -6,6 +6,7 @@
[ext_resource path="res://scenes/camera_room.tscn" type="PackedScene" id=4]
[ext_resource path="res://scripts/camera_room.gd" type="Script" id=5]
[ext_resource path="res://scripts/tracking_camera.gd" type="Script" id=6]
[ext_resource path="res://scenes/game_manager.tscn" type="PackedScene" id=7]
[sub_resource type="CylinderShape" id=1]
height = 5.22615
@ -45,7 +46,7 @@ tracks/0/keys = {
"values": [ 0.0, 1.0 ]
}
[sub_resource type="ProceduralSky" id=5]
[sub_resource type="ProceduralSky" id=7]
sky_top_color = Color( 0.486275, 0.486275, 0.486275, 1 )
sky_horizon_color = Color( 0.180392, 0.180392, 0.180392, 1 )
ground_bottom_color = Color( 0.545098, 0.545098, 0.545098, 1 )
@ -54,7 +55,7 @@ sun_color = Color( 0, 0, 0, 1 )
[sub_resource type="Environment" id=6]
background_mode = 2
background_sky = SubResource( 5 )
background_sky = SubResource( 7 )
ss_reflections_enabled = true
ssao_enabled = true
@ -193,6 +194,8 @@ omni_attenuation = 2.0
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 6 )
[node name="game_manager" parent="." instance=ExtResource( 7 )]
[connection signal="player_entered" from="cameras/camera_room_center" to="cameras" method="_on_camera_room_player_entered"]
[connection signal="player_exited" from="cameras/camera_room_center" to="cameras" method="_on_camera_room_player_exited"]
[connection signal="area_entered" from="cameras/camera_room_center/hitbox" to="cameras/camera_room_center" method="_on_hitbox_area_entered"]

View File

@ -526,7 +526,7 @@ nodes/Blink/position = Vector2( 120, 200 )
nodes/Move/node = SubResource( 16 )
nodes/Move/position = Vector2( -146.667, 200 )
nodes/output/position = Vector2( 586.667, 200 )
node_connections = [ "Blink", 0, "Move", "Blink", 1, "Animation", "Activate", 0, "Blink", "Activate", 1, "Animation 2", "output", 0, "Activate" ]
node_connections = [ "Activate", 0, "Blink", "Activate", 1, "Animation 2", "Blink", 0, "Move", "Blink", 1, "Animation", "output", 0, "Activate" ]
[sub_resource type="AnimationNodeStateMachinePlayback" id=17]
@ -557,7 +557,7 @@ mesh = SubResource( 1 )
skin = SubResource( 2 )
[node name="head_bone" type="BoneAttachment" parent="DungMan/Armature/Skeleton" index="1"]
transform = Transform( 1, -2.20768e-16, 2.40265e-17, -1.35325e-19, 0.107587, 0.994196, -2.22071e-16, -0.994196, 0.107587, -3.31208e-16, -0.0622646, -1.5003 )
transform = Transform( 1, -2.21836e-16, 1.04101e-17, -1.71852e-19, 0.0461024, 0.998937, -2.22081e-16, -0.998937, 0.0461024, -3.32115e-16, -0.0357828, -1.49896 )
bone_name = "Item"
[node name="ItemSpawn" type="Spatial" parent="DungMan/Armature/Skeleton/head_bone"]
@ -651,6 +651,10 @@ margin_right = 524.0
margin_bottom = 128.0
texture = ExtResource( 3 )
[node name="hunger_timer" type="Timer" parent="."]
unique_name_in_owner = true
[connection signal="timeout" from="DungMan/blink_timer" to="." method="_on_blink_timer_timeout"]
[connection signal="timeout" from="hunger_timer" to="." method="_on_hunger_timer_timeout"]
[editable path="DungMan"]

View File

@ -1,19 +1,26 @@
extends KinematicBody
signal starved_to_death
const EPSILON = 0.0001
const SPEED = 10.0
export var inventory = { "ore" : 0 }
var health: int = 4 setget set_health
export var hunger_tick_time = 30.0
export var inventory = {}
var health: int = 4 setget set_health
var item_in_hand
var move_enabled: bool = true
onready var move_playback = $DungMan/AnimationTree["parameters/Move/playback"]
onready var hunger_timer = $"%hunger_timer"
# Called when the node enters the scene tree for the first time.
func _ready():
$hitbox.set_meta("owner", self)
move_playback.travel("idle")
hunger_timer.wait_time = hunger_tick_time
hunger_timer.start()
func _physics_process(delta):
if not move_enabled:
@ -27,18 +34,16 @@ func _physics_process(delta):
move_playback.travel("idle")
move_and_slide(motion)
func _on_hunger_timer_timeout():
set_health(health - 1)
print("player: lost health to hunger tick")
func set_health(new_value):
health = min(new_value, 4)
for child in $"%stomachs".get_children():
child.visible = child.get_index() < health
if health <= 0:
var node = Dialogic.start("starve")
node.pause_mode = PAUSE_MODE_PROCESS
add_child(node)
get_tree().paused = true
yield(node, "timeline_end")
get_tree().paused = false
get_tree().quit() # go back to main menu when such a thing exists
emit_signal("starved_to_death")
func can_afford(item_name, item_amount):
assert(item_amount > 0)

15
scripts/game_manager.gd Normal file
View File

@ -0,0 +1,15 @@
extends Node
onready var player = get_tree().get_nodes_in_group("player")[0]
func _ready():
player.connect("starved_to_death", self, "_on_player_starved_to_death")
func _on_player_starved_to_death():
var node = Dialogic.start("starve")
node.pause_mode = PAUSE_MODE_PROCESS
add_child(node)
get_tree().paused = true
yield(node, "timeline_end")
get_tree().paused = false
get_tree().quit() # go back to main menu when such a thing exists