Skip to content

Instantly share code, notes, and snippets.

@banister
Created January 8, 2009 05:52
Show Gist options
  • Save banister/44601 to your computer and use it in GitHub Desktop.
Save banister/44601 to your computer and use it in GitHub Desktop.
inline do |builder|
builder.prefix %{
VALUE
intersect(VALUE s, VALUE o) {
float x, y, y_offset, x_offset, ox, oy, ox_offset, oy_offset;
x = rb_iv_get(s, "@x");
y = rb_iv_get(s, "@y");
x_offset = rb_iv_get(s, "@x_offset");
y_offset = rb_iv_get(s, "@y_offset");
ox = rb_iv_get(o, "@x");
oy = rb_iv_get(o, "@y");
ox_offset = rb_iv_get(o, "@x_offset");
oy_offset = rb_iv_get(o, "@y_offset");
if(y - y_offset < oy + oy_offset && y + y_offset > oy - oy_offset &&
x - x_offset < ox + ox_offset && x + x_offset > ox - ox_offset)
return Qtrue;
else
return Qfalse;
}
}
builder.c %{
VALUE
check_actor_collision() {
VALUE world, thing;
world = rb_iv_get(self, "@world");
int i;
for(i = 0; i < RARRAY(world)->len; i++) {
thing = rb_ary_entry(world, i);
if(thing == self) continue;
if(intersect(self, thing)) {
rb_funcall(self, rb_intern("do_collision"), thing);
rb_funcall(thing, rb_intern("do_collision"), self);
}
}
return Qnil;
}
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment