public override void Update() { if (Touch != null) { bool hold = (Touch.Position - Pos.ToVector2()).Length() < 1; //Global.Output += Pos + ", " + Touch.Position; Pos = Touch.Position.ToVector3(); if (Touch.State == TouchState.Moved) { if (Touch.Timer < 10) { Speed = SpeedRange = Vector3.Zero; Emit = false; } else if (Touch.Holding) { //SpeedRange = new Vector3(new Vector2(25), 0); Speed = SpeedRange = Vector3.Zero; Emit = true; } else { Speed = SpeedRange = Vector3.Zero; Emit = true; } } else if (Touch.State == TouchState.Touched) { Speed = SpeedRange = Vector3.Zero; //EmitParticle(); } else { Speed = SpeedRange = Vector3.Zero; Emit = false; } if (Touch.State == TouchState.Released || Touch.State == TouchState.None) { Speed = SpeedRange = Vector3.Zero; Emit = false; Touch = null; } } for (int i = 0; i < holdParticles.Length; i++) { var p = holdParticles[i]; float betweenVal = MyMath.BetweenValue(0, holdParticles.Length - 1, i); p.Pos = Pos; if (Touch != null) { p.Alpha += (0.3f - p.Alpha) * 0.8f * Global.Speed * MyMath.Between(1, 0.3f, betweenVal); } else { p.Alpha += -p.Alpha * 0.1f * Global.Speed * MyMath.Between(1, 0.2f, betweenVal); } } base.Update(); }
public static void Update(GameTime time) { controls.update(); Touches.Clear(); foreach (var t in Game.Touches) { Touches.Add(t); } foreach (var t in TouchManager.TouchPoints) { Touches.Add(t); //Output += "Added touch"; } //Output += Touches.Count; if (!TouchManager.SupportsTouch) { TouchState ts = TouchState.None; switch (Controls.MouseLeft) { case ControlState.Pressed: ts = TouchState.Touched; break; case ControlState.Held: ts = TouchState.Moved; break; case ControlState.Released: ts = TouchState.Released; break; } if (mouseTouch == null) { mouseTouch = new TouchPoint() { }; } mouseTouch.Update(); mouseTouch.Position = Controls.MousePos; mouseTouch.State = ts; if (ts != TouchState.None) { if(!Global.Touches.Contains(mouseTouch)) Global.Touches.Add(mouseTouch); } else { if (Global.Touches.Contains(mouseTouch)) { Global.Touches.Remove(mouseTouch); } } } framespeed = (60f) / (1f / (float)time.ElapsedGameTime.TotalSeconds); if (!float.IsNaN(framespeed)) { gamespeed += (speedtarget - gamespeed) * speedspeed * framespeed; speed = MathHelper.Clamp(framespeed * gamespeed, 0, 5); } Effect.View = Matrix.CreateLookAt(Global.Camera.Pos, Global.Camera.LookAtPos, Vector3.Up); Effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 16f / 9f, 1, 1000000); Effect.World = Matrix.CreateTranslation(0, 0, 0); Controls.ScreenSize.X = Game.GraphicsDevice.PresentationParameters.BackBufferWidth; Controls.ScreenSize.Y = Game.GraphicsDevice.PresentationParameters.BackBufferHeight; //speed = 10; ParticleManager.Update(); }
public void SocketMethod() { threadRunning = true; if (tcp.Connected) { bool checkValue = false; string newBuffer = ""; string value = tcp.ReadString(Encoding.ASCII).Replace("\0", ""); for (int i = 0; i < value.Length; i++) { if (value[i] != ';' && !checkValue) { socketBuffer += value[i]; } else { Global.Output += socketBuffer; if (socketBuffer.Contains("move")) { var vals = socketBuffer.Split(':'); foreach (var t in Touches) { int id = (int)(long.Parse(vals[2]) % int.MaxValue); if (t.Id == id) { string[] pos = vals[1].Split(','); t.Position.X = float.Parse(pos[0]) * Global.ScreenSize.X; t.Position.Y = float.Parse(pos[1]) * Global.ScreenSize.Y; } } } else if (socketBuffer.Contains("touch")) { var vals = socketBuffer.Split(':'); var touch = new TouchPoint(); long l = long.Parse(vals[2]); touch.Id = (int)(l % int.MaxValue); touch.State = TouchState.Touched; string[] pos = vals[1].Split(','); touch.Position.X = float.Parse(pos[0]) * Global.ScreenSize.X; touch.Position.Y = float.Parse(pos[1]) * Global.ScreenSize.Y; Touches.Add(touch); Touches = Touches; } else if (socketBuffer.Contains("cancel")) { var vals = socketBuffer.Split(':'); if (vals[1] != "null") { TouchPoint t1 = null; string[] strings = vals[1].Split(','); int[] ids = new int[strings.Length]; for (int o = 0; o < ids.Length; o++) { ids[o] = (int)(long.Parse(strings[o]) % int.MaxValue); } foreach (var t in Touches) { if (!ids.Contains(t.Id)) { t1 = t; break; } } if (t1 != null) { t1.State = TouchState.Released; //Touches.Remove(t1); } } else { foreach (var t in Touches) { t.State = TouchState.Released; } //Touches.Clear(); } } socketBuffer = ""; } } } threadRunning = false; }