Ejemplo n.º 1
0
        public void Draw(GameTime gameTime, SpriteBatch sb, Player player)
        {
            Single depth = 0;
             for (int i = 0; i < map.LayerOrder.Length; i++)
             {
            LayerInfo li = map.LayerOrder[i];
            if (li.LayerType == LayerType.TileLayer)
               map.DrawLayer(sb, map.LayerOrder[i].ID, map.Bounds, depth);
            if (li.LayerType == LayerType.ObjectLayer)
               map.DrawObjectLayer(sb, map.LayerOrder[i].ID, map.Bounds, depth);

             }

             //map.DrawObjectLayer(sb, 0, map.Bounds, 0);
        }
Ejemplo n.º 2
0
        public void Apply(GameTime gt, Player player, Level level)
        {
            float dt = gt.ElapsedGameTime.Milliseconds / 1000f;

             player.velocity.Y += Constants.gravity * dt;

             Box endBox = new Box(player.collision) ;

             float dx = player.velocity.X * dt;
             float dy = player.velocity.Y * dt;

             Rectangle checkRect ;

             IEnumerable<MapObject> collideObjects;

             if (dx != 0)
             {
            endBox.Left += dx;
            checkRect = endBox.rect;
            checkRect.Inflate(1, 1);
            collideObjects = level.map.GetObjectsInRegion(level.collisionLayer, checkRect);

            foreach (var obj in collideObjects)
            {
               Vector2 delta = adjustPos(ref endBox, obj, Axis.X);
               endBox.pos += delta;
            }
             }

             endBox.Top += dy;

             checkRect = endBox.rect;
             checkRect.Inflate(1, 1);
             collideObjects = level.map.GetObjectsInRegion(level.collisionLayer, checkRect);

             foreach (var obj in collideObjects)
             {
            Vector2 delta = adjustPos(ref endBox, obj, Axis.Y);
            endBox.pos -= delta;
            if (delta.Y != 0)
            {
               player.velocity.Y = 0;
               if (delta.Y > 0) player.grounded = true;
            }
             }

             player.pos = endBox.pos;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            physics = new Physics();
             player = new Player();

             currentKeyboardState = new KeyboardState();
             previousKeyboardState = new KeyboardState();

             camera = new Camera2D(player);
             camera.pos = new Vector2(500f, 200f);
             camera.zoom = 1f;
             camera.fixY(450f);

             background = new ParallaxBackground();
             currentLevel = new Level(this);

             base.Initialize();
        }