public void OnTriggerStay(Collider other) { if (other.tag == Tags.CRATE) { crateManager.RemoveCrate(other.gameObject); Destroy(other.gameObject); HealthScript health = null; if (gameObject.GetComponent <HealthScript>()) { health = gameObject.GetComponent <HealthScript>(); } else if (gameObject.GetComponentInParent <HealthScript>()) { health = gameObject.GetComponentInParent <HealthScript>(); } if (health != null) { health.ApplyRegeneration(regenTimePerCrate, regenAmtPerSec); } } else if (other.tag == Tags.POWERUP) { PowerupInfo info = other.gameObject.GetComponent <PowerupInfo>(); _powerupActivator.ActivatePowerup(info); Destroy(other.gameObject); } }
void Start() { info = GetComponent <PowerupInfo> (); ui = GetComponent <PowerupUI> (); getPowerup = GetComponent <GetPowerup> (); uiImage = ui.powerupUI.GetComponent <PowerupUIImage> (); quickdrawObj.SetActive(false); CheckForNextPowerup(); }
//Activate previous powerup after scene has changed, called by gamecontrol public void ActivatePowerup() { if (info == null) { info = GetComponent <PowerupInfo> (); } //If nobody got the powerup last time, don't run this if (GameControl.instance.powerupTargetNum == -1) { return; } info.Invoke(GameControl.instance.activePowerup.function, 0f); }
protected override Asset Read(BinaryReader reader) { Scheme scheme = new Scheme(); scheme.name = reader.ReadString(); scheme.brickDensity = reader.ReadInt32(); int width = reader.ReadInt32(); int height = reader.ReadInt32(); scheme.fieldData = new FieldData(width, height); FieldBlocks[] blocks = scheme.fieldData.GetDataArray(); for (int i = 0; i < blocks.Length; ++i) { blocks[i] = (FieldBlocks)reader.ReadInt32(); } int playersCount = reader.ReadInt32(); PlayerLocationInfo[] playerLocations = new PlayerLocationInfo[playersCount]; for (int i = 0; i < playerLocations.Length; ++i) { int x = reader.ReadInt32(); int y = reader.ReadInt32(); int team = reader.ReadInt32(); playerLocations[i] = new PlayerLocationInfo(i, x, y, team); } scheme.playerLocations = playerLocations; int powerupsCount = reader.ReadInt32(); PowerupInfo[] powerupInfo = new PowerupInfo[powerupsCount]; for (int i = 0; i < powerupInfo.Length; ++i) { powerupInfo[i].powerupIndex = reader.ReadInt32(); powerupInfo[i].bornWith = reader.ReadBoolean(); powerupInfo[i].hasOverride = reader.ReadBoolean(); powerupInfo[i].overrideValue = reader.ReadInt32(); powerupInfo[i].forbidden = reader.ReadBoolean(); } scheme.powerupInfo = powerupInfo; return(scheme); }
protected override Asset Read(BinaryReader reader) { Scheme scheme = new Scheme(); scheme.name = reader.ReadString(); scheme.brickDensity = reader.ReadInt32(); int width = reader.ReadInt32(); int height = reader.ReadInt32(); scheme.fieldData = new FieldData(width, height); FieldBlocks[] blocks = scheme.fieldData.GetDataArray(); for (int i = 0; i < blocks.Length; ++i) { blocks[i] = (FieldBlocks)reader.ReadInt32(); } int playersCount = reader.ReadInt32(); PlayerLocationInfo[] playerLocations = new PlayerLocationInfo[playersCount]; for (int i = 0; i < playerLocations.Length; ++i) { int x = reader.ReadInt32(); int y = reader.ReadInt32(); int team = reader.ReadInt32(); playerLocations[i] = new PlayerLocationInfo(i, x, y, team); } scheme.playerLocations = playerLocations; int powerupsCount = reader.ReadInt32(); PowerupInfo[] powerupInfo = new PowerupInfo[powerupsCount]; for (int i = 0; i < powerupInfo.Length; ++i) { powerupInfo[i].powerupIndex = reader.ReadInt32(); powerupInfo[i].bornWith = reader.ReadBoolean(); powerupInfo[i].hasOverride = reader.ReadBoolean(); powerupInfo[i].overrideValue = reader.ReadInt32(); powerupInfo[i].forbidden = reader.ReadBoolean(); } scheme.powerupInfo = powerupInfo; return scheme; }
public void ActivatePowerup(PowerupInfo powerupInfo) { _powerupTimer = powerupInfo.duration; _activePowerup = powerupInfo.powerupType; switch (_activePowerup) { case PowerupInfo.Type.FasterReload: for (int i = 0; i < _cannonballSpawners.Length; i++) { _cannonballSpawners[i].ChangeCooldown(powerupInfo.reloadTimeFactor); } _bombSpawner.ChangeCooldown(powerupInfo.reloadTimeFactor); break; case PowerupInfo.Type.DamageBoost: for (int i = 0; i < _cannonballSpawners.Length; i++) { _cannonballSpawners[i].ChangeDamage(powerupInfo.damageBoostFactor); } _bombSpawner.ChangeDamage(powerupInfo.reloadTimeFactor); break; case PowerupInfo.Type.MovementSpeedBoost: _shipMovement.ChangeMaxSpeed(powerupInfo.movementSpeedBoostFactor); break; case PowerupInfo.Type.TemporaryBonusHP: _healthScript.AddTempHP(powerupInfo.bonusHP); break; case PowerupInfo.Type.AutoHPRegen: _healthScript.ApplyRegeneration(powerupInfo.duration, powerupInfo.regenerationAmountPerSec); break; default: break; } }
void Update() { if (player.getGameOver()) { return; } float dt = Time.deltaTime; for (int i = 0; i < powerups.Count;) { PowerupInfo pi = powerups[i]; pi.timeSinceObtainment += Time.deltaTime; if (pi.timeSinceObtainment > pi.timeLimit) { powerdown(pi); } else { i++; } } timeSinceLastSpawn += dt; if (timeSinceLastSpawn > spawnTime) { timeSinceLastSpawn = 0; spawnBall(); } timeSinceLastPowerupSpawn += dt; if (timeSinceLastPowerupSpawn > powerupSpawnTime) { timeSinceLastPowerupSpawn = 0; if (Random.Range(0, 100) < 50) { spawnRandomPowerup(); } } }
private void SetupPowerups(PowerupInfo[] powerupInfo) { foreach (PowerupInfo info in powerupInfo) { if (info.bornWith) { List<Player> playerList = players.list; foreach (Player player in playerList) { player.TryAddPowerup(info.powerupIndex); } } } BrickCell[] brickCells = new BrickCell[GetWidth() * GetHeight()]; int count = GetBrickCells(brickCells); if (count == 0) { return; } ShuffleCells(brickCells, count); CVar[] POWERUPS_COUNT = CVars.powerupsCount; int brickIndex = 0; foreach (PowerupInfo info in powerupInfo) { if (info.forbidden || info.bornWith) { continue; } int powerupIndex = info.powerupIndex; int powerupCount = POWERUPS_COUNT[powerupIndex].intValue; if (powerupCount < 0) { if (MathHelp.NextInt(10) < -powerupCount) { continue; } powerupCount = 1; } for (int i = 0; i < powerupCount; ++i) { BrickCell cell = brickCells[brickIndex++]; int cx = cell.GetCx(); int cy = cell.GetCy(); cell.powerup = powerupIndex; if (brickIndex == count) { break; } } if (brickIndex == count) { break; } } }
void powerdown(PowerupInfo pi) { powerups.Remove(pi); pi.powerup.powerdown(player, this); Destroy(pi.powerup.gameObject); }