/// <summary> /// Constructs a new projectile. /// </summary> public Projectile(ParticleSystem explosionParticles, ParticleSystem explosionSmokeParticles, ParticleSystem projectileTrailParticles, MovableEntity origin, MovableEntity aTarget) { this.explosionParticles = explosionParticles; this.explosionSmokeParticles = explosionSmokeParticles; // Start at the origin, firing in a random (but roughly upward) direction. position = origin.getPosition(); target = aTarget.getPosition(); targetEntity = aTarget; //velocity.X = (float)(random.NextDouble() - 0.5) * sidewaysVelocityRange; //velocity.Y = (float)(random.NextDouble() - 0.5) * sidewaysVelocityRange; //velocity.Z = (float)(random.NextDouble() + 0.5) * verticalVelocityRange; double step = Math.PI / 60; //Vector3 mid = (aTarget + aPosition) / 2; float radius = Math.Abs(Vector3.Distance(target, position) / 2); List<Vector3> path = new List<Vector3>(); for (int i = 0; i <= 60; i++) { float thisX = MathHelper.Lerp(position.X, target.X, ((float)i) / 60); float thisY = MathHelper.Lerp(position.Y, target.Y, ((float)i) / 60); float thisZ = MathHelper.Lerp(position.Z, target.Z, ((float)i) / 60) + radius * (float)Math.Cos(step*(i - 30)); path.Add(new Vector3(thisX, thisY, thisZ)); } myPath = new Path(path); // Use the particle emitter helper to output our trail particles. trailEmitter = new ParticleEmitter(projectileTrailParticles, trailParticlesPerSecond, position); }
public Guard(GameState gameState, LevelInfo levelInfo, ModelLoader modelLoader, Path path, int uid, ProjectileManager proj) : base(gameState, levelInfo, modelLoader.getModel3D(modelType.Tank), path, uid, SPEED, RADIUS, FULL_HEALTH, WATER_CAPACITY, 0, 0) { attackRadiusTool = new LineTool(gameState.getGraphics()); attackRadiusTool.setColor(Color.Green.ToVector3()); attackTarget = null; projectiles = proj; }
public Sound(Cue theCue, MovableEntity emitterEntity) { cue = theCue; entity = emitterEntity; emitter = new AudioEmitter(); }
/* Plays a sound positioned in 3D space, with panning and volume adjustments. */ public void playSound(SoundHandle theSound, MovableEntity emitterEntity) { if (soundOn) { if (emitterEntity == null) playSound(theSound); //if the listener isn't set, just play the sound normally AudioEmitter emitter = new AudioEmitter(); emitter.Position = emitterEntity.getPosition(); switch (theSound) { case SoundHandle.Truck: Cue newCue = soundBank.GetCue("truck"); Sound newSound = new Sound(newCue, emitterEntity); newCue.Apply3D(listener, emitter); newCue.Play(); soundList.Add(newSound); break; //case SoundHandle.Punch: soundBank.PlayCue("punch", listener, emitter); break; //case SoundHandle.BGM: soundBank.PlayCue("bgm"); break; } } }
/* Given 2 MovableEntities, check whether they overlap. */ public static bool checkStaticCollision(MovableEntity a, MovableEntity b) { float xDiff = a.position.X - b.position.X; float yDiff = a.position.Y - b.position.Y; double dist = Math.Sqrt(xDiff * xDiff + yDiff * yDiff); return (dist < a.radius + b.radius); }
public override void update() { base.update(); if (isDead()) return; List<Vector3> pointsList = new List<Vector3>(); float step = MathHelper.Pi / 16; for (float i = 0; i <= 32; i++) { Vector3 pointy = LevelInfo.getPositionAt(getPosition().X + (float)Math.Cos(i * step) * ATTACK_RADIUS, getPosition().Y + (float)Math.Sin(i * step) * ATTACK_RADIUS); pointy.Z += 0.25f; pointsList.Add(pointy); } attackRadiusTool.setPointsList(pointsList); if (timeToWait > 0) timeToWait--; if (!hasMoved) //if we stayed still since the last update { /* attack logic */ if (timeToWait == 0) { //attack! if (attackTarget != null) { projectiles.addProjectile(this, attackTarget); //attackTarget.hurt(1); timeToWait = ATTACK_WAIT_TIME; if (attackTarget.isDead()) attackTarget = null; } } } else { attackTarget = null; } }
public void addProjectile(MovableEntity org, MovableEntity tar) { projectiles.Add(new Projectile(explosionParticles, explosionSmokeParticles, projectileTrailParticles, org, tar)); }
public void sendPos(MovableEntity entity) { packetWriter.Write(entity.uniqueID); packetWriter.Write(entity.getPosition()); packetWriter.Write(entity.getOrientation()); session.LocalGamers[0].SendData(packetWriter, SendDataOptions.None); }