public void setGuiControls(IMovableItem movableItem) { if (movableItem is BackgroundItemStruct) { BackgroundItemStruct backgroundItemStruct = (BackgroundItemStruct)movableItem; backgroundRotationText.Text = backgroundItemStruct.rotation.ToString(); backgroundScaleField.Text = backgroundItemStruct.scale.ToString(); backgroundTextureField.Text = backgroundItemStruct.texturePath; } if (movableItem is GameItem) { GameItem item = (GameItem)movableItem; itemPolygonType.SelectedItem = item.polygonType.ToString(); itemTextureBox.Text = item.name; itemWeightBox.Text = item.weight.ToString(); itemRadiusText.Text = item.polygonType == PhysicsPolygonType.Circle ? item.radius.ToString() : item.sideLengths.X.ToString() + "," + item.sideLengths.Y.ToString(); itemRotationTextBox.Text = item.rotation.ToString(); itemDepthSlider.Value = (int)item.startdepth; itemWidthSlider.Value = (int)item.width; itemImmovableBox.Checked = item.immovable; } if (movableItem is SpawnPoint) { SpawnPoint spawn = (SpawnPoint)movableItem; enemyCountBox.Text = spawn.count.ToString(); enemyTypeText.Text = spawn.type.ToString(); enemyLevelTextfield.Text = spawn.weight.ToString(); } }
/// <summary> /// Actualiza posición del elemento moviéndolo una fila o columna dependiendo /// de la dirección de su movimiento. /// Cuando el elemento llega a un límite del tablero aparece por el lado contrario. /// </summary> /// <param name="item"></param> private void updateMovablePosition(IMovableItem item) { var prevFila = item.Coords.Fila; var prevColumna = item.Coords.Columna; switch (item.CurrentDirection) { case Direction.Up: item.Coords.Fila = (item.Coords.Fila - 1); if (item.Coords.Fila <= 0) { item.Coords.Fila = MaxFila - 1; } break; case Direction.Down: item.Coords.Fila = (item.Coords.Fila + 1) % MaxFila; break; case Direction.Right: item.Coords.Columna = (item.Coords.Columna + 1) % MaxColumna; break; case Direction.Left: item.Coords.Columna = (item.Coords.Columna - 1); if (item.Coords.Columna <= 0) { item.Coords.Columna = MaxColumna - 1; } break; } if (item is Cat) { board[prevFila, prevColumna] = null; var moveTo = board[item.Coords.Fila, item.Coords.Columna]; if (moveTo is Mouse) { myMouse.MyValue = -1; } else { RemoveItem(moveTo); board[item.Coords.Fila, item.Coords.Columna] = item; } } }
public void remove(IMovableItem movingItem) { if (movingItem is BackgroundItemStruct) { backgroundItems.Remove((BackgroundItemStruct)movingItem); } if (movingItem is GameItem) { GameItem item = (GameItem)movingItem; items.Remove(item); if (item.guid != null && Game.instance.activeItems.ContainsKey(item.guid)) { Game.instance.activeItems.Remove(item.guid); } } if (movingItem is SpawnPoint) { spawns.Remove((SpawnPoint)movingItem); } }
public override void Update(GameTime gameTime) { if (Game.instance.isEndLevel()) { Game.instance.endLevel(true); } foreach (Being currentplayer in Game.instance.players.Values) { currentplayer.update(gameTime); if (currentplayer.isLocal) { currentplayer.input.update(); if (currentplayer.input.isKeyHit(Keys.S) && Keyboard.GetState().IsKeyDown(Keys.LeftControl)) { exitMapEditor(); } if (currentplayer.input.getButtonHit(Buttons.LeftThumbstickUp)) { cameraOffset.Y++; } if (currentplayer.input.getButtonHit(Buttons.LeftThumbstickDown)) { cameraOffset.Y--; } if (currentplayer.input.getButtonHit(Buttons.LeftThumbstickLeft)) { cameraOffset.X--; } if (currentplayer.input.getButtonHit(Buttons.LeftThumbstickRight)) { cameraOffset.X++; } if (currentplayer.input.isKeyHit(Keys.P)) { control.setPhysicsEnabled(physicsEnabled = !physicsEnabled); } if (previousMouseState.LeftButton == ButtonState.Released && Mouse.GetState().LeftButton == ButtonState.Pressed && Game.instance.res.Contains(Mouse.GetState().X, Mouse.GetState().Y)) { cameraOffset += new Vector2(Mouse.GetState().X, Game.instance.res.ScreenHeight - Mouse.GetState().Y) - getResolution() / 2; } if (currentplayer.input.isKeyHit(Keys.Delete) && movingItem != null) { level.remove(movingItem); control.setGuiControls(movingItem); movingItem = null; } if (Mouse.GetState().RightButton == ButtonState.Pressed && Game.instance.res.Contains(Mouse.GetState().X, Mouse.GetState().Y)) { Vector2 currentLocation = getCurrentLocation(); control.setCurrentPosition(currentLocation); #region begin move items if (previousMouseState.RightButton == ButtonState.Released) { if (Keyboard.GetState().IsKeyDown(Keys.LeftControl)) { movingItem = level.getGameItemAtLocation(currentLocation); } else if (Keyboard.GetState().IsKeyDown(Keys.LeftAlt)) { movingItem = level.getSpawnAtLocation(currentLocation.X, currentLocation.Y); } else if (Keyboard.GetState().IsKeyDown(Keys.LeftShift)) { movingItem = level.getBackgroundItemAtLocation(currentLocation.X, currentLocation.Y); } } #endregion } #region end move items if (ButtonState.Pressed == Mouse.GetState().RightButton&& Game.instance.res.Contains(Mouse.GetState().X, Mouse.GetState().Y) && movingItem != null) { movingItem.setPosition(getCurrentLocation()); } if (ButtonState.Released == Mouse.GetState().RightButton&& ButtonState.Pressed == previousMouseState.RightButton) { movingItem = null; } #endregion previousMouseState = Mouse.GetState(); } } if (!Game.instance.network.isClient()) { Game.instance.spawnManager.update(gameTime); } #region Physics if (previousGameTime == null) { previousGameTime = gameTime; } float timeElapsed = (float)gameTime.TotalGameTime.TotalMilliseconds - (float)previousGameTime.TotalGameTime.TotalMilliseconds; previousGameTime = gameTime; if (physicsEnabled) { Game.instance.physicsSimulator.Update((timeElapsed > .1f) ? timeElapsed : .1f); } #endregion }