private void FixedUpdate() { while (timerVolley.TimeUp(data.refs.ts.DeltaTime())) { VolleyData volley = data.volley; float[] angles = UtilSpread.PopulateAngle(volley.spreadAngle, data.volley.projectile.angle, volley.projectileCount); foreach (float a in angles) { float angle = a; if (data.refs.player != null) { if (volley.aimAtPlayer) { Vector3 playerPos = data.refs.player.transform.position; angle += UtilHeading2D.SignedAngleToPoint(transform.position, playerPos); } } Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward); GameObject projectile = Instantiate(prefabProjectile, transform.position, rotation); EnemyProjectile proj = projectile.GetComponent <EnemyProjectile>(); EnemyProjectile.Data projData = data.volley.projectile.DeepCopy(); projData.angle = angle; proj.SetData(projData); Velocity2D leftMovement = projectile.GetComponent <Velocity2D>(); Velocity2D.Data v2d = new Velocity2D.Data( new Velocity2D.Data.Refs(data.refs.ts), new Vector2(-data.projectileLeftSpeed, 0.0f)); leftMovement.SetData(v2d); } data.volley.projectile.angle += data.volleyDirectionDeltaPerShot; } }
public void SetData(Data val) { oscillatePosition2D.SetData(val.oscData); leftMovement.SetData(val.leftMovementData); enemyAttack.SetData(val.attackData); enemySprite.SetData(val.spriteData); enemyHealth.SetData(val.enemyHealthData); }
private void Start() { Velocity2D.Data dat = new Velocity2D.Data( new Velocity2D.Data.Refs(data.refs.ts), UtilHeading2D.HeadingVectorFromDegrees(data.angle) * data.speed); velocity.SetData(dat); //SetAngleSpeed(data.angle, data.speed); SetColor(data.color); }
// Attempt to drop something. private void DropItem() { ItemType it = data.probItem.Roll(); if (it == ItemType.None) { return; } if (it == ItemType.HealthKit) { GameObject pup = Instantiate(prefabHealthKit, transform.position, Quaternion.identity); ItemHealthKit hk = pup.GetComponent <ItemHealthKit>(); hk.SetData(data.healthKit); Velocity2D.Data v2d = new Velocity2D.Data( new Velocity2D.Data.Refs(data.refs.ts), leftMovement.GetVelocity()); Velocity2D lm = pup.GetComponent <Velocity2D>(); lm.SetData(v2d); } else { // Only drop these powerups if none currently exist. if (!data.refs.playerPowerup.GetPowerupExists()) { GameObject powerup = null; switch (it) { case ItemType.BattleAxe: powerup = Instantiate(prefabBattleAxe, transform.position, Quaternion.identity); break; case ItemType.MoreArms: powerup = Instantiate(prefabMoreArms, transform.position, Quaternion.identity); break; } ItemPowerup pup = powerup.GetComponent <ItemPowerup>(); pup.SetPlayerPowerup(data.refs.playerPowerup); Velocity2D.Data v2d = new Velocity2D.Data( new Velocity2D.Data.Refs(data.refs.ts), leftMovement.GetVelocity()); Velocity2D lm = powerup.GetComponent <Velocity2D>(); lm.SetData(v2d); } } }
public void Kill() { data.refs.score.Add(data.pointsWhenKilled); data.refs.score.PunchedEnemy(); DropItem(); ac.PlaySFX(enemyDeathSounds.GetRandomElement()); GameObject de = Instantiate(deathExplosion, transform.position, Quaternion.identity); Velocity2D.Data v2d = new Velocity2D.Data( new Velocity2D.Data.Refs(data.refs.ts), leftMovement.GetVelocity()); Velocity2D lm = de.GetComponent <Velocity2D>(); lm.SetData(v2d); Destroy(gameObject); }