private bool TryCollideWithRoof(IntVec3 cell) { if (!cell.Roofed(Map)) { return(false); } var bounds = CE_Utility.GetBoundsFor(cell, cell.GetRoof(Map)); float dist; if (!bounds.IntersectRay(ShotLine, out dist)) { return(false); } if (dist * dist > ExactMinusLastPos.sqrMagnitude) { return(false); } var point = ShotLine.GetPoint(dist); ExactPosition = point; landed = true; if (DebugViewSettings.drawInterceptChecks) { MoteMaker.ThrowText(cell.ToVector3Shifted(), Map, "x", Color.red); } Impact(null); return(true); }
void Awake() { minDist = 0.1f; S = this; line = GetComponent <LineRenderer>(); line.enabled = false; points = new List <Vector3> (); }
/// <summary> /// Tries to impact the thing based on whether it intersects the given flight path. Trees have RNG chance to not collide even on intersection. /// </summary> /// <param name="thing">What to impact</param> /// <returns>True if impact occured, false otherwise</returns> private bool TryCollideWith(Thing thing) { if (thing == launcher && !canTargetSelf) { return(false); } var bounds = CE_Utility.GetBoundsFor(thing); float dist; if (!bounds.IntersectRay(ShotLine, out dist)) { return(false); } if (dist * dist > ExactMinusLastPos.sqrMagnitude) { return(false); } // Trees and bushes have RNG chance to collide var plant = thing as Plant; if (plant != null) { //TODO: Remove fillPercent dependency because all fillPercents on trees are 0.25 //Prevents trees near the shooter (e.g the shooter's cover) to be hit float chance = thing.def.fillPercent * ((thing.Position - OriginIV3).LengthHorizontal / 40); if (Controller.settings.DebugShowTreeCollisionChance) { MoteMaker.ThrowText(thing.Position.ToVector3Shifted(), thing.Map, chance.ToString()); } if (!Rand.Chance(chance)) { return(false); } } var point = ShotLine.GetPoint(dist); if (!point.InBounds(this.Map)) { Log.Error("TryCollideWith out of bounds point from ShotLine: obj " + thing.ThingID + ", proj " + this.ThingID + ", dist " + dist + ", point " + point); } ExactPosition = point; landed = true; if (DebugViewSettings.drawInterceptChecks) { MoteMaker.ThrowText(thing.Position.ToVector3Shifted(), thing.Map, "x", Color.red); } Impact(thing); return(true); }
/// <summary> /// Tries to impact the thing based on whether it intersects the given flight path. Trees have RNG chance to not collide even on intersection. /// </summary> /// <param name="thing">What to impact</param> /// <returns>True if impact occured, false otherwise</returns> private bool TryCollideWith(Thing thing) { if (thing == launcher && !canTargetSelf) { return(false); } var bounds = CE_Utility.GetBoundsFor(thing); if (!bounds.IntersectRay(ShotLine, out var dist)) { return(false); } if (dist * dist > ExactMinusLastPos.sqrMagnitude) { return(false); } // Trees and bushes have RNG chance to collide if (thing is Plant) { //Prevents trees near the shooter (e.g the shooter's cover) to be hit var accuracyFactor = def.projectile.alwaysFreeIntercept ? 1 : (thing.Position - OriginIV3).LengthHorizontal / 40 * AccuracyFactor; var chance = thing.def.fillPercent * accuracyFactor; if (Controller.settings.DebugShowTreeCollisionChance) { MoteMaker.ThrowText(thing.Position.ToVector3Shifted(), thing.Map, chance.ToString()); } if (!Rand.Chance(chance)) { return(false); } } var point = ShotLine.GetPoint(dist); if (!point.InBounds(Map)) { Log.Error("TryCollideWith out of bounds point from ShotLine: obj " + thing.ThingID + ", proj " + ThingID + ", dist " + dist + ", point " + point); } ExactPosition = point; landed = true; if (Controller.settings.DebugDrawInterceptChecks) { MoteMaker.ThrowText(thing.Position.ToVector3Shifted(), thing.Map, "x", Color.red); } Impact(thing); return(true); }
/// <summary> /// Tries to impact the thing based on whether it intersects the given flight path. Trees have RNG chance to not collide even on intersection. /// </summary> /// <param name="thing">What to impact</param> /// <returns>True if impact occured, false otherwise</returns> private bool TryCollideWith(Thing thing) { if (thing == launcher && !canTargetSelf) { return(false); } var bounds = CE_Utility.GetBoundsFor(thing); float dist; if (!bounds.IntersectRay(ShotLine, out dist)) { return(false); } if (dist * dist > ExactMinusLastPos.sqrMagnitude) { return(false); } // Trees and bushes have RNG chance to collide var plant = thing as Plant; if (plant != null) { //TODO: Remove fillPercent dependency because all fillPercents on trees are 0.25 //Prevents trees near the shooter (e.g the shooter's cover) to be hit //Dependence to catch the tree from armorPenetration. Large calibers have less chance. var propsCE = def.projectile as ProjectilePropertiesCE; float penetrationAmount = propsCE == null ? 0.1f : propsCE.armorPenetration; //Every projectile, which not use flyoverhead, require armorPenetration stat for calculating collision. float penetrationmultiplier = Mathf.Clamp(((thing.def.fillPercent * 3.2f) - penetrationAmount), 0.05f, 1f); // 2.5-3.5 good values for 0.20-0.30 fillpercent. float rangemultiplier = ((thing.Position - OriginIV3).LengthHorizontal / 15); // 10-20 is fine for prevent to shoot near tree. float chance = penetrationmultiplier * (rangemultiplier < 1f ? rangemultiplier : 1f); // when projectile reach 15 cells distance, we set limit for multiplier bcs chances to hit greatly increased. if (Controller.settings.DebugShowTreeCollisionChance) { MoteMaker.ThrowText(thing.Position.ToVector3Shifted(), thing.Map, chance.ToString()); } if (!Rand.Chance(chance)) { return(false); } } var point = ShotLine.GetPoint(dist); if (!point.InBounds(this.Map)) { Log.Error("TryCollideWith out of bounds point from ShotLine: obj " + thing.ThingID + ", proj " + this.ThingID + ", dist " + dist + ", point " + point); } ExactPosition = point; if (intendedTarget != null) { var fulldistance = (intendedTarget.Position - OriginIV3).LengthHorizontalSquared; var traveleddistance = (thing.Position - OriginIV3).LengthHorizontalSquared; var requireddisttotarget = fulldistance - traveleddistance; if (thing is Building && thing.def.fillPercent > 0.5f) { // Log.Message("fulldist: " + fulldistance.ToString() + " traveled: " + traveleddistance.ToString() + " required: " + requireddisttotarget.ToString()); if (traveleddistance < requireddisttotarget) { return(false); } } } landed = true; // if (Controller.settings.DebugDrawInterceptChecks) MoteMaker.ThrowText(thing.Position.ToVector3Shifted(), thing.Map, "x", Color.red); Impact(thing); return(true); }
// Update is called once per frame void Update() { sinceStart += Time.deltaTime; // delay starting music to avoid weird load issues with beat tracking if (sinceStart > 1.0f && !startedMusic) { soundManager.startMusicSlow(); startedMusic = true; } checkLowerPowerLevel(); sinceReflect += Time.deltaTime; sinceTap += Time.deltaTime; if (frozeActionFrames > 0) { frozeActionFrames++; unfreezeAction(); } if (awaitingReflect && (sinceTap > timingWindow)) { awaitingReflect = false; // "miss early" } // check for game enders if (targetField.targetsRemaining() < 1) { gameState = GameState.End; } if (gameState == GameState.End && !gameEnded) { gameEnded = true; endGame(); } Rigidbody2D ballCollider = null; Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); Ball targetBall = getTargetBall(); if (targetBall) { ballCollider = getTargetBall().GetComponent <Rigidbody2D>(); } // instead of GetMouseButtonDown start looking at touches and figuring out what we need to do // use mouse clicks when in eidtor. Otherwise fall back to touches, which is what will be used on-device if (ballCollider && Input.GetMouseButtonDown(0)) { if (gameState == GameState.Aim) { aimed = true; if (ballCollider.OverlapPoint(mousePosition)) { //do great stuff Debug.Log("Launched"); ShotLine shotLineComponent = shotLine.GetComponent <ShotLine>(); shotLineComponent.clearLaunchPoint(); aimReticle.SetActive(false); getTargetBall().launch(); SetGameState(GameState.Action); aimed = false; } // set ball's target slope based on input point if (aimed) { Debug.Log("Aimed"); // turn on circle collider to detect launch getTargetBall().setCircleCollider(true); aimReticle.transform.position = mousePosition; aimReticle.SetActive(true); getTargetBall().setSlopeByInputPoint(mousePosition); } } else if (gameState == GameState.Action) { // clearCircleColliders(); // check if ball was tapped during action if (ballCollider.OverlapPoint(mousePosition)) { Debug.Log("Tapped Ball In Motion"); checkActionBallTap(); } } } /* * if (Application.isEditor) * { * * } else * { * if (Input.touches.Length > 0) * { * foreach (Touch touch in Input.touches) * { * if (touch.phase == TouchPhase.Began) * { * touchStartPos = touch.position; * } * else if (touch.phase == TouchPhase.Moved) * { * // moving... * } * else if (touch.phase == TouchPhase.Ended) * { * * touchEndPos = touch.position; * // touch/swipe is over, figure out what it was and do it * if (touchStartPos == touchEndPos) * { * // a tap, aim the ball * aimed = true; * } * else if (touchStartPos.y < touchEndPos.y) * { * // swipe up, launch * aimed = false; * } * * // execution * if (gameState == GameState.Aim) * { * if (ballCollider.OverlapPoint(mousePosition)) * { * //do great stuff * Debug.Log("Launched"); * * ShotLine shotLineComponent = shotLine.GetComponent<ShotLine>(); * shotLineComponent.clearLaunchPoint(); * * aimReticle.SetActive(false); * getTargetBall().launch(); * SetGameState(GameState.Action); * aimed = false; * } * * // set ball's target slope based on input point * if (aimed) * { * Debug.Log("Aimed"); * // turn on circle collider to detect launch * getTargetBall().setCircleCollider(true); * aimReticle.transform.position = mousePosition; * aimReticle.SetActive(true); * getTargetBall().setSlopeByInputPoint(mousePosition); * } * } * else if (gameState == GameState.Action) * { * // clearCircleColliders(); * // check if ball was tapped during action * if (ballCollider.OverlapPoint(mousePosition)) * { * Debug.Log("Tapped Ball In Motion"); * checkActionBallTap(); * } * } * * touchStartPos = Vector2.zero; * touchEndPos = Vector2.zero; * } * } * } * } * * * * if (Input.GetMouseButtonDown(0)) * { * * }*/ if (gameState == GameState.Action && getBallsInPlay() == 0) { targetField.advanceField(); SetGameState(GameState.Aim); } }
void Awake() { minDist = 0.1f; S = this; line = GetComponent<LineRenderer>(); line.enabled = false; points = new List<Vector3> (); }
public static void HandleCollision(GameObject hitObject, Ball ball) { GameManager gameManager = hitObject.GetComponentInParent <GameManager>(); Barrier barrierHit = hitObject.GetComponent <Barrier>(); if (!barrierHit) { barrierHit = hitObject.GetComponentInParent <Barrier>(); } BarrierType typeHit = barrierHit.getBarrierType(); // handling for Targets if (typeHit == BarrierType.Target) { //gameManager.soundManager.playBallBounceBarrier(); Target hitTarget = barrierHit as Target; hitTarget.deductResources(ball.getBallResources()); if (hitTarget.breakResources.allResourceSum() < 1) { GameObject.Destroy(hitObject.GetComponentInParent <Target>().gameObject); gameManager.soundManager.playTargetDestroyed(); if (gameManager.getPowerLevel() >= gameManager.powerMax) // split the ball { GameObject splitBall = GameObject.Instantiate(ball.gameObject); splitBall.gameObject.transform.parent = gameManager.gameObject.transform; Ball newBall = splitBall.GetComponent <Ball>(); newBall.isLaunchBall = false; int powerLevel = gameManager.getPowerLevel(); newBall.setResources(powerLevel, powerLevel, powerLevel, powerLevel); newBall.setComponents(); // make the split ball smaller than the original newBall.setHalfBallSize(); if (newBall.reflectedY) { newBall.yDir = !newBall.yDir; } else { newBall.xDir = !newBall.xDir; } newBall.setComponents(); newBall.setCircleCollider(false); newBall.launch(); // clear all circle colliders once we start splitting gameManager.clearCircleColliders(); } } } ShotLine shotLine = barrierHit as ShotLine; if (typeHit == BarrierType.ShotLine) { // see if this is the first ball back if (!shotLine.isLaunchPointSet()) { ball.setLock(true); //ball.transform.position = new Vector2(ball.transform.position.x, -4.61f); shotLine.updateLaunchPoint(ball.transform.position, ball.gameObject); } else { // destroy this extra ball GameObject.Destroy(ball.gameObject); } } // handling for simple Barriers if (typeHit == BarrierType.Barrier) { // gameManager.soundManager.playBallBounceBarrier(); } }