public override void loadContent() { base.loadContent(); m_imgOffsetX = 36 -m_img.getSize().X / 2; m_imgOffsetY = 36 -m_img.getSize().Y / 2; m_position = new CartesianCoordinate(Game.getInstance().getState().getPlayer().getPosition().getGlobalCartesian()); }
public GuiObject(Vector2 a_posV2, string a_sprite) : base(a_posV2, "Images//GUI//" + a_sprite, 0.002f) { m_position = new CartesianCoordinate(a_posV2 - Game.getInstance().getResolution() / 2, Game.getInstance().m_camera.getPosition()); m_bounds.X = (int)a_posV2.X; m_bounds.Y = (int)a_posV2.Y; m_guiSprite = a_sprite; }
public CollisionLine(Vector2 a_start, Vector2 a_end) { m_position = new CartesianCoordinate(a_start); m_endPosition = new CartesianCoordinate(a_end); m_OutBox.X = (int)Math.Floor(Math.Min(m_position.getGlobalX(), m_endPosition.getGlobalX())); m_OutBox.Y = (int)Math.Floor(Math.Min(m_position.getGlobalY(), m_endPosition.getGlobalY())); m_OutBox.Width = (int)Math.Floor(Math.Abs(Math.Max(m_position.getGlobalX(), m_endPosition.getGlobalX()) - Math.Min(m_position.getGlobalX(), m_endPosition.getGlobalX()))); m_OutBox.Height = (int)Math.Floor(Math.Abs(Math.Max(m_position.getGlobalY(), m_endPosition.getGlobalY()) - Math.Min(m_position.getGlobalY(), m_endPosition.getGlobalY()))); }
public Box(Vector2 a_position, float a_width, float a_height, Color a_color, Color a_lineColor, int a_lineWidth, bool a_worldBox) : base(a_position, "", 0.110f) { m_boxTexture = new Texture2D(Game.getInstance().GraphicsDevice, 1, 1, false, SurfaceFormat.Color); m_boxTexture.SetData(new[] { a_color }); if (a_worldBox) { m_position = new CartesianCoordinate(a_position - Game.getInstance().getResolution() / 2); } else { m_position = new CartesianCoordinate(a_position - Game.getInstance().getResolution() / 2, Game.getInstance().m_camera.getPosition()); } m_boxColor = a_color; m_width = a_width; m_height = a_height; m_worldBox = a_worldBox; m_bounds = new Rectangle((int)a_position.X, (int)a_position.Y, (int)a_width, (int)a_height); Vector2 topLeft = a_position; Vector2 topRight = a_position; topRight.X += a_width; Vector2 btmRight = topRight; btmRight.Y += a_height; Vector2 btmLeft = btmRight; btmLeft.X = topLeft.X; m_lineList = new LinkedList<Line>(); if (a_worldBox) { m_lineList.AddLast(new Line(new CartesianCoordinate(topLeft), new CartesianCoordinate(topRight), Vector2.Zero, Vector2.Zero, a_lineColor, a_lineWidth, a_worldBox)); m_lineList.AddLast(new Line(new CartesianCoordinate(topRight), new CartesianCoordinate(btmRight), Vector2.Zero, Vector2.Zero, a_lineColor, a_lineWidth, a_worldBox)); m_lineList.AddLast(new Line(new CartesianCoordinate(btmRight), new CartesianCoordinate(btmLeft), Vector2.Zero, Vector2.Zero, a_lineColor, a_lineWidth, a_worldBox)); m_lineList.AddLast(new Line(new CartesianCoordinate(btmLeft), new CartesianCoordinate(topLeft), Vector2.Zero, Vector2.Zero, a_lineColor, a_lineWidth, a_worldBox)); } else { Position t_camera = Game.getInstance().m_camera.getPosition(); m_lineList.AddLast(new Line(t_camera, t_camera, topLeft - Game.getInstance().getResolution() / 2, topRight - Game.getInstance().getResolution() / 2, a_lineColor, a_lineWidth, a_worldBox)); m_lineList.AddLast(new Line(t_camera, t_camera, topRight - Game.getInstance().getResolution() / 2, btmRight - Game.getInstance().getResolution() / 2, a_lineColor, a_lineWidth, a_worldBox)); m_lineList.AddLast(new Line(t_camera, t_camera, btmRight - Game.getInstance().getResolution() / 2, btmLeft - Game.getInstance().getResolution() / 2, a_lineColor, a_lineWidth, a_worldBox)); m_lineList.AddLast(new Line(t_camera, t_camera, btmLeft - Game.getInstance().getResolution() / 2, topLeft - Game.getInstance().getResolution() / 2, a_lineColor, a_lineWidth, a_worldBox)); } }
public Text(Vector2 a_position, string a_text, string a_spriteFont, Color a_color, bool a_worldFont, float a_layer) : base(a_position, "") { if (a_worldFont) { m_position = new CartesianCoordinate(a_position - Game.getInstance().getResolution() / 2); } else { m_position = new CartesianCoordinate(a_position - Game.getInstance().getResolution() / 2, Game.getInstance().m_camera.getPosition()); } m_text = a_text; m_textOffset = Vector2.Zero; m_font = a_spriteFont; m_color = a_color; m_worldFont = a_worldFont; m_layer = a_layer; loadContent(); }
public Box(Vector2 a_position, int a_width, int a_height, Color a_color, bool a_worldBox) : base(a_position, "", 0.11f) { m_boxTexture = new Texture2D(Game.getInstance().GraphicsDevice, 1, 1, false, SurfaceFormat.Color); if (a_worldBox) { m_position = new CartesianCoordinate(a_position - Game.getInstance().getResolution() / 2); } else { m_position = new CartesianCoordinate(a_position - Game.getInstance().getResolution() / 2, Game.getInstance().m_camera.getPosition()); } m_lineList = new LinkedList<Line>(); m_boxColor = a_color; m_width = a_width; m_height = a_height; m_worldBox = a_worldBox; m_boxTexture.SetData(new[] { a_color }); }
public override void update(GameTime a_gameTime) { Vector2 t_mouse = calculateWorldMouse(); /* ----------------------------------- Middle-mouse drag ----------------------------------- */ if (Game.m_currentMouse.MiddleButton == ButtonState.Pressed && Game.m_previousMouse.MiddleButton == ButtonState.Pressed) { Vector2 t_difference = Game.getInstance().m_camera.getPosition().getGlobalCartesianCoordinates(); t_difference.X = (Mouse.GetState().X - Game.getInstance().getResolution().X / 2) / 20 / Game.getInstance().m_camera.getZoom(); t_difference.Y = (Mouse.GetState().Y - Game.getInstance().getResolution().Y / 2) / 20 / Game.getInstance().m_camera.getZoom(); Game.getInstance().m_camera.getPosition().plusWith(t_difference); } /* ----------------------------------- Left Mouse Button Click Down ----------------------------------- */ if (Game.m_currentMouse.LeftButton == ButtonState.Pressed && Game.m_previousMouse.LeftButton == ButtonState.Released) { if (m_state == State.firRectanglePoint) { m_recPoint = calculateWorldMouse(); m_state = State.drawingRectangle; m_recLines = new Line[4]; CartesianCoordinate t_stopidPoint = new CartesianCoordinate(m_recPoint); for (int i = 0; i < 4; ++i) { m_recLines[i] = new Line(t_stopidPoint, t_stopidPoint, Vector2.Zero, Vector2.Zero, Color.Yellow, 2, true); } } } /* ----------------------------------- Left Mouse Button Drag ----------------------------------- */ if (Game.m_currentMouse.LeftButton == ButtonState.Pressed && Game.m_previousMouse.LeftButton == ButtonState.Pressed) { if (m_state == State.drawingRectangle) { m_recLines[0].setEndPoint(new Vector2(t_mouse.X, m_recPoint.Y)); m_recLines[1].setEndPoint(new Vector2(m_recPoint.X, t_mouse.Y)); m_recLines[2].setEndPoint(t_mouse); m_recLines[3].setEndPoint(t_mouse); m_recLines[2].setStartPoint(new Vector2(t_mouse.X, m_recPoint.Y)); m_recLines[3].setStartPoint(new Vector2(m_recPoint.X, t_mouse.Y)); } } /* ----------------------------------- Left Mouse Button Release ----------------------------------- */ if (Game.m_currentMouse.LeftButton == ButtonState.Released && Game.m_previousMouse.LeftButton == ButtonState.Pressed) { if (m_state == State.drawingRectangle) { addTrigger(new PlayerIsWithinRectangle(m_recPoint.X, m_recPoint.Y, t_mouse.X, t_mouse.Y, Game.getInstance().m_camera.getLayer())); m_state = State.newTrigger; m_recLines = new Line[0]; } } m_backState.updateCamera(); bool t_buttonPressed = false; foreach (Button t_b in m_buttonList) { if (t_b.update()) { t_buttonPressed = true; } } if (m_btnAddEvent.update()) { t_buttonPressed = true; } foreach (GuiObject t_go in m_guiList) { t_go.update(a_gameTime); } if (!t_buttonPressed) { if (m_state == State.selectSwitch && Game.lmbClicked()) { Vector2 t_mousePoint = calculateWorldMouse(); foreach (GameObject t_go in m_backState.getCurrentList()) { if (t_go is LampSwitch && t_go.getBox().Contains((int)t_mousePoint.X, (int)t_mousePoint.Y)) { addTrigger(new SwitchTrigger((LampSwitch)t_go, m_switchTriggerButtons[m_switchTriggerType])); goUpOneState(); goUpOneState(); break; } } } else if (Game.rmbClicked()) { goUpOneState(); } else if (m_state == State.newCutscene && Game.keyClicked(Keys.Enter)) { addEffect(new CutsceneEffect(((TextField)m_guiList.First.Value).getText())); goUpOneState(); } else if (m_state == State.newEquip && Game.keyClicked(Keys.Enter)) { char[] t_delimiterChars = { ':', ' ', '/' }; String[] t_text = ((TextField)m_guiList.First.Value).getText().Split(t_delimiterChars); if (t_text.Length > 1) { addEffect(new EquipEffect(t_text[0], bool.Parse(t_text[1]))); goUpOneState(); } else { ((TextField)(m_guiList.First())).setText("write instead name(string):equip(bool)"); } } else if (m_state == State.newChase && Game.keyClicked(Keys.Enter)) { addTrigger(new ChaseTrigger(Boolean.Parse(((TextField)m_guiList.First.Value).getText()))); goUpOneState(); } else if (m_state == State.newDoorEffect && Game.lmbClicked()) { Vector2 t_mousePoint = calculateWorldMouse(); foreach (GameObject t_go in m_backState.getCurrentList()) { if (t_go is SecurityDoor && t_go.getBox().Contains((int)t_mousePoint.X, (int)t_mousePoint.Y)) { addEffect(new DoorOpenEffect((SecurityDoor)t_go, 10, 10)); goUpOneState(); break; } } } } while (m_eventsToRemove.Count > 0) { Button t_bToRemove = m_eventsToRemove.Pop(); t_bToRemove.kill(); m_events.Remove(t_bToRemove); m_buttonList.Remove(t_bToRemove); m_btnAddEvent.move(new Vector2(0, -25)); } while (m_buttonsToRemove.Count > 0) { m_buttonList.Remove(m_buttonsToRemove.Pop()); } while (m_eventsToAdd.Count > 0) { int i = 0; KeyValuePair<Button, Event>[] t_array = m_events.ToArray(); for (int j = 0; j < t_array.Length; ) { if (i == int.Parse(t_array[j++].Key.getText())) { j = 0; i++; } } Button t_button = new Button("btn_asset_list", new Vector2(0, 100 + ((m_numOfAddedEvents++) * 25)), "" + i, null, Color.Yellow, new Vector2(10, 2)); t_button.m_clickEvent += new Button.clickDelegate(selectEvent); m_events.Add(t_button, m_eventsToAdd.Pop()); m_buttonList.AddFirst(t_button); } while (m_buttonsToAdd.Count > 0) { m_buttonList.AddFirst(m_buttonsToAdd.Pop()); } if (m_numOfAddedEvents != m_events.Count) { Dictionary<Button, Event> t_eventList = m_events; m_events = new Dictionary<Button, Event>(); m_numOfAddedEvents = 0; m_btnAddEvent.setPosition(new Vector2(0, 100)); foreach (KeyValuePair<Button, Event> t_kvPair in t_eventList) { m_events.Add(t_kvPair.Key, t_kvPair.Value); t_kvPair.Key.setPosition(new Vector2(0, 100 + ((m_numOfAddedEvents) * 25))); m_btnAddEvent.move(new Vector2(0, 25)); m_numOfAddedEvents++; } } }
private void updateMouse() { Vector2 t_mouse = MouseHandler.worldMouse(); //----------------------------------- #region Middle-mouse drag if (MouseHandler.mmbPressed()) { Vector2 t_difference = Game.getInstance().m_camera.getPosition().getGlobalCartesian(); t_difference.X = (Mouse.GetState().X - Game.getInstance().getResolution().X / 2) / 20 / Game.getInstance().m_camera.getZoom(); t_difference.Y = (Mouse.GetState().Y - Game.getInstance().getResolution().Y / 2) / 20 / Game.getInstance().m_camera.getZoom(); Game.getInstance().m_camera.getPosition().plusWith(t_difference); } #endregion //----------------------------------- //----------------------------------- #region Left Mouse Button Click Down if (MouseHandler.lmbDown()) { if (m_state == State.firRectanglePoint) { m_recPoint = MouseHandler.worldMouse(); m_state = State.drawingRectangle; m_recLines = new Line[4]; CartesianCoordinate t_stopidPoint = new CartesianCoordinate(m_recPoint); for (int i = 0; i < 4; ++i) { m_recLines[i] = new Line(t_stopidPoint, t_stopidPoint, Vector2.Zero, Vector2.Zero, Color.Yellow, 2, true); } } if (m_state == State.newDoorEffect) { Vector2 t_mousePoint = MouseHandler.worldMouse(); foreach (GameObject t_go in m_backState.getCurrentList()) { if (t_go is SecurityDoor && t_go.getBox().Contains((int)t_mousePoint.X, (int)t_mousePoint.Y)) { m_events[m_selectedEvent].add(new DoorOpenEffect((SecurityDoor)t_go, 1, 1)); selectEvent(m_selectedEvent); m_btnAddEffect.setState(0); break; } } } } #endregion //----------------------------------- //----------------------------------- #region Left Mouse Button Drag if (MouseHandler.lmbPressed()) { if (m_state == State.drawingRectangle) { m_recLines[0].setEndPoint(new Vector2(t_mouse.X, m_recPoint.Y)); m_recLines[1].setEndPoint(new Vector2(m_recPoint.X, t_mouse.Y)); m_recLines[2].setEndPoint(t_mouse); m_recLines[3].setEndPoint(t_mouse); m_recLines[2].setStartPoint(new Vector2(t_mouse.X, m_recPoint.Y)); m_recLines[3].setStartPoint(new Vector2(m_recPoint.X, t_mouse.Y)); } } #endregion //----------------------------------- //----------------------------------- #region Left Mouse Button Release if (MouseHandler.lmbUp()) { if (m_state == State.drawingRectangle) { m_events[m_selectedEvent].add(new PlayerIsWithinRectangle(m_recPoint.X, m_recPoint.Y, t_mouse.X, t_mouse.Y, Game.getInstance().m_camera.getLayer())); m_btnAddTrigger.setState(0); m_state = State.newTrigger; m_recLines = new Line[0]; selectEvent(m_selectedEvent); } if (m_state == State.slctConsumable) { GameObject t_object = null; if ((t_object = selectObject(MouseHandler.worldMouse(), typeof(Consumable))) != null) { m_events[m_selectedEvent].add(new IsDeadTrigger(t_object, true)); m_btnAddTrigger.setState(Button.State.Normal); m_state = State.newTrigger; selectEvent(m_selectedEvent); } } if (m_state == State.slctLightSwitch) { GameObject t_object = null; if ((t_object = selectObject(MouseHandler.worldMouse(), typeof(LampSwitch))) != null) { m_events[m_selectedEvent].add(new SwitchTrigger((LampSwitch)t_object, SwitchTrigger.TriggerType.on)); m_btnAddTrigger.setState(Button.State.Normal); m_state = State.newTrigger; selectEvent(m_selectedEvent); } } } #endregion //----------------------------------- if (MouseHandler.rmbDown()) { deselectEvent(); } }
public void setPosition(Vector2 a_position) { m_position = new CartesianCoordinate(a_position + m_textOffset, Game.getInstance().m_camera.getPosition()); }
public void setPosition(Vector2 a_position) { m_position = new CartesianCoordinate(a_position + m_textOffset, Game.getInstance().m_camera.getPosition()); if (m_font.Equals("MotorwerkLarge")) { m_position.plusYWith(-5); } }
public virtual void draw(GameTime a_gameTime, SpriteBatch a_spriteBatch) { if (!m_isVisible) { return; } CartesianCoordinate t_cartCoord = new CartesianCoordinate(m_position.getLocalCartesian() / Game.getInstance().m_camera.getZoom(), m_position.getParentPosition()); if (m_isPressed || m_currentState == State.Pressed) { a_spriteBatch.Draw(m_pressedTexture, t_cartCoord.getGlobalCartesian(), null, Color.White, 0.0f, Vector2.Zero, new Vector2(1.0f / Game.getInstance().m_camera.getZoom(), 1.0f / Game.getInstance().m_camera.getZoom()), SpriteEffects.None, m_layer); } else if (m_isFocused || m_currentState == State.Hover) { a_spriteBatch.Draw(m_hoverTexture, t_cartCoord.getGlobalCartesian(), null, Color.White, 0.0f, Vector2.Zero, new Vector2(1.0f / Game.getInstance().m_camera.getZoom(), 1.0f / Game.getInstance().m_camera.getZoom()), SpriteEffects.None, m_layer); } else if (m_isToggled || m_currentState == State.Toggled) { a_spriteBatch.Draw(m_toggleTexture, t_cartCoord.getGlobalCartesian(), null, Color.White, 0.0f, Vector2.Zero, new Vector2(1.0f / Game.getInstance().m_camera.getZoom(), 1.0f / Game.getInstance().m_camera.getZoom()), SpriteEffects.None, m_layer); } else { a_spriteBatch.Draw(m_normalTexture, t_cartCoord.getGlobalCartesian(), null, Color.White, 0.0f, Vector2.Zero, new Vector2(1.0f / Game.getInstance().m_camera.getZoom(), 1.0f / Game.getInstance().m_camera.getZoom()), SpriteEffects.None, m_layer); } if (m_text != null) { m_text.draw(a_gameTime); } }