private void handleShipInit(GameEvent e) { ShipInit ee = (ShipInit)e; ClientShip ship = new ClientShip(engine.World, engine.SceneManager, null, ee.PlayerId, ee.Position, ee.Orientation); shipTable.Add(ship.ID, ship); if (ship.ID == engine.PlayerId) engine.AttachCamera(ship); Util.Log("Ship " + ship.ID + "inited. my ID is " + engine.PlayerId); }
private void handleStatUpdate(GameEvent e) { try { StatBoardEvent sbe = (StatBoardEvent)e; if (sbe.Stat == StatBoardEnum.PositiveTime) { int myScore; if (sbe.ValueById.TryGetValue(playerId, out myScore)) { TextRenderer.UpdateTextBox("score", "Game Mode: " + GameModeFactory.GetName(gameMode) + "\nScore: " + myScore); } } } catch (Exception err) { Util.RecordException(err); } }
private void handleShipStateStatus(GameEvent e) { ShipStateStatus ee = (ShipStateStatus)e; List<ShipState> states = ee.getStates(); for (int i = 0; i < states.Count; i++) { ClientShip s; shipTable.TryGetValue(states[i].id, out s); try { s.ShipState = states[i]; } catch (NullReferenceException nre) { Util.Log("Could not find a ship with ID " + i + ", but received a status update for one."); } } }
void handleShipControlStatus(GameEvent e) { ShipControlStatus ee = (ShipControlStatus)e; Ship s; shipTable.TryGetValue(ee.playerID, out s); Vector3 torque = s.GetCorrectiveTorque(); if (Mogre.Math.Abs(s.RotationalVelocity.x) < AUTOCORRECT_CUTOFF) { torque.x = 0; s.RotationalVelocity = new Vector3(0, s.RotationalVelocity.y, s.RotationalVelocity.z); } if (Mogre.Math.Abs(s.RotationalVelocity.y) < AUTOCORRECT_CUTOFF) { torque.y = 0; s.RotationalVelocity = new Vector3(s.RotationalVelocity.x, 0, s.RotationalVelocity.z); } if (Mogre.Math.Abs(s.RotationalVelocity.z) < AUTOCORRECT_CUTOFF) { torque.z = 0; s.RotationalVelocity = new Vector3(s.RotationalVelocity.x, s.RotationalVelocity.y, 0); } if (ee.pitch != UserInputManager.AUTOCORRECT) { torque.x = ee.pitch / ((float)UserInputManager.POSITIVE); } if (ee.yaw != UserInputManager.AUTOCORRECT) { torque.y = ee.yaw / ((float)UserInputManager.POSITIVE); } if (ee.roll != UserInputManager.AUTOCORRECT) { torque.z = ee.roll / ((float)UserInputManager.POSITIVE); } //Console.Out.WriteLine(torque.ToString()); //Console.Out.WriteLine(); s.TorqueRelative(torque); s.ThrustRelative(new Vector3(0.0f, 0.0f, ((float)ee.thrust) / ((float)UserInputManager.FULL))); }
/// <summary> /// Sends a game event over the network. If the caller is a server, it will be broadcast, otherwise it will be sent to the server. /// </summary> /// <param name="e">The game event to be sent</param> public void SendEvent(GameEvent e) { SpiderMessage msg = new SpiderMessage(e.ToByteArray(), SpiderMessageType.Bytes, e.GetType().ToString()); net.SendMessage(msg, e.DeliveryType); }
/// <summary> /// Sends a game event over the network. If the caller is a server, it will be broadcast, otherwise it will be sent to the server. /// </summary> /// <param name="e">The game event to be sent</param> public void SendEvent(GameEvent e) { SpiderMessage msg = new SpiderMessage(e.ToByteArray(), SpiderMessageType.Bytes, e.GetType().ToString()); net.SendMessage(msg, e.DeliveryType); }