/// <summary> /// Sets the multiplier. /// </summary> /// <param name="mult">Mult.</param> public void SetMultiplier(int mult) { SystemLogger.write("Score multiplier set"); this.multi *= mult; this.multiplierText = "x" + multi.ToString(); Multi.Instance.MultiTxtSet(); }
/// <summary> /// Decrease the multiplier /// </summary> /// <param name="mult"></param> public void DecreaseMultiplier(int mult) { SystemLogger.write("Score Multiplier Decreased"); this.multi = mult; this.multiplierText = "x" + multi.ToString(); Multi.Instance.MultiTxtSet(); }
public void LoadPlanet() { if (serializedSamplePointsByPlanet.ContainsKey(planetName) && serializedSamplePointsByPlanet[planetName].samplePointKeys != null) { Vector3[] normals = mesh.normals; int[] triangleIndices = mesh.GetTriangles(0); for (int i = 0; i < triangleIndices.Length - 2; i += 3) { faceNormals.Add((normals[triangleIndices[i]] + normals[triangleIndices[i + 1]] + normals[triangleIndices[i + 2]]) / 3); } SystemLogger.write("Loading sample points from save file."); samplePoints = new Dictionary <long, List <ProceduralGenerationPoint> >(); reconstructSamplePoints(planetName); } else { samplePoints = generatePoisson(minDistance, newPointsCount); } if (generateAllAtOnce) { generateObjectsByName(); StartCoroutine("generateAll"); } else { generateInitialObjects(); serializeSamplePoints(); } }
/// <summary> /// Gets the list of possible grids in which enemies can be spawned. /// </summary> /// <returns>The spawn cells.</returns> /// <param name="playerLoc">Player location.</param> /// <param name="maxCellsAway">Max cells away.</param> /// <param name="minCellsAway">Minimum cells away.</param> /// <param name="direction">Direction.</param> public List <long> getSpawnCells(long playerLoc, int maxCellsAway, int minCellsAway) { SystemLogger.write("Getting cells where enemy can be spawned..."); List <long> possibleKeys = new List <long> (); int y = (int)(playerLoc / gridOffset); int x = (int)(playerLoc - (y * gridOffset)); int minX = x - maxCellsAway; int maxX = x + maxCellsAway; int minY = y - maxCellsAway; int maxY = y + maxCellsAway; int newX, newY; for (int i = minX; i <= maxX; i++) { for (int j = minY; j < maxY; j++) { newX = i; newY = j; if (Mathf.Abs(x - newX) + Mathf.Abs(y - newY) >= minCellsAway) { possibleKeys.Add(newX + (newY * gridOffset)); } } } return(possibleKeys); }
/// <summary> /// Update the current plan /// </summary> /// <returns></returns> private void updateCurrentPlan() { SystemLogger.write("Update current plan"); base.resetTargetIndex(); this.getNewPlan(PlanetNavigation.vertices[Random.Range(0, PlanetNavigation.vertices.Length - 1)]); }
/// <summary> /// Generates the objects in the objectsByName pool. To be used during reloading sample points from save file. /// </summary> public void generateObjectsByName() { SystemLogger.write("Setting objects by name..."); Object[] largeObjects = Resources.LoadAll(folder + "/Large"); Object[] mediumObjects = Resources.LoadAll(folder + "/Medium"); Object[] smallObjects = Resources.LoadAll(folder + "/Small"); int i; objectBySize.Add("Small", new List <GameObject> ()); for (i = 0; i < smallObjects.Length; i++) { objectByName.Add(smallObjects[i].name, (GameObject)smallObjects[i]); } for (i = 0; i < mediumObjects.Length; i++) { objectByName.Add(mediumObjects[i].name, (GameObject)mediumObjects[i]); } for (i = 0; i < largeObjects.Length; i++) { objectByName.Add(largeObjects[i].name, (GameObject)largeObjects[i]); } }
/// <summary> /// Add the bomb pickup to the pickup array /// </summary> public void AddBombPickup() { template bomb = (obj) => { if (obj.gameObject.GetComponent <Shooting>() != null) { Instantiate(bombExplosion, obj.transform.position, obj.transform.rotation); // Get all the objects in a <ExplosionRadius> radius from where the bullet collided Collider[] hitColliders = Physics.OverlapSphere( transform.position, PowerUpManager.Instance.BombRadius, PowerUpManager.Instance.BombLayer); PopUpText.Instance.NewPopUp("Nuke!"); // For every object in the explosion for (int i = 0; i < hitColliders.Length; ++i) { if (hitColliders[i]) { // Try and find an EnemyHealth script on the gameobject hit. EnemyStats enemyHealth = hitColliders[i].gameObject.GetComponentInParent <EnemyStats>(); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage((int)PowerUpManager.Instance.BombDamage); } } } } }; this.Type[6] = bomb; SystemLogger.write("Bomb Pickup Initialized"); }
/// <summary> /// Add the shield pickup to the pickup array /// </summary> public void AddShieldPickup() { template shieldPickup = (obj) => { // If the shield isn't already active if (!PowerUpManager.Instance.Powerups["Shield"].IsActive) { PopUpText.Instance.NewPopUp("Force Field!"); // Make a shield around the player. This may change from my shitty particle effect GameObject shield = Instantiate(PowerUpManager.Instance.ShieldModel, obj.transform.position, obj.transform.rotation) as GameObject; // Parent the shield to the player shield.transform.parent = obj.transform; // Resize the shield to look like it's around the player. shield.transform.localScale = new Vector3( PowerUpManager.Instance.ShieldResizer, PowerUpManager.Instance.ShieldResizer, PowerUpManager.Instance.ShieldResizer); // Start the particle system shield.GetComponent <ParticleSystem>().Play(); } // Activate the shield power up PowerUpManager.Instance.Activate("Shield"); }; this.Type[7] = shieldPickup; SystemLogger.write("Shield Pickup Initialized"); }
/// <summary> /// Triggered when the bullet collides with anything /// </summary> /// <param name="col">The object it collides with</param> void OnCollisionEnter(Collision col) { SystemLogger.write("Bullet collision"); // If it's an enemy if (col.gameObject.CompareTag(this.targetTag)) { // Try and find an EnemyHealth script on the gameobject hit. EnemyStats enemyHealth = col.gameObject.GetComponentInParent <EnemyStats>(); // if not in parent if (enemyHealth == null) { enemyHealth = col.gameObject.GetComponent <EnemyStats>(); } // If the EnemyHealth component exists... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage((int)this.damage); if (PowerUpManager.Instance.Powerups["DamageUp"].IsActive) { enemyHealth.TakeDamage((int)PowerUpManager.Instance.PowerIncrease); } } } }
/// <summary> /// A timer for the power ups /// </summary> /// <param name="Key">The specific power up key</param> /// <returns></returns> IEnumerator Timer(string Key) { // While there's still time left on the timer while (Powerups[Key].Timer > 0f) { // Count down this.Powerups[Key].Timer -= Time.deltaTime; yield return(null); } // Deactive power up this.Powerups[Key].IsActive = false; Powerups[Key].guiIcon.SetActive(false); // If the power up was a multishot, set the max laser count back to 1 if (Key.Equals("Multishot")) { this.maxLaserCount = 1f; } // If the power up was a shield, destroy the shield effect if (Key.Equals("Shield")) { Destroy(GameObject.Find("Shield(Clone)")); } // If the power up was a speed boost, set the speed back to normal if (Key.Equals("SpeedBoost")) { this.CurrentSpeedBoost = 1f; } SystemLogger.write("Power up time complete"); }
public void dropBomb(Vector3 target) { SystemLogger.write("droppin da bomb"); GameObject bomb = Instantiate(enemyBomb, bombSpawnLocation.position, this.transform.rotation) as GameObject; /* * // Everything from here down is basically kinematic equations to calculate the necessary forward velocity * // for the bomb to hit the player at its current location * Vector3 enemyToPlayer = Player.Instance.transform.position - this.transform.position; * float angle = Vector3.Angle(this.transform.forward, enemyToPlayer); * float horizontalDistanceToPlayer = enemyToPlayer.magnitude * Mathf.Cos(angle); * * RaycastHit hit; * if(Physics.Raycast(this.transform.position, -this.transform.up, out hit, maxDistance, LayerMask.NameToLayer("Planet"))) * { * float velocityMagnitude = (horizontalDistanceToPlayer / (Mathf.Sqrt((2 * hit.distance) / 9.8f))); * * bomb.GetComponent<Rigidbody>().velocity = bomb.transform.forward * velocityMagnitude; * * bomb.GetComponent<Rigidbody>().useGravity = true; * bomb.GetComponent<TImedDestroySelf>().lifetime = 25f; * }*/ bomb.GetComponent <Rigidbody>().useGravity = true; mover.flyingTowardsPlayer = false; }
/// <summary> /// Called when the object is created. Used to /// initialize the singleton pattern. /// </summary> void Start() { if (Instance == null) { Instance = this; this.Powerups = new Dictionary <string, Powerup>(); this.Multishot = new Powerup(MultiShotTime, MultiBar, this.MultiBarIcon); this.DamageUp = new Powerup(DamageUpTime, DamageUpBar, this.DamageUpBarIcon); this.Shield = new Powerup(ShieldTime, ShieldBar, this.ShieldBarIcon); this.SpeedBoost = new Powerup(SpeedBoostTime, SpeedBar, this.SpeedBarIcon); this.Bomb = new Powerup(0f, null); Powerups.Add("Multishot", this.Multishot); Powerups.Add("DamageUp", this.DamageUp); Powerups.Add("Shield", this.Shield); Powerups.Add("SpeedBoost", this.SpeedBoost); Powerups.Add("Bomb", this.Bomb); SystemLogger.write("Powerup Manager attached to: " + this.gameObject.name); } else { Destroy(this.gameObject); } }
/// <summary> /// Drop a mine onto the planet /// </summary> private void dropMine() { SystemLogger.write("instantiating new mine"); GameObject newMine = (GameObject)Instantiate(this.mine, this.mineSpawnLocation.position, this.mineSpawnLocation.rotation); // Add self to observable newMine.GetComponent <Obesrvable>().Instantiate(this); }
/// <summary> /// Called every frame. Checks to see if a weapon switch has occured /// </summary> void Update() { // If player 2 pushes up on the dpad, or presses '1' on the keyboard, switch to the default laser if (InputManager.Player2VerticalInput > 0 || Input.GetKeyDown(KeyCode.Alpha1)) { SystemLogger.write("Weapon Switch: Default Laser"); //Set Gui to current weapon WeaponDisplayController.Instance.AllOff(); WeaponDisplayController.Instance.dLaserOn.enabled = true; WeaponDisplayController.Instance.ChangeCursor("laser"); GetComponent <Shooting>().bullet = cache.Laser; } // If player 2 pushes left on the dpad, or presses '2' on the keyboard, switch to the rocket if (InputManager.Player2HorizontalInput < 0 || Input.GetKeyDown(KeyCode.Alpha2)) { // If there's ammo if (cache.Rocket.GetComponent <Weapon>().ammo > 0) { SystemLogger.write("Weapon Switch: Rocket"); // Set Gui to current weapon WeaponDisplayController.Instance.AllOff(); WeaponDisplayController.Instance.rocketsOn.enabled = true; WeaponDisplayController.Instance.ChangeCursor("rocket"); GetComponent <Shooting>().bullet = cache.Rocket; } } // If player 2 pushes right on the dpad, or presses '3' on the keyboard, switch to the laser beam if (InputManager.Player2HorizontalInput > 0 || Input.GetKeyDown(KeyCode.Alpha3)) { // If there's ammo if (cache.LaserBeam.GetComponent <Weapon>().ammo > 0) { SystemLogger.write("Weapon Switch: Laser Beam"); // Set Gui to current weapon WeaponDisplayController.Instance.AllOff(); WeaponDisplayController.Instance.beamOn.enabled = true; WeaponDisplayController.Instance.ChangeCursor("beam"); GetComponent <Shooting>().bullet = cache.LaserBeam; } } // If player 2 pushes down on the dpad, or presses '4' on the keyboard, switch to the mine if (InputManager.Player2VerticalInput < 0 || Input.GetKeyDown(KeyCode.Alpha4)) { // If there's ammo if (cache.Mine.GetComponent <Weapon>().ammo > 0) { SystemLogger.write("Weapon Switch: Mine"); // Set Gui to current weapon WeaponDisplayController.Instance.AllOff(); WeaponDisplayController.Instance.mineOn.enabled = true; WeaponDisplayController.Instance.ChangeCursor("mine"); GetComponent <Shooting>().bullet = cache.Mine; } } }
/// <summary> /// Resets the bolt count. Should be used when /// a new planet is traveled to. /// </summary> public void resetBoltCount() { SystemLogger.write("Bolts Reset"); this.BoltCount = 0f; warpTextActive = false; BoltTxt.text = "Bolt: " + (int)((this.BoltCount / this.BoltGoal) * 100) + "%"; // Call deactivate event PlayerTeleported(); }
/// <summary> /// Called when the laser is destroyed to decrease the laser count by 1 /// </summary> void OnDestroy() { SystemLogger.write("Laser beam destruction"); if (this.Target == "Enemy") { // Decrease the laser count by 1 --PowerUpManager.Instance.CurrentLaserCount; } }
/// <summary> /// Checks if the plan needs to be updated /// </summary> public override void checkPlan() { SystemLogger.write("checking plan"); // Check if plan should be updated if (shouldUpdatePlan()) { this.updateCurrentPlan(); } }
/// <summary> /// Start this instance. /// </summary> void Start() { SystemLogger.write("Initializing Patrolling behavior"); base.init(); base.targetLocation = Player.Instance.getClosestVertice(); base.setMovementScript(this.GetComponent <AStar>()); base.moveTowardsPlayerAtEndOfPath = false; this.updateCurrentPlan(); }
/// <summary> /// Initialize necessary variables /// </summary> void Start() { SystemLogger.write("Instantiating Mine Dropper"); base.init(); // Begin Dropping MInes StartCoroutine(this.dropMines()); }
/// <summary> /// Decreases the score. /// </summary> /// <param name="decreaseAmount">Decrease amount.</param> public void DecreaseScore(int decreaseAmount) { if (!PowerUpManager.Instance.Powerups["Shield"].IsActive) { score -= decreaseAmount; PlayerHitImage.Instance.playerHit(); SystemLogger.write("Score Decreased by: " + decreaseAmount); } }
/// <summary> /// Waits for loading of the save file so that on continue, /// it will wait until the file has been loaded before the /// procedural generation will be set off. /// </summary> /// <returns>The for load.</returns> public IEnumerator waitForLoad() { while (!SaveSystem.Instance.getLoaded()) { yield return(null); } SystemLogger.write("Finished loading save file!"); LoadPlanet(); }
/// <summary> /// Initialize components /// </summary> void Start() { SystemLogger.write("Init Astar"); // Divide by 2 to get radius not diameter this.radius = this.body.GetComponent <Collider>().bounds.size.magnitude *this.multiplier / 2; // Get planets navigation this.planetVertexNavigation = Player.Instance.getPlanetNavigation(); }
/// <summary> /// What happens when this object collides with something /// </summary> /// <param name="obj">The object it collided with</param> void OnTriggerEnter(Collider obj) { if (obj.gameObject.tag == "Player") { SystemLogger.write("Player Picked Up Bolt"); Destroy(this.gameObject); // Activate the pickup type this.Type[this.PickupType](obj.gameObject); } }
/// <summary> /// Move Towards the given target /// </summary> /// <param name="targ"></param> public virtual void move(Vector3 targ) { SystemLogger.write("Moving towards target"); // Set rotation Quaternion destRotation = Quaternion.LookRotation(targ - transform.position, transform.up); transform.rotation = Quaternion.RotateTowards(transform.rotation, destRotation, rotationMaxDegrees * Time.deltaTime); // Move forward this.transform.position = Vector3.MoveTowards(this.transform.position, targ, this.moveSpeed * Time.deltaTime); }
void Awake() { if (Instance == null) { Instance = this; SystemLogger.write("Pickup Cache Instantiated On: " + this.gameObject.name); } else { Destroy(this); } }
private IEnumerator dropMines() { SystemLogger.write("Beginning to drop more mines"); this.shouldDropMines = true; // Will drop mines until max reached while (shouldDropMines) { this.dropMine(); yield return(new WaitForSeconds(this.timeBetweenEachMineDrop)); } }
/// <summary> /// Add the score multiplier to the pickup array /// </summary> public void AddScoreMultiplierPickup() { template pickupThree = (obj) => { GameObject multi = new GameObject(); multi.AddComponent <ScoreMulti>(); PopUpText.Instance.NewPopUp("Multiplier!"); }; this.Type[2] = pickupThree; SystemLogger.write("Score Multiplier Pickup Initialized"); }
/// <summary> /// Sets the name. /// </summary> /// <param name="PlayerName">Player name.</param> public void SetName() { if (SaveSystem.Instance == null) { PlayerName = "LumpyLabs"; } else { PlayerName = SaveSystem.Instance.PlayerID; SystemLogger.write("Player Name Set to: " + PlayerName); } }
public IEnumerator waitForPlanet() { while (Player.instance == null || Player.instance.getPlanetNavigation().gameObject == null) { yield return(null); } SystemLogger.write("The planet has been loaded!"); SystemLogger.write(Player.instance.getPlanetNavigation().gameObject.name); planetName = Player.instance.getPlanetNavigation().gameObject.name; CreateGrid(planetName); }
/// <summary> /// Triggered when the bullet collides with anything /// </summary> /// <param name="obj"></param> void OnCollisionEnter(Collision obj) { SystemLogger.write("Rocket collision"); // Get all the objects in a <ExplosionRadius> radius from where the bullet collided Collider[] hitColliders = Physics.OverlapSphere(transform.position, ExplosionRadius); // Create Explosion object Instantiate(Explosion, transform.position, transform.rotation); // For every object in the explosion for (int i = 0; i < hitColliders.Length; ++i) { if (hitColliders[i]) { // Add an explosion force of <ExplosionForce> to them Rigidbody rb = hitColliders[i].gameObject.GetComponent <Rigidbody>(); if (rb) { rb.AddExplosionForce(ExplosionForce, transform.position, this.ExplosionRadius); } // Try and find an EnemyHealth script on the gameobject hit. EnemyStats enemyHealth = hitColliders[i].gameObject.GetComponentInParent <EnemyStats>(); if (hitColliders[i].CompareTag("Player")) { ScoreManager.Instance.DecreaseScore((int)this.GetComponent <Weapon>().damage); } else if (hitColliders[i].CompareTag("DestructableEnvironment")) { Destroy(hitColliders[i].gameObject); } // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage((int)this.GetComponent <Weapon>().damage); // If the damage up power up is active, do extra damage if (PowerUpManager.Instance.Powerups["DamageUp"].IsActive) { enemyHealth.TakeDamage((int)PowerUpManager.Instance.PowerIncrease); } } } } // Destroy the rocket Destroy(this.gameObject); }