Ejemplo n.º 1
0
 public void AddParallax(Background bgnd)
 {
     this.BackgroundList.Add(bgnd);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Load the level file into the game world
        /// </summary>
        /// <param name="levelFile"></param>
        public void LoadLevel(string levelFile)
        {
            using (var sr = new StreamReader(levelFile))
            {
                string line = sr.ReadLine();

                string[] levelSizeItems = line.Split(new char[] { ',' });

                //size of the level

                LevelSize.Width = Convert.ToInt32(levelSizeItems[0]);
                LevelSize.Height = Convert.ToInt32(levelSizeItems[1]);
                LevelDepth = Convert.ToInt32(levelSizeItems[0]);

                Bitmap temp;
                Color transparentColour;

                line = sr.ReadLine();
                while (line != ENDGRAPHICS)
                {
                    levelSizeItems = line.Split(new char[] { ',' });

                    temp = new Bitmap("images\\" + levelSizeItems[1]);

                    int r = Convert.ToInt32(levelSizeItems[2]);
                    int g = Convert.ToInt32(levelSizeItems[3]);
                    int b = Convert.ToInt32(levelSizeItems[4]);
                    transparentColour = Color.FromArgb(r, g, b);

                    temp.MakeTransparent(transparentColour);

                    //image name name, bitmap
                    GraphicLibrary.Add(levelSizeItems[0], temp);

                    line = sr.ReadLine();
                }

                bool vertical = false;
                line = sr.ReadLine();
                while (line != ENDANIMATIONS)
                {
                    levelSizeItems = line.Split(new char[] { ',' });

                    vertical = levelSizeItems[7] == "Y";

                    var oname = levelSizeItems[0];
                    var image = levelSizeItems[1];
                    var local = new Point(Convert.ToInt32(levelSizeItems[2]), Convert.ToInt32(levelSizeItems[3]));
                    var size = new Size(Convert.ToInt32(levelSizeItems[4]), Convert.ToInt32(levelSizeItems[5]));
                    int numFrames = Convert.ToInt32(levelSizeItems[6]);

                    var go = new GraphicObject(image, size, local, numFrames, vertical);

                    GraphicObjects.Add(oname, go);

                    line = sr.ReadLine();
                }

                Background tmpBgnd;
                line = sr.ReadLine();
                while (line != ENDBACKGROUNDS)
                {
                    string map = sr.ReadLine();

                    tmpBgnd = new Background(line, map);

                    Background.AddParallax(tmpBgnd);

                    line = sr.ReadLine();
                }

                // Next the bump map
                line = sr.ReadLine();

                levelSizeItems = line.Split(new char[] { ',' });

                BumpMapSize.X = Convert.ToInt32(levelSizeItems[0]);
                BumpMapSize.Y = Convert.ToInt32(levelSizeItems[1]);

                int width = LevelSize.Width / BumpMapSize.X;
                int height = LevelSize.Height / BumpMapSize.Y;
                BumpMap = new int[width, height];

                var gridTransfer = new Point(width, height);
                var gridPosition = new Point(0, 0);

                int bump = 0;
                while (gridPosition.Y < gridTransfer.Y) // intuitivo
                {
                    while (gridPosition.X < gridTransfer.X)
                    {
                        if (levelSizeItems[2][bump] == '0')
                            BumpMap[gridPosition.X, gridPosition.Y] = 0;
                        else
                            BumpMap[gridPosition.X, gridPosition.Y] = 1;

                        bump++;
                        gridPosition.X++;
                    }

                    gridPosition.X = 0;
                    gridPosition.Y++;
                }

                // Next the objects
                line = sr.ReadLine();

                while (line != ENDOBJECTS)
                {
                    levelSizeItems = line.Split(new char[] { ',' });

                    if (levelSizeItems.Length == 17)
                    {
                        var objType = levelSizeItems[0];

                        var animTopLeft = levelSizeItems[1];
                        var animTop = levelSizeItems[2];
                        var animTopRight = levelSizeItems[3];
                        var animLeft = levelSizeItems[4];
                        var animStay = levelSizeItems[5];
                        var animRight = levelSizeItems[6];

                        var animBottomLeft = levelSizeItems[7];
                        var animBottom = levelSizeItems[8];
                        var animBottomRight = levelSizeItems[9];

                        var x = levelSizeItems[10];
                        var y = levelSizeItems[11];
                        var z = levelSizeItems[12];
                        var spx = levelSizeItems[13];
                        var spy = levelSizeItems[14];
                        var spz = levelSizeItems[15];
                        var ghost = levelSizeItems[16];

                        var go = new GameObject(objType, animTopLeft, animTop, animTopRight, animLeft, animStay, animRight, animBottomLeft, animBottom, animBottomRight, x, y, z, spx, spy, spz, ghost);
                        WorldObjects.Add(go);
                    }
                    else
                    {
                        var objType = levelSizeItems[0];

                        var animStay = levelSizeItems[1];

                        var x = levelSizeItems[2];
                        var y = levelSizeItems[3];
                        var z = levelSizeItems[4];
                        var spx = levelSizeItems[5];
                        var spy = levelSizeItems[6];
                        var spz = levelSizeItems[7];
                        var ghost = levelSizeItems[8];

                        var go = new GameObject(objType, animStay, x, y, z, spx, spy, spz, ghost);
                        WorldObjects.Add(go);
                    }

                    line = sr.ReadLine();
                }

                // CAMERAS
                line = sr.ReadLine();
                while (line != ENDCAMERAS)
                {
                    levelSizeItems = line.Split(new char[] { ',' });

                    var camType = CameraType.Standard;

                    if (levelSizeItems[6] == "L")
                        camType = CameraType.Left3D;
                    else if (levelSizeItems[6] == "R")
                        camType = CameraType.Right3D;

                    var resolution = new Size(Convert.ToInt32(levelSizeItems[0]), Convert.ToInt32(levelSizeItems[1]));
                    var drawLocation = new Rectangle(Convert.ToInt32(levelSizeItems[2]), Convert.ToInt32(levelSizeItems[3]), Convert.ToInt32(levelSizeItems[4]), Convert.ToInt32(levelSizeItems[5]));

                    var camera = new Camera(resolution, drawLocation, camType);

                    WorldCameras.Add(camera);
                }
            }
        }