Joystick position: Difference between revisions

Content added Content deleted
m (→‎{{header|OCaml}}: minor updates)
Line 644: Line 644:
{{libheader|SFML}}
{{libheader|SFML}}


Using the SFML with its OCaml bindings [http://ocaml-sfml.forge.ocamlcore.org/ ocaml-sfml]:
Using the SFML with its OCaml bindings [https://github.com/fccm/ocaml-sfml ocaml-sfml]:


<lang ocaml>let remove x = List.filter (fun y -> y <> x)
<lang ocaml>let remove x = List.filter (fun y -> y <> x)
let buttons_string b =
let buttons_string b =
String.concat " " (List.map string_of_int b)
String.concat " " (List.map string_of_int b)

let position app x y =
let position app x y =
let view = SFRenderWindow.getView app in
let view = SFRenderWindow.getView app in
Line 657: Line 657:
(hw +. ((x /. 100.0) *. hw),
(hw +. ((x /. 100.0) *. hw),
hh +. ((y /. 100.0) *. hh))
hh +. ((y /. 100.0) *. hh))

let cross =
let cross =
[| 1.0, 1.0; 10.0, 1.0; 10.0, -1.0; 1.0, -1.0;
[| 1.0, 1.0; 10.0, 1.0; 10.0, -1.0; 1.0, -1.0;
1.0, -10.0; -1.0, -10.0; -1.0, -1.0; -10.0, -1.0;
1.0, -10.0; -1.0, -10.0; -1.0, -1.0; -10.0, -1.0;
-10.0, 1.0; -1.0, 1.0; -1.0, 10.0; 1.0, 10.0; |]
-10.0, 1.0; -1.0, 1.0; -1.0, 10.0; 1.0, 10.0; |]

let () =
let () =
let app = SFRenderWindow.make (800, 600) "Joystick Position" in
let app = SFRenderWindow.make (800, 600) "Joystick Position" in
Line 673: Line 673:
SFText.setString text (buttons_string b);
SFText.setString text (buttons_string b);
let x, y = position app x y in
let x, y = position app x y in
SFShape.setPosition shape x y;
SFShape.setPosition shape (x, y);
SFRenderWindow.clear app SFColor.black;
SFRenderWindow.clear app SFColor.black;
SFRenderWindow.drawText app text ();
SFRenderWindow.drawText app text ();
Line 682: Line 682:
| SFEvent.JoystickButtonPressed (0, button) -> ((x, y), button::b)
| SFEvent.JoystickButtonPressed (0, button) -> ((x, y), button::b)
| SFEvent.JoystickButtonReleased (0, button) -> ((x, y), remove button b)
| SFEvent.JoystickButtonReleased (0, button) -> ((x, y), remove button b)
| SFEvent.JoystickMoved (0, SFEvent.JoystickX, av) -> ((av, y), b)
| SFEvent.JoystickMoved (0, SFJoystick.X, av) -> ((av, y), b)
| SFEvent.JoystickMoved (0, SFEvent.JoystickY, av) -> ((x, av), b)
| SFEvent.JoystickMoved (0, SFJoystick.Y, av) -> ((x, av), b)
| _ -> joyd
| _ -> joyd
in
in
Line 700: Line 700:
in
in
loop ((0.0, 0.0), [])</lang>
loop ((0.0, 0.0), [])</lang>

Run with the command:
$ ocaml -I /tmp/ocaml-sfml/src sfml_system.cma sfml_window.cma sfml_graphics.cma joy.ml


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==