private void TimerVolleyFinished(float secondsOverflow) { 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 += Angle.FromPoint(transform.position, playerPos).GetDegrees(); //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>(); leftMovement.SetVelocity(new Vector2(-data.projectileLeftSpeed, 0.0f)); projectile.GetComponent <TimeScale>().SetData(timeScale); } data.volley.projectile.angle += data.volleyDirectionDeltaPerShot; }
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; } }
protected override void Initialize() { base.Initialize(); this.arm = new Arm(100); var arm2 = this.arm.CreateArm(50, Color.Red); var arm3 = arm2.CreateArm(30, Color.Blue); this.arm.Transform.Position = new Vector2(this.GraphicsDevice.Viewport.Width / 2, this.GraphicsDevice.Viewport.Height / 2); var t1 = new Tween2D(TimeSpan.FromSeconds(5), this.arm.Transform, new Transform2D() { Rotation = 5, Position = this.arm.Transform.Position, Scale = new Vector2(2, 2), }, Ease.ElasticInOut); this.tween = new Repeat(new Sequence(new Delay(TimeSpan.FromSeconds(3)), t1)); this.velocity2 = new Velocity2D(arm2.Transform) { Rotation = 2f, Position = Vector2.UnitX * -2f, }; this.velocity3 = new Velocity2D(arm3.Transform) { Rotation = -3.5f, }; }
public void VelocityCannotExceedMaximum() { var velocity = new Velocity2D(Vector2D.Zero, 0.5f); velocity.Accelerate(1.0f, 0); Assert.AreEqual(-0.5f * Vector2D.UnitY, velocity.Velocity); }
public static Velocity2D operator+(Velocity2D vel, Acceleration2D acc) { Velocity2D output = vel + acc; if (output.Velocity.Magnitude > acc.TermV) { output.Velocity.Magnitude = acc.TermV; } return(output); }
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 lm = de.GetComponent <Velocity2D>(); lm.SetVelocity(leftMovement.GetVelocity()); de.GetComponent <TimeScale>().SetData(timeScale); Destroy(gameObject); }
// 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); } } }
void Start() { vel = GetComponent <Velocity2D>(); }
public void VelocityCannotExceedMaximum() { var velocity = new Velocity2D(Vector2D.Zero, 0.5f); velocity.Accelerate(1.0f,0); Assert.AreEqual(-0.5f * Vector2D.UnitY, velocity.Velocity); }
///<exclude/> public bool Equals(Velocity2D other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return other._Vx.Equals(_Vx) && other._Vy.Equals(_Vy) && other._Va.Equals(_Va); }