/src/gosu/jruby/GosuProxy.java

http://jgosu.googlecode.com/ · Java · 81 lines · 62 code · 19 blank · 0 comment · 0 complexity · cf0d5bbd62d00f5c879e7d2bb6aa9cc7 MD5 · raw file

  1. import gosu.Gosu;
  2. import org.jruby.*;
  3. import org.jruby.runtime.builtin.IRubyObject;
  4. import org.jruby.anno.JRubyMethod;
  5. import static org.jruby.RubyNumeric.*;
  6. public abstract class GosuProxy {
  7. public static void createGosuMethods(Ruby runtime) {
  8. RubyModule mGosu = runtime.getModule("Gosu");
  9. mGosu.defineAnnotatedMethods(GosuProxy.class);
  10. }
  11. @JRubyMethod(name = "milliseconds",
  12. module = true)
  13. public static IRubyObject milliseconds(IRubyObject module) {
  14. return module.getRuntime().newFixnum(Gosu.milliseconds());
  15. }
  16. @JRubyMethod(name = "distance",
  17. required = 4,
  18. module = true)
  19. public static IRubyObject distance(IRubyObject module, IRubyObject[] args) {
  20. double result = Gosu.distance(num2dbl(args[0]), num2dbl(args[1]), num2dbl(args[2]), num2dbl(args[3]));
  21. return module.getRuntime().newFloat(result);
  22. }
  23. @JRubyMethod(name = "angle",
  24. required = 4,
  25. module = true)
  26. public static IRubyObject angle(IRubyObject module, IRubyObject[] args) {
  27. double result = Gosu.angle(num2dbl(args[0]), num2dbl(args[1]), num2dbl(args[2]), num2dbl(args[3]));
  28. return module.getRuntime().newFloat(result);
  29. }
  30. @JRubyMethod(name = "angle_diff",
  31. required = 2,
  32. module = true)
  33. public static IRubyObject angleDiff(IRubyObject module, IRubyObject from, IRubyObject to) {
  34. double result = Gosu.angleDiff(num2dbl(from), num2dbl(to));
  35. return module.getRuntime().newFloat(result);
  36. }
  37. @JRubyMethod(name = "offset_x",
  38. required = 2,
  39. module = true)
  40. public static IRubyObject offsetX(IRubyObject module, IRubyObject angle, IRubyObject radius) {
  41. double result = Gosu.offsetX(num2dbl(angle), num2dbl(radius));
  42. return module.getRuntime().newFloat(result);
  43. }
  44. @JRubyMethod(name = "offset_y",
  45. required = 2,
  46. module = true)
  47. public static IRubyObject offsetY(IRubyObject module, IRubyObject angle, IRubyObject radius) {
  48. double result = Gosu.offsetY(num2dbl(angle), num2dbl(radius));
  49. return module.getRuntime().newFloat(result);
  50. }
  51. @JRubyMethod(name = "default_font_name",
  52. module = true)
  53. public static IRubyObject defaultFontName(IRubyObject module) {
  54. return module.getRuntime().newString(Gosu.defaultFontName());
  55. }
  56. @JRubyMethod(name = "random",
  57. required = 2,
  58. module = true)
  59. public static IRubyObject random(IRubyObject module, IRubyObject min, IRubyObject max) {
  60. return module.getRuntime().newFloat(Gosu.random(num2dbl(min), num2dbl(max)));
  61. }
  62. }