Exemple #1
0
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     // Create a new SpriteBatch, which can be used to draw textures.
     _spriteBatch = new SpriteBatch(GraphicsDevice);
     _gameWorld = new GameWorld(this);
     _gameWorld.Setup();
 }
Exemple #2
0
 public Crate(GameWorld gameWorld)
     : base(gameWorld, "crate")
 {
     Body = BodyFactory.CreateRectangle(World, ConvertUnits.ToSimUnits(CrateSize), ConvertUnits.ToSimUnits(CrateSize), 2f, bodyType: BodyType.Dynamic);
     Body.Friction = 0.7f; // Add friciton to it will stick on slopes
     Body.Restitution = 0.01f; // The crates shouldn't bounce
 }
Exemple #3
0
 public LandingZone(GameWorld gameWorld, Rectangle target)
     : base(gameWorld, "landing_zone")
 {
     _target = target;
     Body = BodyFactory.CreateRectangle(World, ConvertUnits.ToSimUnits(target.Width), ConvertUnits.ToSimUnits(target.Height), 1f);
     Body.OnCollision += OnCollision;
     Position = new Vector2(target.X, target.Y);
 }
Exemple #4
0
        protected GameObject(GameWorld gameWorld, string textureName)
        {
            _gameWorld = gameWorld;
            SpriteBatch = gameWorld.SpriteBatch;
            Texture = gameWorld.Content.Load<Texture2D>(textureName);

            _world = gameWorld.World;
            _rectangle = new Rectangle(0, 0, Texture.Width, Texture.Width);
        }
Exemple #5
0
        public Ufo(GameWorld gameWorld)
            : base(gameWorld, "ufo")
        {
            _gameInput = gameWorld.GameInput;
            _chainLinkTexture = gameWorld.Content.Load<Texture2D>("chain_link");
            _chainBallTexture = gameWorld.Content.Load<Texture2D>("chain_ball");

            var body = CreateUfoBody();
            AddBallAndChain(body);

            Body = body;
            Body.OnCollision += OnCollision;
        }
Exemple #6
0
        public CaveWall(GameWorld gameWorld, string textureName)
            : base(gameWorld, textureName)
        {
            // Read the texture data
            var textureData = new uint[Texture.Width * Texture.Height];
            Texture.GetData(textureData);

            // Detect an outline of the texture
            var outline = PolygonTools.CreatePolygon(textureData, Texture.Width);

            // Scale the outline so that it fits the size of my game world
            var scaleVector = ConvertUnits.ToSimUnits(2, 2);
            outline.Scale(scaleVector);

            // Simplify the outline to remove redundant points
            outline = SimplifyTools.CollinearSimplify(outline);

            // Decompose the outline into polygons
            var decomposed = BayazitDecomposer.ConvexPartition(outline);

            // Create the body for the game world
            Body = BodyFactory.CreateCompoundPolygon(World, decomposed, 1f);
        }