This commit is contained in:
Leon Palluch 2019-11-21 21:46:15 +01:00
commit e0c708e8af
20 changed files with 1368 additions and 51 deletions

View File

@ -7,4 +7,5 @@ onready var steps = [
func play_footstep(): func play_footstep():
Logger.trace("Footstep")
steps[0].play() steps[0].play()

View File

@ -0,0 +1,10 @@
extends Spatial
onready var screen_texture = get_node("ScreenTexture") as ColorRect
func _process(delta: float) -> void:
# The factor is 0 when the level is between 0% and 25%; 1 when the level is between 75% and 100%; lerp inbetween
var factor = clamp((Pills.get_level() / Pills.get_max() * 1.5 - 0.25), 0.0, 1.0)
screen_texture.material.set_shader_param("mask_factor", factor)

View File

@ -0,0 +1,17 @@
extends Spatial
var _animation: AnimationPlayer
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
# Taking a pill
if Input.is_action_just_pressed("take_pill"):
Pills.take_pill()
Logger.info("Player took a pill; new level: %s" % [Pills.get_round_level()])
_animation.play("PillTaking")
func _ready():
_animation = get_parent().get_node("PillAnimationPlayer") as AnimationPlayer
assert(null != _animation)

View File

@ -5,6 +5,7 @@ export(NodePath) var body_nodepath
export(NodePath) var lookingAt_nodepath export(NodePath) var lookingAt_nodepath
export(NodePath) var animation_nodepath export(NodePath) var animation_nodepath
export(NodePath) var ui_interact_nodepath export(NodePath) var ui_interact_nodepath
export(NodePath) var camera_nodepath
export(int) var keycard_lvl export(int) var keycard_lvl
export(Array) var key_chain export(Array) var key_chain
@ -36,7 +37,7 @@ func _ready():
_body = get_node(body_nodepath) as Spatial # = $Body _body = get_node(body_nodepath) as Spatial # = $Body
assert(null != _body) assert(null != _body)
_camera = $Body/Camera _camera = get_node(camera_nodepath)
assert(null != _camera) assert(null != _camera)
_animation = get_node(animation_nodepath) as AnimationPlayer _animation = get_node(animation_nodepath) as AnimationPlayer
@ -53,6 +54,7 @@ func _ready():
func _physics_process(delta): func _physics_process(delta):
process_input() process_input()
process_movement(delta) process_movement(delta)
process_collision_layers()
func _process(_delta): func _process(_delta):
check_interact() check_interact()
@ -82,13 +84,6 @@ func process_input():
# sprinting # sprinting
_is_sprinting = Input.is_action_pressed("move_sprint") _is_sprinting = Input.is_action_pressed("move_sprint")
# Taking a pill
# TODO: Should be moved to a different component which only handles pills - this script should only do movement
# Only here for testing purposes!
if Input.is_action_just_pressed("take_pill"):
Pills.take_pill()
Logger.info("Player took a pill; new level: %s" % [Pills.get_round_level()])
func process_movement(delta): func process_movement(delta):
@ -108,6 +103,17 @@ func process_animations():
_animation.playback_speed = _vel.length() / MOVE_SPEED _animation.playback_speed = _vel.length() / MOVE_SPEED
func process_collision_layers():
var new_layer: int = 6
if Pills.get_level() >= Pills.LEVELS.VERY_LOW:
# If the masked view is almost invisible, collision with masked objects is disabled
new_layer -= 1 # See collision layer names in editor
collision_layer = new_layer
collision_mask = new_layer
func check_interact(): func check_interact():
if _lookCast.is_colliding(): if _lookCast.is_colliding():
var collider = _lookCast.get_collider() var collider = _lookCast.get_collider()

View File

@ -1,18 +1,34 @@
[gd_scene load_steps=8 format=2] [gd_scene load_steps=16 format=2]
[ext_resource path="res://Characters/Player/Player.gd" type="Script" id=1] [ext_resource path="res://Characters/Player/Player.gd" type="Script" id=1]
[ext_resource path="res://Characters/Player/Footsteps.gd" type="Script" id=2] [ext_resource path="res://Characters/Player/PillCameras.gd" type="Script" id=2]
[ext_resource path="res://Resources/Audio/Step.wav" type="AudioStream" id=3] [ext_resource path="res://Shaders/PillScreenRenderer.shader" type="Shader" id=3]
[ext_resource path="res://Characters/Player/UI/UI.tscn" type="PackedScene" id=4] [ext_resource path="res://Characters/Player/Footsteps.gd" type="Script" id=4]
[ext_resource path="res://Resources/Audio/Step.wav" type="AudioStream" id=5]
[ext_resource path="res://Characters/Player/UI/UI.tscn" type="PackedScene" id=6]
[ext_resource path="res://Characters/Player/PillTaker.gd" type="Script" id=7]
[ext_resource path="res://Things/pills/Pills.tscn" type="PackedScene" id=8]
[sub_resource type="CylinderShape" id=1] [sub_resource type="ViewportTexture" id=1]
viewport_path = NodePath("Body/PillCameras/MaskedView")
[sub_resource type="Animation" id=2] [sub_resource type="ViewportTexture" id=2]
resource_name = "Walk" viewport_path = NodePath("Body/PillCameras/TrueView")
[sub_resource type="ShaderMaterial" id=3]
resource_local_to_scene = true
shader = ExtResource( 3 )
shader_param/mask_factor = 0.5
shader_param/true_view = SubResource( 2 )
shader_param/masked_view = SubResource( 1 )
[sub_resource type="CylinderShape" id=4]
[sub_resource type="Animation" id=6]
length = 0.8 length = 0.8
loop = true loop = true
tracks/0/type = "value" tracks/0/type = "value"
tracks/0/path = NodePath("Body/Camera:translation") tracks/0/path = NodePath("Body/PillCameras:translation")
tracks/0/interp = 2 tracks/0/interp = 2
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/imported = false tracks/0/imported = false
@ -41,8 +57,47 @@ tracks/1/keys = {
} ] } ]
} }
[sub_resource type="AudioStreamRandomPitch" id=3] [sub_resource type="Animation" id=9]
audio_stream = ExtResource( 3 ) resource_name = "PillTaking"
tracks/0/type = "value"
tracks/0/path = NodePath("PillTaker/Pills:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 1 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ true, false ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("PillTaker/Pills:translation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 1 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Vector3( 0, 0, -1 ), Vector3( 0, 0.7, 0 ) ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("PillTaker/Pills:rotation_degrees")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0, 1 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Vector3( 180, 0, 0 ), Vector3( -90, 0, 0 ) ]
}
[sub_resource type="AudioStreamRandomPitch" id=7]
audio_stream = ExtResource( 5 )
random_pitch = 1.3 random_pitch = 1.3
[node name="Player" type="KinematicBody" groups=[ [node name="Player" type="KinematicBody" groups=[
@ -52,41 +107,84 @@ collision_layer = 5
collision_mask = 5 collision_mask = 5
script = ExtResource( 1 ) script = ExtResource( 1 )
body_nodepath = NodePath("Body") body_nodepath = NodePath("Body")
lookingAt_nodepath = NodePath("Body/Camera/LookingAt") lookingAt_nodepath = NodePath("Body/PillCameras/LookingAt")
animation_nodepath = NodePath("AnimationPlayer") animation_nodepath = NodePath("WalkAnimationPlayer")
ui_interact_nodepath = NodePath("HUD/PressInteract") ui_interact_nodepath = NodePath("HUD/PressInteract")
camera_nodepath = NodePath("Body/PillCameras")
[node name="Body" type="Spatial" parent="."] [node name="Body" type="Spatial" parent="."]
[node name="Camera" type="Camera" parent="Body"] [node name="PillCameras" type="Spatial" parent="Body"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0625, 1.85, 0 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 7.45058e-009, 1.8, 0 )
current = true script = ExtResource( 2 )
[node name="LookingAt" type="RayCast" parent="Body/Camera"] [node name="LookingAt" type="RayCast" parent="Body/PillCameras"]
transform = Transform( -1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0 ) transform = Transform( -1, 0, -8.74228e-008, 0, 1, 0, 8.74228e-008, 0, -1, 0, 0, 0 )
enabled = true enabled = true
cast_to = Vector3( 0, 0, 2 ) cast_to = Vector3( 0, 0, 2 )
[node name="Listener" type="Listener" parent="Body/Camera"] [node name="Listener" type="Listener" parent="Body/PillCameras"]
current = true current = true
[node name="TrueView" type="Viewport" parent="Body/PillCameras"]
size = Vector2( 1024, 600 )
render_target_update_mode = 3
[node name="TrueCamera" type="Camera" parent="Body/PillCameras/TrueView"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 7.45058e-009, 1.8, 0 )
cull_mask = 2
current = true
[node name="MaskedView" type="Viewport" parent="Body/PillCameras"]
size = Vector2( 1024, 600 )
render_target_update_mode = 3
[node name="MaskedCamera" type="Camera" parent="Body/PillCameras/MaskedView"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 7.45058e-009, 1.8, 0 )
cull_mask = 1
current = true
[node name="ScreenTexture" type="ColorRect" parent="Body/PillCameras"]
material = SubResource( 3 )
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
[node name="TrueCameraRemoteTransform" type="RemoteTransform" parent="Body/PillCameras"]
remote_path = NodePath("../TrueView/TrueCamera")
[node name="MaskedCameraRemoteTransform" type="RemoteTransform" parent="Body/PillCameras"]
remote_path = NodePath("../MaskedView/MaskedCamera")
[node name="Collider" type="CollisionShape" parent="."] [node name="Collider" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
shape = SubResource( 1 ) shape = SubResource( 4 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="."] [node name="WalkAnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "Walk" autoplay = "Walk"
anims/Walk = SubResource( 2 ) anims/Walk = SubResource( 6 )
[node name="PillAnimationPlayer" type="AnimationPlayer" parent="."]
playback_speed = 2.0
anims/PillTaking = SubResource( 9 )
[node name="Footsteps" type="Spatial" parent="."] [node name="Footsteps" type="Spatial" parent="."]
script = ExtResource( 2 ) script = ExtResource( 4 )
[node name="Footstep1" type="AudioStreamPlayer3D" parent="Footsteps"] [node name="Footstep1" type="AudioStreamPlayer3D" parent="Footsteps"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1 )
stream = SubResource( 3 ) stream = SubResource( 7 )
unit_db = -25.0 unit_db = -25.0
pitch_scale = 1.5 pitch_scale = 1.5
[node name="HUD" parent="." instance=ExtResource( 4 )] [node name="HUD" parent="." instance=ExtResource( 6 )]
[node name="PillTaker" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
script = ExtResource( 7 )
[node name="Pills" parent="PillTaker" instance=ExtResource( 8 )]
transform = Transform( 0.1, 0, 0, 0, -4.37114e-009, 0.1, 0, -0.1, -4.37114e-009, 0, 0.7, 0 )
visible = false
[editable path="HUD"] [editable path="HUD"]

View File

@ -11,7 +11,7 @@ func _ready():
_pillLevel = get_node("TextureProgress") _pillLevel = get_node("TextureProgress")
# TODO: may use global values in Inspector? # TODO: may use global values in Inspector?
_pillLevel.max_value = Pills._max _pillLevel.max_value = Pills.get_max()
func add_item (name): func add_item (name):

View File

@ -7,9 +7,24 @@ var _max: float = 6.0
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
enum LEVELS {
SOBRE = 0,
VERY_LOW = 1,
LOW = 2,
MEDIUM = 3,
HIGH = 4,
VERY_HIGH = 5,
FULL = 6
}
# Returns the max level
func get_max() -> float:
return _max
# Returns the exact current level as a floating point number between min and max # Returns the exact current level as a floating point number between min and max
func get_level(): func get_level() -> float:
return _level return _level

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=3 format=2] [gd_scene load_steps=4 format=2]
[sub_resource type="CubeMesh" id=1] [sub_resource type="CubeMesh" id=1]
size = Vector3( 26, 12, 14 ) size = Vector3( 26, 12, 14 )
@ -6,9 +6,17 @@ size = Vector3( 26, 12, 14 )
[sub_resource type="SpatialMaterial" id=2] [sub_resource type="SpatialMaterial" id=2]
albedo_color = Color( 1, 0.917647, 0.537255, 1 ) albedo_color = Color( 1, 0.917647, 0.537255, 1 )
[sub_resource type="ConcavePolygonShape" id=3]
data = PoolVector3Array( -13, 6, 7, 13, 6, 7, -13, -6, 7, 13, 6, 7, 13, -6, 7, -13, -6, 7, 13, 6, -7, -13, 6, -7, 13, -6, -7, -13, 6, -7, -13, -6, -7, 13, -6, -7, 13, 6, 7, 13, 6, -7, 13, -6, 7, 13, 6, -7, 13, -6, -7, 13, -6, 7, -13, 6, -7, -13, 6, 7, -13, -6, -7, -13, 6, 7, -13, -6, 7, -13, -6, -7, 13, 6, 7, -13, 6, 7, 13, 6, -7, -13, 6, 7, -13, 6, -7, 13, 6, -7, -13, -6, 7, 13, -6, 7, -13, -6, -7, 13, -6, 7, 13, -6, -7, -13, -6, -7 )
[node name="BuildingBlock" type="Spatial"] [node name="BuildingBlock" type="Spatial"]
[node name="MeshInstance" type="MeshInstance" parent="."] [node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 6, 0 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 6, 0 )
mesh = SubResource( 1 ) mesh = SubResource( 1 )
material/0 = SubResource( 2 ) material/0 = SubResource( 2 )
[node name="StaticBody" type="StaticBody" parent="MeshInstance"]
[node name="CollisionShape" type="CollisionShape" parent="MeshInstance/StaticBody"]
shape = SubResource( 3 )

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=2] [gd_scene load_steps=2 format=2]
[sub_resource type="CylinderMesh" id=4] [sub_resource type="CylinderMesh" id=1]
top_radius = 20.0 top_radius = 20.0
bottom_radius = 35.0 bottom_radius = 35.0
height = 100.0 height = 100.0
@ -10,15 +10,15 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -185, 0, -191 )
[node name="MeshInstance" type="MeshInstance" parent="."] [node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 50, 0 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 50, 0 )
mesh = SubResource( 4 ) mesh = SubResource( 1 )
material/0 = null material/0 = null
[node name="MeshInstance2" type="MeshInstance" parent="."] [node name="MeshInstance2" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 30, 50, 60 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 30, 50, 60 )
mesh = SubResource( 4 ) mesh = SubResource( 1 )
material/0 = null material/0 = null
[node name="MeshInstance3" type="MeshInstance" parent="."] [node name="MeshInstance3" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 30, 50, -60 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 30, 50, -60 )
mesh = SubResource( 4 ) mesh = SubResource( 1 )
material/0 = null material/0 = null

File diff suppressed because one or more lines are too long

BIN
Models/pill/blue.material Normal file

Binary file not shown.

BIN
Models/pill/other.material Normal file

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/DoorClose.wav-a42279a23e15223438fad3653a5f11d2.sample"
[deps]
source_file="res://Resources/Audio/DoorClose.wav"
dest_files=[ "res://.import/DoorClose.wav-a42279a23e15223438fad3653a5f11d2.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=true
edit/normalize=true
edit/loop=false
compress/mode=0

Binary file not shown.

View File

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/DoorOpen.wav-053df945fc1e6b8ed535511515244f05.sample"
[deps]
source_file="res://Resources/Audio/DoorOpen.wav"
dest_files=[ "res://.import/DoorOpen.wav-053df945fc1e6b8ed535511515244f05.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=true
edit/normalize=true
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,11 @@
shader_type canvas_item;
uniform sampler2D true_view;
uniform sampler2D masked_view;
uniform float mask_factor;
void fragment() {
// Add the masked view and the true view depending on the factor
COLOR = (1.0f - mask_factor) * texture(true_view, SCREEN_UV) + mask_factor * texture(masked_view, SCREEN_UV);
}

43
Things/pills/Pills.tscn Normal file

File diff suppressed because one or more lines are too long