Esempio n. 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>();
        }
Esempio n. 2
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();
                }
            }
        }