public void Update(Cursor cursor) { // check cursor value adjust if (cursor.position.X >= knobPosition.X && cursor.position.X <= knobPosition.X + rect.Width && cursor.position.Y >= knobPosition.Y && cursor.position.Y <= knobPosition.Y + rect.Height && cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed && cursor.click == false) { if (start == true) { cursor.click = true; start = false; mouseNum = cursor.position.X; } } if (cursor.position.X >= knobPosition.X && cursor.position.X <= knobPosition.X + rect.Width && cursor.position.Y >= knobPosition.Y && cursor.position.Y <= knobPosition.Y + rect.Height && start == false) { value += (cursor.position.X - mouseNum) * (max - min) / (rect.Width*extent - knobRect.Width); knobPosition.X += cursor.position.X - mouseNum; mouseNum = cursor.position.X; if (value > max) { value = max; } if (value < min) { value = min; } if (knobPosition.X > position.X + rect.Width * extent + (rect.Width * (1.0f - extent)) / 2.0f - knobTex.Width) { knobPosition.X = position.X + rect.Width * extent + (rect.Width * (1.0f - extent)) / 2.0f - knobTex.Width; } if (knobPosition.X < position.X + (rect.Width * (1.0f - extent)) / 2.0f) { knobPosition.X = position.X + (rect.Width * (1.0f - extent)) / 2.0f; } } param.value = value; if (cursor.mouseState.LeftButton == ButtonState.Released && cursor.mouseState.RightButton == ButtonState.Released) { start = true; } }
public void Update(Cursor cursor) { // check cursor value adjust if (cursor.position.X >= position.X && cursor.position.X <= position.X + rect.Width && cursor.position.Y >= position.Y && cursor.position.Y <= position.Y + rect.Height && cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed && cursor.click == false) { if (start == true) { cursor.click = true; start = false; mouseNum = cursor.position.Y; } } if (start == false) { value -= (cursor.position.Y - mouseNum)*(max - min)/200; mouseNum = cursor.position.Y; if (value > max) { value = max; } if (value < min) { value = min; } } param.value = value; if (cursor.mouseState.LeftButton == ButtonState.Released && cursor.mouseState.RightButton == ButtonState.Released) { start = true; } // update position for rotation rotation = ((value - min) / (max - min)) * (float)Math.PI - (float)Math.PI/2.0f; rotPosition.X = position.X + (float)Math.Sin((double)rotation - Math.PI / 4.0) * (diag / 2.0f) + (diag / 2.0f); rotPosition.Y = position.Y - (float)Math.Sin((double)rotation + Math.PI / 4.0) * (diag / 2.0f) + (diag / 2.0f) - 40.0f; }
public void Render(SpriteBatch sbatch,Cursor cursor) { // icon if (cursor.position.X >= position.X && cursor.position.X < (position.X + tex.Width) && cursor.position.Y >= position.Y && cursor.position.Y < (position.Y + tex.Height)) { sbatch.Draw(hTex, position, rect, Microsoft.Xna.Framework.Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, layer); } else { sbatch.Draw(tex, position, rect, Microsoft.Xna.Framework.Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, layer); } // menu if (menu == true) { // arrows if (buildList.Count > buildScreenLength) { full = true; if (scrollPos == (buildList.Count - buildScreenLength)) { if (cursor.position.X >= leftArrowPos.X && cursor.position.X <= leftArrowPos.X + arrow.Width && cursor.position.Y >= leftArrowPos.Y - arrow.Height && cursor.position.Y <= leftArrowPos.Y) { sbatch.Draw(highArrow, leftArrowPos, null, Color.White, -(float)Math.PI / 2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } else { sbatch.Draw(arrow, leftArrowPos, null, Color.White, -(float)Math.PI / 2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } } if (scrollPos == 0) { if (cursor.position.X >= rightArrowPos.X - arrow.Width && cursor.position.X <= rightArrowPos.X && cursor.position.Y >= rightArrowPos.Y && cursor.position.Y <= rightArrowPos.Y + arrow.Height) { sbatch.Draw(highArrow, rightArrowPos, null, Color.White, (float)Math.PI/2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } else { sbatch.Draw(arrow, rightArrowPos, null, Color.White, (float)Math.PI / 2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } } if (scrollPos < (buildList.Count - buildScreenLength) && scrollPos > 0) { if (cursor.position.X >= leftArrowPos.X && cursor.position.X <= leftArrowPos.X + arrow.Width && cursor.position.Y >= leftArrowPos.Y - arrow.Height && cursor.position.Y <= leftArrowPos.Y) { sbatch.Draw(highArrow, leftArrowPos, null, Color.White, -(float)Math.PI / 2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } else { sbatch.Draw(arrow, leftArrowPos, null, Color.White, -(float)Math.PI / 2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } if (cursor.position.X >= rightArrowPos.X - arrow.Width && cursor.position.X <= rightArrowPos.X && cursor.position.Y >= rightArrowPos.Y && cursor.position.Y <= rightArrowPos.Y + arrow.Height) { sbatch.Draw(highArrow, rightArrowPos, null, Color.White, (float)Math.PI / 2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } else { sbatch.Draw(arrow, rightArrowPos, null, Color.White, (float)Math.PI / 2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } } } else { full = false; } // render background sbatch.Draw(dummyTexture, buildPos, buildRectangle, boxColour, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.17f); // render items for (int x = scrollPos; x < (scrollPos + buildScreenLength) && x < buildList.Count; x++) { FloorObject curitem = buildList[x]; curitem.IconRender(sbatch,this); } } }
public void Update(Corpse corpse,NumericalCounter lifeForce, NumericalCounter humanity, NumericalCounter longevity, FloorObject conductor, GameTime gameTime, Cursor cursor,Scientist scientist, Assistant assistant) { // check if resurrection is possible if (conductor.on == true && corpse.visible == true && corpse.alive == false) { doable = true; } else { doable = false; } MouseState mouseState = Mouse.GetState(); // clicking on animate icon if (cursor.position.X >= position.X && cursor.position.X < (position.X + tex.Width) && cursor.position.Y >= position.Y && cursor.position.Y < (position.Y + tex.Height)) { if (mouseState.LeftButton == ButtonState.Pressed | mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false && doable == true) { Animate(scientist, assistant); clickOn = true; } cursor.click = true; } } if (clickOn == true) { clickCount += gameTime.ElapsedGameTime.Milliseconds; if (clickCount > 100) { clickCount = 0; clickOn = false; } } }
public void Render(SpriteBatch sbatch, Cursor cursor) { // icon if (cursor.position.X >= position.X && cursor.position.X < (position.X + tex.Width) && cursor.position.Y >= position.Y && cursor.position.Y < (position.Y + tex.Height) && doable == true && clickOn == false) { sbatch.Draw(hTex, position, rect, Microsoft.Xna.Framework.Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, layer); } else if (clickOn == true) { sbatch.Draw(cTex, position, rect, Microsoft.Xna.Framework.Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, layer); } else { sbatch.Draw(tex, position, rect, Microsoft.Xna.Framework.Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, layer); } }
public void Update(GameTime gametime, GraphicsDevice graphicsDevice, Cursor cursor, NumericalCounter research,NumericalCounter money, NumericalCounter madness, List<MiniProgressBar> proglist, ReachableArea reachable) { // get most recent reachable areas path.Update(reachable); // update position from grid position position = grid.CartesianCoords(gridPosition); // determine later from position and direction of movement if (walking == true) { layer = 0.2f + (0.2f / (float)grid.rows) * walkingTarget.Y + (0.2f / ((float)grid.columns * (float)grid.rows + 1)) * Math.Abs(walkingTarget.X - (float)grid.columns / 2.0f); } else { layer = 0.2f + (0.2f / (float)grid.rows) * gridPosition.Y + (0.2f / ((float)grid.columns * (float)grid.rows + 1)) * Math.Abs(gridPosition.X - (float)grid.columns / 2.0f); } offset = new Vector2((width * scale) / 2.0f, height * scale); // factor of 2 here and in the draw command are just for this test anim, so it's a decent size... // walking.... if (action != null && walking == false && doing == false) { // to corpse if (corpseWork == true) { if (gridPosition != corpsePosition) { walking = true; drawPath = path.PathList(gridPosition, corpsePosition, grid); pathStep = 1; walkingTarget = drawPath[pathStep]; } else { doing = true; currentFrame = 0; gridPosition = drawPath[pathStep - 1]; position = grid.CartesianCoords(gridPosition); } } // to machine else if (gridPosition != floorObject.opPos) { walking = true; drawPath = path.PathList(gridPosition, floorObject.opPos, grid); pathStep = 1; walkingTarget = drawPath[pathStep]; } // arrived at destination, start doing else { doing = true; currentFrame = 0; gridPosition = drawPath[pathStep - 1]; position = grid.CartesianCoords(gridPosition); } } if (walking == true) { direction = (grid.CartesianCoords(walkingTarget) - grid.CartesianCoords(gridPosition)); targetDistance = direction.Length(); direction.Normalize(); walkingOffset += direction * gametime.ElapsedGameTime.Milliseconds * 0.2f; distanceGone = walkingOffset.Length(); if (distanceGone < targetDistance) { Vector2 move = walkingOffset; position += move; } else { pathStep += 1; if (pathStep < drawPath.Count) { gridPosition = drawPath[pathStep - 1]; walkingTarget = drawPath[pathStep]; position = grid.CartesianCoords(gridPosition); } else { walking = false; doing = true; currentFrame = 0; gridPosition = drawPath[pathStep-1]; position = grid.CartesianCoords(gridPosition); } walkingOffset = Vector2.Zero; targetDistance = 0; distanceGone = 0; } } // update animation frame timer += gametime.ElapsedGameTime.Milliseconds; if (timer >= msecsTweenFrames) { timer = 0; if (walking == true) { if (Math.Abs(direction.X) >= Math.Abs(direction.Y)) { if (direction.X >= 0) { anim = 1; } else { anim = 0; } } if (Math.Abs(direction.Y) >= Math.Abs(direction.X)) { if (direction.Y >= 0) { anim = 2; } else { anim = 3; } } if (currentFrame++ == numberOfFrames - 1) { currentFrame = 0; } } // start up menu action if doing is done, animate doing if (doing == true) { anim = 4; if (action != null) { // if not staying, run anim once, start progress bar if (action.remain == false) { if (currentFrame++ == numberOfFrames - 1) { doing = false; proglist.Add(new MiniProgressBar(graphicsDevice, floorObject.position + new Vector2(-5, -105), action, floorObject)); progBar = proglist[-1]; action = null; } } // if staying to work machine... else { // if starting, create progress bar and start anim if (animStart == true) { animStart = false; if (corpseWork == true) { proglist.Add(new MiniProgressBar(graphicsDevice, position + new Vector2(0, -100), action, null)); progBar = proglist[proglist.Count -1]; } else { proglist.Add(new MiniProgressBar(graphicsDevice, floorObject.position + new Vector2(-5, -105), action, floorObject)); progBar = proglist[proglist.Count -1]; } } // run anim until machine work is finished else { if (currentFrame++ == numberOfFrames - 1) { currentFrame = 0; if (action.done == true) { doing = false; action.done = false; action = null; animStart = true; if (corpseWork == true) { corpseWork = false; } } } } } } // animate animation if animating.... else if (animating == true) { anim = 4; if (currentFrame++ == numberOfFrames - 1) { doing = false; animating = false; } } } // if not walking, stand! if (walking == false && doing == false) { anim = 2; currentFrame = 0; } // set anim and frame rect.X = currentFrame * width; rect.Y = height * anim; } }
public void Render(SpriteBatch sbatch,Cursor cursor,SpriteFont font,NumericalCounter money, List<FloorObject> floorObjectList, ReachableArea reachable, Scientist scientist, Assistant assistant) { // draw icon - highlighted if (cursor.position.X >= position.X && cursor.position.X < (position.X + width) && cursor.position.Y >= position.Y && cursor.position.Y < (position.Y + height) && clickOn == false) { sbatch.Draw(hTex, position, rect, Microsoft.Xna.Framework.Color.White, 0, Vector2.Zero,scale, SpriteEffects.None, layer); } // draw icon - clicked else if (clickOn == true) { sbatch.Draw(cTex, position, rect, Microsoft.Xna.Framework.Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, layer); } // draw icon - unhighlighted else { sbatch.Draw(tex, position, rect, Microsoft.Xna.Framework.Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, layer); } // menu if (menu == true) { // find longest string in menu int boxWidth = 0; if (menu == true) { foreach (FloorObject machine in buildList) { if (machine.name.Length + 5 > boxWidth) { boxWidth = machine.name.Length + 5; // set box width for below } } } // draw boxes and outlines for each item, check if highlighted, clicked menuRectangle.Width = boxWidth * 12 + 10; // set width to widest text from above menuRectangle.Height = 30; // menu item height spread Vector2 menuItemPosition = menuPosition - new Vector2(0, menuRectangle.Height); // position of each text menu item menuMouseover = false; MouseState mouseState = Mouse.GetState(); FloorObject remove = null; // built items to remove from build list foreach (FloorObject machine in buildList) { // declare colours Color textColour; Color boxColour; Color lineColour; // IF MOUSE-OVERED change colours, set to highlighted item if (cursor.position.X >= menuItemPosition.X && cursor.position.X < (menuItemPosition.X + menuRectangle.Width) && cursor.position.Y >= menuItemPosition.Y && cursor.position.Y < (menuItemPosition.Y + menuRectangle.Height)) { textColour = Color.Black; boxColour = Color.LightGray; lineColour = Color.LimeGreen; menuHighlightObject = machine; menuMouseover = true; // build item if clicked if (mouseState.LeftButton == ButtonState.Pressed | mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false) { menu = false; if (money.value >= menuHighlightObject.cost) { remove = menuHighlightObject; } } cursor.click = true; } } // IF NOT MOUSE-OVERED else { // set colours to standard textColour = Color.White; boxColour = Color.Gray; lineColour = Color.DarkGray; } // text sbatch.DrawString(font, machine.name + ": $" + machine.cost.ToString(), menuItemPosition + new Vector2(5,0), textColour, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.13f); // text rectangle sbatch.Draw(dummyTexture, menuItemPosition , menuRectangle, boxColour, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.17f); // top line Tuple<Vector2, Vector2> line = new Tuple<Vector2, Vector2>(menuItemPosition, (menuItemPosition + new Vector2(menuRectangle.Width, 0))); float angle = (float)Math.Atan2(line.Item2.Y - line.Item1.Y, line.Item2.X - line.Item1.X); float length = Vector2.Distance(line.Item1, line.Item2); sbatch.Draw(dummyTexture, line.Item1 + new Vector2(0, 0), null, lineColour, angle, Vector2.Zero, new Vector2(length, 3.0f), SpriteEffects.None, 0.15f); // right line Tuple<Vector2, Vector2> line2 = new Tuple<Vector2, Vector2>((menuItemPosition + new Vector2(menuRectangle.Width, menuRectangle.Height)), (menuItemPosition + new Vector2(menuRectangle.Width, 0))); float angle2 = (float)Math.Atan2(line2.Item2.Y - line2.Item1.Y, line2.Item2.X - line2.Item1.X); float length2 = Vector2.Distance(line2.Item1, line2.Item2); sbatch.Draw(dummyTexture, line2.Item1 + new Vector2(0, 0), null, lineColour, angle2, Vector2.Zero, new Vector2(length2, 3.0f), SpriteEffects.None, 0.15f); // left line Tuple<Vector2, Vector2> line3 = new Tuple<Vector2, Vector2>(menuItemPosition, (menuItemPosition + new Vector2(0, menuRectangle.Height))); float angle3 = (float)Math.Atan2(line3.Item2.Y - line3.Item1.Y, line3.Item2.X - line3.Item1.X); float length3 = Vector2.Distance(line3.Item1, line3.Item2); sbatch.Draw(dummyTexture, line3.Item1 + new Vector2(0, 0), null, lineColour, angle3, Vector2.Zero, new Vector2(length3, 3.0f), SpriteEffects.None, 0.15f); // bottom line Tuple<Vector2, Vector2> line4 = new Tuple<Vector2, Vector2>((menuItemPosition + new Vector2(menuRectangle.Width, menuRectangle.Height)), (menuItemPosition + new Vector2(0, menuRectangle.Height))); float angle4 = (float)Math.Atan2(line4.Item2.Y - line4.Item1.Y, line4.Item2.X - line4.Item1.X); float length4 = Vector2.Distance(line4.Item1, line4.Item2); sbatch.Draw(dummyTexture, line4.Item1 + new Vector2(0, 0), null, lineColour, angle4, Vector2.Zero, new Vector2(length4, 3.0f), SpriteEffects.None, 0.15f); // set to height of next text item menuItemPosition -= new Vector2(0, menuRectangle.Height); } // remove anything that has been built from build list, build, update its position if (remove != null) { floorObjectList.Add(remove); // add to floor objects (build) Remove(remove, money); // remove from build list reachable.Update(floorObjectList); // update reachable squares of grid, update character's paths scientist.path.Update(reachable); // update path from updated reachable assistant.path.Update(reachable); // update path from updated reachable remove = null; } // set to close menu if clicking is done outside... if (menuMouseover == false) { if (mouseState.LeftButton == ButtonState.Pressed | mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false) { menu = false; } cursor.click = true; } } } }
public void Render(SpriteBatch sbatch, SpriteFont font, Cursor cursor) { // object itself sbatch.Draw(objectTex, position - offset, rect, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, layer); // menu if (menu == true) { Vector2 menuItemPosition = menuPosition; // position of first text menu item foreach (Tuple<string,Color,Color,Color> item in actions) { textColour = item.Item2; boxColour = item.Item3; lineColour = item.Item4; string actionName = item.Item1; // text sbatch.DrawString(font, actionName, menuItemPosition + new Vector2(5, 0), textColour, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.13f); // text rectangle sbatch.Draw(dummyTexture, menuItemPosition, menuRectangle, boxColour, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.17f); // top line Tuple<Vector2, Vector2> line = new Tuple<Vector2, Vector2>(menuItemPosition, (menuItemPosition + new Vector2(menuRectangle.Width, 0))); float angle = (float)Math.Atan2(line.Item2.Y - line.Item1.Y, line.Item2.X - line.Item1.X); float length = Vector2.Distance(line.Item1, line.Item2); sbatch.Draw(dummyTexture, line.Item1 + new Vector2(0, 0), null, lineColour, angle, Vector2.Zero, new Vector2(length, 3.0f), SpriteEffects.None, 0.15f); // right line Tuple<Vector2, Vector2> line2 = new Tuple<Vector2, Vector2>((menuItemPosition + new Vector2(menuRectangle.Width, menuRectangle.Height)), (menuItemPosition + new Vector2(menuRectangle.Width, 0))); float angle2 = (float)Math.Atan2(line2.Item2.Y - line2.Item1.Y, line2.Item2.X - line2.Item1.X); float length2 = Vector2.Distance(line2.Item1, line2.Item2); sbatch.Draw(dummyTexture, line2.Item1 + new Vector2(0, 0), null, lineColour, angle2, Vector2.Zero, new Vector2(length2, 3.0f), SpriteEffects.None, 0.15f); // left line Tuple<Vector2, Vector2> line3 = new Tuple<Vector2, Vector2>(menuItemPosition, (menuItemPosition + new Vector2(0, menuRectangle.Height))); float angle3 = (float)Math.Atan2(line3.Item2.Y - line3.Item1.Y, line3.Item2.X - line3.Item1.X); float length3 = Vector2.Distance(line3.Item1, line3.Item2); sbatch.Draw(dummyTexture, line3.Item1 + new Vector2(0, 0), null, lineColour, angle3, Vector2.Zero, new Vector2(length3, 3.0f), SpriteEffects.None, 0.15f); // bottom line Tuple<Vector2, Vector2> line4 = new Tuple<Vector2, Vector2>((menuItemPosition + new Vector2(menuRectangle.Width, menuRectangle.Height)), (menuItemPosition + new Vector2(0, menuRectangle.Height))); float angle4 = (float)Math.Atan2(line4.Item2.Y - line4.Item1.Y, line4.Item2.X - line4.Item1.X); float length4 = Vector2.Distance(line4.Item1, line4.Item2); sbatch.Draw(dummyTexture, line4.Item1 + new Vector2(0, 0), null, lineColour, angle4, Vector2.Zero, new Vector2(length4, 3.0f), SpriteEffects.None, 0.15f); // set to height of next text item menuItemPosition += new Vector2(0, menuRectangle.Height); } } // Mouse-over text if (mouseOver == true) { sbatch.DrawString(font, name, cursor.position + textOffset, Microsoft.Xna.Framework.Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.01f); } }
public void Update(GameTime gameTime, MenuAction dissect, MenuAction study,NumericalCounter longevity, NumericalCounter humanity, NumericalCounter lifeforce, Scientist scientist, Assistant assistant, MenuAction talk, Cursor cursor,List<MiniProgressBar> bars, MenuAction clearCorpse) { cursor.corpseMouseover = false; if (flyTimer >= flyTime && alive == false) { flyTimer = 0; flies.AddFlies(1); } flyTimer += gameTime.ElapsedGameTime.Milliseconds; if (flyTimer >= flyLossTime && visible == false) { if (flies.flies.Count > 0) { flyTimer = 0; flies.RemoveFlies(1); } } if (this.visible == true) { // update cut up-ness if (dead == false) { cut = dissect.count * 3 + study.count; } if (cut > 3) { cut = 3; } // check for mouseover & click if (cursor.position.X >= position.X && cursor.position.X <= position.X + fwidth*scale && cursor.position.Y >= position.Y && cursor.position.Y <= position.Y + height && visible == true && corpseMenu == false) { cursor.corpseMouseover = true; // add object mouseover text // turn on menu when object is clicked if (cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false) { corpseMenu = true; menuOpen = true; cursor.corpseMouseover = false; } cursor.click = true; } } // rotting timer and count and flies timer += gameTime.ElapsedGameTime.Milliseconds; rotTimer += gameTime.ElapsedGameTime.Milliseconds; colorTimer += gameTime.ElapsedGameTime.Milliseconds; if (rotTimer >= rotTime * 1000.0 && alive == false && dead == false) { rotTimer = 0; if (rot.value > 1) { rot.value -= 1; flyTime -= 1500; } else { Die(); corpseColor = Microsoft.Xna.Framework.Color.Brown; rot.value = 3; } } if (colorTimer >= colorTime) { colorTimer = 0; if (corpseColor.R > 90) { this.corpseColor.R -= 1; } if (corpseColor.B > 0) { this.corpseColor.B -= 1; } if (corpseColor.G > 60) { this.corpseColor.G -= 1; } } // live corpse dead count && anim change if (alive == true) { longevity.valueChange = -0.01f; if (longevity.value == 0) { Die(); } if (scientist.action == talk && scientist.doing == true) { talking = true; anim = 2; frames = nframes[2]; } else { talking = false; anim = 1; frames = nframes[1]; } } else if (dead == false) { longevity.valueChange = 0; anim = 0; frames = nframes[0]; } // kill if dissected if (dissect.done == true) { Die(); } // kill if studies 3 times if (study.count >= 3) { Die(); } // update anim if (timer >= frate) { timer = 0; if (currentFrame++ == frames - 1) { currentFrame = 0; } rect.Y = cut * height + currentFrame; // * fwidth } // menu setup if (corpseMenu == true && menuOpen == true) { menuPosition = cursor.position; menuOpen = false; // find longest string in menu int boxWidth = 0; actions = new List<Tuple<string, Color, Color, Color>> { }; if (alive == false && dead == false) { menuActions = workMenuActions; foreach (MenuAction action in workMenuActions) { // add actions.Add(new Tuple<string, Color, Color, Color>(action.name, Color.White, Color.Gray, Color.DarkGray)); if (action.name.Length > boxWidth) { boxWidth = action.name.Length; // set box width for below } } } if (alive == true) { menuActions = aliveMenuActions; foreach (MenuAction action in aliveMenuActions) { // add actions.Add(new Tuple<string, Color, Color, Color>(action.name, Color.White, Color.Gray, Color.DarkGray)); if (action.name.Length > boxWidth) { boxWidth = action.name.Length; // set box width for below } } } if (dead == true) { menuActions = deadMenuActions; foreach (MenuAction action in deadMenuActions) { // add actions.Add(new Tuple<string, Color, Color, Color>(action.name, Color.White, Color.Gray, Color.DarkGray)); if (action.name.Length > boxWidth) { boxWidth = action.name.Length; // set box width for below } } } // boxes and outlines menuRectangle.Width = boxWidth * 12 + 10; // set width to widest text from above menuRectangle.Height = 30; // menu item height spread } // menu update if (corpseMenu == true) { menuMouseover = false; Vector2 menuItemPosition = menuPosition; foreach (MenuAction action in menuActions) { // IF MOUSE-OVERED change colours, set to highlighted item if (cursor.position.X >= menuItemPosition.X && cursor.position.X < (menuItemPosition.X + menuRectangle.Width) && cursor.position.Y >= menuItemPosition.Y && cursor.position.Y < (menuItemPosition.Y + menuRectangle.Height)) { textColour = Color.Black; boxColour = Color.LightGray; lineColour = Color.LimeGreen; menuHighlightAction = action; menuMouseover = true; if (cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false) { corpseMenu = false; if (action.scientist == true) { if (scientist.walking == true) { scientist.walking = false; scientist.floorObject = null; scientist.action = null; } else if (scientist.doing == true) { scientist.doing = false; scientist.corpseWork = false; scientist.floorObject = null; bars.Remove(scientist.progBar); scientist.action = null; scientist.animStart = true; } scientist.action = menuHighlightAction; scientist.corpseWork = true; } if (action.assistant == true) { if (assistant.walking == true) { assistant.walking = false; assistant.floorObject = null; assistant.action = null; } else if (assistant.doing == true) { assistant.doing = false; assistant.digging = false; assistant.floorObject = null; bars.Remove(assistant.progBar); assistant.action = null; assistant.animStart = true; } assistant.action = menuHighlightAction; assistant.corpseWork = true; } } cursor.click = true; } } else { textColour = Color.White; boxColour = Color.Gray; lineColour = Color.DarkGray; if (cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false) { corpseMenu = false; } } } int index = menuActions.IndexOf(action); actions[index] = new Tuple<string, Color, Color, Color>(actions[index].Item1, textColour, boxColour, lineColour); menuItemPosition = menuItemPosition + new Vector2(0, menuRectangle.Height); } } } // check for cleared up dead corpse, reset corpse if so. if (clearCorpse.count > 0) { clearCorpse.count = 0; visible = false; dead = false; corpseColor = Color.White; rot.value = 3; } // update the rot counter rot.Update(gameTime); // update fly swarm flies.Update(); }
public void Update(GameTime gameTime, Cursor cursor, List<FloorObject> floorObjectList, FloorObject table, Assistant assistant, Corpse corpse, List<MiniProgressBar> bars,MenuAction dissect,MenuAction study) { if (floorObjectList.Contains(table) && assistant.digging == false && corpse.visible == false && assistant.outside == false && assistant.corpseCarrying == false) { doable = true; } else { doable = false; } // clicking on build icon if (cursor.position.X >= iposition.X && cursor.position.X < (iposition.X + iwidth) && cursor.position.Y >= iposition.Y && cursor.position.Y < (iposition.Y + iheight)) { high = true; if (cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false) { if (doable == true) { assistant.DigUpCorpse(corpse,dissect,study); clickOn = true; } } cursor.click = true; } } else { high = false; } if (clickOn == true) { clickCount += gameTime.ElapsedGameTime.Milliseconds; if (clickCount > 100) { clickCount = 0; clickOn = false; } } }
public void Update(GameTime gameTime, Cursor cursor, List<FloorObject> floorObjectList, FloorObject table, Assistant assistant, Corpse corpse, List<MiniProgressBar> bars) { // check for mouseover and click if (menu == false) { cursor.graveMouseOver = false; // graveyard if (cursor.position.X >= tlcorner.X && cursor.position.X <= brcorner.X && cursor.position.Y >= tlcorner.Y && cursor.position.Y <= brcorner.Y) { cursor.graveMouseOver = true; // add object mouseover text // turn on menu when object is clicked if (cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false) { menu = true; menuStart = true; menuPosition = cursor.position; cursor.graveMouseOver = false; } cursor.click = true; } } } if (menu == true) { if (cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false) { menu = false; if (menuMouseover == true) { if (floorObjectList.Contains(table)) { assistant.DigUpCorpse(corpse); } } } cursor.click = true; } } // set menu dimensions, make list of names and colours for each object if (menu == true && menuStart == true) { // find longest string in menu int boxWidth = 0; actions = new List<Tuple<string, Color, Color, Color>> { }; foreach (MenuAction action in menuActions) { // add actions.Add(new Tuple<string, Color, Color, Color>(action.name, Color.White, Color.Gray, Color.DarkGray)); if (action.name.Length > boxWidth) { boxWidth = action.name.Length; // set box width for below } } // boxes and outlines menuRectangle.Width = boxWidth * 12 + 10; // set width to widest text from above menuRectangle.Height = 30; // menu item height spread } if (menu == true) { menuMouseover = false; Vector2 menuItemPosition = menuPosition; foreach (MenuAction action in menuActions) { // IF MOUSE-OVERED change colours, set to highlighted item if (cursor.position.X >= menuItemPosition.X && cursor.position.X < (menuItemPosition.X + menuRectangle.Width) && cursor.position.Y >= menuItemPosition.Y && cursor.position.Y < (menuItemPosition.Y + menuRectangle.Height)) { textColour = Color.Black; boxColour = Color.LightGray; lineColour = Color.LimeGreen; menuHighlightAction = action; menuMouseover = true; } else { textColour = Color.White; boxColour = Color.Gray; lineColour = Color.DarkGray; } int index = menuActions.IndexOf(action); actions[index] = new Tuple<string, Color, Color, Color>(actions[index].Item1, textColour, boxColour, lineColour); if (cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false) { menu = false; if (menuMouseover == true) { if (action.assistant == true && assistant.outside == false && assistant.corpseCarrying == false) { if (assistant.walking == true) { assistant.walking = false; assistant.floorObject = null; assistant.action = null; } else if (assistant.doing == true) { assistant.doing = false; assistant.digging = false; assistant.floorObject = null; bars.Remove(assistant.progBar); assistant.action = null; assistant.animStart = true; } } } } cursor.click = true; } menuItemPosition = menuItemPosition + new Vector2(0, menuRectangle.Height); } } }
public void Update(Cursor cursor, GameTime gameTime, NumericalCounter money) { // clicking on build icon if (cursor.position.X >= position.X && cursor.position.X < (position.X + width) && cursor.position.Y >= position.Y && cursor.position.Y < (position.Y + height)) { if (cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false) { menu = true; clickOn = true; cursor.click = true; } } } // turn click anim on for a bit if (clickOn == true) { clickCount += gameTime.ElapsedGameTime.Milliseconds; if (clickCount > 100) { clickCount = 0; clickOn = false; } } // turm the menu off if (menuMouseover == false && (cursor.position.X >= position.X && cursor.position.X < (position.X + width) && cursor.position.Y >= position.Y && cursor.position.Y < (position.Y + height)) == false) { if (cursor.position.Y < buildPos.Y) { if (cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed) { if (menu == true) { menu = false; } } } } // remove objects that have been built removeUpdate(); }
public void Render(SpriteBatch sbatch,Cursor cursor,SpriteFont font,NumericalCounter money, List<FloorObject> floorObjectList, ReachableArea reachable, Scientist scientist, Assistant assistant) { // draw icon - highlighted if (cursor.position.X >= position.X && cursor.position.X < (position.X + width) && cursor.position.Y >= position.Y && cursor.position.Y < (position.Y + height) && clickOn == false) { sbatch.Draw(hTex, position, rect, Microsoft.Xna.Framework.Color.White, 0, Vector2.Zero,scale, SpriteEffects.None, layer); } // draw icon - clicked else if (clickOn == true) { sbatch.Draw(cTex, position, rect, Microsoft.Xna.Framework.Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, layer); } // draw icon - unhighlighted else { sbatch.Draw(tex, position, rect, Microsoft.Xna.Framework.Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, layer); } // menu if (menu == true) { // arrows if (buildList.Count > buildScreenLength) { full = true; if (scrollPos == (buildList.Count - buildScreenLength)) { if (cursor.position.X >= leftArrowPos.X && cursor.position.X <= leftArrowPos.X + arrow.Width && cursor.position.Y >= leftArrowPos.Y - arrow.Height && cursor.position.Y <= leftArrowPos.Y) { sbatch.Draw(highArrow, leftArrowPos, null, Color.White, -(float)Math.PI / 2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } else { sbatch.Draw(arrow, leftArrowPos, null, Color.White, -(float)Math.PI / 2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } } if (scrollPos == 0) { if (cursor.position.X >= rightArrowPos.X - arrow.Width && cursor.position.X <= rightArrowPos.X && cursor.position.Y >= rightArrowPos.Y && cursor.position.Y <= rightArrowPos.Y + arrow.Height) { sbatch.Draw(highArrow, rightArrowPos, null, Color.White, (float)Math.PI/2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } else { sbatch.Draw(arrow, rightArrowPos, null, Color.White, (float)Math.PI / 2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } } if (scrollPos < (buildList.Count - buildScreenLength) && scrollPos > 0) { if (cursor.position.X >= leftArrowPos.X && cursor.position.X <= leftArrowPos.X + arrow.Width && cursor.position.Y >= leftArrowPos.Y - arrow.Height && cursor.position.Y <= leftArrowPos.Y) { sbatch.Draw(highArrow, leftArrowPos, null, Color.White, -(float)Math.PI / 2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } else { sbatch.Draw(arrow, leftArrowPos, null, Color.White, -(float)Math.PI / 2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } if (cursor.position.X >= rightArrowPos.X - arrow.Width && cursor.position.X <= rightArrowPos.X && cursor.position.Y >= rightArrowPos.Y && cursor.position.Y <= rightArrowPos.Y + arrow.Height) { sbatch.Draw(highArrow, rightArrowPos, null, Color.White, (float)Math.PI / 2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } else { sbatch.Draw(arrow, rightArrowPos, null, Color.White, (float)Math.PI / 2.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.1f); } } } else { full = false; } // render background sbatch.Draw(dummyTexture, buildPos, buildRectangle, boxColour, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.17f); // render items for (int x = scrollPos; x < (scrollPos + buildScreenLength) && x < buildList.Count; x++) { FloorObject curitem = buildList[x]; curitem.IconRender(sbatch,this); } } }
public void Update(GameTime gametime, GraphicsDevice graphicsDevice, Grid grid, Cursor cursor, NumericalCounter research, NumericalCounter money, NumericalCounter madness, List<MiniProgressBar> proglist, Corpse corpse,NonInteractive door,NonInteractive digger, Resurrect resurrect, NonInteractive Switch, NumericalCounter humanity, NumericalCounter longevity,NumericalCounter lifeForce, Random random, ReachableArea reachable) { path.Update(reachable); if (outside == false) { position = grid.CartesianCoords(gridPosition); if (walking == true) { layer = 0.21f + (0.2f / (float)grid.rows) * walkingTarget.Y + (0.2f / ((float)grid.columns * (float)grid.rows + 1)) * Math.Abs(walkingTarget.X - (float)grid.columns / 2.0f); } else { layer = 0.21f + (0.2f / (float)grid.rows) * gridPosition.Y + (0.2f / ((float)grid.columns * (float)grid.rows + 1)) * Math.Abs(gridPosition.X - (float)grid.columns / 2.0f); } } offset = new Vector2((width * scale) / 2.0f, height * scale); // factor of 2 here and in the draw command are just for this test anim, so it's a decent size... // walking.... // to use a machine if (action != null && walking == false && doing == false) { // to corpse if (corpseWork == true) { if (gridPosition != tableLocation) { walking = true; drawPath = path.PathList(gridPosition, tableLocation, grid); pathStep = 1; walkingTarget = drawPath[pathStep]; } else { doing = true; currentFrame = 0; gridPosition = drawPath[pathStep - 1]; position = grid.CartesianCoords(gridPosition); } } else if (gridPosition != floorObject.opPos) { walking = true; drawPath = path.PathList(gridPosition, floorObject.opPos, grid); pathStep = 1; walkingTarget = drawPath[pathStep]; } else { doing = true; currentFrame = 0; gridPosition = drawPath[pathStep - 1]; position = grid.CartesianCoords(gridPosition); } } else if (gridPosition != defaultGridPosition && walking == false && doing == false) { walking = true; drawPath = path.PathList(gridPosition, defaultGridPosition, grid); pathStep = 1; walkingTarget = drawPath[pathStep]; } // if he's walking, make him walk! if (walking == true) { direction = (grid.CartesianCoords(walkingTarget) - grid.CartesianCoords(gridPosition)); targetDistance = direction.Length(); direction.Normalize(); walkingOffset += direction * gametime.ElapsedGameTime.Milliseconds * 0.2f; distanceGone = walkingOffset.Length(); if (distanceGone < targetDistance) { Vector2 move = walkingOffset; position += move; } else { pathStep += 1; if (pathStep < drawPath.Count) { gridPosition = drawPath[pathStep - 1]; walkingTarget = drawPath[pathStep]; position = grid.CartesianCoords(gridPosition); } else { walking = false; doing = true; currentFrame = 0; gridPosition = drawPath[pathStep - 1]; position = grid.CartesianCoords(gridPosition); } walkingOffset = Vector2.Zero; targetDistance = 0; distanceGone = 0; } } // update animation frame timer += gametime.ElapsedGameTime.Milliseconds; if (timer >= msecsTweenFrames) { timer = 0; if (walking == true) { if (Math.Abs(direction.X) >= Math.Abs(direction.Y)) { if (direction.X >= 0) { anim = 1; } else { anim = 0; } } if (Math.Abs(direction.Y) >= Math.Abs(direction.X)) { if (direction.Y >= 0) { anim = 2; } else { anim = 3; } } if (currentFrame++ == numberOfFrames - 1) { currentFrame = 0; } } // start up menu action if doing is done, animate doing if (doing == true) { // coming through door (either way) if (digging == true) { anim = 4; if (door.animNum == 0) { door.SetAnim(1); door.layer -= 0.3f; } if (currentFrame++ == 2) { digging = false; if (dug == true) { CarryCorpse(); doing = false; dug = false; outside = false; } else { outside = true; layer = 0.61f; position += new Vector2(0, -20); } currentFrame = 0; door.SetAnim(0); door.layer += 0.3f; } else if (dug == true) { layer = 0.595f; anim = 5; } } // animate digging outside else if (outside == true) { outTimer += gametime.ElapsedGameTime.Milliseconds; if (outTimer >= 150 && dug == false) { digger.anim = true; dug = true; outTimer = 0; } if (dug == true && digger.anim == false && outTimer >= 350) { digging = true; outTimer = 0; } } // animate putting corpse on table else if (corpseCarrying == true) { doing = false; corpseCarrying = false; corpse.flies.Restart(0); corpse.visible = true; } // animate animation! else if (animating == true) { anim = 4; if (currentFrame++ == numberOfFrames - 1) { doing = false; animating = false; Switch.SetAnim(1); resurrect.Alive(corpse, humanity, longevity,lifeForce, research,madness, random, this); } } // if not in the usual spot... else if (gridPosition != defaultGridPosition) { anim = 4; if (action != null) { // if not staying to run machine, run doing anim once, create mini progress bar if (action.remain == false) { if (currentFrame++ == numberOfFrames - 1) { doing = false; proglist.Add(new MiniProgressBar(graphicsDevice, floorObject.position + new Vector2(-5, -105), action, floorObject)); progBar = proglist[proglist.Count - 1]; action = null; } } // if staying to run machine... else { // create a progess bar if starting if (animStart == true) { animStart = false; if (corpseWork == true) { proglist.Add(new MiniProgressBar(graphicsDevice, corpse.position + new Vector2(-5, -105), action, floorObject)); progBar = proglist[proglist.Count - 1]; corpseWork = false; } else { proglist.Add(new MiniProgressBar(graphicsDevice, floorObject.position + new Vector2(-5, -105), action, floorObject)); progBar = proglist[proglist.Count - 1]; } } // run animation until finished else { if (currentFrame++ == numberOfFrames - 1) { currentFrame = 0; if (action.done == true) { doing = false; action.done = false; action = null; animStart = true; } } } } } } // if not doing anything, stop... else { walking = false; doing = false; currentFrame = 0; } } // if not walking, do standing anim if (walking == false && doing == false) { anim = 2; currentFrame = 0; } // set frame and anim rect.X = currentFrame * width; rect.Y = height * anim; } }
public void Update(Cursor cursor) { MouseState mouseState = Mouse.GetState(); }
public void Update(GameTime gameTime, Cursor cursor) { mouseover = false; if (cursor.menu == false) { // objects if (cursor.position.X >= position.X && cursor.position.X <= (position.X + width) && cursor.position.Y >= position.Y && cursor.position.Y <= (position.Y + height) && cursor.mouseOver == false) { mouseover = true; // add object mouseover text cursor.menuProgBar = this; } } // change bar length according to vlue - decrease value over time elapsed += (float)gameTime.ElapsedGameTime.Milliseconds; if (elapsed >= timeInterval) { elapsed = 0; value += timeInterval/1000.0f; } if (value > init) { value = init; action.done = true; } bar.Width = (int)(fullWidth * (value / (float)init)); barText = value.ToString("#.#") + "/" + init.ToString("#.#"); }
public void Update(Cursor cursor, Random random, GameTime gameTime) { // update all the positions if coming down.... if (comingDown == true) { drop = gameTime.ElapsedGameTime.Milliseconds / 1.0f; if (drop + totalDrop > fall) { drop = fall - totalDrop; } totalDrop += drop; foreach (Knob knob in controls.Item1) { knob.position.Y += drop; } foreach (Slider slider in controls.Item2) { slider.position.Y += drop; slider.knobPosition.Y += drop; } foreach (Gauge gauge in controls.Item3) { gauge.position.Y += drop; gauge.handPosition.Y += drop; } foreach (SlideGauge slideGauge in controls.Item4) { slideGauge.position.Y += drop; slideGauge.handPosition.Y += drop; } if (totalDrop >= fall) { totalDrop = 0; drop = 0; comingDown = false; down = true; } } if (goingUp == true) { drop = gameTime.ElapsedGameTime.Milliseconds / 1.0f; if (drop + totalDrop > fall) { drop = fall - totalDrop; } totalDrop += drop; foreach (Knob knob in controls.Item1) { knob.position.Y -= drop; } foreach (Slider slider in controls.Item2) { slider.position.Y -= drop; slider.knobPosition.Y -= drop; } foreach (Gauge gauge in controls.Item3) { gauge.position.Y -= drop; gauge.handPosition.Y -= drop; } foreach (SlideGauge slideGauge in controls.Item4) { slideGauge.position.Y -= drop; slideGauge.handPosition.Y -= drop; } if (totalDrop >= fall) { totalDrop = 0; drop = 0; goingUp = false; } } if (down == true || comingDown == true || goingUp == true) { foreach (Knob knob in controls.Item1) { knob.Update(cursor); } foreach (Slider slider in controls.Item2) { slider.Update(cursor); } foreach (Gauge gauge in controls.Item3) { gauge.Update(random,gameTime); } foreach (SlideGauge slideGauge in controls.Item4) { slideGauge.Update(random,gameTime); } } }
// build this object public void Update(GameTime gametime,Cursor cursor,Scientist scientist, Assistant assistant, List<MiniProgressBar> bars, Build build, List<FloorObject> floorObjectList, ReachableArea reachable, NumericalCounter money) { // check for mouseover/click on machine mouseOver = false; if (cursor.position.X >= (position.X - offset.X) && cursor.position.X <= (position.X - offset.X + ((rect.Width * scale) / frames)) && cursor.position.Y >= position.Y - offset.Y && cursor.position.Y <= (position.Y - offset.Y + (rect.Height * scale)) && cursor.corpseMouseover == false && menu == false && menuActions.Count > 0 && build.menu == false) { // turn on menu when object is clicked if (cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false) { menu = true; menuStart = true; menuPosition = cursor.position; cursor.click = true; } } if (menu == false && mouseOver == false && cursor.mouseOver == false) { cursor.menuObject = this; mouseOver = true; // add object mouseover text if no menu cursor.mouseOver = true; } } // check for mouseover/click on build menu icon iconMouseover = false; badIconMouseover = false; if (onBuildList == true) { if (cursor.position.X >= iconPosition.X && cursor.position.X <= iconPosition.X + iconTex.Width && cursor.position.Y >= iconPosition.Y && cursor.position.Y <= iconPosition.Y + iconTex.Height && cursor.buildIconMouseover == false) { iconMouseover = true; cursor.buildIconMouseover = true; cursor.menuObject = this; // build object is clicked if (cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false) { if (money.value >= this.cost) { money.value -= this.cost; build.BuildThis(floorObjectList, this, reachable); cursor.click = true; } else { iconMouseover = false; badIconMouseover = true; } } } } } // animation timer += gametime.ElapsedGameTime.Milliseconds; if (on == true) { currentAnim = 1; } else { currentAnim = 0; } if (timer >= frate) { timer = 0; if (currentFrame++ == frames - 1) { currentFrame = 0; } rect.X = currentFrame * width; rect.Y = currentAnim * height; } // set menu dimensions, make list of names and colours for each object if (menu == true && menuStart == true) { // find longest string in menu int boxWidth = 0; actions = new List<Tuple<string, Color, Color, Color>> { }; foreach (MenuAction action in menuActions) { // add actions.Add(new Tuple<string, Color, Color, Color> ( action.name, Color.White, Color.Gray, Color.DarkGray ) ); if (action.name.Length > boxWidth) { boxWidth = action.name.Length; // set box width for below } } // boxes and outlines menuRectangle.Width = boxWidth * 12 + 10; // set width to widest text from above menuRectangle.Height = 30; // menu item height spread } // menu update if (menu == true) { menuMouseover = false; Vector2 menuItemPosition = menuPosition; foreach (MenuAction action in menuActions) { // IF MOUSE-OVERED change colours, set to highlighted item if (cursor.position.X >= menuItemPosition.X && cursor.position.X < (menuItemPosition.X + menuRectangle.Width) && cursor.position.Y >= menuItemPosition.Y && cursor.position.Y < (menuItemPosition.Y + menuRectangle.Height)) { textColour = Color.Black; boxColour = Color.LightGray; lineColour = Color.LimeGreen; menuHighlightAction = action; menuMouseover = true; if (cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false) { if (action.scientist == true) { if (scientist.walking == true) { scientist.walking = false; scientist.floorObject = null; scientist.action = null; } else if (scientist.doing == true) { scientist.doing = false; scientist.corpseWork = false; scientist.floorObject = null; bars.Remove(scientist.progBar); scientist.action = null; scientist.animStart = true; } scientist.action = menuHighlightAction; scientist.floorObject = this; } if (action.assistant == true && assistant.outside == false && assistant.corpseCarrying == false) { if (assistant.walking == true) { assistant.walking = false; assistant.floorObject = null; assistant.action = null; } else if (assistant.doing == true) { assistant.doing = false; assistant.digging = false; assistant.floorObject = null; bars.Remove(assistant.progBar); assistant.action = null; assistant.animStart = true; } assistant.action = menuHighlightAction; assistant.floorObject = this; } // both using same machine? if (action.assistant == true && action.scientist == true) { assistant.twoWork = true; } menu = false; } cursor.click = true; } } else { textColour = Color.White; boxColour = Color.Gray; lineColour = Color.DarkGray; if (cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false) { menu = false; } } } int index = menuActions.IndexOf(action); actions[index] = new Tuple<string, Color, Color, Color>(actions[index].Item1, textColour, boxColour, lineColour); menuItemPosition = menuItemPosition + new Vector2(0, menuRectangle.Height); } } }
public void Update(Cursor cursor, GameTime gameTime) { // clicking on build icon if (cursor.position.X >= position.X && cursor.position.X < (position.X + width) && cursor.position.Y >= position.Y && cursor.position.Y < (position.Y + height)) { if (cursor.mouseState.LeftButton == ButtonState.Pressed | cursor.mouseState.RightButton == ButtonState.Pressed) { if (cursor.click == false) { menu = true; clickOn = true; } cursor.click = true; } } if (clickOn == true) { clickCount += gameTime.ElapsedGameTime.Milliseconds; if (clickCount > 100) { clickCount = 0; clickOn = false; } } }