예제 #1
0
 private void OnLitterPickedUp(Litter litter)
 {
     LitterPickedUp?.Invoke(this, new PointsEventArgs(litter.Points));
 }
예제 #2
0
        private void LoadLevel()
        {
            var standing = Content.Load <Texture2D>("Hudson Sprites/Standing_scaled");
            var running  = Content.Load <Texture2D>("Hudson Sprites/Running");
            var starting = Content.Load <Texture2D>("Hudson Sprites/Starting");
            var stopping = Content.Load <Texture2D>("Hudson Sprites/Stopping");
            var hit      = Content.Load <Texture2D>("Hudson Sprites/Hit");

            _player = new Player(standing, starting, running, stopping, hit, new Rectangle(8, 16, 48, 32), 5, 16, 8, 20,
                                 3, 330, 300, new Vector2(700, 700));

            var texture = Content.Load <Texture2D>("playzone");

            _camera             = new Camera(new Vector2(400, 400), _player);
            _camera.CameraState = CameraState.Locked;

            var data = new Color[100 * 100];

            for (int i = 0; i < 100 * 100; i++)
            {
                data[i] = Color.Green;
            }
            var tTexture = new Texture2D(GraphicsDevice, 100, 100);

            tTexture.SetData(data);

            data = new Color[100 * 50];
            for (int i = 0; i < 100 * 50; i++)
            {
                data[i] = Color.Blue;
            }
            var pretendCar = new Texture2D(GraphicsDevice, 100, 50);

            pretendCar.SetData(data);

            var vehicleLane =
                new VehicleLane(new Vehicle(pretendCar, new Rectangle(0, 0, 100, 50), 300, HitType.Knockback), 300, 1500,
                                -500, 3000, 1000);

            data = new Color[20 * 20];
            for (int i = 0; i < 20 * 20; i++)
            {
                data[i] = Color.Black;
            }
            var litterthing = new Texture2D(GraphicsDevice, 20, 20);

            litterthing.SetData(data);

            var litter =
                new Litter(litterthing, new Rectangle(0, 0, 20, 20), new Vector2(600, 600), 100);


            _level = new Level(texture, new Rectangle(100, 100, 800, 800), _player, _camera,
                               new[] { new EnvironmentObject(tTexture, new Vector2(50, 80), true, new Rectangle(0, 0, 100, 100)) },
                               new[] { vehicleLane }, new[] { litter }, 3f);

            _level.VehicleLanes[0].BeginSpawning();

            _gameState = GameState.Game;
            _tick      = new Timer(_player.Tick, null, 10, 1000 / 24);

            _lives  = 3;
            _points = 0;

            _level.VehicleHit     += RemoveLife;
            _level.LitterPickedUp += AddPoints;

            IsMouseVisible = false;
        }