/// <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>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); } }