/// <summary> /// Activates the shot statistics text box. /// TODO: make the text box not capable of being dragged off-screen /// </summary> /// <param name="constants">the data container to draw from</param> /// <param name="canvasWidth">used to calculate bounds</param> /// <param name="canvasHeight">used to calculate bounds</param> public void DisplayShotStatistics(InputConstants constants, float canvasWidth, float canvasHeight) { Vector3 position = constants.gesturePosition; int gesturePower = constants.gesturePower; float angleOffset = constants.gestureZAngleOffset; gameObject.SetActive(true); // TODO: maybe later add invisible game object at touch position, child statsGObject to it here transform.position = position + touchOffset; // took this stuff out cause scaling issues were being sad //var newPos = transform.position; // weird units here, hence the *2 and the *4, though I'm not sure why... // clamp the object so that it can't be offscreen in the x direction... //float halfWidth = rect.width / 2; //newPos.x = Mathf.Clamp(newPos.x, halfWidth, canvasWidth - halfWidth * 2); // ... or the y direction //float halfHeight = rect.height / 2; //newPos.y = Mathf.Clamp(newPos.y, halfHeight, canvasHeight - 4 * halfHeight); //transform.position = newPos; // set the text statsText.text = (constants.gesturePower > 0) ? string.Format("Power Level: {0}\nAngle: {1}", gesturePower, (int)angleOffset ) : "Cancel\nShot"; }
public void LoadLevel() { ClearActiveLevel(); string levelPath = GetLevel(activeLevel); GD.Print($"Loading level {levelPath}"); inputState = new InputState(InputConstants.DefaultKeyMappings(), InputConstants.DefaultAxisMappings()); AddChild(inputState); PackedScene packedLevel = (PackedScene)ResourceLoader.Load(levelPath); levelSpatial = (Spatial)packedLevel.Instance(); AddChild(levelSpatial); Spatial spawnPointSpatial = (Spatial)GetNode(new NodePath(levelSpatial.Name + "/" + Constants.SpawnPointName)); Vector3 spawnPoint = spawnPointSpatial.Transform.origin; Player = Constants.RaccoonActor(true, spawnPoint); AddActor(Player); foreach (Node node in levelSpatial.GetChildren()) { if (node.IsInGroup(Constants.HumanSpawnName)) { Spatial spawnSpatial = node as Spatial; AddActor(Constants.HumanActor(spawnSpatial.Transform.origin), false); } } }
/// <summary> /// Refreshes the state and resets the rings /// </summary> private void ResetFields() { state = new InputConstants(); rings.transform.position = Vector3.zero; rings.transform.localScale = new Vector3(1, 1); rings.SetActive(false); }
private void Awake() { if (Instance = null) { Instance = this; } else { Destroy(this); } }
/// <summary> /// Behavior when a gesture is being inputted. Used as delegate /// (callback) from InputController.whenUpdated event /// </summary> /// <param name="input">gesture data</param> internal void GestureUpdated(InputConstants input) { if (inPlay) { mainCameraController.offsetFromCenter = input.cameraOffset; } else { SetCameraFollowMode(CameraMode.Wide); AimRocketWith(input.gestureZAngleOffset, input.gesturePower); // statsController.DisplayShotStatistics(input, canvasWidth, canvasHeight); } }
/// <summary> /// Behavior on the conclusion of a gesture. Used as delegate /// (callback) from InputController.whenEnded event /// </summary> /// <param name="input">gesture data</param> internal void GestureEnded(InputConstants input) { if (inPlay) { mainCameraController.offsetFromCenter = Vector3.zero; return; } if (input.gesturePower > 0) { ShootRocket(input.gestureZAngleOffset, input.gesturePower); } else { ShotCancelled(); } statsController.ResetFields(); }