//instantiates a revolving star at the location and around the point provided GameObject CreateRevolvingStar(float x, float y, float r_point_x, float r_point_y, Color color, Texture texture, float size, float speed) { GameObject rstar = CreateStar(x, y, color, texture, size, false); Starscript scpt = rstar.GetComponent <Starscript>(); scpt.is_revolving = true; scpt.rpoint = new Vector3(r_point_x, r_point_y, 0); scpt.rspeed = speed; scpt.editor_freeze = true; //creating visual representation of path GameObject path1 = Instantiate(revolving_star_path, scpt.rpoint + new Vector3(0, 0, scpt.starSize), new Quaternion(0, 0, 0, 0)) as GameObject; path1.transform.Rotate(new Vector3(0, 90, 90)); path1.transform.localScale *= 2 * (Vector3.Distance(rstar.transform.position, scpt.rpoint) + scpt.starSize); path1.renderer.material.color = scpt.c; GameObject path2 = Instantiate(revolving_star_path, scpt.rpoint + new Vector3(0, 0, scpt.starSize - .2f), new Quaternion(0, 0, 0, 0)) as GameObject; path2.transform.Rotate(new Vector3(0, 90, 90)); path2.transform.localScale *= 2 * (Vector3.Distance(rstar.transform.position, scpt.rpoint) - scpt.starSize); path2.renderer.material.color = Color.black; // path1.transform.parent = rstar.transform; // path2.transform.parent = rstar.transform; GameObject[] temp_arr = new GameObject[rstar_arr.Length + 1]; for (int i = 0; i < rstar_arr.Length; i++) { temp_arr[i] = rstar_arr[i]; } rstar_arr = temp_arr; rstar_arr[rstar_arr.Length - 1] = rstar; return(rstar); }
/* GameObject CreateStar(float x, float y, Color color, Texture texture, float size, bool isBlackHole = false, bool isExplodingStar=false) * { * * * GameObject starE = Instantiate (star, new Vector3(x,y,0), new Quaternion(0,0,0,0)) as GameObject; * Starscript starscript = starE.GetComponent<Starscript>(); * starscript.c = color; * starscript.t = texture; * starscript.starSize = size; * starscript.isBlackHole = isBlackHole; * * if(isBlackHole) * Starscript.BLACK_HOLE_HELPER = true; * * //expand and copy star_arr - if loading a level takes too long, this can be optimized * GameObject[] temp_arr = new GameObject[star_arr.Length+1]; * for(int i=0;i<star_arr.Length;i++) * temp_arr[i] = star_arr[i]; * star_arr = temp_arr; * star_arr[star_arr.Length-1] = starE; * numStars++; * return starE; * } */ GameObject CreateMovingStar(float x, float y, Color color, Texture texture, float size, Vector3 dir, float speed, bool bandf = false) { GameObject mstar = CreateStar(x, y, color, texture, size, false); Starscript scpt = mstar.GetComponent <Starscript>(); scpt.is_moving = true; if (bandf) { scpt.destination = dir; scpt.start_loc = mstar.transform.position; scpt.bandf = true; } else { scpt.dir = dir; } scpt.editor_freeze = true; scpt.speed = speed; //creating visual representation of path // GameObject path0 = Instantiate(moving_star_path, mstar.transform.position, new Quaternion (0, 0, 0, 0)) as GameObject; // path0.transform.Rotate(new Vector3(0,90,0)); //path0.transform.localScale. GameObject[] temp_arr = new GameObject[mstar_arr.Length + 1]; for (int i = 0; i < mstar_arr.Length; i++) { temp_arr[i] = mstar_arr[i]; } mstar_arr = temp_arr; mstar_arr[mstar_arr.Length - 1] = mstar; return(mstar); }
//instantiates star or black hole from prefab at given xy location and of given characteristics //le original method GameObject CreateStar(float x, float y, Color color, Texture texture, float size, bool staticstar = true, bool isBlackHole = false) { GameObject starE = Instantiate(star, new Vector3(x, y, 20), new Quaternion(0, 0, 0, 0)) as GameObject; Starscript starscript = starE.GetComponent <Starscript>(); starscript.c = color; starscript.t = texture; starscript.starSize = size; starscript.isBlackHole = isBlackHole; if (isBlackHole) { Starscript.BLACK_HOLE_HELPER = true; } if (staticstar) { //expand and copy star_arr - if loading a level takes too long, this can be optimized GameObject[] temp_arr = new GameObject[star_arr.Length + 1]; for (int i = 0; i < star_arr.Length; i++) { temp_arr[i] = star_arr[i]; } star_arr = temp_arr; star_arr[star_arr.Length - 1] = starE; numStars++; } return(starE); }
// Use this for initialization void Start() { startx = Screen.width / 3; starty = Screen.height / 6; credits_offset = 10; GameObject s = GameObject.Find("game_state"); state = s.GetComponent <Game_State>(); GameObject starE = Instantiate(star, new Vector3(0, 0, 0), new Quaternion(0, 0, 0, 0)) as GameObject; Starscript starscript = starE.GetComponent <Starscript>(); starscript.c = Color.red; starscript.starSize = 30; starscript.is_revolving = true; starscript.rpoint = new Vector3(20, 20, 0); starscript.rspeed = 45; starscript.editor_freeze = true; }
void Start() { /* GameObject starE = Instantiate (star, new Vector3(70,70,0), new Quaternion(0,0,0,0)) as GameObject; * Starscript starscript = starE.GetComponent<Starscript>(); * starscript.c = Color.red; * starscript.starSize = 15; * starscript.is_revolving = true; * starscript.rpoint = new Vector3(0,0,0); * starscript.rspeed = 65;*/ //instantiate menu learth l = Instantiate(menu_learth, new Vector3(0, -35, 0), new Quaternion(0, 0, 0, 0)) as GameObject; l.renderer.material.color = Color.yellow; lt = Instantiate(yellow_learth_trail, l.transform.position, l.transform.rotation) as GameObject; lt.transform.parent = l.transform; starR = Instantiate(star, new Vector3(-40, 25, 0), new Quaternion(0, 0, 0, 0)) as GameObject; Starscript script = starR.GetComponent <Starscript>(); script.c = Color.cyan; script.starSize = 75; l.transform.position = new Vector3(starR.transform.position.x + script.starSize + Manager.RADIAL_ERROR, starR.transform.position.y, 0); random = Random.Range(0, 3); }
// Update is called once per frame void Update() { //one activated, set isinvincible to true if (is_activated) { Manager.IS_INVINCIBLE = true; Manager.speed *= 1.2f; if (Time.time - start_time > DURATION) { Manager.IS_INVINCIBLE = false; Destroy(gameObject); Destroy(Manager.lt); Starscript scpt = Manager.lastStar.GetComponent <Starscript>(); if (scpt.c == Color.red) { Manager.lt = Instantiate(red_learth_trail, Manager.l.transform.position, Manager.l.transform.rotation) as GameObject; } else if (scpt.c == Manager.orange) { Manager.lt = Instantiate(orange_learth_trail, Manager.l.transform.position, Manager.l.transform.rotation) as GameObject; } else if (scpt.c == Color.yellow) { Manager.lt = Instantiate(yellow_learth_trail, Manager.l.transform.position, Manager.l.transform.rotation) as GameObject; } else if (scpt.c == Manager.green) { Manager.lt = Instantiate(green_learth_trail, Manager.l.transform.position, Manager.l.transform.rotation) as GameObject; } else if (scpt.c == Color.blue) { Manager.lt = Instantiate(blue_learth_trail, Manager.l.transform.position, Manager.l.transform.rotation) as GameObject; } else if (scpt.c == Manager.purple) { Manager.lt = Instantiate(purple_learth_trail, Manager.l.transform.position, Manager.l.transform.rotation) as GameObject; } else if (scpt.c == Manager.aqua) { Manager.lt = Instantiate(aqua_learth_trail, Manager.l.transform.position, Manager.l.transform.rotation) as GameObject; } Manager.lt.transform.parent = Manager.l.transform; Manager.l.renderer.material.color = scpt.c; Learth_Movement.r.light.color = scpt.c; Learth_Movement.r.light.range = 2.5f * Manager.l.transform.localScale.x; } } if (!Level_Editor.delete_button) { //make powerup expand and contract if (!is_activated && Time.time - start_grow_shrink > grow_shrink_time) { shrink = !shrink; start_grow_shrink = Time.time; } if (!is_activated) { int ctrl = shrink ? -1 : 1; transform.localScale += new Vector3(ctrl * grow_shrink_rate, ctrl * grow_shrink_rate, ctrl * grow_shrink_rate); } } }
//outputs level to a text file void SaveLevel(string path) { star_arr = ContractArray(star_arr); rip_arr = ContractArray(rip_arr); coin_arr = ContractArray(coin_arr); mstar_arr = ContractArray(mstar_arr); alien_arr = ContractArray(alien_arr); rstar_arr = ContractArray(rstar_arr); boost_arr = ContractArray(boost_arr); invinc_arr = ContractArray(invinc_arr); wall_arr = ContractArray(wall_arr); //check if file exists if (File.Exists(path)) { } else { //write info to file using (StreamWriter sw = File.CreateText(path)) { //write lengths header (update this line as saving is implemented for other elements) sw.WriteLine(star_arr.Length + "," + rip_arr.Length + "," + coin_arr.Length + "," + mstar_arr.Length + "," + alien_arr.Length + "," + rstar_arr.Length + "," + boost_arr.Length + "," + invinc_arr.Length + "," + wall_arr.Length + "," + isaytime + "," + isaypoints); //stars for (int i = 0; i < star_arr.Length; i++) { Starscript scpt = star_arr[i].GetComponent <Starscript>(); string color = "black"; if (scpt.c.Equals(Color.red)) { color = "red"; } else if (scpt.c.Equals(orange)) { color = "orange"; } else if (scpt.c.Equals(Color.yellow)) { color = "yellow"; } else if (scpt.c.Equals(green)) { color = "green"; } else if (scpt.c.Equals(Color.blue)) { color = "blue"; } else if (scpt.c.Equals(aqua)) { color = "aqua"; } else if (scpt.c.Equals(purple)) { color = "purple"; } string black_hole = "false"; if (scpt.isBlackHole) { black_hole = "true"; } //write to file if star is a static if (!scpt.is_moving && !scpt.is_revolving) { sw.WriteLine(star_arr[i].transform.position.x + "," + star_arr[i].transform.position.y + "," + color + "," + scpt.starSize + "," + black_hole); } } //rips for (int i = 0; i < rip_arr.Length; i++) { sw.WriteLine(rip_arr[i].transform.position.x + "," + rip_arr[i].transform.position.y + ",30,30,0"); } //coins for (int i = 0; i < coin_arr.Length; i++) { sw.WriteLine(coin_arr[i].transform.position.x + "," + coin_arr[i].transform.position.y); } //moving stars for (int i = 0; i < mstar_arr.Length; i++) { Starscript scpt = mstar_arr[i].GetComponent <Starscript>(); string color = "black"; if (scpt.c.Equals(Color.red)) { color = "red"; } else if (scpt.c.Equals(orange)) { color = "orange"; } else if (scpt.c.Equals(Color.yellow)) { color = "yellow"; } else if (scpt.c.Equals(green)) { color = "green"; } else if (scpt.c.Equals(Color.blue)) { color = "blue"; } else if (scpt.c.Equals(aqua)) { color = "aqua"; } else if (scpt.c.Equals(purple)) { color = "purple"; } //append true/false if star is a b and f or not if (scpt.bandf) { sw.WriteLine(mstar_arr[i].transform.position.x + "," + mstar_arr[i].transform.position.y + "," + color + "," + scpt.orbitRadius + "," + scpt.destination.x + "," + scpt.destination.y + "," + scpt.speed + ",true"); } else { sw.WriteLine(mstar_arr[i].transform.position.x + "," + mstar_arr[i].transform.position.y + "," + color + "," + scpt.orbitRadius + "," + scpt.dir.x + "," + scpt.dir.y + "," + scpt.speed + ",false"); } } //aliens for (int i = 0; i < alien_arr.Length; i++) { sw.WriteLine(alien_arr[i].transform.position.x + "," + alien_arr[i].transform.position.y); } //revolving stars for (int i = 0; i < rstar_arr.Length; i++) { Starscript scpt = rstar_arr[i].GetComponent <Starscript>(); string color = "black"; if (scpt.c.Equals(Color.red)) { color = "red"; } else if (scpt.c.Equals(orange)) { color = "orange"; } else if (scpt.c.Equals(Color.yellow)) { color = "yellow"; } else if (scpt.c.Equals(green)) { color = "green"; } else if (scpt.c.Equals(Color.blue)) { color = "blue"; } else if (scpt.c.Equals(aqua)) { color = "aqua"; } else if (scpt.c.Equals(purple)) { color = "purple"; } sw.WriteLine(rstar_arr[i].transform.position.x + "," + rstar_arr[i].transform.position.y + "," + scpt.rpoint.x + "," + scpt.rpoint.y + "," + color + "," + scpt.orbitRadius + "," + scpt.rspeed); } //boosts for (int i = 0; i < boost_arr.Length; i++) { sw.WriteLine(boost_arr[i].transform.position.x + "," + boost_arr[i].transform.position.y); } //invincibilities for (int i = 0; i < invinc_arr.Length; i++) { sw.WriteLine(invinc_arr[i].transform.position.x + "," + invinc_arr[i].transform.position.y); } //walls for (int i = 0; i < wall_arr.Length; i++) { WallScript wallscript = wall_arr[i].GetComponent <WallScript>(); if (wallscript.visible) { sw.WriteLine(wallscript.x1 + "," + wallscript.y1 + "," + wallscript.x2 + "," + wallscript.y2 + ",true"); } else { sw.WriteLine(wallscript.x1 + "," + wallscript.y1 + "," + wallscript.x2 + "," + wallscript.y2 + ",false"); } } } } }
void Update() { RaycastHit hi; if (Physics.Raycast(transform.position, velocity.normalized, out hi)) { last_norm = hi.normal; } //light effect every frame if (!Manager.IS_INVINCIBLE) { r.light.color = renderer.material.color; r.light.range = 2.5f * transform.localScale.x; } else { if (random == 0) { renderer.material.color = Color.blue; } else if (random == 1) { renderer.material.color = Color.yellow; } else if (random == 2) { renderer.material.color = Color.cyan; } random = Random.Range(0, 3); // this.renderer.material.color = Color.white; r.light.color = Color.white; r.light.range = 0; //5.5f*transform.localScale.x; } //calculate velocity every frame velocity = this.transform.position - lastPos.position; lastPos.position = this.transform.position; //regular non-orbiting movement if (!isTangent) { this.transform.position += velocity.normalized * Manager.speed; } //determine if a star is in learth's immediate path of tangency RaycastHit hit; int star_colliders = 1 << 8; if (Physics.Raycast(transform.position, velocity.normalized, out hit) && hit.transform.name == "Collider(Clone)") { Starscript s = hit.transform.parent.transform.gameObject.GetComponent <Starscript>(); //make sure not hitting the star part /* hit.transform.collider.enabled = false; * RaycastHit secondshot; * if(Physics.Raycast(transform.position,velocity.normalized,out secondshot)) { * print ("second hit name: "+secondshot.transform.name); * } * hit.transform.collider.enabled = true; */ s.glow = true; } }
void OnCollisionEnter(Collision collision) { //if learth collides with a space rip, die if (collision.gameObject.name == "Space_Rip(Clone)") { if (!Manager.IS_INVINCIBLE) { Manager.energy -= Manager.SPACE_RIP_COST; } } //if learth collides with a star, die if (collision.gameObject.name == "Star(Clone)") { Starscript scpt = collision.gameObject.GetComponent <Starscript>(); //end level if reach sink /* * * PREVIOUS VERSION END CONDITION * * * if (scpt.is_sink) { * //record delivered energy * Manager.gscpt.energy_delivered = Manager.energy; * //increment level counter * Manager.gscpt.cur_level++; * //set in game to false * Manager.gscpt.in_game = false; * //open the ship outfitter * Application.LoadLevel("Ship_Outfitter"); * } */ //if the invincibility powerup is turned on, instead of dying, blow the star up and steal its energy /* else */ if (Manager.IS_INVINCIBLE && !scpt.isBlackHole) { Manager.Popup(5, "" + Manager.INVINC_ENERGY_BONUS, this.transform.position); Manager.points += Manager.INVINC_ENERGY_BONUS; Starscript col_scpt = collision.gameObject.GetComponent <Starscript>(); col_scpt.removeStar(2); } else if (!scpt.spiral) { //effect Instantiate(reset_effect, Manager.l.transform.position, Manager.l.transform.rotation); Manager.Die(); } } if (collision.gameObject.name == "Wall(Clone)") { WallScript script = collision.gameObject.GetComponent <WallScript>(); if (Manager.IS_INVINCIBLE && script.visible) { Instantiate(explosion, transform.position, transform.rotation); Destroy(collision.gameObject); wall_down = true; } else { //effect Instantiate(reset_effect, Manager.l.transform.position, Manager.l.transform.rotation); //bounce ship off wall - v' = 2 * (v . n) * n - v Vector3 v = Vector3.Normalize(velocity); Vector3 n = last_norm; //normal of the plane we're about to hit float dp = Vector3.Dot(v, n); Vector3 v2 = 2 * dp * n; Vector3 reflected = -1 * (v2 - v); lastPos.position = transform.position - reflected; } } if (collision.gameObject.name == "coin(Clone)") { GameObject go = GameObject.Find("Alien_Exp_Sound"); Alien_Exp_Sound ascpt = go.GetComponent <Alien_Exp_Sound>(); ascpt.coin_grab.Play(); gscpt.coins_collected++; Manager.energy += 3; Manager.Popup(3, "" + Manager.COIN_POINTS, this.transform.position); Manager.points += Manager.COIN_POINTS; cpe = Instantiate(coin_pickup_effect, collision.gameObject.transform.position, collision.gameObject.transform.rotation) as GameObject; Destroy(collision.gameObject); } }