Example #1
0
        public void LoadLevel(LevelDescription description)
        {
            // Add game world
            sky = new Skybox();
            map = new HeightMap(description);
            Game.Components.Add(sky);
            Game.Components.Add(map);

            rootPartition = new Partition(map);
            Game.Components.Add(rootPartition);

            // Add player & camera
            userControlledTank = VehicleFactory.CreateTank(modelType: ModelType.TANK1, HP: 200);
            userControlledTank.transformation.Position = map.PlayerStartPosition;
            userControlledTank.Tag = "Player";
            userControlledTank.AddComponent(new TankController());
            userControlledTank.AddToGameWorld();
            mainCamera = new TargetPointOfViewCamera(userControlledTank, new Vector3(0, 50, 100));
            Game.Components.Add(mainCamera);

            // Add game detail
            pointSprite = new TextRenderer()
            {
                font = Game.Content.Load <SpriteFont>(@"Fonts\Arial"), text = "Point: " + 0, position = new Vector2(50, 50), color = Color.Red
            };
            bloodSprite = new TextRenderer()
            {
                font = Game.Content.Load <SpriteFont>(@"Fonts\Arial"), text = "HP: " + userControlledTank.HP, position = new Vector2(50, 100), color = Color.Red
            };

            Game.Components.Add(bloodSprite);
            Game.Components.Add(pointSprite);

            inputManager = Game.Services.GetService <IInputManager>();
        }
Example #2
0
        public static Vector3 AdvoidObstacleBehaviour(OnlandVehicle tank, Vector3 currentSteering, Map map, float scanRadius = 50)
        {
            Vector3 originalScanVector = Vector3.Normalize(currentSteering) * scanRadius;
            //Vector3 originalSeePoint = currentTransform.Translation + originalScanVector;

            // scan around to find moveable position
            float rotateAngle = 0;
            float rotateStep  = MathHelper.PiOver4;

            List <float> availableAngles = new List <float>();
            Matrix       rotateMatrix;

            while (rotateAngle < MathHelper.TwoPi)
            {
                rotateMatrix = Matrix.CreateRotationY(rotateAngle);
                Vector3 scanPoint = tank.transformation.Position + Vector3.Transform(originalScanVector, rotateMatrix);

                if (tank.Moveable(scanPoint))
                {
                    availableAngles.Add(rotateAngle);
                    return(Vector3.Transform(currentSteering, rotateMatrix));
                }

                rotateAngle += rotateStep;
            }

            if (availableAngles.Count == 0)
            {
                return(tank.transformation.WorldMatrix.Backward);
            }

            availableAngles.Sort(new AngleComparer());
            rotateMatrix = Matrix.CreateRotationY(availableAngles[0]);
            return(Vector3.Transform(currentSteering, rotateMatrix));
        }
Example #3
0
        public override void Update(GameTime gameTime)
        {
            // collision checking with other vehicles
            OnlandVehicle collidedVehicle = null;

            foreach (OnlandVehicle vehicle in FindObjectsInPartition <OnlandVehicle>())
            {
                if (owner == vehicle)
                {
                    continue;
                }

                if (collider.Intersect(vehicle.collider))
                {
                    //Console.Out.WriteLine("Intersect");
                    collidedVehicle = vehicle;
                    break;
                }
            }

            if (collidedVehicle != null)
            {
                collidedVehicle.Damaged(this.damage);
                if (this.owner.Tag.Equals("Player"))
                {
                    FindObjects <GameLevelManager>()[0].Point += 10;
                }
                //Game.Components.Remove(this);
                RemoveFromGameWorld();
            }

            // remove bullet if outside map or hit the ground
            if (!map.IsInsideMap(transformation.Position))
            {
                //Game.Components.Remove(this);
                RemoveFromGameWorld();
                return;
            }

            float bulletHeight = transformation.Position.Y;
            float mapHeight    = map.GetHeight(transformation.Position);

            if (bulletHeight < mapHeight)
            {
                RemoveFromGameWorld();
                //Game.Components.Remove(this);
            }

            base.Update(gameTime);
        }
Example #4
0
        public override void Update(GameTime gameTime)
        {
            List <OnlandVehicle> vehicleList = FindObjectsInPartition <OnlandVehicle>();
            OnlandVehicle        targetTank  = null;

            foreach (OnlandVehicle tank in vehicleList)
            {
                if (tank.collider.Intersect(this.collider))
                {
                    targetTank = tank;
                    break;
                }
            }

            if (targetTank != null)
            {
                targetTank.HP += 10;
                //Game.Components.Remove(this);
                RemoveFromGameWorld();
            }
        }
Example #5
0
        public void SpawnEnemyTank()
        {
            for (int i = 0; i < spawnMaxAttempt; i++)
            {
                Random  r               = new Random();
                int     spawnIndex      = r.Next(map.SpawnPoints.Count);
                Vector3 newTankLocation = map.SpawnPoints[spawnIndex];
                newTankLocation.Y = map.GetHeight(newTankLocation);

                OnlandVehicle enemyVehicle = VehicleFactory.CreateTank(ModelType.TANK1, 60);
                enemyVehicle.Tag = "Enemy";
                enemyVehicle.transformation.Position = newTankLocation;
                enemyVehicle.AddToGameWorld();
                if (enemyVehicle.Moveable(newTankLocation))
                {
                    enemyVehicle.AddComponent(new EnemyTankAI());
                    break;
                }
                else
                {
                    enemyVehicle.RemoveFromGameWorld();
                }
            }
        }