public TurretShot(Particle newParticle, Position target, IGameSprite sprite) : base(newParticle,sprite) { _particle = newParticle; _particle.velocity = GameParameters.TURRET_SHOT_VELOCITY; _type = ObjectType.TURRET_SHOT; _target = target; }
public Particle(Particle particle) { position = particle.position; velocity = particle.velocity; acceleration = particle.acceleration; theta = particle.theta; }
/// <summary> /// Given an initialization vector, returns a packet describing a missile spawn event. /// </summary> /// <param name="startVector"></param> /// <returns>A missile spawn event packet.</returns> public EventPacket MakeSpawnMissileEventPacket(Particle startVector) { SpawnMissileEvent missileSpawn = new SpawnMissileEvent(startVector); byte[] eventData = EventCodec.Instance.Serialize<SpawnMissileEvent>(missileSpawn); EventPacket eventPacket = new EventPacket(EventTypes.SPAWN_MISSILE, eventData); return eventPacket; }
public Missile(Particle newParticle, IGameSprite sprite) { _hullRadius = GameParameters.MISSILE_HULL_RADIUS; _type = ObjectType.MISSILE; _health = 10; _particle = newParticle; _sprite = sprite; }
public IGameObject MakeTurretShot(Particle initialVector, Position target) { IGameSprite turretShotSprite = _spriteFactory.MakeTurretShotSprite(initialVector.position); TurretShot turretShot = new TurretShot(initialVector, target, turretShotSprite); turretShot.OnProximityDetonation += _eventMonitor.OnAirBurstDetonation; return (IGameObject)turretShot; }
public EventPacket MakeSpawnMirvEventPacket(Particle startVector, double deployAltitude) { SpawnMirvEvent missileSpawn = new SpawnMirvEvent(startVector,deployAltitude); byte[] eventData = EventCodec.Instance.Serialize<SpawnMirvEvent>(missileSpawn); EventPacket eventPacket = new EventPacket(EventTypes.SPAWN_MIRV, eventData); return eventPacket; }
public IGameObject MakeMissile(Particle initialVector) { IGameSprite missileSprite = _spriteFactory.MakeMissileSprite(initialVector.position); Missile missile = new Missile(initialVector, missileSprite); missile.OnDetonation += _eventMonitor.OnMissileDetonation; return (IGameObject)missile; }
public IGameObject MakeMirv(Particle initialVector, double deploymentAltitude) { IGameSprite mirvSprite = _spriteFactory.MakeMirvSprite(initialVector.position); Mirv mirv = new Mirv(initialVector, mirvSprite, deploymentAltitude); mirv.OnMirvDeployment += _eventMonitor.OnMirvDeployment; mirv.OnDetonation += _eventMonitor.OnMissileDetonation; return (IGameObject)mirv; }
/// <summary> /// Called when an object wishes to drop a bomb. The hostVector parameter is the kinematic /// description of the object dropping the bomb; this allows us to use this info however /// we want, even though not all of it will be used. /// </summary> /// <param name="hostVector"></param> public void OnBombDrop(Particle hostVector) { Particle startVector = new Particle(hostVector); startVector.velocity = GameParameters.MISSILE_VELOCITY; startVector.acceleration = GameParameters.MISSILE_ACCELERATION; //bomb theta is random, within some range constraint (a downward cone) centered at 3pi/2 startVector.theta = (((double)RandomNumberGenerator.Instance.Rand()) / 47.0) % GameParameters.BOMB_THETA_FUZZ + 1.5 * GameParameters.PI - GameParameters.BOMB_THETA_FUZZ / 2.0; EventPacket packet = _eventFactory.MakeSpawnMissileEventPacket(startVector); _eventBus.Receive(packet); }
/* When a mirv deploys, the missile separates into three separate mirvs. The primary continues on its trajectory; the other two branch off at plus/minus k degrees, respectively. The second mirvs are set * to deploy below 0, so they will effectively never deploy, just act as missiles. */ public void OnMirvDeployment(Particle vector) { int velocityRandomizationPct = 15; //push the second mirv warhead into the event system Particle startParticle = new Particle(vector); //randomize the velocity a max of 15% int rand = RandomNumberGenerator.Instance.Rand(); startParticle.velocity += ((double)(rand % velocityRandomizationPct) / 100.0); startParticle.theta = startParticle.theta + GameParameters.PI / 18; EventPacket mirv2 = _eventFactory.MakeSpawnMirvEventPacket(startParticle, GameParameters.MIN_Y); _eventBus.Receive(mirv2); //push the third mirv warhead startParticle = new Particle(vector); //randomize the velocity a max of 15% rand = RandomNumberGenerator.Instance.Rand(); startParticle.velocity += ((double)(rand % velocityRandomizationPct) / 100.0); startParticle.theta = startParticle.theta - GameParameters.PI / 18; EventPacket mirv3 = _eventFactory.MakeSpawnMirvEventPacket(startParticle, GameParameters.MIN_Y); _eventBus.Receive(mirv3); }
public Bomber(Particle startVector, IGameSprite gameSprite, int numBombs, int dropInterval) { _hullRadius = GameParameters.BOMBER_HULL_RADIUS; _type = ObjectType.BOMBER; _health = 100; _particle = startVector; _dropInterval = dropInterval; if (numBombs >= 0) { _bombs = new bool[numBombs]; for (int i = 0; i < numBombs; i++) { _bombs[i] = true; } } else { Console.WriteLine("ERROR numBombs < 0 in Bomber ctor"); } _sprite = gameSprite; }
public SpawnMissileEvent(Particle startVector) { _startVector = new Particle(startVector); }
public void OnMissileDetonation(Particle particle) { EventPacket packet = _eventFactory.MakeExplosionEventPacket(particle.position); _eventBus.Receive(packet); }
public void OnAirBurstDetonation(Particle particle) { EventPacket packet = _eventFactory.MakeAirBurstEventPacket(particle.position); _eventBus.Receive(packet); }
//ignore the stupidity of these functions. they act on velocity/acceleration as scalars instead of vectors. //update position per velocity public static void UpdatePosition(Particle particle) { particle.position.X += (System.Math.Cos(particle.theta) * particle.velocity); particle.position.Y += (System.Math.Sin(particle.theta) * particle.velocity); }
/// <summary> /// Selects a random target base as target, and builds an event packet around it. This smells /// like business logic that belongs outside of this class... alternatively we could pass in the /// game-object list dependency for selecting a random target. /// </summary> /// <returns></returns> public EventPacket MakeRandomSpawnMissileEventPacket(List<IGameObject> gameObjects) { //initialize a random start location along the top border int xCoor = RandomNumberGenerator.Instance.Rand() % GameParameters.MAX_X; Position startPosition = new Position(xCoor, GameParameters.MAX_Y); //all enemy missiles point at a random city or base, in radians double angleRad = _getTargetTrajectory(startPosition, gameObjects); Particle startVector = new Particle(GameParameters.MISSILE_VELOCITY, GameParameters.MISSILE_ACCELERATION, angleRad, startPosition); EventPacket packet = MakeSpawnMissileEventPacket(startVector); return packet; }
public Mirv(Particle newParticle, IGameSprite sprite, double deployAltitude) : base(newParticle,sprite) { _deployAltitude = deployAltitude; _once = true; _type = ObjectType.MISSILE; }
void spawnTurretShot(EventPacket newEvent) { SpawnTurretShotEvent turretShotEvent = EventCodec.Instance.Deserialize<SpawnTurretShotEvent>(newEvent.Data); double ang = Position.pointTangent(turretShotEvent.Source,turretShotEvent.Target); Particle initialVector = new Particle(GameParameters.TURRET_SHOT_VELOCITY, GameParameters.TURRET_SHOT_ACCELERATION, ang, turretShotEvent.Source); IGameObject turretShot = _objectFactory.MakeTurretShot(initialVector,turretShotEvent.Target); _objectContainer.Add(turretShot); }
public static void Update(Particle particle) { Particle.UpdatePosition(particle); Particle.UpdateVelocity(particle); }
public SpawnMirvEvent(Particle startVector, double deployAltitude) { StartVector = new Particle(startVector); DeployAltitude = deployAltitude; }
public static void UpdateVelocity(Particle particle) { particle.velocity += particle.acceleration; }