Refactor main scene into Game.tscn

This commit is contained in:
Fabien Freling 2019-02-16 18:05:52 +01:00
parent b8c6084c19
commit ceaec1ac03
9 changed files with 49 additions and 70 deletions

View file

@ -1,20 +1,7 @@
extends Node extends Spatial
onready var final_menu := $FinalMenu
onready var player := $Player
signal level_completed() signal level_completed()
#func _process(delta): func _on_Goal_body_entered(body):
# var player = get_node("Player") if body is Player:
# if player.has_reached_goal: emit_signal("level_completed")
# get_node("Panel").visible = true
#func _on_Goal_body_entered(body):
# if body.t is player.:
# emit_signal("level_completed")
func _on_Level_01_level_completed():
player.queue_free()
final_menu.show()
pass # Replace with function body.

View file

@ -1,13 +1,11 @@
[gd_scene load_steps=7 format=2] [gd_scene load_steps=5 format=2]
[ext_resource path="res://levels/Level_01.gd" type="Script" id=1] [ext_resource path="res://levels/Level_01.gd" type="Script" id=1]
[ext_resource path="res://levels/Level_01_env.tres" type="Environment" id=2] [ext_resource path="res://levels/Level_01_env.tres" type="Environment" id=2]
[ext_resource path="res://models/mlib.meshlib" type="MeshLibrary" id=3] [ext_resource path="res://models/mlib.meshlib" type="MeshLibrary" id=3]
[ext_resource path="res://scenes/Player.tscn" type="PackedScene" id=4] [ext_resource path="res://scenes/Goal.tscn" type="PackedScene" id=4]
[ext_resource path="res://scenes/Goal.tscn" type="PackedScene" id=5]
[ext_resource path="res://scenes/FinalMenu.tscn" type="PackedScene" id=6]
[node name="Level_01" type="Node"] [node name="Level_01" type="Spatial"]
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="WorldEnvironment" type="WorldEnvironment" parent="."] [node name="WorldEnvironment" type="WorldEnvironment" parent="."]
@ -25,38 +23,13 @@ __meta__ = {
[node name="Camera" type="Camera" parent="."] [node name="Camera" type="Camera" parent="."]
transform = Transform( 1, 0, 0, 0, 0.939693, 0.34202, 0, -0.34202, 0.939693, 0, 6, 7 ) transform = Transform( 1, 0, 0, 0, 0.939693, 0.34202, 0, -0.34202, 0.939693, 0, 6, 7 )
current = true
fov = 54.1445 fov = 54.1445
[node name="Player" parent="." instance=ExtResource( 4 )] [node name="Goal" parent="." instance=ExtResource( 4 )]
transform = Transform( 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, -2.88637, 2.79728, -2.72332 )
move_speed = 5.0
[node name="Goal" parent="." instance=ExtResource( 5 )]
transform = Transform( 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0.993621, 1.99794, 1.00068 ) transform = Transform( 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0.993621, 1.99794, 1.00068 )
[node name="DirectionalLight" type="DirectionalLight" parent="."] [node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( 0.701566, 0, -0.712605, 0.386011, 0.840578, 0.380031, 0.599, -0.541691, 0.589721, 0, 5.28645, 0 ) transform = Transform( 0.701566, 0, -0.712605, 0.386011, 0.840578, 0.380031, 0.599, -0.541691, 0.589721, 0, 5.28645, 0 )
[node name="FinalMenu" parent="." instance=ExtResource( 6 )]
visible = false
[node name="Panel" type="Panel" parent="."]
editor/display_folded = true
visible = false
margin_left = 330.0
margin_top = 180.0
margin_right = 720.0
margin_bottom = 400.0
[node name="Label" type="Label" parent="Panel"]
margin_left = 70.0
margin_top = 70.0
margin_right = 310.0
margin_bottom = 150.0
text = "Congratulations!
You reached the goal!"
align = 1
valign = 1
[connection signal="level_completed" from="." to="." method="_on_Level_01_level_completed"]
[connection signal="body_entered" from="Goal" to="." method="_on_Goal_body_entered"] [connection signal="body_entered" from="Goal" to="." method="_on_Goal_body_entered"]

View file

@ -21,7 +21,7 @@ _global_script_class_icons={
[application] [application]
config/name="Dora" config/name="Dora"
run/main_scene="res://levels/Level_01.tscn" run/main_scene="res://scenes/Game.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
[importer_defaults] [importer_defaults]
@ -1080,4 +1080,5 @@ scene={
[rendering] [rendering]
environment/default_clear_color=Color( 0.247059, 0.482353, 0.937255, 1 )
environment/default_environment="res://default_env.tres" environment/default_environment="res://default_env.tres"

14
scenes/Game.gd Normal file
View file

@ -0,0 +1,14 @@
extends Node
onready var final_menu := $FinalMenu
onready var player := $Player
onready var level := $Level_01
func _on_Level_01_level_completed():
player.queue_free()
level.queue_free()
final_menu.show()
func _on_FinalMenu_retried():
get_tree().reload_current_scene()

20
scenes/Game.tscn Normal file
View file

@ -0,0 +1,20 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://scenes/Game.gd" type="Script" id=1]
[ext_resource path="res://scenes/Player.tscn" type="PackedScene" id=2]
[ext_resource path="res://levels/Level_01.tscn" type="PackedScene" id=3]
[ext_resource path="res://scenes/FinalMenu.tscn" type="PackedScene" id=4]
[node name="Game" type="Node"]
script = ExtResource( 1 )
[node name="Player" parent="." instance=ExtResource( 2 )]
transform = Transform( 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, -3, 2.0589, -3 )
[node name="Level_01" parent="." instance=ExtResource( 3 )]
[node name="FinalMenu" parent="." instance=ExtResource( 4 )]
visible = false
[connection signal="level_completed" from="Level_01" to="." method="_on_Level_01_level_completed"]
[connection signal="retried" from="FinalMenu" to="." method="_on_FinalMenu_retried"]

View file

@ -2,20 +2,5 @@ extends Spatial
signal body_entered() signal body_entered()
func _ready():
get_node("Area").connect("body_entered", self, "collided")
func collided(body):
if body.has_method("reach_goal"):
get_node("ShineRays").hide()
body.reach_goal()
# Should be done in vertex shader
#func _process(delta):
# var camera_pos = get_viewport().get_camera().global_transform.origin
# camera_pos.y = 0
# look_at(camera_pos, Vector3(0, 1, 0))
func _on_Area_body_entered(body): func _on_Area_body_entered(body):
emit_signal("body_entered", body) emit_signal("body_entered", body)

View file

@ -72,9 +72,6 @@ editor/display_folded = true
[node name="Flag" parent="Pole" index="0"] [node name="Flag" parent="Pole" index="0"]
transform = Transform( 5, 0, 0, 0, -4.37114e-08, -0.5, 0, 1, -2.18557e-08, 4.02201, 0.453122, 0 ) transform = Transform( 5, 0, 0, 0, -4.37114e-08, -0.5, 0, 1, -2.18557e-08, 4.02201, 0.453122, 0 )
[node name="Flag.001" parent="Pole" index="1"]
transform = Transform( 5, 0, 0, 0, -4.37114e-08, -0.5, 0, 1, -2.18557e-08, 5.99137, 0.443566, -0.191931 )
[node name="Lamp" parent="." index="1"] [node name="Lamp" parent="." index="1"]
visible = false visible = false

View file

@ -3,7 +3,7 @@ class_name Player
export var move_speed : float = 3.0 export var move_speed : float = 3.0
const norm_gravity = -100 const norm_gravity = -150
var velocity = Vector3() var velocity = Vector3()
const MAX_SLOPE_ANGLE = 60 const MAX_SLOPE_ANGLE = 60
var has_reached_goal = false var has_reached_goal = false

View file

@ -5,13 +5,15 @@
[sub_resource type="BoxShape" id=1] [sub_resource type="BoxShape" id=1]
extents = Vector3( 1.34689, 1.43545, 1.63476 )
[node name="Player" type="KinematicBody"] [node name="Player" type="KinematicBody"]
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="."] [node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.39138, 0 )
shape = SubResource( 1 ) shape = SubResource( 1 )
[node name="Hedgehog" parent="." instance=ExtResource( 2 )] [node name="Hedgehog" parent="." instance=ExtResource( 2 )]
transform = Transform( 0.8, 0, 0, 0, 0.8, 0, 0, 0, 0.8, 0, 0, 0 ) transform = Transform( 0.8, 0, 0, 0, 0.8, 0, 0, 0, 0.8, 0, 1.29215, 0 )