PageRenderTime 22ms CodeModel.GetById 15ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/gosu/jruby/GosuProxy.java

http://jgosu.googlecode.com/
Java | 81 lines | 62 code | 19 blank | 0 comment | 0 complexity | cf0d5bbd62d00f5c879e7d2bb6aa9cc7 MD5 | raw file
 1import gosu.Gosu;
 2
 3import org.jruby.*;
 4import org.jruby.runtime.builtin.IRubyObject;
 5import org.jruby.anno.JRubyMethod;
 6import static org.jruby.RubyNumeric.*;
 7
 8
 9public abstract class GosuProxy {
10  public static void createGosuMethods(Ruby runtime) {
11    RubyModule mGosu = runtime.getModule("Gosu");
12
13    mGosu.defineAnnotatedMethods(GosuProxy.class);
14  }
15
16  @JRubyMethod(name = "milliseconds",
17               module = true)
18  public static IRubyObject milliseconds(IRubyObject module) {
19    return module.getRuntime().newFixnum(Gosu.milliseconds());
20  }
21
22
23  @JRubyMethod(name = "distance",
24               required = 4,
25               module = true)
26  public static IRubyObject distance(IRubyObject module, IRubyObject[] args) {
27    double result = Gosu.distance(num2dbl(args[0]), num2dbl(args[1]), num2dbl(args[2]), num2dbl(args[3]));
28    return module.getRuntime().newFloat(result);
29  }
30
31
32  @JRubyMethod(name = "angle",
33               required = 4,
34               module = true)
35  public static IRubyObject angle(IRubyObject module, IRubyObject[] args) {
36    double result = Gosu.angle(num2dbl(args[0]), num2dbl(args[1]), num2dbl(args[2]), num2dbl(args[3]));
37    return module.getRuntime().newFloat(result);
38  }
39
40
41  @JRubyMethod(name = "angle_diff",
42               required = 2,
43               module = true)
44  public static IRubyObject angleDiff(IRubyObject module, IRubyObject from, IRubyObject to) {
45    double result = Gosu.angleDiff(num2dbl(from), num2dbl(to));
46    return module.getRuntime().newFloat(result);
47  }
48
49
50  @JRubyMethod(name = "offset_x",
51               required = 2,
52               module = true)
53  public static IRubyObject offsetX(IRubyObject module, IRubyObject angle, IRubyObject radius) {
54    double result = Gosu.offsetX(num2dbl(angle), num2dbl(radius));
55    return module.getRuntime().newFloat(result);
56  }
57
58
59  @JRubyMethod(name = "offset_y",
60               required = 2,
61               module = true)
62  public static IRubyObject offsetY(IRubyObject module, IRubyObject angle, IRubyObject radius) {
63    double result = Gosu.offsetY(num2dbl(angle), num2dbl(radius));
64    return module.getRuntime().newFloat(result);
65  }
66
67
68  @JRubyMethod(name = "default_font_name",
69               module = true)
70  public static IRubyObject defaultFontName(IRubyObject module) {
71    return module.getRuntime().newString(Gosu.defaultFontName());
72  }
73
74
75  @JRubyMethod(name = "random",
76               required = 2,
77               module = true)
78  public static IRubyObject random(IRubyObject module, IRubyObject min, IRubyObject max) {
79    return module.getRuntime().newFloat(Gosu.random(num2dbl(min), num2dbl(max)));
80  }
81}