public override void Update(OldNewInput input) { base.Update(input); // Last bit is to stop it from sending data way to often if (enabled && input.MouseRec.Intersects(insideRec) && input.newMouse.LeftButton == ButtonState.Pressed && input.oldMouse.LeftButton == ButtonState.Released) { selectedX = input.newMouse.X; Color[] pixelColors = new Color[rainbow.Width * rainbow.Height]; rainbow.GetData(pixelColors); selectedColor = pixelColors[(input.newMouse.X - insideRec.X) + ((input.newMouse.Y - insideRec.Y) * rainbow.Width)]; // Event if (colorChangeEvent != null) { colorChangeEvent(); } } // Update the locations of the indicator arrows lowerArrow = new Vector2(selectedX - arrow.Width / 2, insideRec.Y + (insideRec.Height - arrow.Height)); upperArrow = new Vector2(selectedX - arrow.Width / 2, insideRec.Y); }
public override void Update(OldNewInput input) { base.Update(input); if (enabled && input.newMouse.LeftButton == ButtonState.Pressed && input.MouseRec.Intersects(outsideRec)) { active = true; text = ""; } if (active && enabled) { char nextChar; if (input.TryConvertKeyboardInput(out nextChar)) { text += nextChar; } if (input.SingleKey(Keys.Back) && text.Length > 0) { text = text.Remove(text.Length - 1); } if (input.SingleKey(Keys.Escape)) { active = false; text = finalText; } else if (input.SingleKey(Keys.Enter) && text.Length > 1 && text.Length < 20) { finalText = text; active = false; if (onEnterEvent != null) { onEnterEvent(); } if (type == TextButtonType.IP) { // TODO: Call connect method or do it here } else if (type == TextButtonType.UserName) { // TODO: Call name change method or do it here } } } else if (active && !enabled) { active = false; text = finalText; } }
public override void Update(OldNewInput input) { base.Update(input); if (enabled && input.MouseRec.Intersects(outsideRec) && input.SingleLeftClick()) { pressed = true; if (onClickEvent != null) { onClickEvent(); } } }
public override void Update(OldNewInput input) { base.Update(input); if (enabled && input.MouseRec.Intersects(outsideRec) && input.SingleLeftClick()) { isTrue = isTrue ? false : true; // Toggle if (checkedChangeEvent != null) { checkedChangeEvent(); } } }
virtual public void Update(OldNewInput input) { if (enabled && (input.MouseRec.Intersects(outsideRec) || active)) { outSideColor = Color.DarkGray; } else { outSideColor = orgOutSideColor; } if (enabled && input.MouseRec.Intersects(outsideRec) && input.SingleLeftClick() && soundEffect) { clickSound.Play(); } }
public void Input(OldNewInput input, ContentManager content, Dictionary <string, Tank> tanks, GameTime gametime) { if (IsAlive == true) { NetOutgoingMessage outmsg; timer += gametime.ElapsedGameTime.Milliseconds; position = tanks[name].position; #region Movment if (input.newKey.IsKeyDown(Keys.W) && timer >= timerlimit) { //update position, then send it to the server position += direction * speed; //needs to CreateMessage() every time a button is pressed, which means more than once some updates outmsg = Game1.Client.CreateMessage(); outmsg.Write((byte)PacketTypes.MOVE); outmsg.Write(name); outmsg.Write(position.X); outmsg.Write(position.Y); outmsg.Write(angle); Game1.Client.SendMessage(outmsg, NetDeliveryMethod.ReliableUnordered); } if (input.newKey.IsKeyDown(Keys.S) && timer >= timerlimit) { //update position, then send it to the server position -= direction * speed; //needs to CreateMessage() every time a button is pressed, which means more than once some updates outmsg = Game1.Client.CreateMessage(); outmsg.Write((byte)PacketTypes.MOVE); outmsg.Write(name); outmsg.Write(position.X); outmsg.Write(position.Y); outmsg.Write(angle); Game1.Client.SendMessage(outmsg, NetDeliveryMethod.ReliableUnordered); } if (input.newKey.IsKeyDown(Keys.D) && timer >= timerlimit) { angle += MathHelper.Pi / 50; //MathHelper.Pi * 2 is a full turn // / 2 is 90 degrees // divide to smaller pieces for less turn each button press direction.X = (float)Math.Cos(angle); direction.Y = (float)Math.Sin(angle); //needs to CreateMessage() every time a button is pressed, which means more than once some updates outmsg = Game1.Client.CreateMessage(); outmsg.Write((byte)PacketTypes.MOVE); outmsg.Write(name); outmsg.Write(position.X); outmsg.Write(position.Y); outmsg.Write(angle); Game1.Client.SendMessage(outmsg, NetDeliveryMethod.ReliableUnordered); } if (input.newKey.IsKeyDown(Keys.A) && timer >= timerlimit) { angle -= MathHelper.Pi / 50; //MathHelper.Pi * 2 is a full turn // / 2 is 90 degrees // divide to smaller pieces for less turn each button press direction.X = (float)Math.Cos(angle); direction.Y = (float)Math.Sin(angle); //needs to CreateMessage() every time a button is pressed, which means more than once some updates outmsg = Game1.Client.CreateMessage(); outmsg.Write((byte)PacketTypes.MOVE); outmsg.Write(name); outmsg.Write(position.X); outmsg.Write(position.Y); outmsg.Write(angle); Game1.Client.SendMessage(outmsg, NetDeliveryMethod.ReliableUnordered); } #endregion #region shoot if (input.newKey.IsKeyDown(Keys.Space) && input.oldKey.IsKeyUp(Keys.Space)) { //needs to CreateMessage() every time a button is pressed, which means more than once some updates outmsg = Game1.Client.CreateMessage(); outmsg.Write((byte)PacketTypes.SHOOT); outmsg.Write(name); outmsg.Write(position.X); outmsg.Write(position.Y); outmsg.Write(angle); Game1.Client.SendMessage(outmsg, NetDeliveryMethod.ReliableOrdered); } //Reset timer if (timer > timerlimit) { timer = 0; } #endregion } }
public void Update(OldNewInput input) { background.Update(); toLobbyBtn.Update(input); NetIncomingMessage incom; // MEssage that will contain the message comming from the server if ((incom = Game1.Client.ReadMessage()) != null) // Are there any new messanges? { if (incom.MessageType == NetIncomingMessageType.Data) // Is it a "data" message? { switch (incom.ReadByte()) { case (byte)PacketTypes.FINALSCOREBOARD: // Packet contains: /// PacketType /// Player Amount \/ loop /// Player Name /// Player Kills /// Player Deaths /// Player Color R /// Player Color G /// Player Color B scoreBoardItems.Clear(); Debug.WriteLine("Cl-Recevied final scoreboard"); int count = incom.ReadInt32(); List <TempPlayerContainer> tmpPCs = new List <TempPlayerContainer>(); for (int i = 0; i < count; i++) { // TempPlayerContainer tmpPC = new TempPlayerContainer(); tmpPC.name = incom.ReadString(); tmpPC.kills = incom.ReadInt32(); tmpPC.deaths = incom.ReadInt32(); tmpPC.color = new Color(incom.ReadByte(), incom.ReadByte(), incom.ReadByte()); tmpPC.score = (tmpPC.kills * 2) - tmpPC.deaths; tmpPCs.Add(tmpPC); } // Sortera tmpPCs = tmpPCs.OrderBy(o => o.score).ToList(); // Skapa listan som kommer ritas ut for (int i = 0; i < count; i++) { Vector2 pos; if (scoreBoardItems.Count > 0) { pos = new Vector2(50, scoreBoardItems[scoreBoardItems.Count - 1].Position.Y + scoreBoardItems[scoreBoardItems.Count - 1].Height + 10); } else { pos = new Vector2(50, 50); } scoreBoardItems.Add(new ScoreBoardItem(content, pos, tmpPCs[i].kills, tmpPCs[i].deaths, i + 1, tmpPCs[i].score, tmpPCs[i].name, tmpPCs[i].color)); } break; default: break; } } } }
public void Update(OldNewInput input, Dictionary <string, Tank> tanks) { background.Update(); ipBtn.Update(input); // Orkar inte bry mig om polyformism.. nameBtn.Update(input); colorBtn.Update(input); readyBtn.Update(input); connectBtn.Update(input); disconnectBtn.Update(input); exitBtn.Update(input); muteMusicBtn.Update(input); fullScreenBtn.Update(input); playerList.ForEach(p => p.Update()); NetIncomingMessage incom; // MEssage that will contain the message comming from the server if (connected && (incom = Game1.Client.ReadMessage()) != null) // Are there any new messanges? { if (incom.MessageType == NetIncomingMessageType.Data) // Is it a "data" message? { switch (incom.ReadByte()) { case (byte)PacketTypes.LOBBYPLAYERLIST: // Handle a list of players (right side) Debug.WriteLine("Cl-Received the playerlist"); bool animate = playerList.Count == 0 ? true : false; // Animate if the playerlist is new and empty if (playerList.Count == 0 || playerList[0].Statee == PlayerListItem.State.NONE) // To keep the game from removing the initial animation { playerList.Clear(); // Clear the "old" data int incommingPlayers = incom.ReadInt32(); for (int k = 1; k <= incommingPlayers; k++) { string name = incom.ReadString(); Color color = new Color(incom.ReadByte(), incom.ReadByte(), incom.ReadByte()); bool ready = incom.ReadBoolean(); playerList.Add(new PlayerListItem(content, new Vector2(Game1.ScreenRec.Width - 450, k * 50), name, color, ready, animate)); } for (int i = incommingPlayers + 1; i <= 8; i++) { playerList.Add(new PlayerListItem(content, new Vector2(Game1.ScreenRec.Width - 450, i * 50), animate)); } } ConfirmConnection(); break; case (byte)PacketTypes.GAMESTATE: Debug.WriteLine("Cl-Reveiced gamestate change"); background.PlayMusic = false; Notify.NewMessage("Starting Game!", Color.LightBlue); Game1.gameState = (GameStates)incom.ReadByte(); Game1.tankname = nameBtn.Text; // Skapa alla tank klasserna foreach (PlayerListItem player in playerList) { if (player.Name != "") { tanks.Add(player.Name, new Tank(content, player.Name, player.TankColor)); } } ConfirmConnection(); break; case (byte)PacketTypes.HEARTBEAT: // Respond to the Heartbeat request of the server Debug.WriteLine("Cl-Received heartbeat, responding"); NetOutgoingMessage outmsg = Game1.Client.CreateMessage(); outmsg.Write((byte)PacketTypes.HEARTBEAT); outmsg.Write(nameBtn.Text); Game1.Client.SendMessage(outmsg, incom.SenderConnection, NetDeliveryMethod.ReliableOrdered); ConfirmConnection(); break; case (byte)PacketTypes.DISCONNECTREASON: Debug.WriteLine("Cl-Deny packet received"); Notify.NewMessage("Disconnect reason: " + incom.ReadString(), Color.Purple); Disconnect(); break; default: break; } lastBeat = DateTime.Now; // Se alla anslutningar som en heartbeat } } // HeartBeat TimeSpan timeSinceLastBeat = DateTime.Now.Subtract(lastBeat); if (connected && timeSinceLastBeat.TotalSeconds > 10) { Notify.NewMessage("Connection lost", Color.Red); Disconnect(); } }