示例#1
0
 public EditorMover(main main, EditorLevel editor)
 {
     this.main     = main;
     this.location = new Point(1000, 950);
     this.controls = main.getSettings().getControls();
     this.editor   = editor;
 }
示例#2
0
 public EditorLevel(main main) : base(main)
 {
     setCamera(Camera.FollowMode.GLUED);
     mover = new EditorMover(main, this);
     camera.setTarget(mover);
     controls = main.getSettings().getControls();
 }
示例#3
0
        public Level(main main)
        {
            // should only be called by EditorLevel
            players = new List <Player>()
            {
                new Player(main.getSettings().getControlMode())
            };

            platforms = new List <Platform>()
            {
                new Platform(new Point(1000, 1000), 200),
                new Platform(new Point(1000, 800), 200)
            };

            foreach (Player p in players)
            {
                p.setLevel(this);
            }

            Sentry s = new Sentry(Sentry.Type.PUSH, 6);

            s.setPlatform(platforms.ElementAt(1));
            s.setLevel(this);

            sentries = new List <Sentry>()
            {
                s
            };

            this.animations = new List <Animation>();
            this.background = Render.initialBackground();
            this.camera     = new Camera(Camera.FollowMode.STEADY);
            this.main       = main;
        }
示例#4
0
        public static Level fromEditor(EditorLevel editor, main main)
        {
            List <Player> playersCopy = new List <Player>();

            foreach (Player p in editor.getPlayers())
            {
                playersCopy.Add(new Player());
            }

            Player[] players = playersCopy.ToArray();

            List <Platform> ps = new List <Platform>();

            foreach (Platform p in editor.getPlatforms())
            {
                ps.Add(new Platform(p.getLocation(), p.getWidth()));
            }
            Platform[] platforms = ps.ToArray();

            List <Sentry> ss = new List <Sentry>();

            foreach (Sentry s in editor.getSentries())
            {
                ss.Add(new Sentry(s.getType(),
                                  s.getDirection() * s.getSpeed(), s.getSecondary()));
            }
            Sentry[] sentries = ss.ToArray();

            int[] key = new int[sentries.Length];

            for (int i = 0; i < key.Length; i++)
            {
                key[i] = editor.getPlatforms().IndexOf(
                    editor.getSentries().ElementAt(i).getPlatform());
            }

            return(new Level(players, platforms, sentries, key,
                             main.getSettings().getFollowMode(), main,
                             editor.name, editor.note));
        }
示例#5
0
        public static Level fetchLevel(String id, int playerc,
                                       Camera.FollowMode followMode, main main)
        {
            Debug.Assert(playerc == 1 || playerc == 2);

            Player[]   players;
            Platform[] platforms = new Platform[] { new Platform(new Point(1000, 1000), 200) };
            Sentry[]   sentries  = new Sentry[] { };
            int[]      key       = new int[] { };

            if (playerc == 2)
            {
                players = new Player[] { new Player(main.getSettings().getControlMode()),
                                         new Player((GameSettings.ControlMode)(1 -
                                                                               (int)main.getSettings().getControlMode())) };
            }
            else
            {
                players = new Player[] { new Player(main.getSettings().getControlMode()) };
            }

            switch (id)
            {
            case "staircase1":
                platforms = new Platform[] {
                    new Platform(new Point(1000, 1000), 200),
                    new Platform(new Point(800, 900), 200),
                    new Platform(new Point(1200, 800), 200),
                    new Platform(new Point(800, 700), 200),
                    new Platform(new Point(1200, 600), 200),
                    new Platform(new Point(800, 500), 200)
                };
                sentries = new Sentry[] {
                    new Sentry(Sentry.Type.PUSH, 10),
                    new Sentry(Sentry.Type.SPAWN, -10),
                    new Sentry(Sentry.Type.RANDOM, 14)
                };
                key = new int[] { 1, 2, 4 };
                break;

            case "behemoth":
                platforms = new Platform[] {
                    new Platform(new Point(1100, 1250), 100),
                    new Platform(new Point(700, 1150), 200),
                    new Platform(new Point(1150, 1075), 100),
                    new Platform(new Point(1000, 1000), 150),
                    new Platform(new Point(650, 1000), 200),
                    new Platform(new Point(1350, 1000), 150),
                    new Platform(new Point(850, 925), 100),
                    new Platform(new Point(1300, 850), 200),
                    new Platform(new Point(900, 750), 100)
                };
                sentries = new Sentry[] {
                    new Sentry(Sentry.Type.GRAV_DOUBLE, 10),
                    new Sentry(Sentry.Type.MOVE, 14),
                    new Sentry(Sentry.Type.GRAV_INC, 10),
                    new Sentry(Sentry.Type.GRAV_RED, -10),
                    new Sentry(Sentry.Type.GRAV_FLIP, -10),
                    new Sentry(Sentry.Type.PULL, 12)
                };
                key = new int[] { 1, 3, 4, 5, 7, 8 };
                break;

            case "Take Flight":
                platforms = new Platform[] {
                    new Platform(new Point(1100, 1250), 100),
                    new Platform(new Point(700, 1150), 200),
                    new Platform(new Point(2000, 1000), 150)
                };
                sentries = new Sentry[] {
                    new Sentry(Sentry.Type.GRAV_DOUBLE, 10),
                    new Sentry(Sentry.Type.DECAY, 14)
                };
                key = new int[] { 1, 2 };
                break;

            default:
                String file = "../../Resources/" + id + ".txt";
                return(readFromFile(file, players, followMode, main));
            }
            return(new Level(players, platforms, sentries, key, followMode, main));
        }
示例#6
0
        public void doTask()
        {
            if (task != Task.TYPE)
            {
                frame.setIsTyping(false);
            }
            switch (task)
            {
            case Task.UNPAUSE:
                main.unpause();
                break;

            case Task.SET_MODE:
                Mode mode;
                Enum.TryParse(set, out mode);
                main.setMode(mode);
                break;

            case Task.CLOSE:
                main.Close();
                break;

            case Task.SET_PAUSE:
                if (main.getMode() != Mode.PAUSE)
                {
                    main.setMode(Mode.PAUSE);
                }
                main.setPauseFrame(set);
                break;

            case Task.SET_MENU:
                if (main.getMode() != Mode.MENU)
                {
                    main.setMode(Mode.MENU);
                }
                main.setMenuFrame(set);
                break;

            case Task.SWITCH_CONTROLS:
                main.getSettings().switchControlMode();
                List <Player> players = main.getLevel().getPlayers();
                players[0].setControls(
                    main.getSettings().getControlMode());

                if (players.Count > 1)
                {
                    players[1].setControls(1 -
                                           main.getSettings().getControlMode());
                }

                main.refreshPauseFrame();
                break;

            case Task.SWITCH_FOLLOW:
                main.getSettings().switchFollowMode(Int32.Parse(set));
                main.getLevel().setCamera(
                    main.getSettings().getFollowMode());
                main.refreshPauseFrame();
                break;

            case Task.SWITCH_PERIOD:
                main.getSettings().switchPeriod(Int32.Parse(set));
                main.applySettings();
                main.refreshPauseFrame();
                break;

            case Task.SWITCH_WINDOW:
                main.getSettings().switchWindowMode();
                main.applySettings();
                main.refreshPauseFrame();
                break;

            case Task.SWITCH_HUD:
                main.getSettings().switchHUDStatus();
                main.applySettings();
                main.refreshPauseFrame();
                break;

            case Task.TYPE:
                frame.setIsTyping(!frame.getIsTyping());
                break;

            case Task.SAVE_EDITOR:
                main.launchSaveEditor();
                break;
            }
        }
示例#7
0
        public bool update(Cause cause, MouseEventArgs m, KeyEventArgs k)
        {
            // null m XOR k if the cause isn't relevant
            switch (cause)
            {
            case Cause.MOUSE_MOVE:
                for (int i = 0; i < objects.Length; i++)
                {
                    int  x   = (int)(m.X * (1280 / (float)main.getSize().Width));
                    int  y   = (int)(m.Y * (720 / (float)main.getSize().Height));
                    bool val = objects[i].isHovering(new Point(x, y));

                    selVector[i] = val;
                    objects[i].setSelect(val);
                }
                break;

            case Cause.KEY_PRESS:
                // SET CONTROLS
                Keys[] controls = main.getSettings().getControls();
                Keys[] up       = new Keys[] { controls[0], Keys.Up };
                Keys[] down     = new Keys[] { controls[1], Keys.Down };
                Keys[] left     = new Keys[] { controls[2], Keys.Left };
                Keys[] right    = new Keys[] { controls[3], Keys.Right };

                // FIND SELECTED
                int selected = -1;
                for (int i = 0; i < objects.Length; i++)
                {
                    if (selVector[i])
                    {
                        selected = i;
                        break;
                    }
                }

                if (selected == -1)
                {
                    bool assignedSel = false;

                    for (int i = 0; i < objects.Length; i++)
                    {
                        if (objects[i].canBeSelected() && !assignedSel)
                        {
                            selVector[i]     = true;
                            lastSelVector[i] = true;
                            objects[i].setSelect(true);
                            assignedSel = true;
                        }
                        else
                        {
                            selVector[i]     = false;
                            lastSelVector[i] = false;
                            objects[i].setSelect(false);
                        }
                    }
                    return(true);
                }

                int    candIndex       = selected;
                double closestDistance = Double.MaxValue;

                for (int i = 0; i < objects.Length; i++)
                {
                    if (i != selected && objects[i].canBeSelected())
                    {
                        Point old       = objects[selected].getLocation();
                        Point cand      = objects[i].getLocation();
                        bool  direction = false;
                        // Principal direction
                        if (k.KeyCode == up[0] || k.KeyCode == up[1])
                        {
                            // UP
                            direction = cand.Y < old.Y;
                            //direction = cand.Y < old.Y &&
                            //    Math.Abs(cand.Y - old.Y) >
                            //    Math.Abs(cand.X - old.X);
                        }
                        else if (k.KeyCode == down[0] ||
                                 k.KeyCode == down[1])
                        {
                            // DOWN
                            direction = cand.Y > old.Y;
                            //direction = cand.Y > old.Y &&
                            //    Math.Abs(cand.Y - old.Y) >
                            //    Math.Abs(cand.X - old.X);
                        }
                        else if (k.KeyCode == left[0] ||
                                 k.KeyCode == left[1])
                        {
                            // LEFT
                            direction = cand.X < old.X;
                            //direction = cand.X < old.X &&
                            //    Math.Abs(cand.Y - old.Y) <
                            //    Math.Abs(cand.X - old.X);
                        }
                        else if (k.KeyCode == right[0] ||
                                 k.KeyCode == right[1])
                        {
                            // RIGHT
                            direction = cand.X > old.X;
                            //direction = cand.X > old.X &&
                            //    Math.Abs(cand.Y - old.Y) <
                            //    Math.Abs(cand.X - old.X);
                        }

                        if (direction &&
                            MathExt.Distance(old, cand) < closestDistance)
                        {
                            candIndex       = i;
                            closestDistance = MathExt.Distance(old, cand);
                        }
                    }
                }

                if (candIndex != selected)
                {
                    for (int i = 0; i < selVector.Length; i++)
                    {
                        selVector[i] = (i == candIndex);
                        objects[i].setSelect(i == candIndex);
                    }
                }

                break;
            }

            bool different = false;

            for (int i = 0; i < selVector.Length; i++)
            {
                different |= (selVector[i] != lastSelVector[i]);
                // Safe as index has already been compared
                lastSelVector[i] = selVector[i];
            }

            return(different);
        }
示例#8
0
        public static MenuFrame fromString(String s, main main)
        {
            MenuObject[] pauseObjs;

            // for ordered stuff
            int mid    = 360;
            int unit   = 80;
            int offset = 30;

            // for two column setups
            int lc = 480;
            int rc = 800;

            switch (s.ToLower())
            {
            case "main":
                mid  = 360;
                unit = 100;
                MenuObject[] menuObjs = new MenuObject[] {
                    new MenuObject(new Point(640, 100),
                                   Resources.t3logo_664_164, main),
                    new MenuObject(true, "PLAY", 4, new Point(640, mid - unit),
                                   MenuObject.Task.SET_MODE, "GAME", main),
                    new MenuObject(true, "MY CONTENT", 4, new Point(640, mid),
                                   MenuObject.Task.SET_MENU, "my-content", main),
                    new MenuObject(true, "<TODO>", 4, new Point(640, mid + unit),
                                   MenuObject.Task.SET_MENU, "settings-main", main),
                    new MenuObject(true, "QUIT", 4, new Point(640, mid + (2 * unit)),
                                   MenuObject.Task.CLOSE, null, main)
                };
                return(new MenuFrame(menuObjs, main));

            case "my-content":
                mid      = 360;
                unit     = 100;
                menuObjs = new MenuObject[] {
                    new MenuObject(false, "MY CONTENT", 8, new Point(640, 100),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(true, "CAMPAIGNS", 4, new Point(640, mid - unit),
                                   MenuObject.Task.SET_MENU, "my-campaigns", main),
                    new MenuObject(true, "LEVELS", 4, new Point(640, mid),
                                   MenuObject.Task.SET_MENU, "my-levels", main),
                    new MenuObject(true, "LEVEL EDITOR", 4, new Point(640, mid + unit),
                                   MenuObject.Task.SET_MODE, "EDITOR", main),
                    new MenuObject(true, "BACK", 4, new Point(640, 660),
                                   MenuObject.Task.SET_MENU, "main", main)
                };
                return(new MenuFrame(menuObjs, main));

            case "editor-level-finish":
                lc       = 320;
                rc       = 960;
                mid      = 360;
                unit     = 100;
                offset   = 20;
                menuObjs = new MenuObject[] {
                    new MenuObject(false, "LEVEL INFO", 8, new Point(640, 100),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(false, "LEVEL NAME:", 4, new Point(640,
                                                                      mid - unit - offset),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(true, "\"" + main.getEditor().getName() + "\"",
                                   4, new Point(640, mid - unit + offset),
                                   MenuObject.Task.TYPE, "setlevelname", main),
                    new MenuObject(false, "LEVEL NOTE:", 4, new Point(640,
                                                                      mid - offset),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(true, "\"" + main.getEditor().getNote() + "\"",
                                   2, new Point(640, mid + offset),
                                   MenuObject.Task.TYPE, "setlevelnote", main),
                    new MenuObject(true, "SAVE TO FILE", 4, new Point(lc, 660),
                                   MenuObject.Task.SAVE_EDITOR, null, main),
                    new MenuObject(true, "FINISH", 4, new Point(640, 660),
                                   MenuObject.Task.SET_MENU, "my-content", main),
                    new MenuObject(true, "BACK", 4, new Point(rc, 660),
                                   MenuObject.Task.SET_MODE, "EDITOR", main)
                };
                return(new MenuFrame(menuObjs, main));

            case "pause":
                String levelName = main.getLevel().getName().ToUpper();
                String levelNote = main.getLevel().getNote().ToUpper();

                if (levelName != "")
                {
                    if (levelNote == "")
                    {
                        levelNote = " ";
                    }
                    pauseObjs = new MenuObject[] {
                        new MenuObject(false, levelName, 8, new Point(640, 100),
                                       MenuObject.Task.NULL, null, main),
                        new MenuObject(false, levelNote, 2, new Point(640, 150),
                                       MenuObject.Task.NULL, null, main),
                        new MenuObject(true, "RESUME", 4, new Point(640, 260),
                                       MenuObject.Task.UNPAUSE, null, main),
                        new MenuObject(true, "SETTINGS", 4, new Point(640, 360),
                                       MenuObject.Task.SET_PAUSE, "settings-pause", main),
                        new MenuObject(true, "MAIN MENU", 4, new Point(640, 460),
                                       MenuObject.Task.SET_MENU, "main", main),
                        new MenuObject(true, "QUIT", 4, new Point(640, 560),
                                       MenuObject.Task.SET_PAUSE, "are-you-sure", main)
                    };
                    return(new MenuFrame(pauseObjs, main));
                }
                pauseObjs = new MenuObject[] {
                    new MenuObject(false, "PAUSED", 8, new Point(640, 100),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(true, "RESUME", 4, new Point(640, 260),
                                   MenuObject.Task.UNPAUSE, null, main),
                    new MenuObject(true, "SETTINGS", 4, new Point(640, 360),
                                   MenuObject.Task.SET_PAUSE, "settings-pause", main),
                    new MenuObject(true, "MAIN MENU", 4, new Point(640, 460),
                                   MenuObject.Task.SET_MENU, "main", main),
                    new MenuObject(true, "QUIT", 4, new Point(640, 560),
                                   MenuObject.Task.SET_PAUSE, "are-you-sure", main)
                };
                return(new MenuFrame(pauseObjs, main));

            case "are-you-sure":
                pauseObjs = new MenuObject[] {
                    new MenuObject(false, "Are you sure you want to quit?",
                                   4, new Point(640, 310),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(true, "BACK", 4, new Point(540, 410),
                                   MenuObject.Task.SET_PAUSE, "pause", main),
                    new MenuObject(true, "YES", 4, new Point(740, 410),
                                   MenuObject.Task.CLOSE, null, main)
                };
                return(new MenuFrame(pauseObjs, main));

            case "settings-pause":
                GameSettings stgs = main.getSettings();
                mid       = 360;
                unit      = 80;
                offset    = 30;
                pauseObjs = new MenuObject[] {
                    new MenuObject(false, "SETTINGS", 8, new Point(640, 100),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(true, "BACK", 4, new Point(640, 660),
                                   MenuObject.Task.SET_PAUSE, "pause", main),
                    new MenuObject(false, "CAMERA FOLLOW MODE", 3,
                                   new Point(640, mid - (2 * unit)),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(false, stgs.getFollowMode().ToString(), 3,
                                   new Point(640, mid - (2 * unit) + offset),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(true, "<", 3,
                                   new Point(520, mid - (2 * unit) + offset),
                                   MenuObject.Task.SWITCH_FOLLOW, "-1", main),
                    new MenuObject(true, ">", 3,
                                   new Point(760, mid - (2 * unit) + offset),
                                   MenuObject.Task.SWITCH_FOLLOW, "1", main),
                    new MenuObject(false, "WINDOW MODE", 3,
                                   new Point(640, mid - unit),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(false, stgs.getWindowMode().ToString(),
                                   3, new Point(640, mid - unit + offset),
                                   MenuObject.Task.SET_PAUSE, null, main),
                    new MenuObject(true, "<", 3, new Point(520, mid - unit + offset),
                                   MenuObject.Task.SWITCH_WINDOW, null, main),
                    new MenuObject(true, ">", 3, new Point(760, mid - unit + offset),
                                   MenuObject.Task.SWITCH_WINDOW, null, main),
                    new MenuObject(false, "HUD", 3, new Point(640, mid),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(false, stgs.getHUDStatus().ToString(),
                                   3, new Point(640, mid + offset), MenuObject.Task.NULL,
                                   null, main),
                    new MenuObject(true, "<", 3, new Point(520, mid + offset),
                                   MenuObject.Task.SWITCH_HUD, null, main),
                    new MenuObject(true, ">", 3, new Point(760, mid + offset),
                                   MenuObject.Task.SWITCH_HUD, null, main),
                    new MenuObject(false, "CONTROL MODE", 3, new Point(640, mid + unit),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(true, stgs.getControlMode().ToString(),
                                   3, new Point(640, mid + unit + offset), MenuObject.Task.SET_PAUSE,
                                   "controls-pause", main),
                    new MenuObject(true, "<", 3, new Point(520, mid + unit + offset),
                                   MenuObject.Task.SWITCH_CONTROLS, null, main),
                    new MenuObject(true, ">", 3, new Point(760, mid + unit + offset),
                                   MenuObject.Task.SWITCH_CONTROLS, null, main),
                    new MenuObject(false, "GAME SPEED", 3, new Point(640, mid + (2 * unit)),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(false, stgs.gameSpeed(), 3,
                                   new Point(640, mid + (2 * unit) + offset),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(true, "<", 3, new Point(520, mid + (2 * unit) + offset),
                                   MenuObject.Task.SWITCH_PERIOD, "1", main),
                    new MenuObject(true, ">", 3, new Point(760, mid + (2 * unit) + offset),
                                   MenuObject.Task.SWITCH_PERIOD, "-1", main)
                };
                return(new MenuFrame(pauseObjs, main));

            case "controls-pause":
                Keys[] controls = main.getSettings().getControls();
                lc        = 480;
                rc        = 800;
                pauseObjs = new MenuObject[] {
                    new MenuObject(false, "CONTROLS", 8, new Point(640, 100),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(true, "BACK", 4, new Point(640, 660),
                                   MenuObject.Task.SET_PAUSE, "settings-pause", main),
                    new MenuObject(false, "JUMP", 4, new Point(lc, 200),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(false, controls[0].ToString(), 4,
                                   new Point(rc, 200), MenuObject.Task.NULL, null, main),
                    new MenuObject(false, "DROP", 4, new Point(lc, 240),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(false, controls[1].ToString(), 4,
                                   new Point(rc, 240), MenuObject.Task.NULL, null, main),
                    new MenuObject(false, "LEFT", 4, new Point(lc, 280),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(false, controls[2].ToString(), 4,
                                   new Point(rc, 280), MenuObject.Task.NULL, null, main),
                    new MenuObject(false, "RIGHT", 4, new Point(lc, 320),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(false, controls[3].ToString(), 4,
                                   new Point(rc, 320), MenuObject.Task.NULL, null, main),
                    new MenuObject(false, "SAVE LOCATION", 4, new Point(lc, 360),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(false, controls[4].ToString(), 4,
                                   new Point(rc, 360), MenuObject.Task.NULL, null, main),
                    new MenuObject(false, "LOAD LOCATION", 4, new Point(lc, 400),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(false, controls[5].ToString(), 4,
                                   new Point(rc, 400), MenuObject.Task.NULL, null, main),
                    new MenuObject(false, "TELEPORT", 4, new Point(lc, 440),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(false, controls[6].ToString(), 4,
                                   new Point(rc, 440), MenuObject.Task.NULL, null, main),
                    new MenuObject(false, "CAMERA ZOOM", 4, new Point(lc, 480),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(false, controls[7].ToString(), 4,
                                   new Point(rc, 480), MenuObject.Task.NULL, null, main),
                    new MenuObject(false, "PAUSE", 4, new Point(lc, 520),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(false, controls[8].ToString(), 4,
                                   new Point(rc, 520), MenuObject.Task.NULL, null, main)
                };
                return(new MenuFrame(pauseObjs, main));

            default:
                return(new MenuFrame(new MenuObject[] {
                    new MenuObject(false, "THIS DOES NOT EXIST",
                                   8, new Point(640, 100),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(false, "(Yet.)",
                                   16, new Point(640, 360),
                                   MenuObject.Task.NULL, null, main),
                    new MenuObject(true, "RETURN TO MAIN MENU",
                                   4, new Point(640, 660),
                                   MenuObject.Task.SET_MENU, "main", main)
                }, main));
            }
        }