/// <summary>User input.</summary> /// <param name="realm">Realm.</param> /// <param name="user">User.</param> /// <param name="state">Input state.</param> public override void Input(IRealm realm, User user, InputState state) { var player = (Player)user["player"]; player.VectorX = (state.Get<bool>("right") ? 1 : state.Get<bool>("left") ? -1 : 0) * 20; player.VectorY = (state.Get<bool>("up") ? 1 : state.Get<bool>("down") ? -1 : 0) * 80; player.AimAngle = state.Get<float>("aimAngle"); }
/// <summary>New user joined to the game as observer.</summary> /// <param name="realm">Realm.</param> /// <param name="user">User.</param> /// <returns>Aceept user to the game?</returns> public override bool Enter(IRealm realm, User user) { user["player"] = new Player { X = 64 * 3, Name = "Player_" + DateTime.Now.Millisecond, ClientSessionId = user.Session }; realm.AddEntity(user["player"]); return true; }
/// <summary>User input.</summary> /// <param name="realm">Realm.</param> /// <param name="user">User.</param> /// <param name="state">Keys.</param> public override void Input(IRealm realm, User user, InputState state) { var player = (Player)user["player"]; var aimAngle = state.Get<float>("aimAngle"); var kickBall = state.Get<bool>("kick"); var aimAngleRad = aimAngle / 180.0f * Math.PI; // if (kickBall) { foreach (var ball in realm.Entities.OfType<Ball>()) { ball.VectorX = (float)Math.Cos(aimAngleRad) * 25000; ball.VectorY = (float)Math.Sin(aimAngleRad) * 25000; } } }
/// <summary>User input.</summary> /// <param name="realm">Realm.</param> /// <param name="user">User.</param> /// <param name="state">Keys.</param> public override void Input(IRealm realm, User user, InputState state) { var player = (Player)user["player"]; var aimAngle = state.Get<float>("aimAngle"); var fire = state.Get<bool>("fire"); var aimAngleRad = aimAngle / 180.0f * Math.PI; if (fire) { var vectorX = (float)Math.Cos(aimAngleRad); var vectorY = (float)Math.Sin(aimAngleRad); var bullet = new Bullet { X = player.X + vectorX * 25, Y = player.Y + vectorY * 25, VectorX = vectorX * 50, VectorY = vectorY * 50 }; realm.AddEntity(bullet); } }
/// <summary>User outs from the game.</summary> /// <param name="realm">Realm.</param> /// <param name="user">User.</param> public override void Leave(IRealm realm, User user) { realm.RemoveEntity(user["player"]); }
/// <summary>User connection state changed.</summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> void OnUserConnectionStateChanged(object sender, ConnectionEventArgs e) { if (e.State == ConnectionState.Connected) { var user = new Ardelme.Core.User(e.User.Session); e.User["user"] = user; lock (_realm) { _realm.Enter(user); } } else if (e.State == ConnectionState.Disconnected) lock (_realm) { _realm.Leave((Ardelme.Core.User)e.User["user"]); } }
/// <summary>Chat message received.</summary> /// <param name="user">User who sends the message.</param> /// <param name="message">Message.</param> /// <param name="channel">Channel.</param> public void Chat(User user, string message, string channel) { _behaviors.ForEach(x => x.Chat(this, user, message, channel)); }
/// <summary>User disconnected from the game.</summary> /// <param name="user">User.</param> public void Leave(User user) { _behaviors.ForEach(x => x.Leave(this, user)); }
/// <summary>New user joined a game.</summary> /// <param name="user">User.</param> /// <param name="team">Team.</param> /// <returns>Aceept user to the game?</returns> public bool Join(User user, Team team) { return _behaviors.Aggregate(true, (current, b) => current && b.Join(this, user, team)); }
/// <summary>Users input data.</summary> /// <param name="user">User.</param> /// <param name="state">Input data.</param> public void Input(User user, InputState state) { _behaviors.ForEach(x => x.Input(this, user, state)); }
/// <summary>New user connected to the game.</summary> /// <param name="user">User.</param> /// <returns>Accept connection?</returns> public bool Enter(User user) { return _behaviors.Aggregate(true, (current, b) => current && b.Enter(this, user)); }