Skip to content

Commit 169cbb2

Browse files
committed
Fix score reset for VR; isAlive global var deduping
1 parent d586279 commit 169cbb2

6 files changed

+163
-145
lines changed

FallingPlayer.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ var tiltAroundX : float;
4444
var script : ScoreController;
4545
script = GetComponent("ScoreController");
4646

47-
static var isAlive : int = 0;
48-
isAlive = lifeCountdown.isAlive;
47+
static var isAlive : int = 1;
4948

5049
static var lifeStartTime : float = 0;
5150
static var levelStartTime : float = 0;
@@ -220,8 +219,12 @@ function DeathRespawn () {
220219
}
221220

222221
FadeAudio (fadeTime, FadeDir.Out);
223-
224-
script.ResetScore(0);
222+
223+
// VR mode does its own score reset later, due to a longer fade interval/
224+
// interstitial 'back to menu' screen.
225+
if (!FallingLaunch.isVRMode) {
226+
script.ResetScore();
227+
}
225228

226229
yield WaitForSeconds(1);
227230

@@ -265,6 +268,10 @@ function DeathRespawn () {
265268

266269
// TODO: Fade out material here instead of toggling the whole object outright?
267270
deathUIVR.SetActive(false);
271+
272+
// resetting score to max here for VR, to avoid the score
273+
// ticking away over the preceding ~4 WaitForSeconds.
274+
script.ResetScore();
268275

269276
lerpControlIn(3.0);
270277

@@ -310,7 +317,7 @@ function LatestCheckpointRespawn () {
310317
}
311318

312319
function ShowDeathHelp() {
313-
if (introComponent && !FallingLaunch.isVRMode) {
320+
if (introComponent) {
314321
introComponent.DeathHelp();
315322
}
316323
}

FallingPlayerStart.js

+124-124
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,156 @@
1-
#pragma strict
2-
3-
public var force:float = 1.0;
4-
var dir : Vector3 = Vector3.zero;
5-
public var touchingSomething:boolean = false;
6-
7-
private var isLoading = false;
8-
var levelToLoad : String = "scene-helix";
9-
var levelToLoad2 : String = "scene-bluesky";
10-
var levelToLoad3 : String = "falling-column-space";
11-
var levelToLoad4 : String = "scene-bluesky";
12-
13-
// Move object using accelerometer
14-
var speed = 5.0;
15-
var target : Transform;
16-
var smooth = 2.0;
17-
var tiltAngle = 30.0;
18-
19-
var script : ScoreController;
20-
script = GetComponent("ScoreController");
21-
22-
static var isAlive : boolean;
23-
24-
function DeathRespawn () {
25-
var respawnPosition = Respawn.currentRespawn.transform.position;
26-
Camera.main.SendMessage("fadeOut");
27-
isAlive = true;
28-
gameObject.SendMessage ("ResetScore", 0);
29-
yield WaitForSeconds(1);
30-
// gameObject.SendMessage ("DecrementScore");
31-
// gameObject.SendMessage ("ZeroScore", 1);
32-
33-
// Camera.main.transform.position = respawnPosition - (transform.forward * 4) + Vector3.up; // reset camera too
34-
GetComponent.<Collider>().attachedRigidbody.transform.Translate(respawnPosition);
35-
// Relocate the player. We need to do this or the camera will keep trying to focus on the (invisible) player where he's standing on top of the FalloutDeath box collider.
36-
transform.position = respawnPosition; // + Vector3.up;
37-
Camera.main.SendMessage("fadeIn");
38-
}
1+
// #pragma strict
2+
3+
// public var force:float = 1.0;
4+
// var dir : Vector3 = Vector3.zero;
5+
// public var touchingSomething:boolean = false;
6+
7+
// private var isLoading = false;
8+
// var levelToLoad : String = "scene-helix";
9+
// var levelToLoad2 : String = "scene-bluesky";
10+
// var levelToLoad3 : String = "falling-column-space";
11+
// var levelToLoad4 : String = "scene-bluesky";
12+
13+
// // Move object using accelerometer
14+
// var speed = 5.0;
15+
// var target : Transform;
16+
// var smooth = 2.0;
17+
// var tiltAngle = 30.0;
18+
19+
// var script : ScoreController;
20+
// script = GetComponent("ScoreController");
21+
22+
// static var isAlive : boolean;
23+
24+
// function DeathRespawn () {
25+
// var respawnPosition = Respawn.currentRespawn.transform.position;
26+
// Camera.main.SendMessage("fadeOut");
27+
// isAlive = true;
28+
// gameObject.SendMessage ("ResetScore", 0);
29+
// yield WaitForSeconds(1);
30+
// // gameObject.SendMessage ("DecrementScore");
31+
// // gameObject.SendMessage ("ZeroScore", 1);
32+
33+
// // Camera.main.transform.position = respawnPosition - (transform.forward * 4) + Vector3.up; // reset camera too
34+
// GetComponent.<Collider>().attachedRigidbody.transform.Translate(respawnPosition);
35+
// // Relocate the player. We need to do this or the camera will keep trying to focus on the (invisible) player where he's standing on top of the FalloutDeath box collider.
36+
// transform.position = respawnPosition; // + Vector3.up;
37+
// Camera.main.SendMessage("fadeIn");
38+
// }
3939

40-
function Awake () {
41-
// Make the game run as fast as possible in the web player
42-
// Application.targetFrameRate = 60;
43-
Time.timeScale = 1.0;
44-
}
40+
// function Awake () {
41+
// // Make the game run as fast as possible in the web player
42+
// // Application.targetFrameRate = 60;
43+
// Time.timeScale = 1.0;
44+
// }
4545

46-
function Update () {
47-
var dir : Vector3 = Vector3.zero;
48-
49-
var tiltAroundZ = -Input.acceleration.y * tiltAngle;
50-
var tiltAroundX = -Input.acceleration.x * tiltAngle;
51-
var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ);
52-
53-
// Dampen towards the target rotation
54-
transform.rotation = Quaternion.Slerp(transform.rotation, target,
55-
Time.deltaTime * smooth);;
56-
// Debug.Log(isAlive);
57-
// Debug.Log(script.currentScore);
58-
}
46+
// function Update () {
47+
// var dir : Vector3 = Vector3.zero;
48+
49+
// var tiltAroundZ = -Input.acceleration.y * tiltAngle;
50+
// var tiltAroundX = -Input.acceleration.x * tiltAngle;
51+
// var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ);
52+
53+
// // Dampen towards the target rotation
54+
// transform.rotation = Quaternion.Slerp(transform.rotation, target,
55+
// Time.deltaTime * smooth);;
56+
// // Debug.Log(isAlive);
57+
// // Debug.Log(script.currentScore);
58+
// }
5959

60-
// private var speed : Vector3 = Vector3 (3, 0, 0);
61-
// var startingPosition = (0, 129, 0);
62-
var deadlyObjectName : String = "DeathByFire";
63-
var initialRespawn : Respawn; // set this to the initial respawn point for the level.
64-
// var damping:float = 0.7; // is this necessary?
60+
// // private var speed : Vector3 = Vector3 (3, 0, 0);
61+
// // var startingPosition = (0, 129, 0);
62+
// var deadlyObjectName : String = "DeathByFire";
63+
// var initialRespawn : Respawn; // set this to the initial respawn point for the level.
64+
// // var damping:float = 0.7; // is this necessary?
6565

66-
// textfield to hold the score and score variable
67-
private var textfield:GUIText;
68-
private var score:int;
66+
// // textfield to hold the score and score variable
67+
// private var textfield:GUIText;
68+
// private var score:int;
6969

70-
public var simulateAccelerometer:boolean = false;
70+
// public var simulateAccelerometer:boolean = false;
7171

7272

73-
function OnCollisionEnter (collision : Collision) {
74-
// Debug.Log("Hit something!" + collision.contacts[0].normal + dir.x + dir.z + Input.acceleration.x);
75-
Screen.sleepTimeout = 0.0f;
76-
// collider.attachedRigidbody.velocity.y *= damping;
73+
// function OnCollisionEnter (collision : Collision) {
74+
// // Debug.Log("Hit something!" + collision.contacts[0].normal + dir.x + dir.z + Input.acceleration.x);
75+
// Screen.sleepTimeout = 0.0f;
76+
// // collider.attachedRigidbody.velocity.y *= damping;
7777

7878

79-
// collider.attachedRigidbody.AddForce(dir * force);
79+
// // collider.attachedRigidbody.AddForce(dir * force);
8080

81-
// iPhoneUtils.Vibrate ();
82-
// var relativeStartingPosition = transform.InverseTransformPoint(0, -500, 0);
81+
// // iPhoneUtils.Vibrate ();
82+
// // var relativeStartingPosition = transform.InverseTransformPoint(0, -500, 0);
8383

8484

8585

86-
// if (collision.gameObject.name == deadlyObjectName){
87-
if (collision.gameObject.CompareTag ("Death")) {
88-
DeathRespawn ();
89-
}
86+
// // if (collision.gameObject.name == deadlyObjectName){
87+
// if (collision.gameObject.CompareTag ("Death")) {
88+
// DeathRespawn ();
89+
// }
9090

9191

92-
// if (collision.gameObject.layer == 8){
93-
// collider.attachedRigidbody.transform.Translate(relativeStartingPosition);
92+
// // if (collision.gameObject.layer == 8){
93+
// // collider.attachedRigidbody.transform.Translate(relativeStartingPosition);
9494

95-
// Destroy the projectile
96-
// Destroy (gameObject);
97-
//if (relativeStartingPosition.y > 100)
98-
// Debug.Log("You've moved up more than 100 units");
95+
// // Destroy the projectile
96+
// // Destroy (gameObject);
97+
// //if (relativeStartingPosition.y > 100)
98+
// // Debug.Log("You've moved up more than 100 units");
9999

100-
}
100+
// }
101101

102102

103-
// function FixedUpdate () {
104-
// rigidbody.MovePosition(rigidbody.position + speed * Time.deltaTime);}
103+
// // function FixedUpdate () {
104+
// // rigidbody.MovePosition(rigidbody.position + speed * Time.deltaTime);}
105105

106106

107-
function OnTriggerEnter (other : Collider) {
108-
if (other.gameObject.CompareTag ("Score")){
109-
// Debug.Log("You scored!");
110-
gameObject.SendMessage ("IncrementScore", 10);
111-
// if (audio)
112-
// {
113-
// audio.Play();
114-
// }
115-
}
107+
// function OnTriggerEnter (other : Collider) {
108+
// if (other.gameObject.CompareTag ("Score")){
109+
// // Debug.Log("You scored!");
110+
// gameObject.SendMessage ("IncrementScore", 10);
111+
// // if (audio)
112+
// // {
113+
// // audio.Play();
114+
// // }
115+
// }
116116

117-
if (other.gameObject.CompareTag ("CloudLevelSelect")){
118-
isLoading = true;
119-
Camera.main.SendMessage("fadeOut");
120-
yield WaitForSeconds(1);
117+
// if (other.gameObject.CompareTag ("CloudLevelSelect")){
118+
// isLoading = true;
119+
// Camera.main.SendMessage("fadeOut");
120+
// yield WaitForSeconds(1);
121121

122-
Application.LoadLevel(levelToLoad);
123-
}
122+
// Application.LoadLevel(levelToLoad);
123+
// }
124124

125-
if (other.gameObject.CompareTag ("SunsetLevelSelect")){
126-
isLoading = true;
127-
Camera.main.SendMessage("fadeOut");
128-
yield WaitForSeconds(1);
125+
// if (other.gameObject.CompareTag ("SunsetLevelSelect")){
126+
// isLoading = true;
127+
// Camera.main.SendMessage("fadeOut");
128+
// yield WaitForSeconds(1);
129129

130-
Application.LoadLevel(levelToLoad2);
131-
}
130+
// Application.LoadLevel(levelToLoad2);
131+
// }
132132

133-
if (other.gameObject.CompareTag ("SpaceLevelSelect")){
134-
isLoading = true;
135-
Camera.main.SendMessage("fadeOut");
136-
yield WaitForSeconds(1);
133+
// if (other.gameObject.CompareTag ("SpaceLevelSelect")){
134+
// isLoading = true;
135+
// Camera.main.SendMessage("fadeOut");
136+
// yield WaitForSeconds(1);
137137

138-
Application.LoadLevel(levelToLoad3);
139-
}
138+
// Application.LoadLevel(levelToLoad3);
139+
// }
140140

141-
if (other.gameObject.CompareTag ("SkyLevelSelect")){
142-
isLoading = true;
143-
Camera.main.SendMessage("fadeOut");
144-
yield WaitForSeconds(1);
141+
// if (other.gameObject.CompareTag ("SkyLevelSelect")){
142+
// isLoading = true;
143+
// Camera.main.SendMessage("fadeOut");
144+
// yield WaitForSeconds(1);
145145

146-
Application.LoadLevel(levelToLoad4);
147-
}
146+
// Application.LoadLevel(levelToLoad4);
147+
// }
148148

149-
}
149+
// }
150150

151-
function OnGUI() {
152-
if (isLoading) {
153-
GUI.Label ( Rect( (Screen.width/2)-110, (Screen.height / 2) - 60, 400, 70), "Loading...", "mainMenuTitle"); }
154-
}
151+
// function OnGUI() {
152+
// if (isLoading) {
153+
// GUI.Label ( Rect( (Screen.width/2)-110, (Screen.height / 2) - 60, 400, 70), "Loading...", "mainMenuTitle"); }
154+
// }
155155

156-
@script AddComponentMenu("Scripts/FallingPlayerStart")
156+
// @script AddComponentMenu("Scripts/FallingPlayerStart")

FallingStartMenu.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ private var mainCamera: Camera;
4545
var script : ScoreController;
4646
script = GetComponent("ScoreController");
4747

48-
static var isAlive : int = 0;
49-
isAlive = lifeCountdown.isAlive;
48+
var isAlive : int = 1;
5049

5150
static var isPausable : boolean = true;
5251

ScoreController.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#pragma strict
22

33
// Keep track of the player's main score
4-
static var currentScore : float = 20f;
5-
static var maxScore = 25f;
4+
static var currentScore : float = 20.0;
5+
static var maxScore : float = 25.0;
66

77
// Keep track of the currently visible score
8-
static var visibleScore : float = 20f;
8+
static var visibleScore : float = 20.0;
99

1010
function Start() {
11-
ResetScore (25);
11+
ResetScore ();
1212
}
1313

1414
function LerpVisibleScore (start : float, end : float, timer : float) {
@@ -43,4 +43,6 @@ function ScoreUpdate ( timer : float) {
4343
// Debug.Log("Your visibleScore is: " + visibleScore + " and your currentScore is: " + currentScore);
4444
}
4545

46-
function ResetScore ( i : float ) {currentScore = maxScore;}
46+
function ResetScore () {
47+
currentScore = maxScore;
48+
}

WormDeath.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ function Update () {
88
var hit : RaycastHit;
99
if (Physics.Raycast (transform.position, Vector3.up, hit, 100)) {
1010
//Debug.Log(hit.distance);
11-
if (hit.rigidbody != null && lifeCountdown.isAlive == 1) {
11+
if (hit.rigidbody != null && FallingPlayer.isAlive == 1) {
1212
Debug.Log(hit.distance);
13-
lifeCountdown.isAlive = 0;
13+
FallingPlayer.isAlive = 0;
1414
GetComponent(FallingPlayer).DeathRespawn ();
1515
}
1616
}

0 commit comments

Comments
 (0)