Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Drawing;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework;
- using FarseerPhysics.Dynamics;
- using System.IO;
- namespace Platform.Levels
- {
- class LevelLoader
- {
- delegate GameComponent AddFunction(Game1 game, SpriteBatch spriteBatch, World world, int x, int y);
- private static Dictionary<int, AddFunction> Environment= new Dictionary<int, AddFunction>
- {
- {255, (g, sB, w, x, y) => {return new Block(g, sB, w, x * 32, y * 32, BlockType.STONE);}},
- {205, (g, sB, w, x, y) => {return new Block(g, sB, w, x * 32, y * 32, BlockType.BOX);}}
- };
- public static Level LoadLevel(string name, Game1 game, SpriteBatch spriteBatch)
- {
- Level level = new Level(game, spriteBatch);
- Bitmap levelBmp = (Bitmap)Bitmap.FromFile(Directory.GetCurrentDirectory() + "\\" + name + ".png");
- for (int y = 0; y < levelBmp.Height; y++)
- {
- for (int x = 0; x < levelBmp.Width; x++)
- {
- var pixel = levelBmp.GetPixel(x, y);
- if (pixel.R > 0)
- {
- }
- else if (pixel.G > 0)
- {
- try
- {
- level.AddComponent(Environment[pixel.G](game, spriteBatch, level.world, x, y));
- }
- catch (Exception)
- {
- }
- }
- else if (pixel.B > 0)
- {
- }
- }
- }
- return level;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment