// Use this for initialization void Start() { for (int row = 0; row < 5; row++) { managedGrid.Add(new List <GridInfo>()); for (int col = 0; col < 6; col++) { GameObject go = (GameObject)Instantiate(gridCollider, new Vector3(col * 0.86f, -row * 0.86f, 0) + gridOffset, Quaternion.Euler(0, 0, 45f)); go.transform.localScale = new Vector3(0.6f, 0.6f); go.transform.parent = this.transform; GridInfo gi = new GridInfo(); gi.gridObject = null; gi.collider = go; gi.marked = false; managedGrid[row].Add(gi); } } for (int i = 0; i < PlayerMonster.Count && i < 3; i++) { GameObject go = PlayerMonster.Spawn(i, new Vector3(i * 1.5f - (6 / 3) / 2 - 0.5f, 1.95f)); go.transform.localScale = new Vector3(0.3f, 0.3f); playerHealth += go.GetComponent <Monster>().MaxHealth; activeMonster.Add(go); } playerMaxHealth = playerHealth; }
public static void Load() { if (!File.Exists(savePath)) { return; } string line; StreamReader file = new StreamReader(savePath); while ((line = file.ReadLine()) != null) { string[] exp = line.Split(';'); if (exp[0] == "gold") { PlayerCoin.Set(int.Parse(exp[1])); } else if (exp[0] == "monster") { PlayerMonster.Add(exp[1], int.Parse(exp[2])); } else if (exp[0] == "item") { PlayerItems.Add(exp[1], int.Parse(exp[2])); } else if (exp[0] == "field") { if (exp[2] == "0") { PlayerField.Add(int.Parse(exp[1]), FieldStatus.FIELD_FAILED); } else if (exp[2] == "1") { PlayerField.Add(int.Parse(exp[1]), FieldStatus.FIELD_1STAR); } else if (exp[2] == "2") { PlayerField.Add(int.Parse(exp[1]), FieldStatus.FIELD_2STAR); } else if (exp[2] == "3") { PlayerField.Add(int.Parse(exp[1]), FieldStatus.FIELD_3STAR); } else { PlayerField.Add(int.Parse(exp[1]), FieldStatus.FIELD_EMPTY); } } PlayerMonster.Load(); } file.Close(); }
void Start() { PlayerSave.Auto(); if (monsterTemplate.Count > 0 && !PlayerMonster.IsLoaded) { PlayerMonster.Load(); PlayerMonster.Add(monsterTemplate[0].name, 0); PlayerMonster.Add(monsterTemplate[1].name, 0); PlayerMonster.Add(monsterTemplate[2].name, 0); } }
private bool Buy(string name, int cost) { if (PlayerCoin.Get() > cost) { Debug.Log("Player buy: " + name + " at cost " + cost); PlayerMonster.Add(name, 0); PlayerCoin.Spend(cost); return(true); } return(false); }
public async Task <List <PlayerMonster> > GetList(Player player) { var playerCatches = await _monsterContext.PlayerCatch.Where(x => x.PlayerId == player.PlayerId).ToListAsync(); var playerMonsters = new List <PlayerMonster>(); foreach (var playerCatch in playerCatches) { PlayerMonster pm = new PlayerMonster(); pm.playerCatch = playerCatch; pm.monster = await _monsterContext.Monster.FirstOrDefaultAsync(x => x.MonsterId == playerCatch.MonsterId); playerMonsters.Add(pm); } return(playerMonsters.OrderBy(x => x.monster.Name).ThenBy(x => x.playerCatch.Level).ToList()); }
public static void Save() { StreamWriter file = new StreamWriter(savePath); file.WriteLine("gold;" + PlayerCoin.Get()); for (int i = 0; i < PlayerMonster.Count; i++) { file.WriteLine("monster;" + PlayerMonster.Get(i).monsterName + ";" + PlayerMonster.Get(i).exp); } foreach (KeyValuePair <string, int> pair in PlayerItems.Items) { file.WriteLine("item;" + pair.Key + ";" + pair.Value); } for (int i = 0; PlayerField.Has(i); i++) { switch (PlayerField.Get(i)) { case FieldStatus.FIELD_EMPTY: file.WriteLine("field;" + i.ToString() + ";-1"); break; case FieldStatus.FIELD_FAILED: file.WriteLine("field;" + i.ToString() + ";0"); break; case FieldStatus.FIELD_1STAR: file.WriteLine("field;" + i.ToString() + ";1"); break; case FieldStatus.FIELD_2STAR: file.WriteLine("field;" + i.ToString() + ";2"); break; case FieldStatus.FIELD_3STAR: file.WriteLine("field;" + i.ToString() + ";3"); break; } } file.Close(); }
// Update is called once per frame void Update() { if (Input.GetMouseButtonUp(0)) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); bool found = false; if (hit.transform != null) { if (hit.transform.gameObject == prevButton) { Previous(); } else if (hit.transform.gameObject == nextButton) { Next(); } else { for (int i = 1; i < colliderList.Count; i++) { if (hit.transform.gameObject == colliderList[i].gameObject) { found = true; PlayerMonster.Swap(i - 1, i); break; } } } } if (found) { RefreshDisplay(); } } }
public void RefreshDisplay() { int oldPage = currentPage; currentPage = 0; for (int i = 0; i < this.transform.childCount; i++) { Destroy(this.transform.GetChild(i).gameObject); } petList.Clear(); colliderList.Clear(); Vector3 offset = new Vector3(-1.38f, 0.77f); maxPage = Mathf.CeilToInt(PlayerMonster.Count / 3.0f); for (int i = 0; i < PlayerMonster.Count; i++) { int page = i / 3; offset = new Vector3(-1.38f + (page * 6), 0.77f); GameObject go = PlayerMonster.Spawn(i, new Vector3(0, -i % 3 * 2.20f, 0) + offset); go.GetComponent <SpriteRenderer>().sortingOrder = 1; go.name = Reference.Asset.monsterTemplate[i].name; go.transform.localScale = new Vector3(0.3f, 0.3f); go.transform.parent = this.transform; GameObject collider = (GameObject)Instantiate(listCollider, new Vector3(page * 6, go.transform.position.y), Quaternion.identity); collider.transform.parent = this.transform; colliderList.Add(collider); if (i < 3) { GameObject usedText = new GameObject("usedText"); usedText.AddComponent <SpriteRenderer>(); usedText.GetComponent <SpriteRenderer>().sprite = usedTemplate; usedText.GetComponent <SpriteRenderer>().sortingOrder = 2; usedText.transform.position = new Vector3(-1, 1 + (-i % 3 * 2.20f), 0) + offset; usedText.transform.parent = this.transform; } Vector3 textOffset = new Vector3(1.25f, 0.55f, 0); GameObject text = (GameObject)Instantiate(Reference.Asset.textUtility, new Vector3(0, -i % 3 * 2.20f, -1) + offset + textOffset, Quaternion.identity); text.GetComponent <TextMesh>().text = go.name + " Lv." + go.GetComponent <Monster>().Level; text.GetComponent <TextMesh>().color = new Color(0, 0, 0); text.transform.parent = this.transform; textOffset = new Vector3(1.3f, 0f, 0); ShowText(healthTemplate, go.GetComponent <Monster>().MaxHealth + " (+" + go.GetComponent <Monster>().MaxHealthInc + ")", new Vector3(0, -i % 3 * 2.20f, 0) + offset + textOffset); textOffset = new Vector3(1.3f, -0.55f, 0); ShowText(damageTemplate, go.GetComponent <Monster>().Damage + " (+" + go.GetComponent <Monster>().DamageInc + ")", new Vector3(0, -i % 3 * 2.20f, 0) + offset + textOffset); textOffset = new Vector3(2.58f, -0.7f, 0); ShowText(goldButton, (go.GetComponent <Monster>().Level *go.GetComponent <Monster>().Cost / 10).ToString(), new Vector3(0, -i % 3 * 2.20f, 0) + offset + textOffset); textOffset = new Vector3(3.6f, -0.7f, 0); ShowText(sellButton, "", new Vector3(0, -i % 3 * 2.20f, 0) + offset + textOffset); petList.Add(go); } for (int i = 0; i < oldPage; i++) { Next(); } RefreshButtonPrevNext(); }
private void ShowGameEnd() { if (!messageBox.activeSelf) { int bonusMin = (PlayerMonster.IndexEnemy + 1) * 9; int bonusMax = (PlayerMonster.IndexEnemy + 1) * 12; if (playerHealth <= 0) { bonusMin = (PlayerMonster.IndexEnemy + 1) * 1; bonusMax = (PlayerMonster.IndexEnemy + 1) * 3; } int goldBonus = Random.Range(bonusMin, bonusMax); PlayerCoin.Add(goldBonus); GameObject gold = messageBox.transform.FindChild("GoldDisplay").gameObject; gold.GetComponent <TextMesh>().text = "+" + goldBonus; // Apply database foreach (GameObject go in activeMonster) { PlayerMonster.Get(go.GetComponent <Monster>().StorageIndex).exp = go.GetComponent <Monster>().Exp; } List <GameObject> dropItem = new List <GameObject>(); foreach (GameObject item in Reference.Asset.itemTemplate) { int rand = Random.Range(0, 100); if (rand <= item.GetComponent <Item>().DropWeight) { PlayerItems.Add(item.name, 1); dropItem.Add(item); } } int count = 0; foreach (GameObject go in dropItem) { GameObject item = (GameObject)Instantiate(go, new Vector3(count, 0, 0), Quaternion.identity); item.GetComponent <SpriteRenderer>().sortingOrder = 2; count++; } switch (defeatedEnemy) { case 0: if (PlayerField.Get(PlayerMonster.IndexEnemy) != FieldStatus.FIELD_3STAR && PlayerField.Get(PlayerMonster.IndexEnemy) != FieldStatus.FIELD_2STAR && PlayerField.Get(PlayerMonster.IndexEnemy) != FieldStatus.FIELD_1STAR) { PlayerField.Add(PlayerMonster.IndexEnemy, FieldStatus.FIELD_FAILED); } break; case 1: if (PlayerField.Get(PlayerMonster.IndexEnemy) != FieldStatus.FIELD_3STAR && PlayerField.Get(PlayerMonster.IndexEnemy) != FieldStatus.FIELD_2STAR) { PlayerField.Add(PlayerMonster.IndexEnemy, FieldStatus.FIELD_1STAR); } break; case 2: if (PlayerField.Get(PlayerMonster.IndexEnemy) != FieldStatus.FIELD_3STAR) { PlayerField.Add(PlayerMonster.IndexEnemy, FieldStatus.FIELD_2STAR); } break; case 3: PlayerField.Add(PlayerMonster.IndexEnemy, FieldStatus.FIELD_3STAR); break; } messageBox.SetActive(true); } GameObject title = messageBox.transform.FindChild("TextHelper").gameObject; if (playerHealth > 0) { title.GetComponent <TextMesh>().text = "Victory"; title.GetComponent <TextMesh>().color = new Color(255, 226, 0); } else { title.GetComponent <TextMesh>().text = "Defeated"; title.GetComponent <TextMesh>().color = new Color(233, 0, 0); } }
void Awake() { spineAnimation = gameObject.FindChildByComponent<SkeletonAnimation> (); // spineAnimation = GetComponent<SkeletonAnimation> (); if ( spineAnimation == null ) { playerMonster = RandomMonster; RandomMonster = ( PlayerMonster ) ( ( (int)RandomMonster + 1 ) % 3 ); switch ( playerMonster ) { case PlayerMonster.Godzilla: spineAnimation = gameObject.InstantiateChild ( Game.Instance.prefabs.Godzilla ).GetComponent<SkeletonAnimation> (); break; case PlayerMonster.Poulpe: spineAnimation = gameObject.InstantiateChild ( Game.Instance.prefabs.Poulpe ).GetComponent<SkeletonAnimation> (); break; case PlayerMonster.Robot: spineAnimation = gameObject.InstantiateChild ( Game.Instance.prefabs.Robot ).GetComponent<SkeletonAnimation> (); break; } spineAnimation.gameObject.transform.localScale = Vector3.one; spineAnimation.gameObject.transform.localPosition = Vector3.zero; } }
internal void OnHit( int attackPower, PlayerMonster fromMonster ) { Audio.Instance.PlaySound ( HitSound ); SkeletonAnimation fx = GameObject.Instantiate ( Game.Instance.prefabs.HitFx ).GetComponent<SkeletonAnimation>(); switch ( fromMonster ) { case PlayerMonster.Godzilla: fx.AnimationName = "FX_ImpactAttack_Godzilla"; break; case PlayerMonster.Poulpe: fx.AnimationName = "FX_ImpactAttack_Poulpe"; break; case PlayerMonster.Robot: fx.AnimationName = "FX_ImpactAttack_Robot"; break; } if ( playerSide == PlayerSide.Right ) { Vector3 ls = fx.transform.localScale; ls.y = -ls.y; fx.transform.localScale = ls; } fx.transform.position = HitEndPosition; fx.transform .scaleTo ( 0.125f, 2.0f ) .eases ( GoEaseType.QuadInOut ); // .setOnCompleteHandler ( c => // { // fx.gameObject.DestroySelf (); // } ); fx.state.Complete += ( Spine.AnimationState state, int trackIndex, int loopCount ) => fx.gameObject.DestroySelf (); lifeBar.Life = Mathf.Max ( lifeBar.Life - ( attackPower * 0.05f ), 0 ); lifeBar.UpdateColor (); if ( lifeBar.Life == 0 ) { Go.killAllTweens (); switch ( opponent.playerMonster ) { case PlayerMonster.Godzilla: Application.LoadLevel ( "GodzillaWon" ); break; case PlayerMonster.Poulpe: Application.LoadLevel ( "PoulpeWon" ); break; case PlayerMonster.Robot: Application.LoadLevel ( "RobotWon" ); break; } } spineAnimation.state.Complete += HitAnimationComplete; spineAnimation.loop = false; spineAnimation.AnimationName = "HIT"; }