Ejemplo n.º 1
0
        public override void Update(GameTime gametime)
        {
            min = MIN + CurrentPosition;
            max = MAX + CurrentPosition;
            tankBox = new BoundingBox(min, max);
            //float distance = Vector3.Subtract(targetTank.CurrentPosition, this.CurrentPosition).Length();
            //distance > Tank.destinationThreshold &&
            //if (tankBox.Contains(tankBox) == ContainmentType.Disjoint)
            if (tankBox.Contains(targetTank.tankBox) == ContainmentType.Disjoint)
            {

            //if (Mouse.GetState().LeftButton == ButtonState.Pressed && mousepick.GetCollisionPosition().HasValue == true)
            //{
                //pickPosition = mousepick.GetCollisionPosition().Value;
                Point start = Map.WorldToMap(CurrentPosition);

                Point end = Map.WorldToMap(targetTank.CurrentPosition);
                //Point end = Map.WorldToMap(pickPosition);
                if (end.X < 20 && end.X>=0&&end.Y < 20&&end.Y>=0)
                {
                pathfinder = new Pathfinder(map);
                path = pathfinder.FindPath(start, end);
                //pathdebug = path;
                }

            }

            if(path!=null&& moveorder<path.Count)
            {
                distanceTopickPosition = Vector3.Distance(path[moveorder], CurrentPosition);
                if (distanceTopickPosition > desThresholdtoplayer)
                {
                    speed = velocity.Length();
                    currentAngle = (float)Math.Atan2(velocity.Z, velocity.X);
                    moveAngle = currentAngle - initialAngle;
                    rotation = Matrix.CreateRotationY(-moveAngle);
                    //wheelRotationValue = (float)gametime.TotalGameTime.TotalSeconds * 10;
                    //canonRotationValue = (float)Math.Sin(gametime.TotalGameTime.TotalSeconds * 0.25f) * 0.333f - 0.333f;
                    //hatchRotationValue = MathHelper.Clamp((float)Math.Sin(gametime.TotalGameTime.TotalSeconds * 2) * 2, -1, 0);
                    velocity += steer.seek(path[moveorder], CurrentPosition, velocity) * (float)gametime.ElapsedGameTime.TotalSeconds;
                    CurrentPosition += velocity * (float)gametime.ElapsedGameTime.TotalSeconds;
                    translation = Matrix.CreateTranslation(CurrentPosition);
                }
                else moveorder++;

            }
            else
            {
                moveorder = 0;
                if (path != null) path.Clear();
            }
            //base.Update(gametime);
            //turretRorationValue = (float)Math.Sin(gametime.TotalGameTime.TotalSeconds);
        }
Ejemplo n.º 2
0
 public PursuitEnemy(Model model, Vector3 position,GraphicsDevice device, Camera camera,Tank tank)
     : base(model, device, camera)
 {
     tankBox = new BoundingBox(MIN, MAX);
     CurrentPosition = position;
     pickPosition = CurrentPosition;
     translation = Matrix.CreateTranslation(Map.MapToWorld(new Point(10, 10)));
     velocity = Vector3.Zero;
     new Tank(model, device, camera);
     steer = new Steering(100f, 100f);
     map = new Map();
     pathfinder = new Pathfinder(map);
     isMoving = false;
     initialAngle = MathHelper.PiOver2;
     moveorder = 0;
     mousepick = new MousePicking(device, camera);
     targetTank = tank;
 }
Ejemplo n.º 3
0
 public ModelManager(Game game)
     : base(game)
 {
     map = new Map();
     pathfinder = new Pathfinder(map);
     wallstone = new Wallstone[map.barrierList.Count];
     XElement level = XElement.Load(@"Content/config/levelsetting.xml");
     //tank1 = new Tank1(Game.Content.Load<Model>(@"Models/Tank/tank"), ((Game1)Game).GraphicsDevice,
     //   ((Game1)Game).camera);
     foreach (XElement levelnumber in level.Elements()) {
     foreach (XElement parameters in levelnumber.Elements())
     {
         levelInfoList.Add(new LevelInfo(int.Parse(parameters.Attribute("minSpawnTime").Value),
                         int.Parse(parameters.Attribute("maxSpawnTime").Value),
                         int.Parse(parameters.Attribute("numberEnemies").Value),
                         int.Parse(parameters.Attribute("minspeed").Value),
                         int.Parse(parameters.Attribute("maxSpeed").Value),
                         int.Parse(parameters.Attribute("missAllowed").Value),
                         int.Parse(parameters.Attribute("numHuman").Value)
           ));
      }
     }
     /*    levelInfoList.Add(new LevelInfo(10,100,5,2,21,10));
     levelInfoList.Add(new LevelInfo(900,2800,10,3,6,9));
     levelInfoList.Add(new LevelInfo(800, 2600, 15, 4, 6, 8));
     levelInfoList.Add(new LevelInfo(700, 2400,20, 5, 7, 7));
     levelInfoList.Add(new LevelInfo(600, 2200, 25, 6, 7, 6));
     levelInfoList.Add(new LevelInfo(500, 2000, 30, 7, 7, 5));
     levelInfoList.Add(new LevelInfo(400, 1800, 35, 8, 7, 4));
     levelInfoList.Add(new LevelInfo(300, 1600, 40, 8, 8, 3));
     levelInfoList.Add(new LevelInfo(200, 1400, 45, 8, 8, 2));
     levelInfoList.Add(new LevelInfo(100, 1200, 55, 8, 9, 1));
     levelInfoList.Add(new LevelInfo(50, 1000, 60, 8, 9, 0));
     levelInfoList.Add(new LevelInfo(50, 800, 65,8, 9, 0));
     levelInfoList.Add(new LevelInfo(50, 600, 70, 8, 10, 0));
     levelInfoList.Add(new LevelInfo(25, 400, 75, 8, 10, 0));
     levelInfoList.Add(new LevelInfo(0, 200, 80, 8, 20, 0));
      */
     this.game = game;
 }