Esempio n. 1
0
        public BattleGameModel(BattleGameModelData data)
        {
            this.data = data;
            ship      = data.Player;
            ship.DeletePhysics();
            ship.Position = new Vector2D(data.MapSize.Width / 2, data.MapSize.Height / 2);

            GameBasicCamera = new SmoothCamera(data.CameraSize, ship);

            Controls = data.Controls;
            Controls.MouseHandler.ChangeCamera(GameBasicCamera);


            Time = data.Time;

            gameTick = new Timer(8);

            Physics = new World(new Vector2(0, 0));
            Physics.SetContactListener(new GlobalContactListner());

            map = new GameMap(new Size(1, 1), data.MapSize, Physics);

            map.AddGameObjects(ship);

            manager = new BattleGameManager(data.Enemy, map, ship);

            manager.Win += () =>
            {
                win = true;
            };

            ship.OnDestroy += GameOver;

            gameTick.Elapsed += FrameTick;
        }
Esempio n. 2
0
        private void StartBattle(MapEnemy obj)
        {
            Pause();
            var position = new Vector2D(player.Position.X, player.Position.Y);

            map.RemoveObject(player);
            var data = new BattleGameModelData
            {
                MapSize    = new Size(20000, 20000),
                Player     = player,
                Controls   = Controls,
                Enemy      = obj,
                Time       = Time,
                CameraSize = GameBasicCamera.Size,
                MainModel  = this
            };
            var model = new BattleGameModel(data);

            model.GameModelChanged += m =>
            {
                obj.Destoy();
                player.Position = position;
                map.AddGameObject(player);
                Controls.MouseHandler.ChangeCamera(GameBasicCamera);
                Run();
            };
            GameModelChanged?.Invoke(model);
            model.Run();
        }