public override void Update() { if (waitframes == 0) { flying = (random.Next(0, 6) > 1); speed = new Vector2(random.Next(-8, 8), random.Next(-8, 8)); if (!flying) { Position += new Vector2(0, 16); } waitframes = random.Next(10, 30) * (flying ? 1: 2); } if (flying) { Position += speed; } else { SpriteIndex = 0; } waitframes--; if (Mouse.CheckPressed(MouseButtons.Left)) { // If clicked on the fly if (Bounds.Contains(Mouse.Position)) { Room.Objects.Remove(this); } } }
//private void startGame(object sender, EventArgs e) //{ // stateOfGame++; // if (stateOfGame > 2) // { // stateOfGame = 0; // return; // } //} //Return mouse click position public Vector2 GetMouseLeftClickedPos() { if (Mouse.CheckPressed(MouseButtons.Left) || Keyboard.CheckPressed(Keys.Z)) { return(Mouse.Position); } return(new Vector2(-1, -1)); }
public override void Update() { if (tick % sendNewLocationDelay == 0) { SocketHandler.SendMessage(PacketTypes.MOUSE, Mouse.Position.X, Mouse.Position.Y, Mouse.AverageMovement().X, Mouse.AverageMovement().Y); } var data = SocketHandler.GetData(); if (data != null) { if (data.BaseStream.Length > 1) { data.BaseStream.Position = 0; positions.Clear(); Timer = data.ReadInt32(); int numflies = data.ReadInt32(); for (int i = 0; i < numflies; i++) { try { positions.Add(data.ReadInt32(), new Vector2(data.ReadSingle() * Graphics.PreferredBackBufferWidth / 1920, data.ReadSingle() * Graphics.PreferredBackBufferHeight / 1080)); } catch { } } } } if (Mouse.CheckPressed(MouseButtons.Left)) { Rectangle bounds = new Rectangle(Mouse.Position.ToPoint() - new Point(10, 8), new Point(30, 38)); foreach (var fly in positions) { if (bounds.Contains(fly.Value)) { SocketHandler.SendMessage(PacketTypes.SWAT, fly.Key); } } } tick++; }
/// <summary> /// Handles all mouse interaction /// </summary> private void HandleMouse() { bool wasHovered = Hover; Hover = new Rectangle((int)(bounds.X * View.Scale.X), (int)(bounds.Y * View.Scale.Y), (int)(bounds.Width * View.Scale.X), (int)(bounds.Height * View.Scale.Y)).Contains(Mouse.Position); if (Hover) { Mouse.Cursor = MouseCursor.IBeam; } else { if (wasHovered) { Mouse.Cursor = Mouse.DefaultCursor; } } if (Mouse.CheckPressed(MouseButtons.Left)) { if (Hover) { Focussed = true; Keyboard.String = ""; MoveCursorToCharacterByPosition(Mouse.Position.ToPoint()); mouseStartPosition = Mouse.Position; } else { // If clicked outside textbox, stop focussing Focussed = false; } } if (Mouse.Check(MouseButtons.Left)) { mousePosition = Mouse.Position; SelectStart = GetCharacterByPosition(mouseStartPosition.ToPoint()); SelectEnd = GetCharacterByPosition(mousePosition.ToPoint()); } }
public override void Update() { View.Scale = new Vector2(Graphics.PreferredBackBufferHeight / 1080f); if (new Rectangle((int)(960 * View.Scale.X), (int)(570 * View.Scale.Y), (int)(190 * View.Scale.X), (int)(60 * View.Scale.Y)).Contains(Mouse.Position) && Mouse.Check(MouseButtons.Left)) { registerpage = true; } else if (new Rectangle((int)(770 * View.Scale.X), (int)(570 * View.Scale.Y), (int)(190 * View.Scale.X), (int)(60 * View.Scale.Y)).Contains(Mouse.Position) && Mouse.CheckPressed(MouseButtons.Left)) { registerpage = false; } if (Keyboard.CheckTriggered(Keys.Tab)) { if (UserBox.Focussed) { UserBox.Focussed = false; PassBox.Focussed = true; } else if (PassBox.Focussed == true) { UserBox.Focussed = true; PassBox.Focussed = false; } } if (Keyboard.CheckPressed(Keys.Enter)) { LoginButton.Clicked = true; } }
public override void Update() { BinaryReader roomdata = null; try { roomdata = SocketHandler.GetData(); } catch { // don't worry, we're probably single player } if (roomdata != null) { if (roomdata.BaseStream.Length == 66) { for (int _x = 0; _x < 8; _x++) { for (int _y = 0; _y < 8; _y++) { board[_x, _y] = (int)roomdata.ReadByte() - 1; } } CurrentPlayer = roomdata.ReadByte(); } else { string datastring = "["; for (int i = 0; i < roomdata.BaseStream.Length; i++) { datastring += (int)roomdata.ReadByte() + ","; } datastring += "]"; Logger.WriteLine("Got unexpected roomdata for mainboard: " + datastring, LogLevel.WARN); } } Position = Mouse.Position - boardPos - new Vector2(boxSize / 2); Position.X = (float)Math.Round(Math.Min(Math.Max(0, Position.X / boxSize), 7)) * boxSize + boxSize * 0.5f; Position.Y = (float)Math.Round(Math.Min(Math.Max(0, Position.Y / boxSize), 7)) * boxSize + boxSize * 0.5f; SpriteIndex = CurrentPlayer; int x = (int)(Position.X - 32) / (int)boxSize; int y = (int)(Position.Y - 32 - 1) / (int)boxSize; if (CanPlace(x, y)) { SpriteColor = Color.White; } else { SpriteColor = new Color(Color.White, 0.5f); } if (Mouse.CheckPressed(MouseButtons.Left)) { if (board[x, y] == -1 || board[x, y] > 3) { if (CanPlace(x, y)) { board[x, y] = CurrentPlayer; DoMove(x, y, CurrentPlayer); CurrentPlayer++; try { SocketHandler.SendMessage(PacketTypes.SETMOVE, (byte)x, (byte)y); } catch { Logger.WriteLine("Mainboard seems to see that you are not connected to a room", LogLevel.WARN); } } } else { board[x, y] += 4; try { SocketHandler.SendMessage(PacketTypes.SETMOVE, (byte)x, (byte)y); } catch { Logger.WriteLine("Mainboard seems to see that you are not connected to a room", LogLevel.WARN); } CurrentPlayer++; } if (CurrentPlayer == 4) { CurrentPlayer = 0; } } Position += boardPos; }
public override void Update() { float offset = (float)(Math.PI * 2) / totalCovers; Dictionary <int, Vector2> positions = new Dictionary <int, Vector2>(); for (int i = 0; i < totalCovers; i++) { positions.Add(i, new Vector2(500 + (float)Math.Sin(tt + offset * i) * 450, 250 + (float)Math.Cos(tt + offset * i) * 200)); } sortedpositions = from entry in positions orderby entry.Value.Y ascending select entry; bottompanel = sortedpositions.Last().Key; if (!automove && Position.X < 10) { if (Mouse.CheckPressed(MouseButtons.Left)) { mousestartpos = Mouse.Position; starttt = tt; } if (Mouse.Check(MouseButtons.Left)) { tt = starttt + (Mouse.Position.X - mousestartpos.X) / 500; } if (Mouse.CheckReleased(MouseButtons.Left)) { Dictionary <int, float> distances = new Dictionary <int, float>(); if (Math.Abs(Mouse.Position.X - mousestartpos.X) < 5) { foreach (var position in sortedpositions) { if (position.Value.Y > 40) { if (new Rectangle((position.Value + new Vector2(460, 200) + Position - Covers.Center).ToPoint(), Covers.Size.ToPoint()).Contains(Mouse.Position)) { distances.Add(position.Key, Vector2.Distance(position.Value + new Vector2(460, 200) + Position, Mouse.Position)); } } } } if (distances.Count > 0) { var clickeditem = distances.OrderBy(kvp => kvp.Value).First(); switch (clickeditem.Key) { case 0: Room.GotoRoom(typeof(Minigames.ClimbTheMountain.ClimbTheMountain)); break; case 1: Room.GotoRoom(typeof(Minigames.FlySwat.FlySwat)); break; case 2: Room.GotoRoom(typeof(Minigames.DontTapWhite.Donttapwhite)); break; case 3: Room.GotoRoom(typeof(Minigames.Quiz.Quiz)); break; case 4: Room.GotoRoom(typeof(Minigames.DinoCollectStuff.DinoCollectStuff)); break; case 5: Room.GotoRoom(typeof(Rooms.Room1)); break; default: throw new IndexOutOfRangeException("Tried to open a room that does not exist"); } } } } }