public override void OnSyncedUpdate(Navi navi, ChipLogic c) { c.frametimer -= Time.deltaTime; if (c.chip_anim_frame > 1) // attack is active on 3rd frame { int i = 0; while (i < affectedArea.Count) { if (!affectedArea[i].hit) // no hit from space yet, so check for hit // tests for hit and set to true if there is one so it won't check again { affectedArea[i].hit = navi.shot_handler.check_position(c.power, navi.playerNumber, c.stun, affectedArea[i].row, affectedArea[i].col, c.elem); } i++; } } if (c.frametimer <= 0) { c.frametimer = c.chipFR; if (c.chip_anim_frame < c.chip_sprite.Length - 1) // advance to next frame if not at end { c.chip_anim_frame++; foreach (SurroundTile bt in affectedArea) // update sprite of all burning tiles { bt.renderer.GetComponent <SpriteRenderer>().sprite = c.chip_sprite[c.chip_anim_frame]; } } else { c.deactivate(navi); } } }
// Use this for initialization void Start() { ChipDatabase chipDataBase = GameObject.Find("Chip Database").GetComponent <ChipDatabase>(); // !! temp: selects random key List <string> chipKeys = new List <string>(chipDataBase.chipDB.Keys); chip_logic = chipDataBase.chipDB[chipKeys[Random.Range(0, chipDataBase.chipDB.Count - 1)]]; Debug.Log(chip_logic.ID); // set cost and color code //cost = Random.Range(1, 6); // !!! Placeholder: Random Cost generation !!! //base_cost = cost; base_cost = chip_logic.base_cost; cost = chip_logic.cost; cost_icon.transform.GetChild(0).GetComponent <Text>().text = "" + cost; //color_code = Random.Range(0, 12); color_code = chip_logic.color_code; cost_icon.GetComponent <Image>().color = ChipData.color_codes[color_code]; // set power and element //elem = Random.Range(0, 9); // !!! Placeholder: Random Elem generation !!! elem = chip_logic.elem; elem_icon.GetComponent <Image>().sprite = ChipData.elems[elem]; power = chip_logic.power; // !!! Placeholder: Power Ratio to Cost !!! power_text.text = "" + power; }
public override void OnSyncedUpdate(Navi navi, ChipLogic c) { c.frametimer -= Time.deltaTime; if (c.frametimer <= 0) { c.frametimer = c.chipFR; if (c.chip_anim_frame < c.chip_sprite.Length - 1) // advance to next frame if not at end { c.chip_anim_frame++; c.chip_renderObj.GetComponent <SpriteRenderer>().sprite = c.chip_sprite[c.chip_anim_frame]; if (c.chip_anim_frame > 0) // cannon animation has 1 frame more than shoot at the front { navi.controlledSpriteSet(c.chip_anim_frame - 1); } if (c.chip_anim_frame == 2) { navi.shot_handler.check_bust(c.power, navi.playerNumber, c.stun, c.elem); // shot fired on 3rd frame } } else // animation finished { c.deactivate(navi); } } }
public override void deactivate(Navi navi, ChipLogic c) { navi.rate_controlled = false; // Navi controls its own animation again navi.swordAnim = false; UnityEngine.Object.Destroy(slash_renderer); // removes the slash effect base.deactivate(navi, c); }
public override void OnSyncedUpdate(Navi navi, ChipLogic c) { if (recov_amount > 3) // HP text number increase effect (going by 3s reduces strain) { recov_amount -= 3; navi.HP += 3; } else if (recov_amount > 0) // for non divisible by 3 { navi.HP += recov_amount; recov_amount = 0; } c.frametimer -= Time.deltaTime; if (c.frametimer <= 0) { c.frametimer = c.chipFR; if (c.chip_anim_frame < c.chip_sprite.Length - 1) // advance to next frame if not at end { c.chip_anim_frame++; c.chip_renderObj.GetComponent <SpriteRenderer>().sprite = c.chip_sprite[c.chip_anim_frame]; } else // animation finished { if (recov_amount > 0) // add any remaining chip.power to HP if animation was too short for HOT effect { navi.HP += recov_amount; recov_amount = 0; } c.deactivate(navi); } } }
public override void initAnim(Navi navi, ChipLogic c) { c.chip_sprite = effectAnim; c.chip_anim_frame = 0; c.frametimer = c.chipFR; current_row = navi.row; target_column = (navi.myNavi()) ? navi.column + 3 : navi.column - 3; // moves right if my navi, moves left if opponents target_column = (target_column < 0) ? 0 : target_column; target_column = (target_column > 5) ? 5 : target_column; target_top = navi.field.grid[0][target_column].gameObject.transform; target_bottom = navi.field.grid[2][target_column].gameObject.transform; //create the render object and set its position forward 3 rows c.chip_renderObj = new GameObject(); c.chip_renderObj.transform.position = navi.field.grid[current_row][target_column].gameObject.transform.position; c.chip_renderObj.AddComponent <SpriteRenderer>(); c.chip_renderObj.GetComponent <SpriteRenderer>().sortingOrder = 3; //!!!!!! NEED TO FIND SOME WAY OF ORGANIZING THESE SORTING LAYERS!!!!!! c.chip_renderObj.GetComponent <SpriteRenderer>().sprite = c.chip_sprite[c.chip_anim_frame]; // initialize values move_up = false; loop_up = true; move_speed = 1.5f; // MOVE SPEED HARD CODED duration = c.power / 2.0f; // Duration hard coded based on chip power hit_row = false; }
} // empty constructor (surround pulls all animations from Tower public override void initAnim(Navi navi, ChipLogic c) { // grab effect sprite from Towers EffectDB.TOWER.initAnim(navi, c); // initAnim() stores sprite in c.chip_sprite c.chip_anim_frame = 0; // create renderer objects in all tiles surrounding navi int col = 1; while (col >= -1) // spawn in columns above, in, and below { if ((navi.column + col <= 5) && (navi.column + col >= 0)) // do not try to spawn off board { int r = 1; while (r >= -1) // spawn in rows ahead, in, and behind (for all good columns) { if ((navi.row + r <= 2) && (navi.row + r >= 0)) // do not try to spawn off board { if ((col != 0) || (r != 0)) // do not spawn on navi { GameObject attack_render = new GameObject(); attack_render.transform.position = navi.field.grid[navi.row + r][navi.column + col].transform.position; attack_render.AddComponent <SpriteRenderer>(); attack_render.GetComponent <SpriteRenderer>().sprite = c.chip_sprite[c.chip_anim_frame]; attack_render.GetComponent <SpriteRenderer>().sortingOrder = 1; SurroundTile st = new SurroundTile(navi.row + r, navi.column + col, false, attack_render); affectedArea.Add(st); } } r--; // row completed or failed } } col--; // column completed or failed } }
//public void OnSyncedUpdate() { // called by the active Chip_Logic script // duration_ring.fillAmount = duration; //} public void RecieveData(ChipLogic chip) { active_chip = chip; chip_name.text = chip.chipName; elem_icon.sprite = ChipData.elems[chip.elem]; chip_image.sprite = chip.chipimg; }
public virtual void deactivate(Navi navi, ChipLogic c) { if (c.chip_renderObj != null) { UnityEngine.Object.Destroy(c.chip_renderObj); // removes the chip's sprite } navi.running_chips.Remove(c); // removes self from running chips list to no longer be called on synced update }
public override void initAnim(Navi navi, ChipLogic c) { List <Sprite> subarray = new List <Sprite>(); int start; // index of first frame in sheet switch (c.sword_size) { case 1: // sword (1x1) start = 4; break; case 2: // longsword (1x2) start = 0; break; case -1: // widesword (3x1) start = 8; break; default: // unlisted sword size: NOT A SWORD start = 0; break; } int i = 0; while (i < 4) // animation is 4 frames long { subarray.Add(effectAnim[start + i]); i++; } slash_eff = subarray.ToArray(); // load only corresponding cannon frames // prepare renderer for slash effect then deactivate until time to render slash_renderer = new GameObject(); slash_renderer.AddComponent <SpriteRenderer>(); slash_frame = 0; slash_renderer.GetComponent <SpriteRenderer>().sprite = slash_eff[slash_frame]; slash_renderer.GetComponent <SpriteRenderer>().sortingOrder = 6; //top layer, hit effect shows above auras if (!navi.myNavi()) // flip slash effect horizontally when created by opponent { slash_renderer.GetComponent <SpriteRenderer>().flipX = true; } slash_renderer.SetActive(false); hit = true; // reset hit check boolean to true until active frame of attack // take control of navi sword animation to sync animations c.chip_anim_frame = 0; c.frametimer = 2 * c.chipFR; // first frame is longer navi.rate_controlled = true; navi.swordAnim = true; navi.controlledSpriteSet(0); //sound navi.GetComponent <AudioSource>().PlayOneShot(Resources.Load <AudioClip>("Audio/s_sword")); c.interrupt = true; //sword attacks can be interrupted at any time }
public override void deactivate(Navi navi, ChipLogic c) { int i = 0; while (i < affectedArea.Count) // clean up render objects { UnityEngine.Object.Destroy(affectedArea[i].renderer); i++; } affectedArea.Clear(); // clear list base.deactivate(navi, c); }
public override void initAnim(Navi navi, ChipLogic c) { c.chip_sprite = effectAnim; c.chip_renderObj.transform.position += navi.body_offset; // offset sprite up to match navi c.chip_anim_frame = 0; c.chip_renderObj.GetComponent <SpriteRenderer>().sprite = c.chip_sprite[c.chip_anim_frame]; c.chip_renderObj.GetComponent <SpriteRenderer>().sortingOrder = 4; // sorted just below barrier effects c.chip_renderObj.GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 0.9f); c.frametimer = c.chipFR; recov_amount = c.power; //audio navi.GetComponent <AudioSource>().PlayOneShot(Resources.Load <AudioClip>("Audio/Recover HQ")); }
public override void initAnim(Navi navi, ChipLogic c) { c.chip_sprite = new Sprite[] { effectAnim[effectAnim.Length - 1] }; //Wrecker is currently only throw object being used and is last index c.chip_anim_frame = 0; c.frametimer = c.chipFR; navi.throwAnim = true; navi.rate_controlled = true; navi.controlledSpriteSet(c.chip_anim_frame); c.chip_renderObj.transform.position = navi.transform.position + (navi.throw_offset[c.chip_anim_frame] * navi.transform.localScale.x); this.row = navi.row; this.col = navi.column; c.interrupt = true; // thrown attacks can be interrupted up until the point when the object is actually thrown }
public override void OnSyncedUpdate(Navi navi, ChipLogic c) { c.frametimer -= Time.deltaTime; if (!hit) // try hit { hit = navi.shot_handler.check_sword(c.power, navi.playerNumber, c.stun , System.Math.Abs(c.sword_size), (c.sword_size < 0), c.elem); } if (c.frametimer <= 0) { c.frametimer = c.chipFR; if (c.chip_anim_frame < navi.swordSprite.Length - 1) // advance to next frame if not at end { c.chip_anim_frame++; if (c.chip_renderObj != null) // chip has a sword overlay to display { c.chip_renderObj.GetComponent <SpriteRenderer>().sprite = c.chip_sprite[c.chip_anim_frame]; } navi.controlledSpriteSet(c.chip_anim_frame); // sword effects and sword anim have same number of frames if (slash_renderer.activeInHierarchy) // animate slash effect when active { if (slash_frame < slash_eff.Length - 1) { slash_frame++; slash_renderer.GetComponent <SpriteRenderer>().sprite = slash_eff[slash_frame]; } else { slash_renderer.SetActive(false); // deactivate when animation finishes } } if (c.chip_anim_frame == 2) // attack takes place on 3rd frame { hit = false; // flag hit as false to start checking for hits // place slash effect 1 space in front of navi int target_space = (navi.myNavi()) ? navi.field_space + 1 : navi.field_space - 1; slash_renderer.transform.position = navi.field.spaces[target_space].transform.position; slash_renderer.SetActive(true); } } else // animation finished { c.deactivate(navi); } } }
public override void initAnim(Navi navi, ChipLogic c) { List <Sprite> subarray = new List <Sprite>(); int start; // index of first frame in sheet switch (c.ID) { case 2: // HiCannon start = 6; break; case 3: // MCannon start = 12; break; default: // Cannon or ID not listed, so default to Cannon start = 0; break; } int i = 0; while (i < 6) // animation is 6 frames long { subarray.Add(effectAnim[start + i]); i++; } c.chip_sprite = subarray.ToArray(); // load only corresponding cannon frames c.chip_renderObj.transform.position += navi.buster_offset; // offset sprite to match navi c.chip_anim_frame = 0; c.chip_renderObj.GetComponent <SpriteRenderer>().sprite = c.chip_sprite[c.chip_anim_frame]; c.chip_renderObj.GetComponent <SpriteRenderer>().sortingOrder = 2; //sorted just above navi c.frametimer = c.chipFR; // take control of navi shoot animation to sync animations navi.rate_controlled = true; navi.shootAnim = true; navi.controlledSpriteSet(0); //audio navi.GetComponent <AudioSource>().PlayOneShot(Resources.Load <AudioClip>("Audio/Cannon HQ")); // audio clip needs silenced trimmed from start c.interrupt = true; // cannons can be interrupted at any time }
public override void OnSyncedUpdate(Navi navi, ChipLogic c) { c.frametimer -= TrueSyncManager.DeltaTime.AsFloat(); if (c.frametimer <= 0) // advance frame //TODO: may need 2 frame variables for animated throw objs { c.chip_anim_frame++; c.frametimer = c.chipFR; if (c.chip_anim_frame < navi.throw_offset.Length) // throw obj still following throw anim { c.chip_renderObj.transform.position = navi.transform.position + (navi.throw_offset[c.chip_anim_frame] * navi.transform.localScale.x); } if (c.chip_anim_frame < navi.throwSprite.Length) { navi.controlledSpriteSet(c.chip_anim_frame); } else // throw animation finished { navi.throwAnim = false; navi.rate_controlled = false; } } if (c.chip_anim_frame >= navi.throw_offset.Length) // trajectory calculation { c.interrupt = false; // object has left the hand, can no longer be interrupted c.chip_renderObj.transform.SetParent(navi.field.grid[row][col].transform); //!!! WARNING BAD MATH AHEAD !!! float x = c.chip_renderObj.transform.position.x; x += (5.7f * TrueSyncManager.DeltaTime.AsFloat()) * ((navi.myNavi())?2:-2); //float x = (-0.18f + (5.5f * TrueSyncManager.DeltaTime.AsFloat())); float y = c.chip_renderObj.transform.position.y; y += (4.6f * TrueSyncManager.DeltaTime.AsFloat()) - 0.027f * Math.Abs(navi.field.grid[0][col].transform.position.x - c.chip_renderObj.transform.position.x); //c.chip_renderObj.transform.position = new Vector3(x, ((-0.112f * (x * x)) + (0.399f * x) + (navi.field.grid[navi.row][0].transform.position.y))); c.chip_renderObj.transform.position = new Vector3(x, y); if ((Math.Abs(c.chip_renderObj.transform.position.x - c.chip_renderObj.transform.parent.position.x)) >= 12) { c.deactivate(navi); } } }
public void set_info(ChipLogic chip_logic) { info_comp.SetActive(true); this.chip_ID = chip_logic.ID; //set name and image chip_name.text = chip_logic.chipName; chip_text.text = chip_logic.chipText; chip_image.sprite = chip_logic.chipimg; // set cost and color code base_cost = chip_logic.base_cost; cost_icon.transform.GetChild(0).GetComponent <Text>().text = "" + base_cost; this.color_code = chip_logic.color_code; cost_icon.GetComponent <Image>().color = ChipData.color_codes[chip_logic.color_code]; // set power and element elem = chip_logic.elem; elem_icon.GetComponent <Image>().sprite = ChipData.elems[elem]; power = chip_logic.power; power_text.text = "" + power; }
public bool nextTower(Navi navi, ChipLogic c, int row, int col) { if (navi.field.grid[row][col].state < 0) // towers cannot appear on broken tiles { return(false); } GameObject tower = new GameObject(); tower.transform.position = navi.field.grid[row][col].transform.position; // position new tower on target tile //tower.transform.localScale = new Vector3(10.0f, 10.0f, 1.0f); tower.AddComponent <SpriteRenderer>(); tower.GetComponent <SpriteRenderer>().sprite = c.chip_sprite[0]; tower.GetComponent <SpriteRenderer>().sortingOrder = 1; // low sorting order !!!!! finalize later tower_renderers.Add(tower); tower_data.Add(new Tower(row, col, 0, false)); // next tower will appear above/below/in line with this tower based on opponent's position if (row > navi.shot_handler.opponent_ref(navi).row) { next_row = row - 1; } else if (row < navi.shot_handler.opponent_ref(navi).row) { next_row = row + 1; } else { next_row = row; } next_col = (navi.myNavi()) ? col + 1 : col - 1; // moves right if my navi, moves left if opponents // audio currently only available for thunder if (c.elem == ChipData.ELEC) { //navi.GetComponent<AudioSource>().PlayOneShot(Resources.Load<AudioClip>("Audio/Thunder HQ")); } return(true); // tower could be made }
public void RecieveData(DeckSlot d) { //ChipDatabase chipDataBase = GameObject.Find("Chip Database").GetComponent<ChipDatabase>(); //chip_logic = chipDataBase.chipDB[d.cardID]; chip_logic = ChipDatabase.chipDB[d.cardID]; chip_logic.initColor(d.color_code); Debug.Log(chip_logic.chipName); //set name and image chip_name.text = chip_logic.chipName; chip_image.sprite = chip_logic.chipimg; // set cost and color code base_cost = chip_logic.base_cost; cost = chip_logic.cost; cost_icon.transform.GetChild(0).GetComponent <Text>().text = "" + cost; color_code = chip_logic.color_code; cost_icon.GetComponent <Image>().color = ChipData.color_codes[color_code]; // set power and element elem = chip_logic.elem; elem_icon.GetComponent <Image>().sprite = ChipData.elems[elem]; power = chip_logic.power; power_text.text = "" + power; }
public abstract void initAnim(Navi navi, ChipLogic c);
public override void OnSyncedUpdate(Navi navi, ChipLogic c) { c.frametimer -= TrueSyncManager.DeltaTime.AsFloat(); if (duration > 0) { if (c.chip_anim_frame >= hit_frame) // attack is active so check for hit and update duration { if (!hit_row) { navi.field.grid[current_row][target_column].indanger = true; hit_row = (navi.shot_handler.check_position( c.power, navi.playerNumber, c.stun, current_row, target_column, c.elem)); } duration -= TrueSyncManager.DeltaTime; } if (c.frametimer <= 0) { c.frametimer = c.chipFR; if (c.chip_anim_frame < c.chip_sprite.Length - 1) // advance to next frame if not at end { if (loop_up) { c.chip_anim_frame++; } else { c.chip_anim_frame--; } c.chip_renderObj.GetComponent <SpriteRenderer>().sprite = c.chip_sprite[c.chip_anim_frame]; if (c.chip_anim_frame <= loop_frame) { loop_up = true; } } else // reverse looped section of sprite { c.chip_anim_frame--; loop_up = false; c.chip_renderObj.GetComponent <SpriteRenderer>().sprite = c.chip_sprite[c.chip_anim_frame]; } } if (c.chip_anim_frame >= hit_frame) // Sprite moves while attack active { if (move_up) { c.chip_renderObj.transform.position = Vector3.MoveTowards(c.chip_renderObj.transform.position, target_top.position, move_speed * TrueSyncManager.DeltaTime.AsFloat()); } else { c.chip_renderObj.transform.position = Vector3.MoveTowards(c.chip_renderObj.transform.position, target_bottom.position, move_speed * TrueSyncManager.DeltaTime.AsFloat()); } if (c.chip_renderObj.transform.position == target_top.position) { move_up = false; } else if (c.chip_renderObj.transform.position == target_bottom.position) { move_up = true; } float to_bottom = Vector3.Distance(target_bottom.position, c.chip_renderObj.transform.position); float to_top = Vector3.Distance(target_top.position, c.chip_renderObj.transform.position); // determine row being hit int oldrow = current_row; if (to_top > 3 * to_bottom) { current_row = 2; } else if (to_bottom > 3 * to_top) { current_row = 0; } else { current_row = 1; } if (oldrow != current_row) // row changed so check for new hit { hit_row = false; navi.field.grid[oldrow][target_column].indanger = false; } } } else // attack of chip finished { navi.field.grid[current_row][target_column].indanger = false; if (c.frametimer <= 0) { c.frametimer = c.chipFR; if (c.chip_anim_frame > 0) // rewind anim to begining { c.chip_anim_frame--; c.chip_renderObj.GetComponent <SpriteRenderer>().sprite = c.chip_sprite[c.chip_anim_frame]; } else // animation has finished { c.deactivate(navi); } } } }
public override void initAnim(Navi navi, ChipLogic c) { List <Sprite> subarray = new List <Sprite>(); int start = 0; // index of first frame in sheet int frames = 0; // number of frames in animation switch (c.elem) { case ChipData.FIRE: start = 0; frames = 6; trigger_frame = 4; hit_frame = 3; break; case ChipData.WATER: start = 7; frames = 9; trigger_frame = 7; hit_frame = 3; break; case ChipData.WOOD: start = 17; frames = 4; trigger_frame = 3; hit_frame = 1; break; case ChipData.ELEC: start = 22; frames = 5; trigger_frame = 4; hit_frame = 1; break; default: // chips element does not match any defined tower type start = 0; frames = 0; break; } int i = 0; while (i < frames) { subarray.Add(effectAnim[start + i]); i++; } int b = 0; if (c.elem == ChipData.FIRE) { // flicker once for fire subarray.Add(effectAnim[start + i - 1]); subarray.Add(effectAnim[start + i - 2]); subarray.Add(effectAnim[start + i - 1]); subarray.Add(effectAnim[start + i]); // flicker twice subarray.Add(effectAnim[start + i - 1]); subarray.Add(effectAnim[start + i - 2]); subarray.Add(effectAnim[start + i - 1]); subarray.Add(effectAnim[start + i]); } if (c.elem != ChipData.ELEC) // elec tower does not reverse animation { while (b < frames) { subarray.Add(effectAnim[start + i - b]); b++; } } c.chip_sprite = subarray.ToArray(); // load only corresponding tower frames c.chip_anim_frame = 0; c.frametimer = c.chipFR; }
public override void OnSyncedUpdate(Navi navi, ChipLogic c) { if (tower_renderers.Count == 0) // first update: add first tower { int target_column = (navi.myNavi()) ? navi.column + 1 : navi.column - 1; // moves right if my navi, moves left if opponents nextTower(navi, c, navi.row, target_column); // generate first tower in navi's row } List <int> trim = new List <int>(); // flag towers in list for destroying bool add_tower = false; // set to true when a tower hits its trigger frame and needs to create a new tower c.frametimer -= Time.deltaTime; for (int i = 0; i < tower_renderers.Count; i++) // iterate through all towers on field { Tower tower = tower_data[i]; if (!tower.hit) // no hit from tower yet, so check for hit // tests for hit and set to true if there is one so it won't check again { tower.hit = (navi.shot_handler.check_position(c.power, navi.playerNumber, c.stun, tower.row, tower.col, c.elem)); } if (c.frametimer <= 0) { if (tower.frame < c.chip_sprite.Length - 1) // advance to next frame if not at end { tower.frame++; tower_renderers[i].GetComponent <SpriteRenderer>().sprite = c.chip_sprite[tower.frame]; // next tower to be made if (tower.frame == trigger_frame) { add_tower = true; } } else // reached end of animation { trim.Add(i); // adjust later for reverse animations } } } // done iterating through towers if (c.frametimer <= 0) // frame timer needs to be reset after all towers have been iterated through to allow simultaneous animation { c.frametimer = c.chipFR; } // destroy finished towers and remove from lists foreach (int t in trim) { UnityEngine.Object.Destroy(tower_renderers[t]); tower_renderers.RemoveAt(t); tower_data.RemoveAt(t); } if (add_tower) // trigger frame hit while iterating, so a new tower must be made { if ((next_col >= 0) && (next_col <= 5)) // tower hasn't reached field's edge { nextTower(navi, c, next_row, next_col); } } if (tower_renderers.Count == 0) // all towers are finished { c.deactivate(navi); } }
public abstract void OnSyncedUpdate(Navi navi, ChipLogic c);
public override void deactivate(Navi navi, ChipLogic c) { navi.rate_controlled = false; // Navi controls its own animation again navi.shootAnim = false; base.deactivate(navi, c); }