Ejemplo n.º 1
0
    public ObjectMap(string pathToMap, int w, int h) : base(pathToMap, w, h)
    {
        Dictionary <string, LinkedList <string> > mapXML = Utils.GetXMLEntriesHash(pathToMap);
        Dictionary <string, LinkedList <string> > objectXML;

        try
        {
            // load the objects.
            objectXML = Utils.GetXMLEntriesHash(Path.GetDirectoryName(pathToMap) + @"\" + mapXML["object"].First.Value);
        }
        catch
        {
            Utils.Log("ObjectMap " + pathToMap + " failed to load object XML properly");
            return;
        }

        objectRows = new LinkedList <AD2Object> [BaseMap.Height];
        for (int i = 0; i != BaseMap.Height; i++)
        {
            objectRows[i] = new LinkedList <AD2Object>();
        }

        // try
        {
            LinkedList <string>            allObjects   = objectXML["object"];
            Dictionary <string, Texture2D> textureCache = new Dictionary <string, Texture2D>();

            foreach (string s in allObjects)
            {
                string[]  param = s.Split(',');
                AD2Object a     = new AD2Object();
                param[0] = Path.GetDirectoryName(pathToMap) + "\\objects\\" + param[0];
                a.X      = Int32.Parse(param[1]);
                a.Y      = Int32.Parse(param[2]);
                if (!textureCache.ContainsKey(param[0]))
                {
                    textureCache[param[0]] = Utils.TextureLoader(param[0]);
                }
                a.t = textureCache[param[0]];

                objectRows[a.Y + (a.t.Height - 1)].AddFirst(a);
            }
        }
        // catch (Exception e)
        {
            //     Utils.Log("Some objects failed to load");

            //     return;
        }
    }
Ejemplo n.º 2
0
    public ObjectMap(string pathToMap, int w, int h)
        : base(pathToMap,w,h)
    {
        Dictionary<string, LinkedList<string>> mapXML = Utils.GetXMLEntriesHash(pathToMap);
        Dictionary<string, LinkedList<string>> objectXML;

        try
        {
            // load the objects.
            objectXML = Utils.GetXMLEntriesHash(Path.GetDirectoryName(pathToMap) + @"\" + mapXML["object"].First.Value);
        }
        catch
        {
            Utils.Log("ObjectMap " + pathToMap + " failed to load object XML properly");
            return;
        }

        objectRows = new LinkedList<AD2Object>[BaseMap.Height];
        for(int i = 0; i != BaseMap.Height; i++)
        {
            objectRows[i] = new LinkedList<AD2Object>();
        }

           // try
        {
            LinkedList <string> allObjects = objectXML["object"];
            Dictionary<string, Texture2D> textureCache = new Dictionary<string, Texture2D>();

            foreach(string s in allObjects)
            {
                string[] param = s.Split(',');
                AD2Object a = new AD2Object();
                param[0] = Path.GetDirectoryName(pathToMap) + "\\objects\\" + param[0];
                a.X = Int32.Parse(param[1]);
                a.Y = Int32.Parse(param[2]);
                if (!textureCache.ContainsKey(param[0]))
                    textureCache[param[0]] = Utils.TextureLoader(param[0]);
                a.t = textureCache[param[0]];

                objectRows[a.Y + (a.t.Height - 1)].AddFirst(a);
            }
        }
           // catch (Exception e)
        {
           //     Utils.Log("Some objects failed to load");

           //     return;
        }
    }
Ejemplo n.º 3
0
    protected override void AD2Logic(int ms, KeyboardState keyboardState, SlimDX.DirectInput.JoystickState[] gamePadState)
    {
        mouseX = Mouse.GetState().X;
        mouseY = Mouse.GetState().Y;


        //Minus = object left
        if (keyboardState.IsKeyDown(Keys.OemMinus) && genericNewKey)
        {
            if (putPointer == 0)
            {
                putPointer = TextureList.Length - 1;
            }
            else
            {
                putPointer = putPointer - 1;
            }
        }

        //Plus = object forward
        if (keyboardState.IsKeyDown(Keys.OemPlus) && genericNewKey)
        {
            putPointer = (putPointer + 1) % TextureList.Length;
        }

        //Click = place or erase object.
        if (Mouse.GetState().LeftButton == ButtonState.Pressed && !newMouseLeft)
        {
            if (putMode)
            {
                AD2Object a = new AD2Object();
                a.X       = camX + mouseX;
                a.Y       = camY + mouseY;
                a.t       = TextureList[putPointer];
                a.collide = CollideTextureList[putPointer];
                a.name    = TextureName[putPointer];
                //Where is the bottom?
                if (collide(0, 0, baseMap.Width, baseMap.Height, a.X, a.Y))
                {
                    objectsList[a.Y + (a.t.Height - 1)].AddFirst(a);
                }
            }
            else
            {
                for (int i = 0; i != objectsList.Length; i++)
                {
                    LinkedList <AD2Object> removeList = new LinkedList <AD2Object>();

                    foreach (AD2Object a in objectsList[i])
                    {
                        if (collide(a.X, a.Y, a.t.Width, a.t.Height, camX + mouseX, camY + mouseY))
                        {
                            removeList.AddFirst(a);
                        }
                    }

                    foreach (AD2Object a in removeList)
                    {
                        objectsList[i].Remove(a);
                    }
                }
            }
        }


        // mode switch
        if (Mouse.GetState().RightButton == ButtonState.Pressed && !newMouseRight)
        {
            putMode = !putMode;
        }

        if (keyboardState.IsKeyDown(Keys.F1) && genericNewKey)
        {
            generateNew();
        }

        if (keyboardState.IsKeyDown(Keys.F2) && genericNewKey)
        {
            LevelIO.Save(this);
        }

        if (keyboardState.IsKeyDown(Keys.F3) && genericNewKey)
        {
            loadNew();
        }


        if (keyboardState.IsKeyDown(Keys.C) && genericNewKey)
        {
            objectsCanCollide = !objectsCanCollide;
        }

        if (keyboardState.IsKeyDown(Keys.V) && genericNewKey)
        {
            switch (Viewmode)
            {
            case Viewmodes.Collide:
                Viewmode = Viewmodes.Object;
                break;

            case Viewmodes.FiftyPercent:
                Viewmode = Viewmodes.Collide;
                break;

            case Viewmodes.Object:
                Viewmode = Viewmodes.FiftyPercent;
                break;
            }
        }

        newMouseLeft  = Mouse.GetState().LeftButton == ButtonState.Pressed;
        newMouseRight = Mouse.GetState().RightButton == ButtonState.Pressed;
        genericNewKey = keyboardState.GetPressedKeys().Length == 0;


        if (mouseX < BaseWidth * TRANSITION_AREA)
        {
            camX -= SCROLL_SPEED;
        }
        if (mouseX > BaseWidth * (1.0 - TRANSITION_AREA))
        {
            camX += SCROLL_SPEED;
        }

        if (mouseY < BaseHeight * TRANSITION_AREA)
        {
            camY -= SCROLL_SPEED;
        }
        if (mouseY > BaseHeight * (1.0 - TRANSITION_AREA))
        {
            camY += SCROLL_SPEED;
        }
    }
Ejemplo n.º 4
0
    public void loadNew()
    {
        // Load a new map, but this time, for the objects, read the object XML and put it in.
        System.Windows.Forms.OpenFileDialog baseMapD = new System.Windows.Forms.OpenFileDialog();
        baseMapD.Title = "Select the Base Map";
        baseMapD.ShowDialog();

        System.Windows.Forms.OpenFileDialog collideMapD = new System.Windows.Forms.OpenFileDialog();
        collideMapD.Title = "Select the Collide Map";
        collideMapD.ShowDialog();

        System.Windows.Forms.FolderBrowserDialog folderBrowserD = new System.Windows.Forms.FolderBrowserDialog();
        folderBrowserD.Description = "Select the folder containing the objects WITH collision";
        folderBrowserD.ShowDialog();

        System.Windows.Forms.OpenFileDialog objectxmlD = new System.Windows.Forms.OpenFileDialog();
        objectxmlD.Title = "Select the Object.XML";
        objectxmlD.ShowDialog();

        // Process input if the user clicked OK.
        baseMap     = Utils.TextureLoader(baseMapD.FileName, false);
        collideMap  = Utils.TextureLoader(collideMapD.FileName, false);
        objectsList = new LinkedList <AD2Object> [baseMap.Height];
        for (int i = 0; i != baseMap.Height; i++)
        {
            objectsList[i] = new LinkedList <AD2Object>();
        }

        //Default: go to utils.
        objectDirectory = folderBrowserD.SelectedPath;
        string[] files = Directory.GetFiles(objectDirectory);

        TextureName        = new string[files.Length];
        TextureList        = new Texture2D[files.Length];
        CollideTextureList = new Texture2D[files.Length];

        for (int i = 0; i != files.Length; i++)
        {
            TextureName[i]        = Path.GetFileName(files[i]);
            TextureList[i]        = Utils.TextureLoader(objectDirectory + "\\" + Path.GetFileName(files[i]), false);
            CollideTextureList[i] = Utils.TextureLoader(objectDirectory + "\\collide\\" + Path.GetFileName(files[i]), false);
        }

        Dictionary <string, LinkedList <string> > objsInPlace = Utils.GetXMLEntriesHash(objectxmlD.FileName, false);

        foreach (string obj in objsInPlace["object"])
        {
            AD2Object newObj = new AD2Object();
            string[]  args   = obj.Split(',');
            newObj.name = args[0];
            newObj.X    = Int32.Parse(args[1]);
            newObj.Y    = Int32.Parse(args[2]);
            for (int i = 0; i != TextureName.Length; i++)
            {
                if (newObj.name.Equals(TextureName[i]))
                {
                    newObj.t       = TextureList[i];
                    newObj.collide = CollideTextureList[i];
                    break;
                }
            }
            objectsList[newObj.Y + (newObj.t.Height - 1)].AddFirst(newObj);
        }
    }