private static void HandleBlock(Block b) { if (b.IsMoveable) { Vector2 newPos = b.Position + GetDirection(); if (!OutOfBounds(newPos)) { if (map.GetIndex(newPos) != 1) { b.Push(GetDirection()); map.SetIndex(LayerType.Collision, (int)b.Position.X, (int)b.Position.Y, 0); map.SetIndex(LayerType.Collision, (int)(b.Position.X + GetDirection().X), (int)(b.Position.Y + GetDirection().Y), 1); } } } }
public static void Load(ContentManager cm) { if (map != null) map.Reset(); MapContentManager = cm; map = MapContentManager.Load<Map>("Maps/Start"); font = MapContentManager.Load<SpriteFont>("Arial"); boxTexture = MapContentManager.Load<Texture2D>("Textures/tile"); Map.CollisionTexture = MapContentManager.Load<Texture2D>("Textures/collision"); Map.BlockTexture = MapContentManager.Load<Texture2D>("Textures/block"); Block b = new Block(); b.Position = new Vector2(5, 4); b.Size = new Vector2(32, 32); b.IsMoveable = true; map.Blocks.Add(b); map.SetIndex(LayerType.Collision, (int)b.Position.X, (int)b.Position.Y, 1); player = new Player(); Player.Load(MapContentManager, "Textures/Player"); Player.Position = new Vector2(64, 64); fadeIn = true; fadeTexture = MapContentManager.Load<Texture2D>("Textures/fade"); }