public void Swipe(double degree, Vector3 dir) { if (isInit()) { Player.simulator.Simulation.Awakener.AwakenBody(golfBallRef.Handle); float force = 30; QuixConsole.Log("Swipé log", degree); Vector2 rot2d = Player.GetXYRotation(); Vector3 rot = new Vector3(rot2d.X, 0, rot2d.Y); /* golfBallRef.Velocity.Linear.Y += force; * golfBallRef.Velocity.Linear.X -= rot.X*force; * golfBallRef.Velocity.Linear.Z -= rot.Y*force;*/ Quaternion quat = QuaternionEx.CreateFromAxisAngle(rot, (float)degree); Matrix4x4 matrix = Matrix4x4.CreateFromQuaternion(quat); Vector3 result = Vector3.Transform(rot, matrix); QuixConsole.Log("direction", dir); dir.X *= -1; dir.Y *= -1; dir.Z *= -1; golfBallRef.Velocity.Linear.Y += dir.Y * force; golfBallRef.Velocity.Linear.X += dir.X * force; golfBallRef.Velocity.Linear.Z += dir.Z * force; QuixConsole.Log("Result", result); } }
private void _checkToChangeState(AgentState ms) { if (this.state != null) { //QuixConsole.Log("Check change"); if (ms == this.state) { this.state.OnRepeat(); } else { if (this.state != null) { this.state.OnDesactivate(); } this.state = ms; QuixConsole.Log("State", ms.GetType().ToString()); this.state.OnActivate(); } } else { this.state = ms; } }
public void Activate(bool active) { if (!isInit()) { var timer = new PhyInterval(1, Player.simulator); timer.Completed += OnTick; golfBallRef = Player.golfball.GetReference(); vehicle = new Vehicle(Player.golfball); Player.simulator.Simulation.Awakener.AwakenBody(golfBallRef.Handle); } if (isInit()) { //golfBallRef. QuixConsole.Log("Gauntlet", active); vehicle.isActive = active; Player.simulator.Simulation.Awakener.AwakenBody(golfBallRef.Handle); } if (!hasStopped) { // Player.golfball.Stop(); hasStopped = true; } if (!active) { hasStopped = false; } }
public void SetPositionToStartPoint() { QuixConsole.Log("Start position", (simulator.map.startPositions[0].AsBsonDocument["x"])); reference.Pose.Position.X = (float)simulator.map.startPositions[0].AsBsonDocument["x"].AsDouble; reference.Pose.Position.Y = (float)simulator.map.startPositions[0].AsBsonDocument["y"].AsDouble; reference.Pose.Position.Z = (float)simulator.map.startPositions[0].AsBsonDocument["z"].AsDouble; }
public void Jump(MoveMessage message) { if (!Agent.IsLocked()) { QuixConsole.Log("Jump"); Agent.ChangeState(jumpState); Agent.Lock(130); } }
private void LoadMeshes() { LoadMesh("Stadiums/CrocoLoco/piedra1"); LoadMesh("Stadiums/CrocoLoco/piedra2"); LoadMesh("Stadiums/CrocoLoco/stand_croco"); LoadMesh("Stadiums/CrocoLoco/start_position"); LoadMesh("newt"); QuixConsole.Log("Reload meshes"); }
public void OnActivate() { // throw new NotImplementedException(); PhyTimeOut timeOut = new PhyTimeOut(10, player.simulator); timeOut.Completed += SendMessage; Snap(); QuixConsole.Log("Snapped state"); }
public void ChangeState(AgentState state) { QuixConsole.Log("Is locked", isLocked, state, lockedTime); if (!this.isLocked) { //QuixConsole.Log("Changing state to",state.GetType().ToString()); this._checkToChangeState(state); } }
internal void Swipe(string data) { QuixConsole.Log("Swiping", data); SwipeMessage j2 = JsonConvert.DeserializeObject <SwipeMessage>(data); //objects[] Player2 onb2 = (Player2)simulator.users[j2.client].player; // Simulation.Awakener.AwakenBody(ob.bodyHandle); onb2.Swipe(j2.degree, j2.direction); }
internal void UseGauntlet(string data) { QuixConsole.Log("Use gauntlet", data); GauntletMessage j2 = JsonConvert.DeserializeObject <GauntletMessage>(data); //objects[] Player2 onb2 = (Player2)simulator.users[j2.client].player; // Simulation.Awakener.AwakenBody(ob.bodyHandle); onb2.UseGauntlet(j2.active); }
private void CreateUser() { User s = new User(state.owner, this); if (!simulator.users.ContainsKey(state.owner)) { simulator.users.Add(state.owner, s); } else { QuixConsole.Log("User has been already added"); } }
private bool IsAnyPlayerVisible(TimeData arg) { foreach (var user in crocoLoco.simulator.users) { var distance = Vector3.Distance(crocoLoco.reference.Pose.Position, user.Value.player.reference.Pose.Position); QuixConsole.Log(distance); if (distance < properties.watchLength) { return(true); } } return(false); }
public void ReadCallback(IAsyncResult ar) { ConnectionState state = (ConnectionState)ar.AsyncState; String content = String.Empty; // Retrieve the state object and the handler socket // from the asynchronous state object. Socket handler = state.workSocket; // Read data from the client socket. if (handler.Connected) { try{ int bytesRead = handler.EndReceive(ar); if (bytesRead > 0) { // There might be more data, so store the data received so far. state.sb.Append(Encoding.ASCII.GetString( state.buffer, 0, bytesRead)); // Check for end-of-file tag. If it is not there, read // more data. content = state.sb.ToString(); var splited = content.Split("<L@>"); for (int a = 0; a < splited.Length; a++) { if (state.simulator != null) { if (splited[a] != "") { state.simulator.commandReader.AddCommandToBeRead(splited[a]); } } } state.sb.Clear(); handler.BeginReceive(state.buffer, 0, ConnectionState.BufferSize, 0, new AsyncCallback(ReadCallback), state); } }catch (SocketException e) { QuixConsole.Log("Socket exception", e); } } }
public void Tick() { if (this.state != null) { this.state.Tick(); } if (this.isLocked) { if (this.lockedTick == this.lockedTime) { QuixConsole.Log("unLocked", lockedTick); this.Unlock(); } this.lockedTick++; } }
public void StartListening() { IPAddress ipAddress = IPAddress.Parse("127.0.0.1"); IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 1337); // Create a TCP/IP socket. Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); //Simulator simulator = new Simulator(new ConnectionState(), this); // Bind the socket to the local endpoint and listen for incoming connections. try { listener.Bind(localEndPoint); listener.Listen(); QuixConsole.Log("QuixPhysicsServer is", "running"); while (isRunning) { // Set the event to nonsignaled state. allDone.Reset(); // Start an asynchronous socket to listen for connections. QuixConsole.WriteLine("Waiting for a connection..."); listener.BeginAccept( new AsyncCallback(AcceptCallback), listener); // Wait until a connection is made before continuing. allDone.WaitOne(); } } catch (Exception e) { QuixConsole.WriteLine(e.ToString()); } QuixConsole.WriteLine("\nPress ENTER to continue..."); }
private void Jump() { QuixConsole.Log("Jumping!"); phy.reference.Awake = true; phy.reference.Velocity.Linear.Y += 50; }
internal void ReadCommand() { //Console.WriteLine("Read command: {0}", v); try { foreach (var item in commandsList) { JsonSerializerSettings setting = new JsonSerializerSettings(); setting.CheckAdditionalContent = false; Newtonsoft.Json.Linq.JObject message = JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>((string)item, setting); string type = (string)message["type"]; switch (type) { case "create": // Console.WriteLine(message); if (message["data"]["halfSize"] != null) { BoxState ob = JsonConvert.DeserializeObject <BoxState>(((object)message["data"]).ToString()); simulator.Create(ob); } if (message["data"]["radius"] != null) { SphereState ob = JsonConvert.DeserializeObject <SphereState>(((object)message["data"]).ToString()); simulator.Create(ob); break; } break; case "createBoxes": //Console.WriteLine("Create boxes"); // simulator.boxToCreate = 10; simulator.createObjects(); break; case "gauntlet": UseGauntlet(((object)message["data"]).ToString()); break; case "move": MoveMessage j = JsonConvert.DeserializeObject <MoveMessage>(((object)message["data"]).ToString()); //objects[] Player2 onb = (Player2)simulator.users[j.client].player; // Simulation.Awakener.AwakenBody(ob.bodyHandle); onb.Move(j); break; case "rotate": MoveMessage j2 = JsonConvert.DeserializeObject <MoveMessage>(((object)message["data"]).ToString()); //objects[] Player2 onb2 = (Player2)simulator.users[j2.client].player; // Simulation.Awakener.AwakenBody(ob.bodyHandle); onb2.Rotate(j2); break; case "jump": Jump(((object)message["data"]).ToString()); break; case "shoot": Shoot(((object)message["data"]).ToString()); break; case "swipe": Swipe(((object)message["data"]).ToString()); break; case "generateMap": var map = this.simulator.server.dataBase.GetMap((string)message["data"]); this.simulator.map = map; foreach (var obj in map.objects) { //obj.ToJson(); if (obj.Contains("halfSize")) { obj["halfSize"].AsBsonDocument.Remove("__refId"); obj.Remove("_id"); var stri = JsonConvert.DeserializeObject <BoxState>(obj.ToJson()); stri.quaternion = JsonConvert.DeserializeObject <Quaternion>(obj["quat"].ToJson()); this.simulator.Create(stri); } if (obj.Contains("radius")) { // obj["radius"].AsBsonDocument.Remove("__refId"); obj.Remove("_id"); var stri = JsonConvert.DeserializeObject <SphereState>(obj.ToJson()); stri.quaternion = JsonConvert.DeserializeObject <Quaternion>(obj["quat"].ToJson()); this.simulator.Create(stri); } } break; case "close": //Console.WriteLine("Close"); simulator.Close(); break; default: QuixConsole.WriteLine("Command not registred " + type); break; } } commandsList.Clear(); } catch (InvalidOperationException e) { QuixConsole.Log("Collection was modifieded", e); } catch (JsonReaderException e) { QuixConsole.Log("Json Problem ", e); } catch (Exception e) { QuixConsole.WriteLine(e); } }