public void Fire(float charge) { //Debug.Break(); if (Time.time - lastFireTime > cooldownTime) { if (!firing) // Prevent calling this in multiple consecutive frames { firing = true; //Debug.Log("Fire!"); // Reset variables chargeStartTime = -1.0f; maxCharge = false; maxChargeStartTime = -1.0f; // Fire a rowball if loaded if (loaded) { Vector3 aiming3 = new Vector3(ship.aiming.x, ship.aiming.y); Vector3 spawnPosition = position + aiming3; Rowball r = ObjectManager.AddRowball(spawnPosition, Color.white); r.level = (int)(charge * (float)(r.frames.Length - 1)); r.AddImpulse(charge * ship.aiming * firepower); r.shooter = ship; } // Apply recoil to the ship Vector2 recoilVector = charge * recoil * -ship.aiming; ship.AddImpulse(recoilVector); // Start firing animation StartCoroutine(FireRowballAnimation()); } } }
void Spawn() { Rowball r = ObjectManager.AddRowball(transform.position, color); r.velocity = direction * speed; //r.level=2; spawn = false; }
public static Rowball AddRowball(Vector2 position, Color color) { Debug.Log("Rowball Spawned"); Rowball r = Instantiate(instance.rowball, position, Quaternion.identity) as Rowball; r.color = color; return(r); }
public void ProcessExit(Collider2D other) { //Clear rowball shot if (other.gameObject.layer == module.rowballLayer) { Rowball rowball = other.GetComponent <Rowball>(); if (rowball.shooter != null && !rowball.clearedShot) { rowball.clearedShot = true; } } }
RowballState GetRowballState(Rowball rowball) { //float relativeSpeed = rowball.RelativeVelocity(velocity).magnitude; //Pickup if rowball is slower than you or the relative speed is low enough //if(relativeSpeed<module.damageSpeed || rowball.speed<=speed){ if (rowball.level < 2) { //Debug.Log("Rowball collision validated pass at "+relativeSpeed+" (relative speed)"); return(RowballState.Pickup); } //Kill if the rowball is faster than you and the relative speed is high enough else {// //if(relativeSpeed>=module.damageSpeed && rowball.speed>speed){ //Debug.Log("Rowball collision killed player at "+relativeSpeed+" (relative speed)"); return(RowballState.Kill); } //If the rowball is faster than you but the relative speed is too low to damage, bounce //else return RowballState.Bounce; }
RowballState GetRowballState(Rowball rowball) { float relativeSpeed = rowball.RelativeVelocity(velocity).magnitude; //Pickup if rowball is slower than you or the relative speed is low enough if (relativeSpeed < module.damageSpeed || rowball.speed <= speed) { return(RowballState.Pickup); } //Kill if the rowball is faster than you and the relative speed is high enough else if (relativeSpeed >= module.damageSpeed && rowball.speed > speed) { //Debug.Log("Rowball collision totaled breakable at "+relativeSpeed+" (relative speed)"); return(RowballState.Kill); } //If the rowball is faster than you but the relative speed is too low to damage, bounce else { return(RowballState.Bounce); } }
//Observe void OnKill(ShipRevamped targetShip, Rowball rowball) { int targetScore = PlayerManager.GetPlayer(targetShip).score; PlayerManager.PlayerInfo shooter = PlayerManager.GetPlayer(rowball.shooter.GetComponent <ShipRevamped>()); PlayerManager.Player target = PlayerManager.GetPlayer(targetShip).player; CreateExplosion(rowball.position); string killContext = ""; PlayerManager.GetPlayer(targetShip).spree = 0; if (scoreMode == ScoreMode.KILL) { if (rowball.shooter != null) { float score = baseScorePoints; if (shooter.player.team == target.team) { score = penaltyPoints; killContext += "SUICIDE"; //+" (-1)\n"; killContext += "\n"; Observer.OnSuicide.Invoke(); shooter.Score((int)score); shooter.suicides++; } else { if (Time.time <= shooter.lastKillTime + multiKillThreshhold) { shooter.multikill++; } else { shooter.multikill = 0; } shooter.lastKillTime = Time.time; shooter.spree++; if (shooter.spree > shooter.longestSpree) { shooter.longestSpree = shooter.spree; } if (PlayerManager.GetPlayer(targetShip) == PlayerManager.leader && PlayerManager.leader.score != 0) { //score *= leaderKillBonus; score++; killContext += "LEADER KILL"; //+" (+1) \n"; killContext += "\n"; shooter.leaderKills++; // Observer.OnLeaderKill.Invoke(); //Debug.Log ("Leader has been killed! x" + leaderKillBonus + "\n"); } //float relativeSpeed = rowball.RelativeVelocity (targetShip.velocity).magnitude; // if (relativeSpeed > brutalityThreshold) { // score += (baseScorePoints * (relativeSpeed / 1000)); // if(displayPercentScore) // shooter.player.textRef.text += "Brutality (+" + (baseScorePoints * relativeSpeed/1000)/scoreToWin * 100 + "%)" + "\n"; // else // shooter.player.textRef.text += "Brutality (+" + (int)(baseScorePoints * relativeSpeed/1000) + ")" + "\n"; // Debug.Log ("Brutality: +" + (baseScorePoints * relativeSpeed / 1000)); // } if (shooter.multikill > 0) { score += (shooter.multikill); // Multikill bonus killContext += shooter.multikill == 1?"DOUBLE KILL": shooter.multikill == 2?"TRIPLE KILL": "MULTI: " + (shooter.multikill + 1); killContext += "\n"; // if (shooter.multikill == 1) { Observer.OnDoubleKill.Invoke(); } else if (shooter.multikill == 2) { Observer.OnTripleKill.Invoke(); } //Stats if (shooter.multikill > 0) { shooter.multiKills++; } //killContext+=" (+" + shooter.player.multikill + ")" + "\n"; //Debug.Log ("Multi ("+ shooter.player.multikill +"): x" + (shooter.player.multikill * (1.0f + multiKillMultiplier))); } if (shooter.spree >= spreeThreshhold) { score++; killContext += "SPREE: " + shooter.spree; // + " (+1)\n"; killContext += "\n"; //Debug.Log ("Spree: " + shooter.player.spree); } //Debug.Log ("Player has earned " + score + " points for a kill."); shooter.Score((int)score); } if (score != 1) { InterfaceManager.CreateTextEffect( killContext, target.ship.position, PlayerManager.TeamColor(shooter.player.team) ); } //else /* * InterfaceManager.CreateTextEffect( * InterfaceManager.instance.deathMessages[(int)Random.Range (0, InterfaceManager.instance.deathMessages.Length)], * target.ship.position, * PlayerManager.TeamColor(shooter.player.team), * 2,13 * ); */ } } else if (scoreMode == ScoreMode.LMS) { if (rowball.shooter != null) { if (rowball.shooter == targetShip || shooter.player.team == target.team) { shooter.Score(penaltyPoints + targetScore / 10); } else { shooter.Score(baseScorePoints); } } } float respawnTimePenalty = (targetScore > scoreToWin / 2)? targetScore / 100 * penaltyMultiplier:0.0f; if (useRespawns && winners == null) { targetShip.Respawn(respawnTime + respawnTimePenalty); } }
//Events void OnKill(ShipRevamped target, Rowball r) { AddSound(target.destroyExplosion, PlayerPrefs.GetFloat("effectsVolume", 1.0f), Random.Range(smashPitchRange.x, smashPitchRange.y)); AddEffect(killClips[(int)(Random.Range(0, killClips.Length))]); }
// void OnKill(ShipRevamped targetShip, Rowball rowball) { //StartCoroutine(Shake(0.5f)); RemoveAllPoints(targetShip); }
void OnKill(ShipRevamped targetShip, Rowball rowball) { Rumble(killShake.amount, killShake.speed, killShake.damping, killShake.time); Slomo(killSlomo.factor, killSlomo.time, killSlomo.delay); ColorShift(night, day, killSlomo.time, killSlomo.delay); }
//Collision public void ProcessCollision(Collider2D other) { if (!totaled) { //Process rowball if (other.gameObject.layer == module.rowballLayer) { Rowball rowball = other.GetComponent <Rowball>(); RowballState state = GetRowballState(rowball); if (state == RowballState.Kill) { //Process totaled = true; effector.enabled = false; bounds.enabled = false; collisionBounds.gameObject.SetActive(false); //Drop rowball if carrying one Vector2 relativeVelocity = rowball.RelativeVelocity(velocity); if (hasRowball) { Rowball r = SpawnRowball(); r.AddImpulse(relativeVelocity * module.rowballDropFactor); } //Break closest point float minDistance = size * 2; //Arbitrary number, should always be larger Point targetPoint = null; foreach (Vertex v in edge) { Point p = vertexPoint(v); float distance; if (p != null) { distance = Vector2.Distance(p.position, rowball.position); if (distance < minDistance) { minDistance = distance; targetPoint = p; } } } center.RemoveLink(targetPoint); targetPoint.RemoveLinks(); //Random destruction and force for (int i = 0; i < center.linkCount; ++i) { if (Random.Range(0f, 1f) > (1 - module.frameworkDestroyChance)) { center.RemoveLink(i); //Framework } } foreach (Point p in points) { if (p != null) { if (p != center && Random.Range(0f, 1f) > (1 - module.edgeDestroyChance)) { p.RemoveLinks(); //Edge } //Force (no else, in order to process dummy links) p.AddImpulse(relativeVelocity * Random.Range(module.minDestroyForce, module.maxDestroyForce)); } } } } //Ramming (stealing) if (other.gameObject.layer == module.pointLayer) { Point p = other.GetComponent <Point>(); if (p.handler != null && p.handler.GetComponent <ShipRevamped>() != null) { ShipRevamped s = p.handler.GetComponent <ShipRevamped>(); Vector2 relativeVelocity = center.velocity - s.center.velocity; //Check if relative velocity is above threshold and stealer is moving faster if (relativeVelocity.magnitude > module.stealSpeed && s.center.velocity.magnitude > center.velocity.magnitude) { Pass(s); } } } } }
public void ProcessCollision(Collider2D other) { if (!totaled) { //Process rowball if (other.gameObject.layer == module.rowballLayer) { Rowball rowball = other.GetComponent <Rowball>(); RowballState state = GetRowballState(rowball); // float comparator = 2 * shipModule.volleyWidth - 1; for (float x = -1; x <= 1; x += 0.3f) { for (float y = -1; y <= 1; y += 0.3f) { Vector2 v = new Vector2(x, y).normalized; float d0 = Vector2.Dot(aiming.normalized, v); float d1 = Vector2.Dot(rowball.velocity.normalized, v); Debug.DrawRay(position, -v * 32, (d0 < comparator) ? Color.green : Color.red, 4); if (d1 < comparator) { Debug.DrawRay(position, v * 16, Color.blue, 4); } } } //if (volley && rowball.shooter != null && rowball.level > 1) //{ // float dotProduct = Vector2.Dot(rowball.velocity.normalized, aiming.normalized); // if (dotProduct < comparator) // { // rowball.velocity = (new Vector2(-1 * shipModule.volleySpeed * rowball.velocity.x, -1 * shipModule.volleySpeed * rowball.velocity.y)); // rowball.shooter = this.gameObject; //Update shooter on volley // InterfaceManager.CreateTextEffect( // "VOLLEY", // position + new Vector2(Random.Range(size, size * 2), Random.Range(size, size * 2)), // color, 0.3f //Magic number // ); // PlayerManager.GetPlayer(this).volleys++; // //Hardcoded for now // return; // } //} if (state == RowballState.Kill) { if (!rowball.clearedShot && rowball.shooter == this) { //Debug.Log("Rowball hasn't cleared shot!"); return; } // Only allow kills when game is in active state (not in ready/end state) if (GameManager.instance.roundState != GameManager.RoundState.PLAYING) { return; } //Process Debug.Log("Player totaled"); this.totaled = true; effector.enabled = false; bounds.enabled = false; collisionBounds.gameObject.SetActive(false); //Drop rowball if carrying one Vector2 relativeVelocity = rowball.RelativeVelocity(velocity); if (hasRowball) { Rowball r = ObjectManager.AddRowball(this.position, Color.white);; r.AddImpulse(relativeVelocity * module.rowballDropFactor); hasRowball = false; } //Break closest point float minDistance = size * 2; //Arbitrary number, should always be larger Point targetPoint = null; foreach (Vertex v in edge) { Point p = vertexPoint(v); float distance; if (p != null) { distance = Vector2.Distance(p.position, rowball.position); if (distance < minDistance) { minDistance = distance; targetPoint = p; } } } if (targetPoint != null) { center.RemoveLink(targetPoint); targetPoint.RemoveLinks(); } //Random destruction and force for (int i = 0; i < center.linkCount; ++i) { if (Random.Range(0f, 1f) > (1 - module.frameworkDestroyChance)) { center.RemoveLink(i); //Framework } } foreach (Point p in points) { if (p != null && p != center) { if (Random.Range(0f, 1f) > (1 - module.edgeDestroyChance)) { p.RemoveLinks(); //Edge } //Force (no else, in order to process dummy links) Vector2 explosionDirection = (relativeVelocity.normalized + (p.position - position).normalized) * 0.5f; p.AddImpulse(explosionDirection * Random.Range(module.minDestroyForce, module.maxDestroyForce)); } } //Event Debug.Log("Player killed"); Observer.OnKill.Invoke(this, rowball); } else {//if(state==RowballState.Pickup){ if (!hasRowball && Time.time - cannon.lastFireTime > cannon.cooldownTime) { //Process pickup //InitSpritePosition(rowball.position); hasRowball = true; Destroy(rowball.gameObject); } else if (rowball.shooter == null || rowball.clearedShot) { rowball.velocity = new Vector2(this.velocity.x * 2, this.velocity.y * 2); //Magic numbers } } } //Ramming (force-fire and stealing) if (other.gameObject.layer == module.pointLayer) { Point p = other.GetComponent <Point>(); if (p.handler != null && p.handler.GetComponent <ShipRevamped>() != null) { ShipRevamped s = p.handler.GetComponent <ShipRevamped>(); Vector2 relativeVelocity = center.velocity - s.center.velocity; //Check if relative velocity is above threshold and stealer is moving faster if (hasRowball && relativeVelocity.magnitude > module.stealSpeed && s.center.velocity.magnitude > center.velocity.magnitude) { string stealString = "BUMP"; if (!s.hasRowball) { Pass(s); stealString = "STEAL"; PlayerManager.GetPlayer(this).steals++; } //else this.cannon.Fire(0.1f); InterfaceManager.CreateTextEffect( stealString, position + new Vector2(Random.Range(size, size * 2), Random.Range(size, size * 2)), s.color, 0.3f //Magic number ); } //Ramming if (s.center.velocity.magnitude > center.velocity.magnitude && Vector2.Dot(relativeVelocity.normalized, (s.center.position - center.position).normalized) > 0 ) { AddImpulseAtPoint(-relativeVelocity * module.ramMultiplier, p.position, module.ramScale); } } } } }