public void shootViewProjectile(byte[] ProjectileBytes) { try { ProjectileData projData = ProjectileData.deserialize(ProjectileBytes); projData.startTime = getTime(); if (projData.hitTime < projData.startTime + 100) // Min take 100ms to hit. { projData.hitTime = projData.startTime + 100; } projData.isView = true; PlayerGameState oppGameState = getOpponentGameState(); Monster target = oppGameState.monsterRef[projData.targetSerializeId]; Vector2 source = oppGameState.viewMapRef.getTile(projData.startCoord.row, projData.startCoord.col).transform.position; Projectile proj = projectilePool.GetProjectile(); proj.projData = projData; proj.target = target; proj.source = source; proj.spriteR.sprite = TowerR.getById(projData.towerId).projectileSprite; proj.splashR.color = TowerR.getById(projData.towerId).splashColor; if (oppGameState.sendMapData) { SoundManager.instance.PlayShoot(TowerR.getById(projData.towerId).shootingSound); } proj.Initialize(); } catch (KeyNotFoundException e) { Debug.LogWarning(e.StackTrace); } }
public void shootProjectile(ProjectileData projData) { try { PlayerGameState ownGameState = getOwnGameState(); Monster target = ownGameState.monsterRef[projData.targetSerializeId]; Vector2 source = ownGameState.viewMapRef.getTile(projData.startCoord.row, projData.startCoord.col).transform.position; Projectile proj = projectilePool.GetProjectile(); proj.projData = projData; proj.target = target; proj.source = source; proj.spriteR.sprite = TowerR.getById(projData.towerId).projectileSprite; proj.splashR.color = TowerR.getById(projData.towerId).splashColor; if (!getOpponentGameState().sendMapData) { SoundManager.instance.PlayShoot(TowerR.getById(projData.towerId).shootingSound); } proj.Initialize(); if (getOwnGameState().sendMapData&& PhotonNetwork.connected) { photonView.RPC("shootViewProjectile", PhotonTargets.Others, projData.serialize()); } } catch (KeyNotFoundException e) { Debug.LogWarning(e.StackTrace); } }
public void increaseGold(int amount) { gold += amount; int extra = 0; for (int i = 0; i < map.numRows; ++i) { for (int j = 0; j < map.numCols; ++j) { if (map.getTileData(i, j).towerType / 10 == 9) // integer division truncates. id 90+ is the gold towers. { extra += TowerR.getById(map.getTileData(i, j).towerType).damage; } } } gold += extra; }
// Upgrade towers public void UpgradeTower() { if (selectedTile.tower.upgradeCost > GameState.gold || selectedTile.tower.upgradeCost <= 0) { return; } GameState.gold -= selectedTile.tower.upgradeCost; int currentTowerID = selectedTile.tower.towerId; int upgradedTowerID = currentTowerID + 1; Tower upgradedTower = TowerR.getById(upgradedTowerID); Tower tower = Instantiate(upgradedTower); selectedTile.setTower(tower); // Refresh display. DisplayUpgradePanel(tower); DisplayTowerInfo(tower); }
// Use this for initialization void Start() { PlayMap playMap = Object.FindObjectOfType <PlayMap>(); Transform grid = transform.GetChild(0); foreach (Tower towerPrefab in TowerR.getBaseTowers()) { GameObject towerbtn = Instantiate(TowerButton); towerbtn.name = towerPrefab.name + " button"; towerbtn.transform.SetParent(grid, false); towerbtn.transform.localScale = new Vector3(1, 1, 1); towerbtn.GetComponent <Image>().sprite = towerPrefab.GetComponent <SpriteRenderer>().sprite; towerbtn.GetComponent <Image>().color = towerPrefab.GetComponent <SpriteRenderer>().color; towerbtn.GetComponent <Button>().onClick.AddListener(delegate { playMap.onTowerBtnClick(towerPrefab); }); towerbtn.transform.GetChild(0).GetComponent <Text>().text = "$" + towerPrefab.price; } }
public void refreshMap() { for (int i = 0; i < numRows; ++i) { for (int j = 0; j < numCols; ++j) { int updated_towerid = grid[i, j].tileData.towerType; int current_towerid = (grid[i, j].tower == null ? 0 : grid[i, j].tower.towerId); if (updated_towerid == 0 && current_towerid != 0) // Tower got removed. { grid[i, j].removeTower(); } else if (updated_towerid != current_towerid) // Tower changed. { Tower tower = Instantiate(TowerR.getById(grid[i, j].tileData.towerType)); tower.enabled = false; grid[i, j].setTower(tower); } ; } } }