diff --git a/test_vr_godot/Game.gd b/test_vr_godot/Game.gd index ec9233cbbd676464b0e836b9cd8022a6bfebe3c3..ac8cff496e34beeb10d4e7f866e84e330824ee30 100644 --- a/test_vr_godot/Game.gd +++ b/test_vr_godot/Game.gd @@ -3,7 +3,7 @@ extends Spatial # Declare member variables here. Examples: # var a = 2 # var b = "text" - +var score = 0 # Called when the node enters the scene tree for the first time. func _ready(): var VR = ARVRServer.find_interface("Oculus") @@ -20,3 +20,9 @@ func _ready(): # Called every frame. 'delta' is the elapsed time since the previous frame. #func _process(delta): # pass + +func increase_score(): + score=score+1 + +func get_score(): + return score \ No newline at end of file diff --git a/test_vr_godot/Game.tscn b/test_vr_godot/Game.tscn index cf758ea081deaf033686e474e9e33c34f7ff5b79..5c408bb48ae3df0405befc1fe26219bf5f3ed139 100644 --- a/test_vr_godot/Game.tscn +++ b/test_vr_godot/Game.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=15 format=2] +[gd_scene load_steps=19 format=2] [ext_resource path="res://Game.gd" type="Script" id=1] [ext_resource path="res://Player.gd" type="Script" id=2] +[ext_resource path="res://pickup.gd" type="Script" id=3] [sub_resource type="SphereShape" id=1] @@ -37,6 +38,13 @@ bounce = 0.5 [sub_resource type="PhysicsMaterial" id=12] bounce = 0.5 +[sub_resource type="CubeMesh" id=13] + +[sub_resource type="SpatialMaterial" id=14] +albedo_color = Color( 0.992157, 0.905882, 0, 1 ) + +[sub_resource type="BoxShape" id=15] + [node name="Game" type="Spatial"] script = ExtResource( 1 ) @@ -52,7 +60,6 @@ script = ExtResource( 2 ) [node name="Camera" type="Camera" parent="Player"] transform = Transform( 1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107, 0, 10.7425, 10.738 ) -visible = false [node name="CollisionShape" type="CollisionShape" parent="Player"] shape = SubResource( 1 ) @@ -67,23 +74,21 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 7.4796, 11 ) [node name="ARVRCamera" type="ARVRCamera" parent="Player/ARVROrigin"] -[node name="StaticBody" type="StaticBody" parent="."] +[node name="floor" type="StaticBody" parent="."] editor/display_folded = true transform = Transform( 10, 0, 0, 0, 0.01, 0, 0, 0, 10, 0, 0, 0 ) -[node name="MeshInstance" type="MeshInstance" parent="StaticBody"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4.07057, 0 ) +[node name="MeshInstance" type="MeshInstance" parent="floor"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.000484419, 2.2213, 0.000886536 ) mesh = SubResource( 4 ) material/0 = SubResource( 5 ) -[node name="CollisionShape" type="CollisionShape" parent="StaticBody"] +[node name="CollisionShape" type="CollisionShape" parent="floor"] shape = SubResource( 6 ) [node name="walls" type="Node" parent="."] -editor/display_folded = true [node name="northWall" type="StaticBody" parent="walls"] -editor/display_folded = true transform = Transform( 10, 0, 0, 0, 1, 0, 0, 0, 0.3, 0, 1, -10 ) physics_material_override = SubResource( 7 ) @@ -130,8 +135,145 @@ shape = SubResource( 8 ) mesh = SubResource( 9 ) material/0 = null +[node name="Score" type="Label" parent="."] +margin_left = 21.259 +margin_top = 39.1908 +margin_right = 61.259 +margin_bottom = 53.1908 +text = "Score" + +[node name="Win" type="Label" parent="."] +margin_left = 447.0 +margin_top = 184.0 +margin_right = 591.0 +margin_bottom = 258.0 +size_flags_stretch_ratio = 2.38 +text = "win" +align = 1 +valign = 1 + [node name="Pickups" type="Node" parent="."] + +[node name="pickup" type="Area" parent="Pickups"] +transform = Transform( 0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, -5.94239, 1.35348, -5.10558 ) +script = ExtResource( 3 ) + +[node name="MeshInstance" type="MeshInstance" parent="Pickups/pickup"] +mesh = SubResource( 13 ) +material/0 = SubResource( 14 ) + +[node name="CollisionShape" type="CollisionShape" parent="Pickups/pickup"] +shape = SubResource( 15 ) + +[node name="pickup2" type="Area" parent="Pickups"] +editor/display_folded = true +transform = Transform( 0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, -5.95064, 1.03515, 0.217007 ) +script = ExtResource( 3 ) + +[node name="MeshInstance" type="MeshInstance" parent="Pickups/pickup2"] +mesh = SubResource( 13 ) +material/0 = SubResource( 14 ) + +[node name="CollisionShape" type="CollisionShape" parent="Pickups/pickup2"] +transform = Transform( 0.341421, -0.0585786, 0.2, 0.2, 0.2, -0.282843, -0.0585786, 0.341421, 0.2, 0, 0, 0 ) +shape = SubResource( 15 ) + +[node name="pickup3" type="Area" parent="Pickups"] +editor/display_folded = true +transform = Transform( 0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, -5.95064, 1.03515, 3.71801 ) +script = ExtResource( 3 ) + +[node name="MeshInstance" type="MeshInstance" parent="Pickups/pickup3"] +mesh = SubResource( 13 ) +material/0 = SubResource( 14 ) + +[node name="CollisionShape" type="CollisionShape" parent="Pickups/pickup3"] +transform = Transform( 0.341421, -0.0585786, 0.2, 0.2, 0.2, -0.282843, -0.0585786, 0.341421, 0.2, 0, 0, 0 ) +shape = SubResource( 15 ) + +[node name="pickup4" type="Area" parent="Pickups"] +editor/display_folded = true +transform = Transform( 0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, -1.81294, 1.03515, 5.51762 ) +script = ExtResource( 3 ) + +[node name="MeshInstance" type="MeshInstance" parent="Pickups/pickup4"] +mesh = SubResource( 13 ) +material/0 = SubResource( 14 ) + +[node name="CollisionShape" type="CollisionShape" parent="Pickups/pickup4"] +transform = Transform( 0.341421, -0.0585786, 0.2, 0.2, 0.2, -0.282843, -0.0585786, 0.341421, 0.2, 0, 0, 0 ) +shape = SubResource( 15 ) + +[node name="pickup5" type="Area" parent="Pickups"] +editor/display_folded = true +transform = Transform( 0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 1.64553, 1.03515, 5.51762 ) +script = ExtResource( 3 ) + +[node name="MeshInstance" type="MeshInstance" parent="Pickups/pickup5"] +mesh = SubResource( 13 ) +material/0 = SubResource( 14 ) + +[node name="CollisionShape" type="CollisionShape" parent="Pickups/pickup5"] +transform = Transform( 0.341421, -0.0585786, 0.2, 0.2, 0.2, -0.282843, -0.0585786, 0.341421, 0.2, 0, 0, 0 ) +shape = SubResource( 15 ) + +[node name="pickup6" type="Area" parent="Pickups"] +editor/display_folded = true +transform = Transform( 0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 4.28147, 1.03515, 2.90757 ) +script = ExtResource( 3 ) + +[node name="MeshInstance" type="MeshInstance" parent="Pickups/pickup6"] +mesh = SubResource( 13 ) +material/0 = SubResource( 14 ) + +[node name="CollisionShape" type="CollisionShape" parent="Pickups/pickup6"] +transform = Transform( 0.341421, -0.0585786, 0.2, 0.2, 0.2, -0.282843, -0.0585786, 0.341421, 0.2, 0, 0, 0 ) +shape = SubResource( 15 ) + +[node name="pickup7" type="Area" parent="Pickups"] editor/display_folded = true +transform = Transform( 0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 4.28147, 1.03515, -1.57881 ) +script = ExtResource( 3 ) -[node name="RigidBody" type="RigidBody" parent="Pickups"] +[node name="MeshInstance" type="MeshInstance" parent="Pickups/pickup7"] +mesh = SubResource( 13 ) +material/0 = SubResource( 14 ) +[node name="CollisionShape" type="CollisionShape" parent="Pickups/pickup7"] +transform = Transform( 0.341421, -0.0585786, 0.2, 0.2, 0.2, -0.282843, -0.0585786, 0.341421, 0.2, 0, 0, 0 ) +shape = SubResource( 15 ) + +[node name="pickup8" type="Area" parent="Pickups"] +editor/display_folded = true +transform = Transform( 0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 4.28147, 1.03515, -6.06925 ) +script = ExtResource( 3 ) + +[node name="MeshInstance" type="MeshInstance" parent="Pickups/pickup8"] +mesh = SubResource( 13 ) +material/0 = SubResource( 14 ) + +[node name="CollisionShape" type="CollisionShape" parent="Pickups/pickup8"] +transform = Transform( 0.341421, -0.0585786, 0.2, 0.2, 0.2, -0.282843, -0.0585786, 0.341421, 0.2, 0, 0, 0 ) +shape = SubResource( 15 ) + +[node name="pickup9" type="Area" parent="Pickups"] +transform = Transform( 0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 0.208534, 1.03515, -6.06925 ) +script = ExtResource( 3 ) + +[node name="MeshInstance" type="MeshInstance" parent="Pickups/pickup9"] +mesh = SubResource( 13 ) +material/0 = SubResource( 14 ) + +[node name="CollisionShape" type="CollisionShape" parent="Pickups/pickup9"] +transform = Transform( 0.341421, -0.0585786, 0.2, 0.2, 0.2, -0.282843, -0.0585786, 0.341421, 0.2, 0, 0, 0 ) +shape = SubResource( 15 ) + +[connection signal="body_entered" from="Pickups/pickup" to="Pickups/pickup" method="_on_pickup_body_entered"] +[connection signal="body_entered" from="Pickups/pickup2" to="Pickups/pickup2" method="_on_pickup_body_entered"] +[connection signal="body_entered" from="Pickups/pickup3" to="Pickups/pickup3" method="_on_pickup_body_entered"] +[connection signal="body_entered" from="Pickups/pickup4" to="Pickups/pickup4" method="_on_pickup_body_entered"] +[connection signal="body_entered" from="Pickups/pickup5" to="Pickups/pickup5" method="_on_pickup_body_entered"] +[connection signal="body_entered" from="Pickups/pickup6" to="Pickups/pickup6" method="_on_pickup_body_entered"] +[connection signal="body_entered" from="Pickups/pickup7" to="Pickups/pickup7" method="_on_pickup_body_entered"] +[connection signal="body_entered" from="Pickups/pickup8" to="Pickups/pickup8" method="_on_pickup_body_entered"] +[connection signal="body_entered" from="Pickups/pickup9" to="Pickups/pickup9" method="_on_pickup_body_entered"] diff --git a/test_vr_godot/Player.gd b/test_vr_godot/Player.gd index 5c69fbac570b11b9b20c361b01d5f8638e9658ec..cd811936107ce29b68480bb0fa0f5161fc85d6ed 100644 --- a/test_vr_godot/Player.gd +++ b/test_vr_godot/Player.gd @@ -1,6 +1,6 @@ extends RigidBody -var speed = 10 +var speed = 20 # Declare member variables here. Examples: # var a = 2 # var b = "text" @@ -22,4 +22,5 @@ func _process(delta): velocity.z += 1 if Input.is_action_pressed("ui_up"): velocity.z -= 1 - add_force(velocity*speed,Vector3(0,0,0)) \ No newline at end of file + add_force(velocity*speed,Vector3(0,0,0)) + diff --git a/test_vr_godot/pickup.gd b/test_vr_godot/pickup.gd new file mode 100644 index 0000000000000000000000000000000000000000..9058f421f4223d60a00d16737ddfba36559ec7cc --- /dev/null +++ b/test_vr_godot/pickup.gd @@ -0,0 +1,36 @@ +extends Area + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" +var score_lbl +var lbl_win +var game_control +# Called when the node enters the scene tree for the first time. +func _ready(): + score_lbl = get_node("/root/Game/Score") + lbl_win = get_node("/root/Game/Win") + game_control=get_node("/root/Game") + lbl_win.set_text("") + display_score() + pass # Replace with function body. + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass +func _process(delta): + rotate_x(deg2rad(15*delta)) + rotate_y(deg2rad(30*delta)) + rotate_z(deg2rad(45*delta)) + +func _on_pickup_body_entered(body): + if body is RigidBody: + game_control.increase_score() + display_score() + queue_free() + +func display_score(): + var score =game_control.get_score() + score_lbl.set_text("score: "+str(score)) + if score>=9: + lbl_win.set_text("YOU WIN!") \ No newline at end of file