public static void Update(int screenwidth, int screenheight) { if (map_ != null) { Background.Update(screenwidth, screenheight); Particles.Update(); map_.Update(character_, screenwidth, screenheight); character_.Update(map_, screenwidth, screenheight); if (Input.IsPressedOnce(Keys.Escape)) { map_ = null; //Maps.Initialize(); //TitleScreen.Initialize(screenwidth, screenheight); TitleScreen.Activate(); } else if (Input.IsPressedOnce(Keys.R)) { SetMap(map_.Name_); } if (Input.IsPressedOnce(Keys.Enter)) { Message.Close(); } if (timer_on_) { timer_end_ = DateTime.Now; } } }
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(); }
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_; }