Beispiel #1
0
        private void CharacterEntered(object sender, EventInput.CharacterEventArgs e)
        {
            if (StateManager.GameState != GameStates.Menu || StateManager.MenuState != MenuStates.NewGame || Confirmation)
            {
                return;
            }
            // Add key to text buffer. If not a symbol key.
            if (!((int)e.Character < 32 || (int)e.Character > 126)) //From space to tilde
            {
                // Capitals are already supported in DLL so we don't have to worry about checking shift
                if (!(ShortcutProvider.IsKeyDown(Keys.LeftControl) || ShortcutProvider.IsKeyDown(Keys.RightControl)))
                {
                    if (TextBuffer.Length < 10)
                    {
                        TextBuffer += e.Character;
                    }
                }
            }

            // Backspace - remove character if there are any
            if ((int)e.Character == 0x08 && TextBuffer.Length > 0)
            {
                TextBuffer = TextBuffer.Remove(TextBuffer.Length - 1);
            }
        }
        public void RebuildItems()
        {
            List <SaveState> saveStates = new List <SaveState>();

            string[] files = Directory.GetFiles(SaveManager.SaveFilePath, "*.svf", SearchOption.TopDirectoryOnly);
            foreach (string file in files)
            {
                FileStream      fs = new FileStream(file, FileMode.Open);
                BinaryFormatter bf = new BinaryFormatter();
                saveStates.Add((SaveState)bf.Deserialize(fs));
                fs.Close();
            }
            slot1 = saveStates.Count == 0 || String.IsNullOrEmpty(saveStates[0].PlayerName) ? "---" : saveStates[0].PlayerName;
            slot2 = saveStates.Count <= 1 || String.IsNullOrEmpty(saveStates[1].PlayerName) ? "---" : saveStates[1].PlayerName;
            slot3 = saveStates.Count <= 2 || String.IsNullOrEmpty(saveStates[2].PlayerName) ? "---" : saveStates[2].PlayerName;

            menuItems.Clear();
            menuItems.Add(new MenuItem(slot1, fontName, true));
            menuItems.Add(new MenuItem(slot2, fontName));
            menuItems.Add(new MenuItem(slot3, fontName));
            menuItems.Add(new MenuItem(back, fontName));

            SetPositions();

            menuItems[3].ItemPosition += itemOffset;

            menuLabels.Clear();
            menuLabels.Add(new MenuLabel(select, fontName));
            menuLabels[0].Position = ShortcutProvider.ScreenCenter - ShortcutProvider.GetFontCenter(fontName, select) - 3 * itemOffset;
        }
Beispiel #3
0
 protected void SetPositions()
 {
     for (int i = 0; i < menuItems.Count; ++i)
     {
         menuItems[i].ItemPosition = ShortcutProvider.ScreenCenter - ShortcutProvider.GetFontCenter(fontName, menuItems[i].ItemName) + (i - 2) * itemOffset;
     }
 }
Beispiel #4
0
 public override void Update()
 {
     base.Update();
     if (ShortcutProvider.KeyPressedNowButNotLastFrame(Keys.Escape))
     {
         StateManager.GameState = GameStates.Title;
     }
 }
 public override void Update()
 {
     base.Update();
     if (ShortcutProvider.KeyPressedNowButNotLastFrame(Keys.Escape))
     {
         StateManager.OptionsState = OptionStates.Overview;
     }
 }
Beispiel #6
0
        public override void Compute(MSInput input, out MSOutput output)
        {
            output = new MSOutput();
            var trajectory = input.Trajectory;

            ShortcutProvider.Init(input, output, false);

            LinkedList <TPoint2D> prevShortestPath = null;

            for (var level = input.NumLevels; level >= 1; level--)
            {
                var epsilon        = input.GetEpsilon(level);
                var levelShortcuts = ShortcutProvider.GetShortcuts(level, epsilon);

                LinkedList <TPoint2D> shortestPath;

                if (prevShortestPath == null)
                {
                    var pointPath = ShortestPathProvider.FindShortestPath(levelShortcuts, trajectory.First(), trajectory.Last());
                    shortestPath = pointPath.Points;
                }
                else
                {
                    shortestPath = new LinkedList <TPoint2D>();
                    var prevPoint = trajectory.First();

                    foreach (var point in prevShortestPath)
                    {
                        if (point == trajectory.First())
                        {
                            continue;
                        }

                        var pointPath = ShortestPathProvider.FindShortestPath(levelShortcuts, prevPoint, point);

                        foreach (var p in pointPath.Points)
                        {
                            shortestPath.AddLast(p);
                        }

                        prevPoint = point;
                    }
                }

                shortestPath.AddFirst(trajectory.First());

                var newTrajectory = new Trajectory2D(shortestPath);

                //report shortest path
                //output.LogObject("Level Shortest Path", levelTrajectory);
                output.LogLine("Level " + level + " trajectory found. Length: " + newTrajectory.Count);
                output.SetTrajectoryAtLevel(level, newTrajectory);

                prevShortestPath = shortestPath;

                ShortcutProvider.SetSearchIntervals(shortestPath);
            }
        }
Beispiel #7
0
 public static void HandleGeneralInput()
 {
     if (ShortcutProvider.KeyPressedNowButNotLastFrame(Keys.Escape))
     {
         StateManager.MenuState  = MenuStates.Ingame;
         StateManager.GamePaused = true;
         StateManager.InputLock  = true;
     }
 }
 private void PreferencesForm_Load(object sender, EventArgs e)
 {
     autoStartCheckBox.Checked              = ShortcutProvider.ShortcutExists();
     autoUpdateCheckBox.Checked             = Settings.Main.UpdateOnStartup;
     rememberTimeStampCheckBox.Checked      = Settings.Main.SaveTimestamp;
     timeDifferenceCheckBox.Enabled         = rememberTimeStampCheckBox.Checked;
     timeDifferenceCheckBox.Checked         = Settings.Main.SaveDifference;
     minimizeInsteadOfCloseCheckBox.Checked = Settings.Main.MinimizeInsteadOfClose;
 }
 private void autoStartCheckBox_CheckedChanged(object sender, EventArgs e)
 {
     if (autoStartCheckBox.Checked)
     {
         ShortcutProvider.CreateShortcut();
     }
     else
     {
         ShortcutProvider.DeleteShortcut();
     }
 }
        public ShortcutOptions(BindingList <ShortcutProvider> shortcutProviders, ShortcutProvider ChosenShortcutProvider,
                               BindingList <ShortestPathProvider> shortestPathroviders, ShortestPathProvider ChosenShortestPathProvider)
        {
            InitializeComponent();

            this.shortcutProviders    = shortcutProviders;
            this.shortestPathroviders = shortestPathroviders;

            PopulateControls();

            shortestPathProviderComboBox.SelectedItem = ChosenShortestPathProvider;
            shortcutProviderComboBox.SelectedItem     = ChosenShortcutProvider;
        }
Beispiel #11
0
 public void Draw(SpriteBatch spriteBatch)
 {
     spriteBatch.DrawString(
         font,
         Text,
         ShortcutProvider.Vector2Point(Position),
         Color.White,
         0,
         Vector2.Zero,
         1,
         SpriteEffects.None,
         .2f);
 }
Beispiel #12
0
 public void Draw(SpriteBatch spriteBatch)
 {
     spriteBatch.DrawString(
         font,
         ItemName,
         ShortcutProvider.Vector2Point(ItemPosition),
         itemColor,
         0,
         Vector2.Zero,
         1,
         SpriteEffects.None,
         0.2f
         );
 }
Beispiel #13
0
 public override void Update()
 {
     base.Update();
     if (ShortcutProvider.KeyPressedNowButNotLastFrame(Keys.Escape))
     {
         if (StateManager.GamePaused)
         {
             StateManager.MenuState = MenuStates.Ingame;
         }
         else
         {
             StateManager.MenuState = MenuStates.Main;
         }
     }
 }
Beispiel #14
0
 public virtual void ResolveMouseSelection()
 {
     foreach (MenuItem menuItem in menuItems)
     {
         if (ShortcutProvider.MouseIntersectsRectangle(ShortcutProvider.GetFontRectangle(menuItem.ItemPosition, fontName, menuItem.ItemName)))
         {
             foreach (MenuItem item in menuItems)
             {
                 item.IsSelected = false;
             }
             menuItem.IsSelected = true;
             break;
         }
     }
 }
Beispiel #15
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);

            spriteBatch.DrawString(
                FontProvider.GetFont(fontName),
                confirmText + GameVariableProvider.SaveState.PlayerName + "?",
                ShortcutProvider.Vector2Point(menuItems[0].ItemPosition - itemOffset - new Vector2(ShortcutProvider.GetFontCenter(fontName, confirmText + GameVariableProvider.SaveState.PlayerName + "?").X, 0)),
                Color.White,
                0,
                Vector2.Zero,
                1,
                SpriteEffects.None,
                .2f);
        }
Beispiel #16
0
 public override void Update()
 {
     base.Update();
     if (StateManager.InputLock)
     {
         StateManager.InputLock = false;
     }
     else
     {
         if (ShortcutProvider.KeyPressedNowButNotLastFrame(Keys.Escape))
         {
             StateManager.GamePaused = false;
             StateManager.MenuState  = MenuStates.Null;
         }
     }
 }
Beispiel #17
0
        public NewGameMenu()
        {
            menuLabels.Add(new MenuLabel(name, fontName));
            menuItems.Add(new MenuItem(ok, fontName, false));
            menuItems.Add(new MenuItem(back, fontName, true));

            menuLabels[0].Position    = ShortcutProvider.ScreenCenter - ShortcutProvider.GetFontCenter(fontName, menuItems[0].ItemName) + new Vector2(-200, 0);
            menuItems[0].ItemPosition = ShortcutProvider.ScreenCenter - ShortcutProvider.GetFontCenter(fontName, menuItems[1].ItemName) + 2 * itemOffset;
            menuItems[1].ItemPosition = ShortcutProvider.ScreenCenter - ShortcutProvider.GetFontCenter(fontName, menuItems[1].ItemName) + 3 * itemOffset;

            EventInput.EventInput.Initialize(VariableProvider.Game.Window);
            EventInput.EventInput.CharEntered += new EventInput.CharEnteredHandler(CharacterEntered);
            TextBuffer = "";

            confirmDialog = new ConfirmOverlay(this);
        }
        public static void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(
                font,
                displayText,
                ShortcutProvider.Vector2Point(textPosition),
                Color.White,
                0,
                Vector2.Zero,
                1,
                SpriteEffects.None,
                0.2f);

            spriteBatch.Draw(
                dialog[currentDialogue].MugShot,
                ShortcutProvider.Vector2Point(mugShotPosition),
                new Rectangle(0, 0, CurrentMugShot.Width, CurrentMugShot.Height),
                Color.White,
                0,
                Vector2.Zero,
                1,
                SpriteEffects.None,
                0.2f);

            spriteBatch.DrawString(
                font,
                CurrentName,
                new Vector2(83, 480),
                Color.White,
                0,
                Vector2.Zero,
                1,
                SpriteEffects.None,
                .2f);

            spriteBatch.Draw(
                VariableProvider.WhiteTexture,
                new Vector2(80, 480),
                new Rectangle(0, 0, 640, 120),
                Color.Black,
                0,
                Vector2.Zero,
                1f,
                SpriteEffects.None,
                0.3f);
        }
        public static void Update(Menu menu)
        {
            if (InputMapper.STRICTDOWN)
            {
                menu.NextMenuItem();
            }

            if (InputMapper.STRICTUP)
            {
                menu.PreviousMenuItem();
            }

            menu.ResolveMouseSelection();

            if (InputMapper.STRICTACTION || ShortcutProvider.LeftButtonClickedNowButNotLastFrame())
            {
                menu.SelectMenuItem();
            }
        }
        public override void Compute(MSInput input, out MSOutput output)
        {
            output = new MSOutput();
            var trajectory = input.Trajectory;

            ShortcutProvider.Init(input, output, false);

            ICollection <TPoint2D> prevShortestPath = trajectory;

            for (var level = 1; level <= input.NumLevels; level++)
            {
                var epsilon = input.GetEpsilon(level);

                var levelShortcuts = ShortcutProvider.GetShortcuts(level, epsilon);

                var levelShortestPath = ShortestPathProvider.FindShortestPath(levelShortcuts, trajectory.First(), trajectory.Last()).Points;
                levelShortestPath.AddFirst(trajectory.First());

                //O(n)
                var levelTrajectory = new Trajectory2D(levelShortestPath);

                //O(n)
                var levelShortestPathSet = new HashSet <TPoint2D>(levelShortestPath);

                //report level trajectory
                output.SetTrajectoryAtLevel(level, levelTrajectory);

                //prune shortcutgraph and shortcuts
                //only consider points that are not the first/last
                foreach (var point in prevShortestPath)
                {
                    //O(1)
                    if (!levelShortestPathSet.Contains(point))
                    {
                        //remove shortcuts from shortcut set
                        ShortcutProvider.RemovePoint(point);
                    }
                }

                prevShortestPath = levelShortestPath;
            }
        }
        public override void Draw(GameObject obj, SpriteBatch spriteBatch)
        {
            SpriteEffects effects = SpriteEffects.None;

            if (flipped)
            {
                effects = SpriteEffects.FlipHorizontally;
            }

            spriteBatch.Draw(
                animations[currentAnimation].Texture,
                ShortcutProvider.Vector2Point(obj.Position),
                animations[currentAnimation].FrameRectangle,
                Color.White,
                0,
                Vector2.Zero,
                1,
                effects,
                drawDepth);
        }
Beispiel #22
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            if (Confirmation)
            {
                confirmDialog.Draw(spriteBatch);
                return;
            }

            base.Draw(spriteBatch);

            spriteBatch.DrawString(
                FontProvider.GetFont(fontName),
                TextBuffer,
                ShortcutProvider.Vector2Point(menuLabels[0].Position + new Vector2(FontProvider.GetFont(fontName).MeasureString(menuLabels[0].Text).X + 14, 0)),
                Color.White,
                0,
                Vector2.Zero,
                1,
                SpriteEffects.None,
                .2f);
        }
Beispiel #23
0
        public override void Update()
        {
            if (Confirmation)
            {
                confirmDialog.Update();
                return;
            }

            if (ShortcutProvider.KeyPressedNowButNotLastFrame(Keys.Down))
            {
                NextMenuItem();
            }

            if (ShortcutProvider.KeyPressedNowButNotLastFrame(Keys.Up))
            {
                PreviousMenuItem();
            }

            ResolveMouseSelection();

            if (ShortcutProvider.KeyPressedNowButNotLastFrame(Keys.Enter) || ShortcutProvider.LeftButtonClickedNowButNotLastFrame())
            {
                SelectMenuItem();
            }

            foreach (MenuItem menuItem in menuItems)
            {
                menuItem.Update();
            }
            if (InputMapper.STRICTCANCEL)
            {
                StateManager.MenuState = MenuStates.Main;
            }
            if (TextBuffer.Length == 0)
            {
                menuItems[0].IsSelected = false;
                menuItems[1].IsSelected = true;
            }
        }
Beispiel #24
0
        public override void Compute(MSInput input, out MSOutput output)
        {
            output = new MSOutput();
            var trajectory = input.Trajectory;

            ShortcutProvider.Init(input, output, false);

            for (var level = 1; level <= input.NumLevels; level++)
            {
                var epsilon = input.GetEpsilon(level);

                var levelShortcuts = ShortcutProvider.GetShortcuts(level, epsilon);

                var shortestPath = ShortestPathProvider.FindShortestPath(levelShortcuts, trajectory.First(), trajectory.Last()).Points;

                shortestPath.AddFirst(trajectory.First());

                //O(n)
                var levelTrajectory = new Trajectory2D(shortestPath);

                output.SetTrajectoryAtLevel(level, levelTrajectory);
            }
        }
        public override void Compute(MSInput input, out MSOutput output)
        {
            output = new MSOutput();
            var trajectory = input.Trajectory;

            ShortcutProvider.Init(input, output, false);

            var onDemandShortcutProvider = (ShortcutsOnDemand)ShortcutProvider;
            var prevTrajectory           = trajectory;

            for (var level = 1; level <= input.NumLevels; level++)
            {
                var epsilon = input.GetEpsilon(level);

                var shortcutAlgo  = onDemandShortcutProvider.Algorithm;
                var shortcutInput = new MSSInput(prevTrajectory, new List <double> {
                    epsilon
                });
                MSSOutput shortcutOutput;

                shortcutAlgo.Compute(shortcutInput, out shortcutOutput);
                var levelShortcuts = shortcutOutput.GetShortcuts(1);

                output.LogObject("Number of shortcuts found on level " + level, levelShortcuts.Count);

                var levelShortestPath = ShortestPathProvider.FindShortestPath(levelShortcuts, prevTrajectory.First(), prevTrajectory.Last()).Points;
                levelShortestPath.AddFirst(prevTrajectory.First());

                //O(n)
                var levelTrajectory = new Trajectory2D(levelShortestPath);

                //report level trajectory
                output.SetTrajectoryAtLevel(level, levelTrajectory);

                prevTrajectory = levelTrajectory;
            }
        }
Beispiel #26
0
        protected override void Update(GameTime gameTime)
        {
            if (Form.ActiveForm == parentForm)
            {
                if (CurrentMap != null)
                {
                    Viewport.Location = new Location(hscroll.Value, vscroll.Value);
                    Camera.Position   = new Vector2(hscroll.Value, vscroll.Value);
                    InputProvider.Update();
                    CurrentMap.Update(gameTime.ElapsedGameTime.Milliseconds);

                    MouseState ms = InputProvider.MouseState;
                    if ((ms.X > 0) && (ms.Y > 0) && (ms.X < Camera.ViewPortWidth) && (ms.Y < Camera.ViewPortHeight))
                    {
                        Vector2 mouseLoc = Camera.ScreenToWorld(new Vector2(ms.X, ms.Y));
                        int     cellX    = (int)MathHelper.Clamp(TileMap.GetCellByPixelX((int)mouseLoc.X), 0, TileMap.MapWidth - 1);
                        int     cellY    = (int)MathHelper.Clamp(TileMap.GetCellByPixelY((int)mouseLoc.Y), 0, TileMap.MapHeight - 1);

                        if (Camera.WorldRectangle.Contains((int)mouseLoc.X, (int)mouseLoc.Y))
                        {
                            if (!RectangleMode)
                            {
                                if (ShortcutProvider.LeftButtonClicked())
                                {
                                    TileMap.GetMapSquareAtCell(cellX, cellY).Passable = Passable;
                                }
                                if (ShortcutProvider.RightButtonClicked())
                                {
                                    if (SetCode)
                                    {
                                        ((EditorForm)parentForm).SetCodeList(cellX, cellY);
                                    }
                                    else
                                    {
                                        ((EditorForm)parentForm).GetCodeList(TileMap.GetCellCodes(cellX, cellY));
                                    }
                                }
                            }
                            else
                            {
                                if (ShortcutProvider.LeftButtonClickedNowButNotLastFrame())
                                {
                                    if (!waitingForSecondClick)
                                    {
                                        startCell             = new Vector2(cellX, cellY);
                                        waitingForSecondClick = true;
                                    }
                                    else
                                    {
                                        Vector2 endCell = new Vector2(cellX, cellY);
                                        waitingForSecondClick = false;

                                        for (int cellx = (int)startCell.X; cellx <= endCell.X; ++cellx)
                                        {
                                            for (int celly = (int)startCell.Y; celly <= endCell.Y; ++celly)
                                            {
                                                TileMap.GetMapSquareAtCell(cellx, celly).Passable = Passable;
                                            }
                                        }
                                    }
                                }
                                else if (ShortcutProvider.RightButtonClickedButNotLastFrame())
                                {
                                    if (!waitingForSecondClick)
                                    {
                                        startCell             = new Vector2(cellX, cellY);
                                        waitingForSecondClick = true;
                                    }
                                    else
                                    {
                                        Vector2 endCell = new Vector2(cellX, cellY);
                                        waitingForSecondClick = false;

                                        for (int cellx = (int)startCell.X; cellx <= endCell.X; ++cellx)
                                        {
                                            for (int celly = (int)startCell.Y; celly <= endCell.Y; ++celly)
                                            {
                                                if (SetCode)
                                                {
                                                    ((EditorForm)parentForm).SetCodeList(cellx, celly);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            base.Update(gameTime);
        }
        public override void Compute(MSInput input, out MSOutput output)
        {
            //output = new MSOutput();
            output = new Output();

            var trajectory = input.Trajectory;

            ShortcutProvider.Init(input, output, true);

            var shortcutGraphs = ((Output)output).Graphs;
            //var shortcutGraphs = new Dictionary<int, ShortcutGraph>();

            ShortcutGraph prevShortcutGraph = null;

            for (var level = 1; level <= input.NumLevels; level++)
            {
                var epsilon = input.GetEpsilon(level);

                ShortcutGraph shortcutGraph;
                if (prevShortcutGraph != null)
                {
                    //clone graph from previous level
                    shortcutGraph = (ShortcutGraph)prevShortcutGraph.Clone();
                }
                else
                {
                    //build initial graph (just a simple sequence of nodes like in the trajectory)
                    shortcutGraph = new ShortcutGraph(trajectory);
                }

                //select correct shortcuts
                var shortcutsLevel = ShortcutProvider.GetShortcuts(level, epsilon);
                //output.LogObject("Number of shortcuts found for level " + level, () => shortcutsLevel.Count);

                if (level == 1)
                {
                    foreach (var shortcut in shortcutsLevel)
                    {
                        shortcutGraph.AddShortcut(shortcut);
                    }
                }
                else
                {
                    var weights         = new Dictionary <Shortcut, int>();
                    var shortcutWeights = GetShortcutWeights(shortcutGraph, shortcutsLevel);

                    foreach (var pair in shortcutWeights)
                    {
                        var shortcut = pair.Key;
                        var weight   = pair.Value;
                        weights[shortcut] = weight;
                    }

                    foreach (var shortcut in shortcutsLevel)
                    {
                        shortcutGraph.AddShortcut(shortcut, weights[shortcut]);
                    }

                    //increment weights of all edges by 1
                    shortcutGraph.IncrementAllWeights();
                }

                //output.LogObject("Shortcut Graph", shortcutGraph);

                shortcutGraphs[level] = shortcutGraph;
                prevShortcutGraph     = shortcutGraph;
            }

            output.LogLine("Shortcut graph size at scale m: " + shortcutGraphs[input.NumLevels].Count);
            output.LogLine("Average amount of shortcuts handled per scale: " + shortcutGraphs[input.NumLevels].Count / input.NumLevels);

            output.LogLine("");
            output.LogLine("Starting calculations of level trajectories bottom-up");
            output.LogLine("");

            //bottom up calculation of level trajectories
            LinkedList <TPoint2D> prevShortestPath = null;

            for (var level = input.NumLevels; level >= 1; level--)
            {
                var shortcutGraph = shortcutGraphs[level];
                LinkedList <TPoint2D> shortestPath;

                if (prevShortestPath == null)
                {
                    var pointPath = ShortestPathProvider.FindShortestPath(shortcutGraph, trajectory.First(), trajectory.Last());
                    shortestPath = pointPath.Points;
                }
                else
                {
                    shortestPath = new LinkedList <TPoint2D>();
                    var prevPoint = trajectory.First();

                    foreach (var point in prevShortestPath)
                    {
                        var pointPath = ShortestPathProvider.FindShortestPath(shortcutGraph, prevPoint, point);

                        foreach (var p in pointPath.Points)
                        {
                            shortestPath.AddLast(p);
                        }

                        prevPoint = point;
                    }
                }

                var newTrajectory = new Trajectory2D();
                newTrajectory.AppendPoint(trajectory.First().X, trajectory.First().Y);
                foreach (var point in shortestPath)
                {
                    newTrajectory.AppendPoint(point.X, point.Y);
                }

                //report shortest path
                //output.LogObject("Level Shortest Path", levelTrajectory);
                output.LogLine("Level " + level + " trajectory found. Length: " + newTrajectory.Count);
                output.SetTrajectoryAtLevel(level, newTrajectory);

                prevShortestPath = shortestPath;
            }
        }
        private void shortcutProviderComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ChosenShortcutProvider = (ShortcutProvider)shortcutProviderComboBox.SelectedItem;

            shortcutProviderOptions.Fill(ChosenShortcutProvider.Options);
        }