Beispiel #1
0
        public void Update(GameTime gametime)
        {

            if (!isCreated) return;

            soundBuzz.Pan = MathHelper.Clamp(factory.Objects[plane].sprite.Location.X, 0, (float)GameWorld.WorldWidth) / (float)GameWorld.WorldWidth;

            factory.Objects[plane].sprite.Location += new Vector2(planeSpeed * direction, 0);
            if (factory.Objects[plane].sprite.Location.X > 12234 - LengthAddedfromZoom)
            {
                direction = -1;
                currentPlane = (currentPlane + 1) % 4;
                //audioManager.SoundEffect("airplane").Play(0.2f, 0, 0);
                //factory.Objects[plane].sprite.flipType = Sprite.FlipType.HORIZONTAL;
            }
            if (factory.Objects[plane].sprite.Location.X < -LengthAddedfromZoom - factory.Objects[plane].sprite.BoundingBoxRect.Width)
            {
                direction = 1;
                currentPlane = (currentPlane + 1) % 4;
                //audioManager.SoundEffect("airplane").Play(0.2f, 0, 0);
                
                //factory.Objects[plane].sprite.flipType = Sprite.FlipType.NONE;
            }

            factory.Objects[plane].sprite.Frame = currentPlane;

            if (planeState == PlaneState.BOMB)
            {
                timeElapsed += gametime.ElapsedGameTime.Milliseconds;

                //make three dogs and drop them from plane
                if (timeElapsed >= 2000f)
                {
                    int dog = factory.Create((int)RaginRovers.GameObjectTypes.DOG,
                        Vector2.Zero,
                        "spritesheet",
                        Vector2.Zero,
                        0f,
                        0f,
                        0f);
                    if (direction == 1)
                    {
                        factory.Objects[dog].sprite.Location = new Vector2(factory.Objects[plane].sprite.Location.X + factory.Objects[plane].sprite.BoundingBoxRect.Width - factory.Objects[dog].sprite.BoundingBoxRect.Width, factory.Objects[plane].sprite.Location.Y + factory.Objects[plane].sprite.BoundingBoxRect.Height);
                    }
                    if (direction == -1)
                    {
                        factory.Objects[dog].sprite.Location = new Vector2(factory.Objects[plane].sprite.Location.X, factory.Objects[plane].sprite.Location.Y + factory.Objects[plane].sprite.BoundingBoxRect.Height);
                        factory.Objects[dog].sprite.flipType = Sprite.FlipType.HORIZONTAL;
                    }

                    factory.Objects[dog].sprite.OnCollision += new OnCollisionEventHandler(CollisionEvents.dog_OnCollision);
                    factory.Objects[dog].sprite.PlayerNumber = playerWhoBombed;
                    timeElapsed = 0f;
                    DogsDropped++;
                }
                if (DogsDropped == 3)
                {
                    planeState = PlaneState.NORMAL;
                    DogsDropped = 0;
                }
            }
        }
Beispiel #2
0
 public void Bomb(int playerWhoHit)
 {
     planeState = PlaneState.BOMB;
     playerWhoBombed = playerWhoHit;
 }
Beispiel #3
0
 public void StartFalling()
 {
     if (state == PlaneState.Flying)
     body.Velocity.Y = 0;
       state = PlaneState.Falling;
 }
Beispiel #4
0
        public void Tick(double deltaMS)
        {
            reloadedCountdown.Tick(deltaMS);

              if (StickPosition == StickPosition.Lift)
            Rotation = (Rotation + rotationSpeed * deltaMS) % (Math.PI * 2);
              if (StickPosition == StickPosition.Dive)
            Rotation = (Rotation + Math.PI * 2 - rotationSpeed * deltaMS) % (Math.PI * 2);

              // Engine if flying
              if (state == PlaneState.Flying)
              {
            float acc = Acceleration(Rotation);
            //Vector2 acc = EngineAcc(Rotation);
            float vel = Velocity();
            vel += 0.1f * acc;
            if (vel < fallAtSpeedBelow)
            {
              SystemSounds.Beep.Play();
              state = PlaneState.Falling;
            }
            else
              //vel += acc.Length;
              //acc.Normalize();
              body.Velocity = vel * new Vector2((float)Math.Cos(Rotation), (float)Math.Sin(Rotation));
              }
              else
              {
            body.Velocity -= Vector2.UnitY * gravity;
            if (body.Velocity.Length > regainFlightAtSpeedAbove && RegainFlightRotation(Rotation))
            {
              SystemSounds.Exclamation.Play();
              state = PlaneState.Flying;
              body.Velocity = body.Velocity.Length * new Vector2((float)Math.Cos(Rotation), (float)Math.Sin(Rotation));
            }
              }

              if (Velocity() > maxvel)
            body.Velocity *= maxvel / body.Velocity.Length;

              // Stall?
              // float stallSpeed = 0.025f;
              //if (body.Velocity.Length < stallSpeed)
              //  state = PlaneState.Falling;

              // Gravity
              // body.Velocity -= Vector2.UnitY * (float)deltaMS * 0.0001f;

              // Regain fly state?
              //if( state == PlaneState.Falling)
              //{
              //  double halfang = 10;
              //  double mindir = 270 - halfang;
              //  double maxdir = 270 + halfang;
              //  mindir *= Calc.Deg2Rad;
              //  maxdir *= Calc.Deg2Rad;
              //  if (mindir <= rotation && rotation <= maxdir && body.Velocity.Length > stallSpeed)
              //    state = PlaneState.Flying;
              //}

              // Air resistance
              //float airResitance = 0.6f;
              //if (state == PlaneState.Falling)
              //  airResitance *= 2;
             // body.Velocity -= airResitance * body.Velocity * body.Velocity.Length;

              body.Tick(deltaMS);
        }
 public Airplane(int airplaneID, string type, double cruisingKPH, double fuelConsPerHour, int currentAirportID)
 {
     this.airplaneID = airplaneID;
     this.type = type;
     this.state = PlaneState.Landed;
     this.cruisingKPH = cruisingKPH;
     this.fuelConsPerHour = fuelConsPerHour;
     this.currentAirRouteID = -1;
     this.distanceAlongRoute = 0;
     this.currentAirportID = currentAirportID;
     this.timeLanded = 0;
     this.fuel = 0;
     this.currentAirport = null;
     this.currentAirRoute = null;
     this.simTime = 0;
 }