2
0
Эх сурвалжийг харах

Cache shaders on the menu

Aaron Franke 4 жил өмнө
parent
commit
235d9a912f

+ 1 - 1
door/door.gd

@@ -5,6 +5,6 @@ var open = false
 onready var animation_player = $DoorModel/AnimationPlayer
 
 func _on_door_body_entered(body):
-	if not open and body is preload("res://player/player.gd"):
+	if not open and body is Player:
 		animation_player.play("doorsimple_opening")
 		open = true

+ 2 - 1
enemies/red_robot/laser/impact_effect/blast.gd

@@ -9,4 +9,5 @@ func _ready():
 
 
 func _process(_delta):
-	light_rays.look_at(camera.global_transform.origin, Vector3.UP)
+	if camera:
+		light_rays.look_at(camera.global_transform.origin, Vector3.UP)

+ 8 - 5
enemies/red_robot/red_robot.gd

@@ -14,14 +14,15 @@ const AIM_TIME = 1
 const AIM_PREPARE_TIME = 0.5
 const BLEND_AIM_SPEED = 0.05
 
+export(int) var health = 5
+export(bool) var test_shoot = false
+
 var state = State.APPROACH
 
 var shoot_countdown = SHOOT_WAIT
 var aim_countdown = AIM_TIME
 var aim_preparing = AIM_PREPARE_TIME
-var health = 5
 var dead = false
-var test_shoot = false
 
 var player = null
 var velocity = Vector3()
@@ -54,6 +55,8 @@ func _ready():
 	orientation = global_transform
 	orientation.origin = Vector3()
 	$AnimationTree.active = true
+	if test_shoot:
+		shoot_countdown = 0.0
 
 
 func resume_approach():
@@ -125,7 +128,7 @@ func shoot():
 		var blast = blast_scene.instance()
 		get_tree().get_root().add_child(blast)
 		blast.global_transform.origin = col.position
-		if col.collider == player:
+		if col.collider == player and player is Player:
 			yield(get_tree().create_timer(0.1), "timeout")
 			player.add_camera_shake_trauma(13)
 
@@ -238,10 +241,10 @@ func _clip_ray(length):
 
 
 func _on_area_body_entered(body):
-	if body is preload("res://player/player.gd"):
+	if body is Player or body.name == "Target":
 		player = body
 
 
 func _on_area_body_exited(body):
-	if body is preload("res://player/player.gd"):
+	if body is Player:
 		player = null

+ 1 - 8
level/level.tscn

@@ -1,9 +1,7 @@
-[gd_scene load_steps=17 format=2]
+[gd_scene load_steps=15 format=2]
 
 [ext_resource path="res://level/level.gd" type="Script" id=1]
 [ext_resource path="res://level/geometry/scenes/props.tscn" type="PackedScene" id=2]
-[ext_resource path="res://level/shader_cache.gd" type="Script" id=3]
-[ext_resource path="res://player/bullet/bullet.tscn" type="PackedScene" id=4]
 [ext_resource path="res://level/geometry/giprobe_data.res" type="GIProbeData" id=5]
 [ext_resource path="res://player/player.tscn" type="PackedScene" id=6]
 [ext_resource path="res://enemies/red_robot/red_robot.tscn" type="PackedScene" id=7]
@@ -50,11 +48,6 @@ script = ExtResource( 1 )
 [node name="WorldEnvironment" type="WorldEnvironment" parent="."]
 environment = ExtResource( 16 )
 
-[node name="ShaderCache" type="Node" parent="WorldEnvironment"]
-script = ExtResource( 3 )
-
-[node name="Bullet" parent="WorldEnvironment/ShaderCache" instance=ExtResource( 4 )]
-
 [node name="GIProbe" type="GIProbe" parent="."]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -6.09263, 1.28266, 2.88598 )
 subdiv = 2

+ 0 - 18
level/shader_cache.gd

@@ -1,18 +0,0 @@
-extends Node
-
-var fade_in_frame_counter = 100
-
-func _ready():
-	# We don't want the cache bullet to make noise. So make it silent.
-	$Bullet/ExplosionAudio.unit_db = -INF
-
-
-func _physics_process(_delta):
-	fade_in_frame_counter -= 1
-	# Fade in progressively to hide artifacts.
-	if fade_in_frame_counter == 20:
-		# Hide after a few frames to be sure the shaders compiled.
-		$Bullet.hide()
-	if fade_in_frame_counter == 0:
-		# This node has served its purpose, and now it's time to stop existing.
-		self.queue_free()

+ 6 - 3
menu/menu.gd

@@ -1,7 +1,7 @@
-extends Spatial
+extends Node
 
-var res_loader : ResourceInteractiveLoader = null
-var loading_thread : Thread = null
+var res_loader: ResourceInteractiveLoader = null
+var loading_thread: Thread = null
 
 signal replace_main_scene
 #warning-ignore:unused_signal
@@ -56,6 +56,9 @@ onready var loading_done_timer = loading.get_node(@"DoneTimer")
 func _ready():
 	get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_2D, SceneTree.STRETCH_ASPECT_KEEP, Vector2(1920, 1080))
 	play_button.grab_focus()
+	var sound_effects = $BackgroundCache/RedRobot/SoundEffects
+	for child in sound_effects.get_children():
+		child.unit_db = -200
 
 
 func interactive_load(loader):

+ 46 - 3
menu/menu.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=38 format=2]
+[gd_scene load_steps=42 format=2]
 
 [ext_resource path="res://menu/menu.gd" type="Script" id=1]
 [ext_resource path="res://menu/experiment.hdr" type="Texture" id=2]
@@ -18,6 +18,8 @@
 [ext_resource path="res://menu/button_focus.tres" type="StyleBox" id=16]
 [ext_resource path="res://menu/button_hover.tres" type="StyleBox" id=17]
 [ext_resource path="res://menu/button_action_pressed.tres" type="StyleBox" id=18]
+[ext_resource path="res://enemies/red_robot/red_robot.tscn" type="PackedScene" id=19]
+[ext_resource path="res://player/bullet/bullet.tscn" type="PackedScene" id=20]
 
 [sub_resource type="PanoramaSky" id=1]
 panorama = ExtResource( 2 )
@@ -33,6 +35,7 @@ glow_hdr_threshold = 0.34
 glow_bicubic_upscale = true
 
 [sub_resource type="QuadMesh" id=3]
+size = Vector2( 15, 15 )
 
 [sub_resource type="SpatialMaterial" id=4]
 albedo_texture = ExtResource( 4 )
@@ -128,7 +131,13 @@ corner_radius_top_right = 10
 corner_radius_bottom_right = 10
 corner_radius_bottom_left = 10
 
-[node name="Menu" type="Spatial"]
+[sub_resource type="BoxShape" id=20]
+extents = Vector3( 2, 1, 2 )
+
+[sub_resource type="BoxShape" id=21]
+extents = Vector3( 5, 5, 1 )
+
+[node name="Menu" type="Node"]
 script = ExtResource( 1 )
 
 [node name="WorldEnvironment" type="WorldEnvironment" parent="."]
@@ -150,7 +159,7 @@ __meta__ = {
 }
 
 [node name="Floor" type="MeshInstance" parent="."]
-transform = Transform( 15, 0, 0, 0, 0, 15, 0, -15, 0, 0, 0, 0 )
+transform = Transform( 1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0 )
 mesh = SubResource( 3 )
 material/0 = SubResource( 4 )
 
@@ -611,6 +620,38 @@ __meta__ = {
 [node name="DoneTimer" type="Timer" parent="UI/Loading"]
 wait_time = 0.5
 one_shot = true
+
+[node name="BackgroundCache" type="Spatial" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -15, -10, -10 )
+__meta__ = {
+"_editor_description_": "This section forces Godot to cache the models/materials/shaders by creating them on the menu. Everything is out of sight because it is behind the floor, but it's within the camera's view frustum."
+}
+
+[node name="RedRobot" parent="BackgroundCache" instance=ExtResource( 19 )]
+health = 1
+test_shoot = true
+
+[node name="Floor" type="StaticBody" parent="BackgroundCache"]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
+collision_layer = 2147483651
+collision_mask = 3
+
+[node name="CollisionShape" type="CollisionShape" parent="BackgroundCache/Floor"]
+shape = SubResource( 20 )
+
+[node name="Target" type="StaticBody" parent="BackgroundCache"]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 3 )
+collision_layer = 2147483650
+collision_mask = 2147483650
+
+[node name="CollisionShape" type="CollisionShape" parent="BackgroundCache/Target"]
+shape = SubResource( 21 )
+
+[node name="Bullet" parent="BackgroundCache" instance=ExtResource( 20 )]
+transform = Transform( -1, 8.4334e-08, 3.14739e-07, 0, 0.965926, -0.258819, -3.25841e-07, -0.258819, -0.965926, 0, -20, -80 )
+
+[node name="ExplosionAudio" parent="BackgroundCache/Bullet" index="4"]
+unit_db = -80.0
 [connection signal="pressed" from="UI/Main/Play" to="." method="_on_play_pressed"]
 [connection signal="pressed" from="UI/Main/Settings" to="." method="_on_settings_pressed"]
 [connection signal="pressed" from="UI/Main/Quit" to="." method="_on_quit_pressed"]
@@ -619,3 +660,5 @@ one_shot = true
 [connection signal="timeout" from="UI/Loading/DoneTimer" to="." method="_on_loading_done_timer_timeout"]
 
 [editable path="PlayerModel"]
+
+[editable path="BackgroundCache/Bullet"]

+ 1 - 2
player/bullet/bullet.gd

@@ -3,7 +3,6 @@ extends KinematicBody
 const BULLET_VELOCITY = 20
 
 var time_alive = 5
-var direction = Vector3()
 var hit = false
 
 onready var animation_player = $AnimationPlayer
@@ -16,7 +15,7 @@ func _physics_process(delta):
 	if time_alive < 0:
 		hit = true
 		animation_player.play("explode")
-	var col = move_and_collide(delta * direction * BULLET_VELOCITY)
+	var col = move_and_collide(-delta * BULLET_VELOCITY * transform.basis.z)
 	if col:
 		if col.collider and col.collider.has_method("hit"):
 			col.collider.hit()

+ 2 - 2
player/player.gd

@@ -1,3 +1,4 @@
+class_name Player
 extends KinematicBody
 
 const CAMERA_MOUSE_ROTATION_SPEED = 0.001
@@ -157,9 +158,8 @@ func _physics_process(delta):
 			var bullet = preload("res://player/bullet/bullet.tscn").instance()
 			get_parent().add_child(bullet)
 			bullet.global_transform.origin = shoot_origin
-			bullet.direction = shoot_dir
 			# If we don't rotate the bullets there is no useful way to control the particles ..
-			bullet.look_at(bullet.global_transform.origin + shoot_dir, Vector3.UP)
+			bullet.look_at(shoot_origin + shoot_dir, Vector3.UP)
 			bullet.add_collision_exception_with(self)
 			var shoot_particle = $PlayerModel/Robot_Skeleton/Skeleton/GunBone/ShootFrom/ShootParticle
 			shoot_particle.restart()

+ 8 - 2
project.godot

@@ -8,14 +8,20 @@
 
 config_version=4
 
-_global_script_classes=[  ]
+_global_script_classes=[ {
+"base": "KinematicBody",
+"class": "Player",
+"language": "GDScript",
+"path": "res://player/player.gd"
+} ]
 _global_script_class_icons={
-
+"Player": ""
 }
 
 [application]
 
 config/name="Godot Third-Person Shooter Demo"
+config/description="Godot Third Person Shooter with high quality assets and lighting"
 run/main_scene="res://main/main.tscn"
 config/icon="res://icon.png"