Esempio n. 1
0
        protected override void Initialize()
        {
            DateTime start = DateTime.Now;

            base.Initialize();
            Drawer.Initialize(graphics);
            Drawer.DisableFullScreen();
            Maps.Initialize();
            TitleScreen.Initialize();
            TitleScreen.Activate();
            Background.Initialize(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            Particles.Initialize();
            base.Initialize();
            Console.WriteLine("Initialization took " + (DateTime.Now - start).ToString());
            Message.Compute();
        }
Esempio n. 2
0
        public static void SetMap(string str, bool map_finished = false)
        {
            Message.Close();
            timer_on_ = false;
            Drawer.Fade(500);
            character_.Freeze(500);
            Thread thread = new Thread(() =>
            {
                #region New best score
                do
                {
                    if (map_finished)
                    {
                        XmlDocument xmlDocument = new XmlDocument();
                        try
                        {
                            xmlDocument.Load("../../../../LightContent/database/scores.xml");
                        }
                        catch
                        {
                            Console.WriteLine("Unable to save: cannot load XML.");
                            break;
                        }
                        XmlNode root = xmlDocument.DocumentElement;
                        XmlNode node = xmlDocument.SelectSingleNode("//scores");
                        node         = root.SelectSingleNode("descendant::score[name='" + map_.Name_ + "']");
                        if (node != null)
                        {
                            XmlNode score = root.SelectSingleNode("//best-score");
                            if (score != null)
                            {
                                string score_str = score.InnerText;
                                int hours        = Convert.ToInt32(score_str.Split(':')[0]);
                                int minutes      = Convert.ToInt32(score_str.Split(':')[1]);
                                int seconds      = Convert.ToInt32(score_str.Split(':')[2].Split('.')[0]);
                                int milliseconds = Convert.ToInt32(score_str.Split(':')[2].Split('.')[1].Substring(0, 3));
                                TimeSpan prev    = new TimeSpan(0, hours, minutes, seconds, milliseconds);
                                if (timer_end_ - timer_start_ >= prev)
                                {
                                    break;
                                }
                            }
                            root.RemoveChild(node);
                        }
                        XmlElement elem       = xmlDocument.CreateElement("score");
                        XmlElement name       = xmlDocument.CreateElement("name");
                        name.InnerText        = map_.Name_;
                        XmlElement best_score = xmlDocument.CreateElement("best-score");
                        best_score.InnerText  = (timer_end_ - timer_start_).ToString();
                        elem.AppendChild(name);
                        elem.AppendChild(best_score);
                        root.AppendChild(elem);
                        Console.WriteLine("Saving new score...");
                        try
                        {
                            xmlDocument.Save("../../../../LightContent/database/scores.xml");
                            Console.WriteLine("Score saved.");
                            TitleScreen.Initialize();
                        }
                        catch
                        {
                            Console.WriteLine("Unable to save: cannot write.");
                        }
                    }
                } while (false);
                #endregion
                Thread.Sleep(500);
                map_ = Maps.Maps_[str];
                map_.ResetLight();
                map_.SetCheckpoint(map_.Initial_position_, map_.Initial_gravity_);
                character_.SetPosition(map_, map_.Initial_position_);
                Character.Gravity_sign_ = map_.Initial_gravity_;
                Map.Block_type_enabled_ = 1;
                timer_start_            = DateTime.Now;
                timer_end_ = DateTime.Now;
                timer_on_  = true;
            });

            thread.Start();
        }
Esempio n. 3
0
        public static void Update(int screenwidth, int screenheight)
        {
            mouseState_ = Mouse.GetState();
            if (!thread_part1_ && !thread_part2_)
            {
                if (MapChooser.Active_)
                {
                    MapChooser.Update(screenwidth, screenheight);
                }
                else if (EditorOptions.Active_)
                {
                    EditorOptions.Update(screenwidth, screenheight);
                }
                else
                {
                    #region Zoom
                    if (mouseState_.ScrollWheelValue - oldMouseState_.ScrollWheelValue < 0)
                    {
                        if (Map.Size_ > 2)
                        {
                            Map.Size_--;
                        }
                        int max_shift_x = Math.Max(0, width_ * Map.Size_ - screenwidth);
                        int max_shift_y = Math.Max(0, height_ * Map.Size_ - screenheight);
                        map_.Shift_x_ = Math.Min(max_shift_x, map_.Shift_x_);
                        map_.Shift_y_ = Math.Min(max_shift_y, map_.Shift_y_);
                    }
                    else if (mouseState_.ScrollWheelValue - oldMouseState_.ScrollWheelValue > 0)
                    {
                        if (Map.Size_ < 200)
                        {
                            Map.Size_++;
                        }
                        int max_shift_x = Math.Max(0, width_ * Map.Size_ - screenwidth);
                        int max_shift_y = Math.Max(0, height_ * Map.Size_ - screenheight);
                        map_.Shift_x_ = Math.Min(max_shift_x, map_.Shift_x_);
                        map_.Shift_y_ = Math.Min(max_shift_y, map_.Shift_y_);
                    }
                    #endregion
                    if (mouseState_.X <= 105 && mouseState_.Y <= 55)
                    {
                        side_ = true;
                    }
                    else
                    {
                        side_ = false;
                    }
                    #region Shift
                    if (width_ * Map.Size_ < screenwidth)
                    {
                        map_.F_shift_x_ = -(screenwidth - width_ * Map.Size_) / 2;
                        map_.Shift_x_   = 0;
                    }
                    else
                    {
                        map_.F_shift_x_ = 0;
                        if (mouseState_.X < 100 && map_.Shift_x_ - 4 >= 0)
                        {
                            map_.Shift_x_ -= 4;
                        }
                        if (mouseState_.X >= screenwidth - 100 && map_.Shift_x_ + 4 <= width_ * Map.Size_ - screenwidth)
                        {
                            map_.Shift_x_ += 4;
                        }
                    }
                    if (height_ * Map.Size_ < screenheight)
                    {
                        map_.F_shift_y_ = -(screenheight - height_ * Map.Size_) / 2;
                        map_.Shift_y_   = 0;
                    }
                    else
                    {
                        map_.F_shift_y_ = 0;
                        if (mouseState_.Y < 100 && map_.Shift_y_ - 4 >= 0)
                        {
                            map_.Shift_y_ -= 4;
                        }
                        if (mouseState_.Y >= screenheight - 100 && map_.Shift_y_ + 4 <= height_ * Map.Size_ - screenheight)
                        {
                            map_.Shift_y_ += 4;
                        }
                    }
                    #endregion
                    #region Inputs
                    if (mouseState_.LeftButton == ButtonState.Pressed)
                    {
                        if (Input.IsPressed(Keys.LeftShift) || Input.IsPressed(Keys.RightShift))
                        {
                            map_.SetPosition((mouseState_.X + map_.Shift_x_ + map_.F_shift_x_) / Map.Size_, (mouseState_.Y + map_.Shift_y_ + map_.F_shift_y_) / Map.Size_);
                        }
                        else
                        {
                            map_.ChangeCell((mouseState_.X + map_.Shift_x_ + map_.F_shift_x_) / Map.Size_, (mouseState_.Y + map_.Shift_y_ + map_.F_shift_y_) / Map.Size_, layer_, contents_[content_].Item1_);
                        }
                    }
                    else if (mouseState_.RightButton == ButtonState.Pressed)
                    {
                        try
                        {
                            int n = 0;
                            foreach (var w in contents_)
                            {
                                if (w.Item1_ == map_.Cells_[(mouseState_.X + map_.Shift_x_ + map_.F_shift_x_) / Map.Size_, (mouseState_.Y + map_.Shift_y_ + map_.F_shift_y_) / Map.Size_].Content_[layer_])
                                {
                                    break;
                                }
                                n++;
                            }
                            content_ = n;
                            if (move_panel_.IsAlive)
                            {
                                move_panel_.Abort();
                            }
                            InitThread();
                            move_panel_.Start();
                        }
                        catch { }
                    }
                    if (oldMouseState_.LeftButton == ButtonState.Pressed && mouseState_.LeftButton == ButtonState.Released)
                    {
                        if (contents_[content_].Item1_ == 6)
                        {
                            MapChooser.Initialize(screenwidth, screenheight);
                            MapChooser.Activate();
                        }
                    }
                    if (Input.IsPressedOnce(Keys.Up))
                    {
                        content_--;
                        if (content_ < 0)
                        {
                            content_ = contents_.Count() - 1;
                        }
                        if (move_panel_.IsAlive)
                        {
                            move_panel_.Abort();
                        }
                        InitThread();
                        move_panel_.Start();
                    }
                    else if (Input.IsPressedOnce(Keys.Down))
                    {
                        content_++;
                        content_ %= contents_.Count();
                        if (move_panel_.IsAlive)
                        {
                            move_panel_.Abort();
                        }
                        InitThread();
                        move_panel_.Start();
                    }
                    if (Input.IsPressedOnce(Keys.Right))
                    {
                        layer_ = layer_ == 2 ? layer_ : layer_ + 1; /* FIXME: 3 layers => layer_ == 2 */
                    }
                    else if (Input.IsPressedOnce(Keys.Left))
                    {
                        layer_ = layer_ == 0 ? layer_ : layer_ - 1;
                    }
                    if (Input.IsPressedOnce(Keys.S))
                    {
                        Save();
                    }
                    if (Input.IsPressedOnce(Keys.O))
                    {
                        EditorOptions.Initialize(screenwidth, screenheight);
                        EditorOptions.Activate();
                    }
                    if (Input.IsPressedOnce(Keys.Escape))
                    {
                        Thread thread2 = new Thread(() =>
                        {
                            thread_part1_str_ = "Updating map...";
                            Thread thread1    = new Thread(() =>
                            {
                                thread_part1_ = true;
                                Maps.Initialize(name_);
                                thread_part1_     = false;
                                thread_part2_str_ = "Map updated.";
                                thread_part2_     = true;
                            });
                            thread1.Start();
                            DateTime start = DateTime.Now;
                            while (DateTime.Now - start < new TimeSpan(0, 0, 0, 0, 250))
                            {
                                shade_ = 0.75f * (float)(DateTime.Now - start).TotalMilliseconds / 250f;
                            }
                            while (thread_part1_)
                            {
                                ;
                            }
                            Thread.Sleep(500);
                            start = DateTime.Now;
                            while (DateTime.Now - start < new TimeSpan(0, 0, 0, 0, 250))
                            {
                                shade_ = 0.75f + 0.25f * (float)(DateTime.Now - start).TotalMilliseconds / 250f;
                            }
                            TitleScreen.Initialize();
                            TitleScreen.Activate();
                            Map.Size_ = 20;
                            Thread.Sleep(50);
                            thread_part2_ = false;
                        });
                        thread2.Start();
                    }
                    #endregion
                    #region Auto update layer
                    switch (contents_[content_].Item1_)
                    {
                    case 3:
                    case 7:
                        layer_ = 1;
                        break;

                    case -2:
                        layer_ = 2;
                        break;

                    case 2:
                    case 4:
                    case 5:
                    case 6:
                    case 8:
                    case 9:
                    case 10:
                    case 11:
                    case 12:
                    case 13:
                    case 14:
                    case 15:
                    case 16:
                        layer_ = 0;
                        break;

                    default:
                        break;
                    }
                    #endregion
                }
            }
            oldMouseState_ = mouseState_;
        }