/// <summary> /// Allows the game component to perform any initialization it needs to before starting /// to run. This is where it can query for any required services and load content. /// </summary> public override void Initialize() { cursorTexture = mGame.Content.Load<Texture2D>("reg_cursor"); grabTexture = mGame.Content.Load<Texture2D>("grab_cursor"); wCursor = new WorldObject(cursorTexture); wCursor.setTexture(cursorTexture); base.Initialize(); }
public void createGrid() { float widthLeft = Width; float heightLeft = Height; for (float i = 0; i < widthLeft; i += gridTexture.Width) { for (float j = 0; j < heightLeft; j += gridTexture.Height) { gridObj = new WorldObject(); gridObj.setTexture(gridTexture); gridObj.PositionInWorldSpace = new Vector2(i + gridTexture.Width/2, j + gridTexture.Height/2); gridList.Add(gridObj); } } }
/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { KeyboardState currentKeys = Keyboard.GetState(); currentMouseState = Mouse.GetState(); cursorPos.X = currentMouseState.X + camera.xOffset; cursorPos.Y = currentMouseState.Y + camera.yOffset; if (currentMouseState.LeftButton == ButtonState.Pressed && currentKeys.IsKeyUp(Keys.LeftShift)) { wCursor.setTexture(grabTexture); //Check if cursor is trying to drag an object already on screen foreach (WorldObject obj in world.worldObjectList) { if (wCursor.Collides(obj) && objDragged == null) { objDragged = obj; } } //Check if cursor is clicking an icon of object in objMenu if (wCursor.Collides(objMenu.currObject) && objDragged == null) { objDragged = new WorldObject(); objDragged.setTexture(objMenu.currObject.Texture); objDragged.TextureName = objMenu.currObject.TextureName; } //Causes selected object to follow cursor if (objDragged != null) { objDragged.PositionInWorldSpace = cursorPos; } } //If leftshift and left mouse are pressed, delete object in world else if (currentMouseState.LeftButton == ButtonState.Pressed && currentKeys.IsKeyDown(Keys.LeftShift)) { foreach (WorldObject obj in world.worldObjectList) { if (wCursor.Collides(obj) && objDragged == null) { world.deleteList.Add(obj); } } } else { //Drop object and place in list of object in world if (objDragged != null && !world.worldObjectList.Contains(objDragged)) world.worldObjectList.Add(objDragged); objDragged = null; wCursor.setTexture(cursorTexture); } wCursor.PositionInWorldSpace = cursorPos; base.Update(gameTime); }
private void LoadMenu(ContentManager content, String wordFile) { using (XmlReader reader = XmlReader.Create(new StreamReader(wordFile))) { XDocument xml = XDocument.Load(reader); XElement root = xml.Root; foreach (XElement elem in root.Elements()) { WorldObject obj = new WorldObject(); foreach (XElement innerElem in elem.Elements()) { XMLParse.AddValueToClassInstance(innerElem, obj); } obj.setTexture(content.Load<Texture2D>(obj.TextureName)); obj.objScale = 1f/(obj.Texture.Width) * 100; objIconList.Add(obj); } } //init icon background iconObj = new WorldObject(); iconObj.setTexture(iconBack); iconObj.color = Color.Gray; iconObj.objScale = 1f / (iconObj.Texture.Width) * 100; iconObj.PositionInWorldSpace = iconPos; }