public void updatePassiveShipState(GameTime gameTime, Matrix _view) { switch (currentPassiveState) { case (passiveState.SpiralFire): { SpriteObjects.Shot aShot = new SpriteObjects.Shot(world, base.mSpriteBody.Position, spiralShotRotation, damage, this.removeShot); aShot.LoadContent(theContentManager, graphics); aShot.fire(base.mSpriteBody.Position, spiralShotRotation, shotSpeed); mShots.Add(aShot); spiralShotRotation += 0.1f; if(spiralShotRotation == 6.3){ spiralShotRotation = 0; } break; } } if (isAIControlled) { Vector2 raycaststart; Vector2 raycastD; for (int x = 0; x < numberOfRayCasts; x++) { raycaststart = this.mSpriteBody.Position + GravitationUtils.rotateVector(new Vector2(0, -0.6f), this.mSpriteBody.Rotation + (radianIncrementation * x)); raycastStartPointList[x] = raycaststart; raycastD = GravitationUtils.rotateVector(new Vector2(0, BASE_SHIP_RAYCAST_LENGTH), this.mSpriteBody.Rotation + (radianIncrementation * x)); raycastEndPointList[x] = raycastStartPointList[x] + raycastD; raycastPointList[x] = Vector2.Zero; raycastNormalList[x] = Vector2.Zero; raycastHitList[x] = false; world.RayCast((f, p, n, fr) => { //String data = Convert.ToString(f.UserData); //Console.WriteLine("Ship data retrieved = " + data); raycastHitList[x] = true; raycastPointList[x] = p; raycastNormalList[x] = n; return fr; }, raycastStartPointList[x], raycastEndPointList[x]); } } }
public void fire() { switch(currentFireState) { case (fireState.Standard): { if (timer) { SpriteObjects.Shot aShot = new SpriteObjects.Shot(world, base.mSpriteBody.Position, base.mSpriteBody.Rotation, damage, this.removeShot); aShot.LoadContent(theContentManager, graphics); //foreach (Fixture fixturec in aShot.mSpriteBody.FixtureList) //{ // fixturec.UserData = fixturec.UserData + ":" + this.shipId; // TODO : setup shots to have shipid , so as to avoid friendly fire, also so raycast doesn't catch own shots //} aShot.fire(base.mSpriteBody.Position, base.mSpriteBody.Rotation, shotSpeed); mShots.Add(aShot); mPlayer.playSound(SoundHandler.Sounds.SHIP_FIRE1); timer = false; } break; } case (fireState.Shotgun): { if (timer) { SpriteObjects.Shot aShot = new SpriteObjects.Shot(world, base.mSpriteBody.Position, base.mSpriteBody.Rotation, damage, this.removeShot); SpriteObjects.Shot bShot = new SpriteObjects.Shot(world, base.mSpriteBody.Position, base.mSpriteBody.Rotation, damage, this.removeShot); SpriteObjects.Shot cShot = new SpriteObjects.Shot(world, base.mSpriteBody.Position, base.mSpriteBody.Rotation, damage, this.removeShot); aShot.LoadContent(theContentManager, graphics); bShot.LoadContent(theContentManager, graphics); cShot.LoadContent(theContentManager, graphics); aShot.fire(base.mSpriteBody.Position, base.mSpriteBody.Rotation, shotSpeed); bShot.fire(base.mSpriteBody.Position, base.mSpriteBody.Rotation + 0.05f, shotSpeed); cShot.fire(base.mSpriteBody.Position, base.mSpriteBody.Rotation - 0.05f, shotSpeed); mShots.Add(aShot); mShots.Add(bShot); mShots.Add(cShot); mPlayer.playSound(SoundHandler.Sounds.SHIP_FIRE1); timer = false; } break; } case(fireState.Laser): { if (timer) { SpriteObjects.Shot aShot = new SpriteObjects.Shot(world, base.mSpriteBody.Position, base.mSpriteBody.Rotation, 1, this.removeShot); aShot.LoadContent(theContentManager, graphics); aShot.fire(base.mSpriteBody.Position, base.mSpriteBody.Rotation, (shotSpeed * 100)); mShots.Add(aShot); timer = false; } break; } case (fireState.Machinegun): { if(timer) { float randomRotation = rand.Next(-1, 1); float secondRotation = rand.Next(-9,9); secondRotation = secondRotation / 100; randomRotation = (randomRotation / 10) + secondRotation; SpriteObjects.Shot aShot = new SpriteObjects.Shot(world, base.mSpriteBody.Position, base.mSpriteBody.Rotation, damage, this.removeShot); aShot.LoadContent(theContentManager, graphics); aShot.fire(base.mSpriteBody.Position, base.mSpriteBody.Rotation + randomRotation, shotSpeed); mShots.Add(aShot); mPlayer.playSound(SoundHandler.Sounds.SHIP_FIRE1); timer = false; } break; } } }