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
        public void UpdateMap(BasicCamera camera, Size overrun = new Size())
        {
            var chunksCoordinate = GetChunksCoordinateFromCamera(camera, overrun);

            chunksCoordinate
            .ForEach(CheckChunk);
        }
Esempio n. 3
0
        public List <GameObject> GetGameObjects(BasicCamera basicCamera, Size overrun = new Size())
        {
            var chunksCoordinate = GetChunksCoordinateFromCamera(basicCamera, overrun);

            lastChunks.SetNewFrameData(chunksCoordinate);

            return(chunksCoordinate
                   .Select(coordinate => chunks[coordinate.X, coordinate.Y].GetGameObjects())
                   .SelectMany(x => x).ToList());
        }
Esempio n. 4
0
        public MainGameModel()
        {
            Physics = new World(new Vector2(0, 0));
            Physics.SetContactListener(new GlobalContactListner());

            map = new GameMap(new Size(100, 100), new Size(1000, 1000), Physics);

            const int border             = 3000;
            var       allowedCoordinates = new Rectangle(border,
                                                         border,
                                                         map.MapSize.Width - 2 * border,
                                                         map.MapSize.Height - 2 * border);

            player          = new Player(allowedCoordinates, new Vector2D(5000, 5000));
            GameBasicCamera = new SmoothCamera(new Size(), player);

            Controls = new Controls(GameBasicCamera);

            var axes = new HashSet <Axis>
            {
                new Axis("horizontal", Keys.D, Keys.A),
                new Axis("vertical", Keys.W, Keys.S)
            };

            Controls.AxesHandler = axes.ToDictionary(x => x.Name);
            Input.Create(Controls);

            Time = new TimeData();
            VoidTime.Time.Create(Time);

            gameTick = new Timer(16.66667F);

            var planet = new Planet {
                Position = new Vector2D(5000, 5000), DrawingPriority = 1
            };

            map.AddGameObjects(planet, player);
            gameTick.Elapsed += FrameTick;

            player.StartingBattle += StartBattle;
        }
Esempio n. 5
0
        private List <Point> GetChunksCoordinateFromCamera(BasicCamera camera, Size overrun)
        {
            var bottomLeftPoint =
                ChunkCoordinateFromVector(camera.BottomLeft + new Vector2D(-overrun.Width, -overrun.Height));
            var topRightPoint =
                ChunkCoordinateFromVector(camera.TopRight + new Vector2D(overrun.Width, overrun.Height));
            var xMin   = Math.Max(bottomLeftPoint.X, 0);
            var xMax   = Math.Min(topRightPoint.X, MapSizeInChunks.Width - 1);
            var yMin   = Math.Max(bottomLeftPoint.Y, 0);
            var yMax   = Math.Min(topRightPoint.Y, MapSizeInChunks.Height - 1);
            var result = new List <Point>();

            for (var x = xMin; x <= xMax; x++)
            {
                for (var y = yMin; y <= yMax; y++)
                {
                    result.Add(new Point(x, y));
                }
            }
            return(result);
        }
Esempio n. 6
0
 public Controls(BasicCamera camera)
 {
     KeysHandler  = new HashSet <Keys>();
     MouseHandler = new MouseContol(camera);
 }
Esempio n. 7
0
 private void FrameTick(List <GameObject> objectsToDraw, BasicCamera gameBasicCamera)
 {
     drawObjects = (from objectToDraw in objectsToDraw.OrderByDescending(x => x.DrawingPriority)
                    let positionOnDisplay = gameBasicCamera.GamePositionToWindow(objectToDraw.Position)
                                            select new ObjectOnDisplay(objectToDraw, positionOnDisplay)).ToList();
 }
Esempio n. 8
0
 public void ChangeCamera(BasicCamera camera)
 {
     currentCamera = camera;
 }
Esempio n. 9
0
 public MouseContol(BasicCamera camera)
 {
     currentCamera = camera;
 }