//Teleport rowball to other ship void Pass(ShipRevamped s) { if (hasRowball && !s.totaled && !s.hasRowball) { hasRowball = false; //Process pickup s.InitSpritePosition(rowballSprite.transform.position); s.hasRowball = true; } }
//Teleport rowball to other ship void Pass(ShipRevamped s) { if (hasRowball) { hasRowball = false; cannon.lastFireTime = Time.time; //Process pickup s.hasRowball = true; } }
//public static PlayerInfo GetPlayer(Ship s){ // foreach(PlayerInfo p in ActivePlayers())if(p.player.ship!=null && p.player.ship==s)return p; // return null; //} public static PlayerInfo GetPlayer(ShipRevamped s) { foreach (PlayerInfo p in ActivePlayers()) { if (p.player.ship != null && p.player.ship == s) { return(p); } } return(null); }
void Start() { if (isShip) { Point p = transform.parent.parent.GetComponent <Point>(); if (p.handler != null) { handler = p.handler.GetComponent <ShipRevamped>(); } } cachedScale = transform.localScale.x; }
//need to rework for variable paddling //get load var and play at that void OnPaddle(ShipRevamped s, bool l) { bool ship = s.gameObject == transform.parent.GetComponent <Point>().handler; //hack, fix! if (ship && ((l && left) || (!l && !left))) //simplify boolean { animator.Play("Paddle"); } if (tapAnimation) { StartCoroutine(Brake(s, l)); //multithreading? } }
//Method to encapsulate whether we should turn off the terrain affector void DetectsTerrainAffectorOff(ShipRevamped s) { if (s != null) { PlayerManager.PlayerInfo p = PlayerManager.GetPlayer(s); //Debug.Log ("Points cache size is " + pointsCache.Count); if (!pointsCache.ContainsKey(s)) { return; } if (p != null && pointsCache[s].Count == 0) { //Debug.Log ("Setting terrainAffector off"); s.SetTerrainAffectorOff(); } } }
void Spawn() { readyToLoad = false; Clear(); if (GameManager.instance.roundState == GameManager.RoundState.SETUP) { playerInfo = new PlayerInfo[players.Length]; //Checks if game has been initialized before } usageCache = new bool[players.Length]; colorCache = new PlayerColor[players.Length]; teamColors = new PlayerColor[players.Length]; int spawnPoint = 0; for (int i = 0; i < players.Length; ++i) { if (GameManager.instance.roundState == GameManager.RoundState.SETUP) { playerInfo[i] = new PlayerInfo(); //Initialize info playerInfo[i].ready = false; //Initialize PlayerReady boolean in ship if game has not been initialized before } if (players[i].inUse) { //Spawn player and set data ShipRevamped s = Instantiate(shipType, WorldManager.SpawnPoint(spawnPoint), Quaternion.identity) as ShipRevamped; players[i].ship = s; s.control = players[i].control; spawnPoint++; //Debug.Log("Spawned player " + i + " with control " + players[i].control.ToString()); usageCache[i] = true; } UpdatePlayer(players[i], i); } //Update team colors UpdateTeamColors(); foreach (PlayerInfo p in playerInfo) { UpdatePlayerShip(p); } readyToLoad = true; }
IEnumerator ChargeCannon(ShipRevamped s) { while (s.cannon.charge == 0) { yield return(0); //Wait for input } // float pitch = chargeRange.x; // lastChargeTime=Time.time; AudioSource a = AddSound(charge, PlayerPrefs.GetFloat("effectsVolume", 1.0f), -1, true); while (s.cannon.charge > 0 && s != null) { pitches[sources.IndexOf(a)] = Mathf.Lerp(chargeRange.x, chargeRange.y, s.cannon.charge); yield return(0); } DestroySound(a); }
void OnTriggerExit2D(Collider2D c) { //Debug.Log ("On Trigger Exit"); //Debug.Log (c.GetComponent<Point> ().position); ShipRevamped s = null; //Checks if ship has collided with goal if (c.gameObject.layer == pointLayer && c.GetComponent <Point> ().handler != null) { s = c.GetComponent <Point> ().handler.GetComponent <ShipRevamped> (); if (s != null && !s.totaled) { pointsCache[s].Remove(c.GetComponent <Point> ()); } } DetectsTerrainAffectorOff(s); }
IEnumerator Brake(ShipRevamped s, bool l) { while ((l?s.leftIn.input:s.rightIn.input) == 0) { //hm... yield return(0); } while ((l?s.leftIn.input:s.rightIn.input) > 0) { if (animator.state != "Paddle") { animator.Play("Brake"); } yield return(0); } if (animator.state == "Brake") { animator.Play("Default"); } }
IEnumerator CannonShake(ShipRevamped s) { while (s.cannon.charge == 0) { yield return(0); //Wait for input } ShakeLayer l = new ShakeLayer(cannonShake.amount, cannonShake.speed, cannonShake.damping); shakeLayers.Add(l); while (s.cannon.charge > 0 && s != null) { yield return(0); } //Wait to clear l.amount = 0; while (l.lastPosition != Vector2.zero) { yield return(0); } shakeLayers.Remove(l); }
void OnTriggerEnter2D(Collider2D c) { //print(c.gameObject.name+" entered"); //Debug.Log ("On Trigger Enter"); //Debug.Log (c.GetComponent<Point> ().position); ShipRevamped s = null; //Checks if ship has collided with goal if (c.gameObject.layer == pointLayer && c.GetComponent <Point> ().handler != null) { s = c.GetComponent <Point> ().handler.GetComponent <ShipRevamped> (); if (s != null && !s.totaled) { if (!pointsCache.ContainsKey(s)) { pointsCache.Add(s, new List <Point> ()); } pointsCache[s].Add(c.GetComponent <Point> ()); } } if (s != null && !s.totaled && pointsCache[s].Count > 0) { //Debug.Log ("Ship is not null"); PlayerManager.PlayerInfo p = PlayerManager.GetPlayer(s); if (p != null) { //Debug.Log ("Setting terrainAffector on"); s.SetTerrainAffectorOn(terrainAffectorDragFactor); } else { //Debug.Log ("Player is null"); } } }
//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); } }
void OnFireBegin(ShipRevamped s) { StartCoroutine(ChargeCannon(s)); }
//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))]); }
//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); } } } } }
void OnTriggerEnter2D(Collider2D c) { ShipRevamped s = null; Rowball[] rs = null; float distance = 0; //Checks if ship has collided with goal if (c.gameObject.layer == pointLayer && c.GetComponent <Point> ().handler != null) { s = c.GetComponent <Point> ().handler.GetComponent <ShipRevamped> (); } //Checks if rowball has collided with goal if (c.gameObject.layer == 8 && c.GetComponents <Rowball>().Length > 0) { rs = c.GetComponents <Rowball> (); if (rs != null) { foreach (Rowball r in rs) { if (r != null) { //Shield check if (health > 0) { if (r.speed > 3) { for (int j = 0; j < sides; ++j) { _goalShieldCache [health - 1][j].startColor = Color.clear; _goalShieldCache[health - 1][j].endColor = Color.clear; } health--; } //TODO: Figure out if deterministic physics are good r.velocity = -r.velocity; r.velocity += new Vector2(Random.Range(-2, 2), Random.Range(-2, 2)); break; } else { s = r.shooter.GetComponent <ShipRevamped>(); distance = Vector3.Distance(r.shotPosition, transform.position); break; } } } } } if (s != null) { if (health > 0) { return; } //PlayerManager.PlayerInfo p = (s.hasRowball || rs != null) ? PlayerManager.GetPlayer(s) : null; //if(p!=null && p.player.team==team && GameManager.instance.roundState==GameManager.RoundState.PLAYING && !GameManager.instance.roundOver){ // s.scoredGoal = true; // s.shotDistance = distance; // Observer.OnGoal.Invoke (s); //} } }
// void OnKill(ShipRevamped targetShip, Rowball rowball) { //StartCoroutine(Shake(0.5f)); RemoveAllPoints(targetShip); }
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); } } } } }
//Observe void OnFireBegin(ShipRevamped s) { StartCoroutine(CannonShake(s)); }
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); }