Ejemplo n.º 1
0
        public void LoadMap(TiledMap map)
        {
            _collisionSpace = new CollisionComponent(new RectangleF(-1, -1, map.WidthInPixels + 2, map.HeightInPixels + 2));
            // Setup the fake walls
            var leftWall = new DummyCollisionEntity();

            leftWall.Position = new Vector2(-1, -1);
            leftWall.Bounds   = new RectangleF(leftWall.Position.ToPoint(), new Size2(1, map.HeightInPixels + 2));

            var rightWall = new DummyCollisionEntity();

            rightWall.Position = new Vector2(map.WidthInPixels + 1, -1);
            rightWall.Bounds   = new RectangleF(rightWall.Position.ToPoint(), new Size2(1, map.HeightInPixels + 2));

            var topWall = new DummyCollisionEntity();

            topWall.Position = new Vector2(-1, -1);
            topWall.Bounds   = new RectangleF(topWall.Position.ToPoint(), new Size2(map.WidthInPixels + 2, 1));

            var bottomWall = new DummyCollisionEntity();

            bottomWall.Position = new Vector2(-1, map.HeightInPixels + 1);
            bottomWall.Bounds   = new RectangleF(bottomWall.Position.ToPoint(), new Size2(map.WidthInPixels + 2, 1));

            _collisionSpace.Insert(leftWall);
            _collisionSpace.Insert(rightWall);
            _collisionSpace.Insert(topWall);
            _collisionSpace.Insert(bottomWall);
        }
Ejemplo n.º 2
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);
            _gameObjects.ForEach(delegate(GameObject gameObject) { gameObject.LoadContent(Content); });

            _collisionComponent.Insert(_paddle);
            _fieldBoundary.Colliders.ForEach(delegate(ICollisionActor collider) { _collisionComponent.Insert(collider); });
        }
Ejemplo n.º 3
0
        private void SpawnPlayers()
        {
            PlayerOne = entityManager.AddEntity(new Player());
            PlayerTwo = entityManager.AddEntity(new Player());

            Vector2 playerOnePosition = new Vector2(GraphicsDevice.Viewport.TitleSafeArea.X + 50, GraphicsDevice.Viewport.TitleSafeArea.Y + GraphicsDevice.Viewport.TitleSafeArea.Height / 2);
            Vector2 playerTwoPosition = new Vector2(GraphicsDevice.Viewport.TitleSafeArea.X + 200, GraphicsDevice.Viewport.TitleSafeArea.Y + GraphicsDevice.Viewport.TitleSafeArea.Height / 2);

            PlayerOne.Initialize(Content.Load <Texture2D>("player1"), playerOnePosition, new PlayerControls(Keys.Right, Keys.Left, Keys.Up, Keys.Down));
            PlayerTwo.Initialize(Content.Load <Texture2D>("player2"), playerTwoPosition, new PlayerControls(Keys.D, Keys.A, Keys.W, Keys.S));

            collisionComponent.Insert(PlayerOne);
            collisionComponent.Insert(PlayerTwo);
        }
Ejemplo n.º 4
0
        public override void LoadContent()
        {
            base.LoadContent();
            PresentationParameters pp = GraphicsDevice.PresentationParameters;

            lightsRenderTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight);
            mainRenderTarget   = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight);
            lightMask          = Content.Load <Texture2D>("lightmask");
            lightEffect        = Content.Load <Effect>("lighteffect");

            map         = Content.Load <TiledMap>("map");
            mapRenderer = new TiledMapRenderer(GraphicsDevice, map);

            collisionComponent = new CollisionComponent(new RectangleF(-10000, -5000, 20000, 10000));

            var nonBlankTiles = map.TileLayers.FirstOrDefault()?.Tiles.Where(tile => !tile.IsBlank);

            if (nonBlankTiles != null)
            {
                foreach (var mapTile in nonBlankTiles)
                {
                    var stationaryCollisionObject =
                        new StationaryCollisionObject(new Vector2((mapTile.X + 1) * map.TileWidth, (mapTile.Y + 1) * map.TileWidth));
                    collisionComponent.Insert(stationaryCollisionObject);
                    StationaryCollisionObjects.Add(stationaryCollisionObject);
                }
            }


            SpawnPlayers();
        }
Ejemplo n.º 5
0
        private void GenerateTileMap()
        {
            _tiledMap         = _game.Content.Load <TiledMap>("Test");
            _tiledMapRenderer = new TiledMapRenderer(_game.GraphicsDevice, _tiledMap);

            _mapWidth  = _tiledMap.WidthInPixels;
            _mapHeight = _tiledMap.HeightInPixels;

            _collisionComponent = new CollisionComponent(new RectangleF(0, 0, _mapWidth, _mapHeight));

            TiledMapTileLayer collidables = _tiledMap.GetLayer <TiledMapTileLayer>("Collidable");

            if (collidables != null)
            {
                foreach (TiledMapTile t in collidables.Tiles)
                {
                    // Global Identifier 0 means tile is empty
                    if (t.GlobalIdentifier == 0)
                    {
                        continue;
                    }

                    Vector2 pos = Vector2.Zero;

                    pos.X = t.X * collidables.TileWidth;
                    pos.Y = t.Y * collidables.TileHeight;

                    Size2 size = new Size2(collidables.TileWidth, collidables.TileHeight);

                    Wall w = new Wall(pos, size);
                    _collisionComponent.Insert(w);
                }
            }
        }
Ejemplo n.º 6
0
 public T AddEntity <T>(T entity) where T : Entity
 {
     _entities.Add(entity);
     if (entity is ICollisionActor actor)
     {
         _collisionSpace.Insert(actor);
     }
     return(entity);
 }
Ejemplo n.º 7
0
        public void LoadContent()
        {
            GenerateTileMap();
            GenerateHud();
            GeneratePlayer();
            GenerateShipObjects();

            _font = _game.Content.Load <BitmapFont>("GUI/Pixellari");

            foreach (IEntity entity in _entities)
            {
                _collisionComponent.Insert(entity);
            }

            Random rand = new Random();

            _nextEvent  = rand.Next(_minTimer, _maxTimer);
            _brokenList = new StringBuilder().AppendLine("Broken Components:");
        }
Ejemplo n.º 8
0
        public override void Init()
        {
            _collisionComponent = new CollisionComponent(new RectangleF(0, 0, m_game._graphics.GraphicsDevice.Viewport.Width, m_game._graphics.GraphicsDevice.Viewport.Height));

            //Insert Objects
            m_ObjManager.Add(new ObjCube(m_game, "PlayerAnim.sf", new Point2(20, 30), new Point2(300, 16), 1, "Player"));
            m_ObjManager.Add(new ObjGrass(m_game, "grass", new Point2(1000, 32), new Point2(125, 126), 0, "Terrain"));

            //Insert Objects inside CollisionComponent to collision work
            for (int i = 0; i < m_ObjManager.Count; i++)
            {
                _collisionComponent.Insert(m_ObjManager.Objects[i]);
            }

            //Init Objects
            m_ObjManager.Init();
        }
Ejemplo n.º 9
0
        protected override void LoadContent()
        {
            _collisionComponent = new CollisionComponent(new RectangleF(-10000, -5000, 20000, 10000));
            _actors             = new List <DemoActor>();


            _spriteBatch = new SpriteBatch(GraphicsDevice);
            var spikeyBallTexture = Content.Load <Texture2D>("Textures/spike_ball");

            _spikyBallTexture = spikeyBallTexture;

            _blankTexture = new Texture2D(GraphicsDevice, 1, 1);
            _blankTexture.SetData(new[] { Color.WhiteSmoke });

            var spikeyBallRight = new DemoBall(new Sprite(_spikyBallTexture))
            {
                Position = new Vector2(600, 240),
                Velocity = new Vector2(0, 120)
            };

            _actors.Add(spikeyBallRight);

            var controllableBall = new ControllableBall(new Sprite(_spikyBallTexture))
            {
                Position = new Vector2(400, 240),
                Velocity = new Vector2(0, 0)
            };

            _actors.Add(controllableBall);
            _controllableBall = controllableBall;

            var topWall = new DemoWall(new Sprite(_blankTexture))
            {
                Bounds   = new RectangleF(0, 0, 800, 20),
                Position = new Vector2(0, 0)
            };

            _actors.Add(topWall);

            var bottomWall = new DemoWall(new Sprite(_blankTexture))
            {
                Position = new Vector2(0, 460),
                Bounds   = new RectangleF(0, 0, 800, 20)
            };

            _actors.Add(bottomWall);

            var spikeyBallCenter = new StationaryBall(new Sprite(_spikyBallTexture))
            {
                Position = new Vector2(400, 240),
                Velocity = Vector2.Zero,
            };

            _actors.Add(spikeyBallCenter);

            foreach (var actor in _actors)
            {
                _collisionComponent.Insert(actor);
            }

            base.LoadContent();
        }
Ejemplo n.º 10
0
        public void PenetrationVectorSameCircleTest()
        {
            Point2 pos1 = Point2.Zero;
            Point2 pos2 = Point2.Zero;

            IShapeF shape1 = new CircleF(pos1, 2.0f);
            IShapeF shape2 = new CircleF(pos2, 2.0f);

            var actor1 = new BasicActor()
            {
                Position = pos1,
                Bounds   = shape1
            };
            var actor2 = new BasicWall()
            {
                Position = pos2,
                Bounds   = shape2
            };

            Assert.True(shape1.Intersects(shape2));
            collisionComponent.Insert(actor1);
            collisionComponent.Insert(actor2);
            collisionComponent.Update(_gameTime);
            Assert.True(Math.Abs(actor1.Position.Y - -4f) < float.Epsilon);
        }